From b1c694d68943cd7e27acaebf84cf7e6ce453d19c Mon Sep 17 00:00:00 2001 From: navba-MSFT <57353862+navba-MSFT@users.noreply.github.com> Date: Thu, 19 Jan 2023 14:50:25 +0530 Subject: [PATCH 1/6] {AzureContainerApp} fixes Azure/azure-cli-extensions#5781 fix for 'NoneType' object does not support item assignment fix for TypeError: 'NoneType' object does not support item assignment while running the `az containerapp dapr enable` command --- src/containerapp/azext_containerapp/custom.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/containerapp/azext_containerapp/custom.py b/src/containerapp/azext_containerapp/custom.py index 139c22c797d..9cb3f463e84 100644 --- a/src/containerapp/azext_containerapp/custom.py +++ b/src/containerapp/azext_containerapp/custom.py @@ -2366,10 +2366,13 @@ def enable_dapr(cmd, name, resource_group_name, if 'configuration' not in containerapp_def['properties']: containerapp_def['properties']['configuration'] = {} - if 'dapr' not in containerapp_def['properties']['configuration']: - containerapp_def['properties']['configuration']['dapr'] = {} + if not safe_get(containerapp_def, "properties", "configuration", "dapr"): + if "dapr" not in containerapp_def['properties']['configuration']: + containerapp_def['properties']['configuration']['dapr'] = {} - if dapr_app_id: + if not safe_get(containerapp_def, "properties", "configuration", "dapr", "appId"): + if dapr_app_id not in containerapp_def['properties']['configuration']['dapr']: + containerapp_def['properties']['configuration']['dapr']['appId'] = {} containerapp_def['properties']['configuration']['dapr']['appId'] = dapr_app_id if dapr_app_port: From a9261bf80c10fd5dcf9e23fb85b9a7665181fb08 Mon Sep 17 00:00:00 2001 From: navba-MSFT <57353862+navba-MSFT@users.noreply.github.com> Date: Tue, 24 Jan 2023 15:34:41 +0530 Subject: [PATCH 2/6] Update custom.py --- src/containerapp/azext_containerapp/custom.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containerapp/azext_containerapp/custom.py b/src/containerapp/azext_containerapp/custom.py index 9cb3f463e84..1a1222c9b21 100644 --- a/src/containerapp/azext_containerapp/custom.py +++ b/src/containerapp/azext_containerapp/custom.py @@ -2368,10 +2368,10 @@ def enable_dapr(cmd, name, resource_group_name, if not safe_get(containerapp_def, "properties", "configuration", "dapr"): if "dapr" not in containerapp_def['properties']['configuration']: - containerapp_def['properties']['configuration']['dapr'] = {} + safe_get(containerapp_def, "properties", "configuration", "dapr", default=[]) if not safe_get(containerapp_def, "properties", "configuration", "dapr", "appId"): - if dapr_app_id not in containerapp_def['properties']['configuration']['dapr']: + if dapr_app_id not in safe_get(containerapp_def['properties']['configuration']['dapr'], default=[]): containerapp_def['properties']['configuration']['dapr']['appId'] = {} containerapp_def['properties']['configuration']['dapr']['appId'] = dapr_app_id From 8c14e24fffe70406b4f7ede38d3abbbb0e2d53ea Mon Sep 17 00:00:00 2001 From: navba-MSFT <57353862+navba-MSFT@users.noreply.github.com> Date: Wed, 1 Feb 2023 13:22:03 +0530 Subject: [PATCH 3/6] Update test_containerapp_commands.py --- .../tests/latest/test_containerapp_commands.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 142e9ac2681..9b28a3d3b19 100644 --- a/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py +++ b/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py @@ -615,7 +615,12 @@ def test_containerapp_dapr_e2e(self, resource_group): JMESPathCheck('logLevel', "warn"), JMESPathCheck('enableApiLogging', True), ]) - + + self.cmd('containerapp dapr enable -g {} -n {} --dapr-app-id containerapp1 --dapr-app-port 80 --dapr-app-protocol http --dal --dhmrs 6 --dhrbs 60 --dapr-log-level warn'.format(resource_group, ca_name, env_name), checks=[ + JMESPathCheck('appId', "containerapp1"), + JMESPathCheck('enabled', True) + ]) + self.cmd('containerapp show -g {} -n {}'.format(resource_group, ca_name), checks=[ JMESPathCheck('properties.configuration.dapr.appId', "containerapp1"), JMESPathCheck('properties.configuration.dapr.appPort', 80), From ba1895e0ca6dcb40077efd16399ef5600b99f43e Mon Sep 17 00:00:00 2001 From: navba-MSFT <57353862+navba-MSFT@users.noreply.github.com> Date: Wed, 1 Feb 2023 13:24:56 +0530 Subject: [PATCH 4/6] Update HISTORY.rst --- src/containerapp/HISTORY.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/containerapp/HISTORY.rst b/src/containerapp/HISTORY.rst index 0ce871a675d..cdb096c8d97 100644 --- a/src/containerapp/HISTORY.rst +++ b/src/containerapp/HISTORY.rst @@ -2,6 +2,10 @@ Release History =============== +Upcoming +++++++ +* Fix for 'az containerapp dapr enable' cli command resulting in 'TypeError: 'NoneType' object does not support item assignment' exception. + 0.3.21 ++++++ * Fix the PermissionError caused for the Temporary files while running `az containerapp up` command on Windows From 344207ea671fda5ec9bb9e48732537d41be46b73 Mon Sep 17 00:00:00 2001 From: navba-MSFT <57353862+navba-MSFT@users.noreply.github.com> Date: Wed, 1 Feb 2023 14:14:21 +0530 Subject: [PATCH 5/6] Update test_containerapp_commands.py --- .../tests/latest/test_containerapp_commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 9b28a3d3b19..71971949ae8 100644 --- a/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py +++ b/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py @@ -617,8 +617,8 @@ def test_containerapp_dapr_e2e(self, resource_group): ]) self.cmd('containerapp dapr enable -g {} -n {} --dapr-app-id containerapp1 --dapr-app-port 80 --dapr-app-protocol http --dal --dhmrs 6 --dhrbs 60 --dapr-log-level warn'.format(resource_group, ca_name, env_name), checks=[ - JMESPathCheck('appId', "containerapp1"), - JMESPathCheck('enabled', True) + JMESPathCheck('properties.configuration.dapr.appId', "containerapp1"), + JMESPathCheck('properties.configuration.dapr.enabled', True) ]) self.cmd('containerapp show -g {} -n {}'.format(resource_group, ca_name), checks=[ From 5765b3fecec4f7cbd51506c598d94b1027530ab3 Mon Sep 17 00:00:00 2001 From: navba-MSFT <57353862+navba-MSFT@users.noreply.github.com> Date: Wed, 1 Feb 2023 14:34:05 +0530 Subject: [PATCH 6/6] Update test_containerapp_commands.py --- .../latest/test_containerapp_commands.py | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) 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 71971949ae8..55dff498a68 100644 --- a/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py +++ b/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py @@ -615,12 +615,7 @@ def test_containerapp_dapr_e2e(self, resource_group): JMESPathCheck('logLevel', "warn"), JMESPathCheck('enableApiLogging', True), ]) - - self.cmd('containerapp dapr enable -g {} -n {} --dapr-app-id containerapp1 --dapr-app-port 80 --dapr-app-protocol http --dal --dhmrs 6 --dhrbs 60 --dapr-log-level warn'.format(resource_group, ca_name, env_name), checks=[ - JMESPathCheck('properties.configuration.dapr.appId', "containerapp1"), - JMESPathCheck('properties.configuration.dapr.enabled', True) - ]) - + self.cmd('containerapp show -g {} -n {}'.format(resource_group, ca_name), checks=[ JMESPathCheck('properties.configuration.dapr.appId', "containerapp1"), JMESPathCheck('properties.configuration.dapr.appPort', 80), @@ -654,6 +649,34 @@ def test_containerapp_dapr_e2e(self, resource_group): JMESPathCheck('properties.configuration.dapr.enableApiLogging', True), ]) + @AllowLargeResponse(8192) + @ResourceGroupPreparer(location="eastus2") + def test_containerapp_up_dapr_e2e(self, resource_group): + """ Ensure that dapr can be enabled if the app has been created using containerapp up """ + location = os.getenv("CLITestLocation") + if not location: + location = 'eastus' + + self.cmd('configure --defaults location={}'.format(location)) + + image = 'mcr.microsoft.com/azuredocs/aks-helloworld:v1' + env_name = self.create_random_name(prefix='containerapp-env', length=24) + ca_name = self.create_random_name(prefix='containerapp', length=24) + + create_containerapp_env(self, env_name, resource_group) + + self.cmd( + 'containerapp up -g {} -n {} --environment {} --image {}'.format( + resource_group, ca_name, env_name, image)) + + self.cmd( + 'containerapp dapr enable -g {} -n {} --dapr-app-id containerapp1 --dapr-app-port 80 ' + '--dapr-app-protocol http --dal --dhmrs 6 --dhrbs 60 --dapr-log-level warn'.format( + resource_group, ca_name, env_name), checks=[ + JMESPathCheck('appId', "containerapp1"), + JMESPathCheck('enabled', True) + ]) + class ContainerappEnvStorageTests(ScenarioTest): @AllowLargeResponse(8192)