From c7001612f1c15a4084fe4c7e7e8d57bb8fc0c732 Mon Sep 17 00:00:00 2001 From: Haroon Feisal Date: Mon, 6 Jun 2022 14:44:57 -0400 Subject: [PATCH 1/2] Changed --labels to --source-label, target-label. --- src/containerapp/azext_containerapp/_help.py | 4 +- .../azext_containerapp/_params.py | 3 +- src/containerapp/azext_containerapp/custom.py | 39 +++++++++---------- .../latest/test_containerapp_commands.py | 2 +- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/containerapp/azext_containerapp/_help.py b/src/containerapp/azext_containerapp/_help.py index 3bc64a6f88b..60ac9dd1d58 100644 --- a/src/containerapp/azext_containerapp/_help.py +++ b/src/containerapp/azext_containerapp/_help.py @@ -293,9 +293,9 @@ type: command short-summary: Swap a revision label between two revisions with associated traffic weights. examples: - - name: Swap a revision label between two revisions.. + - name: Swap a revision label between two revisions. text: | - az containerapp revision label swap -n MyContainerapp -g MyResourceGroup --labels myLabel1 myLabel2 + az containerapp revision label swap -n MyContainerapp -g MyResourceGroup --source-label myLabel1 --target-label myLabel2 """ # Environment Commands diff --git a/src/containerapp/azext_containerapp/_params.py b/src/containerapp/azext_containerapp/_params.py index 46fd18ab7fc..410b1a5e5a2 100644 --- a/src/containerapp/azext_containerapp/_params.py +++ b/src/containerapp/azext_containerapp/_params.py @@ -214,7 +214,8 @@ def load_arguments(self, _): c.argument('yes', options_list=['--yes', '-y'], help='Do not prompt for confirmation.') with self.argument_context('containerapp revision label') as c: - c.argument('labels', nargs='*', help='Labels to be swapped.') + c.argument('source_label', help='Source label to be swapped.') + c.argument('target_label', help='Target label to be swapped to.') with self.argument_context('containerapp ingress') as c: c.argument('allow_insecure', help='Allow insecure connections for ingress traffic.') diff --git a/src/containerapp/azext_containerapp/custom.py b/src/containerapp/azext_containerapp/custom.py index 7d9d78fcfe0..b857a106e2a 100644 --- a/src/containerapp/azext_containerapp/custom.py +++ b/src/containerapp/azext_containerapp/custom.py @@ -1445,13 +1445,10 @@ def add_revision_label(cmd, resource_group_name, revision, label, name=None, no_ handle_raw_exception(e) -def swap_revision_label(cmd, name, resource_group_name, labels, no_wait=False): +def swap_revision_label(cmd, name, resource_group_name, source_label, target_label, no_wait=False): _validate_subscription_registered(cmd, CONTAINER_APPS_RP) - if not labels or len(labels) != 2: - raise ArgumentUsageError("Usage error: --labels requires two labels to be swapped.") - - if labels[0] == labels[1]: + if source_label == target_label: raise ArgumentUsageError("Label names to be swapped must be different.") containerapp_def = None @@ -1468,24 +1465,24 @@ def swap_revision_label(cmd, name, resource_group_name, labels, no_wait=False): traffic_weight = containerapp_def['properties']['configuration']['ingress']['traffic'] if 'traffic' in containerapp_def['properties']['configuration']['ingress'] else {} - label1_found = False - label2_found = False + source_label_found = False + target_label_found = False for weight in traffic_weight: if "label" in weight: - if weight["label"].lower() == labels[0].lower(): - if not label1_found: - label1_found = True - weight["label"] = labels[1] - elif weight["label"].lower() == labels[1].lower(): - if not label2_found: - label2_found = True - weight["label"] = labels[0] - if not label1_found and not label2_found: - raise ArgumentUsageError(f"Could not find label '{labels[0]}' nor label '{labels[1]}' in traffic.") - if not label1_found: - raise ArgumentUsageError(f"Could not find label '{labels[0]}' in traffic.") - if not label2_found: - raise ArgumentUsageError(f"Could not find label '{labels[1]}' in traffic.") + if weight["label"].lower() == source_label.lower(): + if not source_label_found: + source_label_found = True + weight["label"] = target_label + elif weight["label"].lower() == target_label.lower(): + if not target_label_found: + target_label_found = True + weight["label"] = source_label + if not source_label_found and not target_label_found: + raise ArgumentUsageError(f"Could not find label '{source_label}' nor label '{target_label}' in traffic.") + if not source_label_found: + raise ArgumentUsageError(f"Could not find label '{source_label}' in traffic.") + if not target_label_found: + raise ArgumentUsageError(f"Could not find label '{target_label}' in traffic.") containerapp_patch_def = {} containerapp_patch_def['properties'] = {} diff --git a/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py b/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py index 9fde7792b3e..bd78e7e1211 100644 --- a/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py +++ b/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py @@ -541,7 +541,7 @@ def test_containerapp_revision_label_e2e(self, resource_group): else: self.assertEqual(traffic["weight"], 50) - traffic_weight = self.cmd(f"containerapp revision label swap -g {resource_group} -n {ca_name} --labels {labels[0]} {labels[1]}").get_output_in_json() + traffic_weight = self.cmd(f"containerapp revision label swap -g {resource_group} -n {ca_name} --source-label {labels[0]} --target-label {labels[1]}").get_output_in_json() for revision in revision_names: traffic = [w for w in traffic_weight if "revisionName" in w and w["revisionName"] == revision][0] From e96650dc3f8430c3e86937e68f2bbcfe6ca8e643 Mon Sep 17 00:00:00 2001 From: Haroon Feisal Date: Mon, 6 Jun 2022 16:52:57 -0400 Subject: [PATCH 2/2] Dropped -label from params in label swap. --- src/containerapp/azext_containerapp/_help.py | 2 +- src/containerapp/azext_containerapp/_params.py | 4 ++-- .../tests/latest/test_containerapp_commands.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/containerapp/azext_containerapp/_help.py b/src/containerapp/azext_containerapp/_help.py index 60ac9dd1d58..881b63372e1 100644 --- a/src/containerapp/azext_containerapp/_help.py +++ b/src/containerapp/azext_containerapp/_help.py @@ -295,7 +295,7 @@ examples: - name: Swap a revision label between two revisions. text: | - az containerapp revision label swap -n MyContainerapp -g MyResourceGroup --source-label myLabel1 --target-label myLabel2 + az containerapp revision label swap -n MyContainerapp -g MyResourceGroup --source myLabel1 --target myLabel2 """ # Environment Commands diff --git a/src/containerapp/azext_containerapp/_params.py b/src/containerapp/azext_containerapp/_params.py index 410b1a5e5a2..2d972547917 100644 --- a/src/containerapp/azext_containerapp/_params.py +++ b/src/containerapp/azext_containerapp/_params.py @@ -214,8 +214,8 @@ def load_arguments(self, _): c.argument('yes', options_list=['--yes', '-y'], help='Do not prompt for confirmation.') with self.argument_context('containerapp revision label') as c: - c.argument('source_label', help='Source label to be swapped.') - c.argument('target_label', help='Target label to be swapped to.') + c.argument('source_label', options_list=['--source'], help='Source label to be swapped.') + c.argument('target_label', options_list=['--target'], help='Target label to be swapped to.') with self.argument_context('containerapp ingress') as c: c.argument('allow_insecure', help='Allow insecure connections for ingress traffic.') diff --git a/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py b/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py index bd78e7e1211..6ec2764696a 100644 --- a/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py +++ b/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py @@ -541,7 +541,7 @@ def test_containerapp_revision_label_e2e(self, resource_group): else: self.assertEqual(traffic["weight"], 50) - traffic_weight = self.cmd(f"containerapp revision label swap -g {resource_group} -n {ca_name} --source-label {labels[0]} --target-label {labels[1]}").get_output_in_json() + traffic_weight = self.cmd(f"containerapp revision label swap -g {resource_group} -n {ca_name} --source {labels[0]} --target {labels[1]}").get_output_in_json() for revision in revision_names: traffic = [w for w in traffic_weight if "revisionName" in w and w["revisionName"] == revision][0]