Skip to content

Commit ba0ba29

Browse files
authored
[App Service] az functionapp plan update: Add zone redundant update support for Flex (#31415)
1 parent b3ee5b1 commit ba0ba29

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

src/azure-cli/azure/cli/command_modules/appservice/custom.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,6 +3231,9 @@ def update_functionapp_app_service_plan(cmd, instance, sku=None, number_of_worke
32313231
if number_of_workers is not None:
32323232
number_of_workers = validate_range_of_int_flag('--number-of-workers / --min-instances',
32333233
number_of_workers, min_val=0, max_val=20)
3234+
if is_plan_flex(cmd, instance):
3235+
return update_flex_app_service_plan(instance)
3236+
32343237
return update_app_service_plan(cmd, instance, sku, number_of_workers)
32353238

32363239

@@ -5022,6 +5025,20 @@ def create_flex_app_service_plan(cmd, resource_group_name, name, location, zone_
50225025
return LongRunningOperation(cmd.cli_ctx)(poller)
50235026

50245027

5028+
def update_flex_app_service_plan(instance):
5029+
instance.target_worker_count = None
5030+
instance.target_worker_size = None
5031+
instance.is_xenon = None
5032+
instance.hyper_v = None
5033+
instance.per_site_scaling = None
5034+
instance.maximum_elastic_worker_count = None
5035+
instance.elastic_scale_enabled = None
5036+
instance.is_spot = None
5037+
instance.target_worker_size_id = None
5038+
instance.sku.capacity = None
5039+
return instance
5040+
5041+
50255042
def create_functionapp_app_service_plan(cmd, resource_group_name, name, is_linux, sku, number_of_workers=None,
50265043
max_burst=None, location=None, tags=None, zone_redundant=False):
50275044
SkuDescription, AppServicePlan = cmd.get_models('SkuDescription', 'AppServicePlan')
@@ -5052,6 +5069,14 @@ def is_plan_consumption(cmd, plan_info):
50525069
return False
50535070

50545071

5072+
def is_plan_flex(cmd, plan_info):
5073+
SkuDescription, AppServicePlan = cmd.get_models('SkuDescription', 'AppServicePlan')
5074+
if isinstance(plan_info, AppServicePlan):
5075+
if isinstance(plan_info.sku, SkuDescription):
5076+
return plan_info.sku.tier.lower() == 'flexconsumption'
5077+
return False
5078+
5079+
50555080
def is_plan_elastic_premium(cmd, plan_info):
50565081
SkuDescription, AppServicePlan = cmd.get_models('SkuDescription', 'AppServicePlan')
50575082
if isinstance(plan_info, AppServicePlan):

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_functionapp_commands.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,10 +853,44 @@ def test_functionapp_flex_zone_redundant_not_active(self, resource_group, storag
853853
.format(resource_group, functionapp_name, FLEX_ASP_LOCATION_FUNCTIONAPP, storage_account)).get_output_in_json()
854854

855855
server_farm_id =functionapp['properties']['serverFarmId']
856-
function_plan = self.cmd('az functionapp plan show --ids {}'
856+
function_plan = self.cmd('functionapp plan show --ids {}'
857857
.format(server_farm_id)).get_output_in_json()
858858
self.assertTrue(function_plan['zoneRedundant'] == False)
859859

860+
@ResourceGroupPreparer(location=FLEX_ASP_LOCATION_FUNCTIONAPP)
861+
@StorageAccountPreparer()
862+
def test_functionapp_flex_plan_enable_zone_redundant(self, resource_group, storage_account):
863+
functionapp_name = self.create_random_name(
864+
'functionapp', 40)
865+
866+
functionapp = self.cmd('functionapp create -g {} -n {} -f {} -s {} --runtime python --runtime-version 3.11'
867+
.format(resource_group, functionapp_name, FLEX_ASP_LOCATION_FUNCTIONAPP, storage_account)).get_output_in_json()
868+
869+
server_farm_id = functionapp['properties']['serverFarmId']
870+
function_plan = self.cmd('functionapp plan show --ids {}'.format(server_farm_id)).get_output_in_json()
871+
self.assertTrue(function_plan['zoneRedundant'] == False)
872+
updated_plan = self.cmd('functionapp plan update --id {} --set zoneRedundant=true'.format(server_farm_id)).get_output_in_json()
873+
self.assertTrue(updated_plan['zoneRedundant'] == True)
874+
function_plan = self.cmd('functionapp plan show --ids {}'.format(server_farm_id)).get_output_in_json()
875+
self.assertTrue(function_plan['zoneRedundant'] == True)
876+
877+
@ResourceGroupPreparer(location=FLEX_ASP_LOCATION_FUNCTIONAPP)
878+
@StorageAccountPreparer()
879+
def test_functionapp_flex_plan_disable_zone_redundant(self, resource_group, storage_account):
880+
functionapp_name = self.create_random_name(
881+
'functionapp', 40)
882+
883+
functionapp = self.cmd('functionapp create -g {} -n {} -f {} -s {} --runtime python --runtime-version 3.11 --zone-redundant'
884+
.format(resource_group, functionapp_name, FLEX_ASP_LOCATION_FUNCTIONAPP, storage_account)).get_output_in_json()
885+
886+
server_farm_id = functionapp['properties']['serverFarmId']
887+
function_plan = self.cmd('functionapp plan show --ids {}'.format(server_farm_id)).get_output_in_json()
888+
self.assertTrue(function_plan['zoneRedundant'] == True)
889+
updated_plan = self.cmd('functionapp plan update --id {} --set zoneRedundant=false'.format(server_farm_id)).get_output_in_json()
890+
self.assertTrue(updated_plan['zoneRedundant'] == False)
891+
function_plan = self.cmd('functionapp plan show --ids {}'.format(server_farm_id)).get_output_in_json()
892+
self.assertTrue(function_plan['zoneRedundant'] == False)
893+
860894
@ResourceGroupPreparer(location=FLEX_ASP_LOCATION_FUNCTIONAPP)
861895
@StorageAccountPreparer()
862896
def test_functionapp_flex_scale_config(self, resource_group, storage_account):

0 commit comments

Comments
 (0)