From 735236811d442389600ad61a0fb609c51acfb5f1 Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Wed, 15 Mar 2023 17:10:02 -0400 Subject: [PATCH 1/8] Add an offer to the existing test --- tests/integration/bundle/test-overlays/test-overlay4.yaml | 7 +++++++ tests/integration/test_model.py | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/integration/bundle/test-overlays/test-overlay4.yaml diff --git a/tests/integration/bundle/test-overlays/test-overlay4.yaml b/tests/integration/bundle/test-overlays/test-overlay4.yaml new file mode 100644 index 000000000..619bab2d3 --- /dev/null +++ b/tests/integration/bundle/test-overlays/test-overlay4.yaml @@ -0,0 +1,7 @@ +description: Another overlay to create an offer +applications: + grafana: + offers: + dashboards: + endpoints: + - dashboards diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index 7658f8645..385ecc047 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -265,8 +265,9 @@ async def test_deploy_bundle_with_multiple_overlays_with_include_files(event_loo bundle_yaml_path = TESTS_DIR / 'integration' / 'bundle' / 'bundle.yaml' overlay1_path = OVERLAYS_DIR / 'test-overlay2.yaml' overlay2_path = OVERLAYS_DIR / 'test-overlay3.yaml' + overlay3_path = OVERLAYS_DIR / 'test-overlay4.yaml' - await model.deploy(str(bundle_yaml_path), overlays=[overlay1_path, overlay2_path]) + await model.deploy(str(bundle_yaml_path), overlays=[overlay1_path, overlay2_path, overlay3_path]) assert 'influxdb' not in model.applications assert 'test' not in model.applications From 7a1111bd16fa9483cba31f35a287843808e17d92 Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Thu, 16 Mar 2023 00:17:02 -0400 Subject: [PATCH 2/8] Attempt a fix --- juju/bundle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/juju/bundle.py b/juju/bundle.py index f5c303666..c70f9a868 100644 --- a/juju/bundle.py +++ b/juju/bundle.py @@ -1022,7 +1022,7 @@ async def run(self, context): def __str__(self): endpoints = "" if self.endpoints is not None: - endpoints = ":{}".format(self.endpoints.join(",")) + endpoints = ":{}".format(",".join(self.endpoints)) return "create offer {offer_name} using {application}{endpoints}".format(offer_name=self.offer_name, application=self.application, endpoints=endpoints) From 609eeb4267bf65087d458316f490838604c8905a Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Thu, 11 May 2023 23:26:26 -0400 Subject: [PATCH 3/8] Revert "Add an offer to the existing test" This reverts commit 735236811d442389600ad61a0fb609c51acfb5f1. --- tests/integration/bundle/test-overlays/test-overlay4.yaml | 7 ------- tests/integration/test_model.py | 3 +-- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 tests/integration/bundle/test-overlays/test-overlay4.yaml diff --git a/tests/integration/bundle/test-overlays/test-overlay4.yaml b/tests/integration/bundle/test-overlays/test-overlay4.yaml deleted file mode 100644 index 619bab2d3..000000000 --- a/tests/integration/bundle/test-overlays/test-overlay4.yaml +++ /dev/null @@ -1,7 +0,0 @@ -description: Another overlay to create an offer -applications: - grafana: - offers: - dashboards: - endpoints: - - dashboards diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index 34a53bb01..65f83747e 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -304,9 +304,8 @@ async def test_deploy_bundle_with_multiple_overlays_with_include_files(event_loo bundle_yaml_path = TESTS_DIR / 'integration' / 'bundle' / 'bundle.yaml' overlay1_path = OVERLAYS_DIR / 'test-overlay2.yaml' overlay2_path = OVERLAYS_DIR / 'test-overlay3.yaml' - overlay3_path = OVERLAYS_DIR / 'test-overlay4.yaml' - await model.deploy(str(bundle_yaml_path), overlays=[overlay1_path, overlay2_path, overlay3_path]) + await model.deploy(str(bundle_yaml_path), overlays=[overlay1_path, overlay2_path]) assert 'influxdb' not in model.applications assert 'test' not in model.applications From dea7412d84b934113abc0b8627a4092d9b8b316f Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Wed, 15 Mar 2023 17:10:02 -0400 Subject: [PATCH 4/8] Add an offer to the existing test --- tests/integration/bundle/test-overlays/test-overlay4.yaml | 7 +++++++ tests/integration/test_model.py | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/integration/bundle/test-overlays/test-overlay4.yaml diff --git a/tests/integration/bundle/test-overlays/test-overlay4.yaml b/tests/integration/bundle/test-overlays/test-overlay4.yaml new file mode 100644 index 000000000..619bab2d3 --- /dev/null +++ b/tests/integration/bundle/test-overlays/test-overlay4.yaml @@ -0,0 +1,7 @@ +description: Another overlay to create an offer +applications: + grafana: + offers: + dashboards: + endpoints: + - dashboards diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index 3a9dcd658..f83c7aacd 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -321,8 +321,9 @@ async def test_deploy_bundle_with_multiple_overlays_with_include_files(event_loo bundle_yaml_path = TESTS_DIR / 'integration' / 'bundle' / 'bundle.yaml' overlay1_path = OVERLAYS_DIR / 'test-overlay2.yaml' overlay2_path = OVERLAYS_DIR / 'test-overlay3.yaml' + overlay3_path = OVERLAYS_DIR / 'test-overlay4.yaml' - await model.deploy(str(bundle_yaml_path), overlays=[overlay1_path, overlay2_path]) + await model.deploy(str(bundle_yaml_path), overlays=[overlay1_path, overlay2_path, overlay3_path]) assert 'influxdb' not in model.applications assert 'test' not in model.applications From b89b1e2991f3fceaea648bbcbe9459de2d051756 Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Thu, 22 Jun 2023 15:35:34 -0600 Subject: [PATCH 5/8] Add useful fields to ApplicationOffer --- juju/remoteapplication.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/juju/remoteapplication.py b/juju/remoteapplication.py index 0f0bc74e2..960a08fd3 100644 --- a/juju/remoteapplication.py +++ b/juju/remoteapplication.py @@ -44,3 +44,11 @@ class ApplicationOffer(model.ModelEntity): @property def tag(self): return tag.application(self.name) + + @property + def offer_name(self): + return self.safe_data['offer-name'] + + @property + def application_name(self): + return self.safe_data['application-name'] From d7e369444c3241309cbff99d864a648d780161c4 Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Thu, 22 Jun 2023 15:36:13 -0600 Subject: [PATCH 6/8] Avoid parsing endpoint unless needed --- juju/controller.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/juju/controller.py b/juju/controller.py index 932cb8e22..b4ac9611f 100644 --- a/juju/controller.py +++ b/juju/controller.py @@ -728,24 +728,32 @@ async def create_offer(self, model_uuid, endpoint, offer_name=None, application_ consumers. @param endpoint: holds the application and endpoint you want to offer - @param offer_name: over ride the offer name to help the consumer + @param offer_name: override the offer name to help the consumer + @param application_name: overrides the application name in the endpoint """ - try: - offer = parse_offer_endpoint(endpoint) - except OfferParseError as e: - log.error(e.message) - raise - if offer_name is None: - offer_name = offer.application + # If we have both the offer_name and the application_name + # then we're coming from bundle/overlays, so no need to parse the endpoint + # Also we accept endpoints without a colon (:) in the overlays + if offer_name and application_name: + o_name = offer_name + a_name = application_name + eps = {endpoint : endpoint} + else: + try: + offer = parse_offer_endpoint(endpoint) + except OfferParseError as e: + log.error(e.message) + raise - if application_name is None: - application_name = offer.application + o_name = offer_name if offer_name else offer.application + a_name = application_name if application_name else offer.application + eps = {name: name for name in offer.endpoints} params = client.AddApplicationOffer() - params.application_name = application_name - params.endpoints = {name: name for name in offer.endpoints} - params.offer_name = offer_name + params.application_name = a_name + params.endpoints = eps + params.offer_name = o_name params.model_tag = tag.model(model_uuid) facade = client.ApplicationOffersFacade.from_connection(self.connection()) From 2480258c1742be9b5047d4e5f23056779b6d6bc4 Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Thu, 22 Jun 2023 15:36:40 -0600 Subject: [PATCH 7/8] Update test to check the offer added in an overlay --- tests/integration/test_model.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index f83c7aacd..4cbb6fc5a 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -329,6 +329,10 @@ async def test_deploy_bundle_with_multiple_overlays_with_include_files(event_loo assert 'test' not in model.applications assert 'memcached' not in model.applications assert 'grafana' in model.applications + assert 'grafana' in model.application_offers + assert 'grafana' == model.application_offers['grafana'].application_name + assert 'dashboards' == model.application_offers['grafana'].offer_name + @base.bootstrapped From d8f3fde828847f17967aa3125a65ffdfb248f6f2 Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Thu, 22 Jun 2023 15:47:16 -0600 Subject: [PATCH 8/8] Fix linter --- juju/controller.py | 2 +- tests/integration/test_model.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/juju/controller.py b/juju/controller.py index b4ac9611f..fd1cf4234 100644 --- a/juju/controller.py +++ b/juju/controller.py @@ -738,7 +738,7 @@ async def create_offer(self, model_uuid, endpoint, offer_name=None, application_ if offer_name and application_name: o_name = offer_name a_name = application_name - eps = {endpoint : endpoint} + eps = {endpoint: endpoint} else: try: offer = parse_offer_endpoint(endpoint) diff --git a/tests/integration/test_model.py b/tests/integration/test_model.py index 4cbb6fc5a..b97bb1137 100644 --- a/tests/integration/test_model.py +++ b/tests/integration/test_model.py @@ -334,7 +334,6 @@ async def test_deploy_bundle_with_multiple_overlays_with_include_files(event_loo assert 'dashboards' == model.application_offers['grafana'].offer_name - @base.bootstrapped @pytest.mark.asyncio async def test_deploy_local_charm_folder_symlink(event_loop):