X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=n2vc%2Flibjuju.py;h=053aaa82c06238c74bf719215a8eb1b1b87296e6;hb=a8ceea3b6c2c24202649e08e45d4bc60b6446b1d;hp=7492acc87166921f2de553a454da5237f4cb373b;hpb=1cfed49811309ce587c2b034be690bc352065e81;p=osm%2FN2VC.git 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