X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Flibjuju.py;fp=n2vc%2Flibjuju.py;h=053aaa82c06238c74bf719215a8eb1b1b87296e6;hp=7492acc87166921f2de553a454da5237f4cb373b;hb=a07f69539ffcb24fd44371960be23ab9e4a32573;hpb=085942e581b846f59ac6cb94b0e6ff72663d86e2 diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index 7492acc..053aaa8 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -1267,10 +1267,10 @@ class Libjuju: try: await model.add_relation(endpoint_1, endpoint_2) except juju.errors.JujuAPIError as e: - if "not found" in e.message: + if self._relation_is_not_found(e): self.log.warning("Relation not found: {}".format(e.message)) return - if "already exists" in e.message: + if self._relation_already_exist(e): self.log.warning("Relation already exists: {}".format(e.message)) return # another exception, raise it @@ -1279,6 +1279,18 @@ class Libjuju: await self.disconnect_model(model) await self.disconnect_controller(controller) + def _relation_is_not_found(self, juju_error): + text = "not found" + return (text in juju_error.message) or ( + juju_error.error_code and text in juju_error.error_code + ) + + def _relation_already_exist(self, juju_error): + text = "already exists" + return (text in juju_error.message) or ( + juju_error.error_code and text in juju_error.error_code + ) + async def offer(self, endpoint: RelationEndpoint) -> Offer: """ Create an offer from a RelationEndpoint