Skip to content

Commit

Permalink
[App Service] Fix Azure#12090: az webapp create: Allow plan in diff…
Browse files Browse the repository at this point in the history
…erent resource group from web app (Azure#21469)

* Loop through existing plans and match name to allow for plan being on a different resource group.

* Fixed small bug.

* Check resource group for plan before looking outside of rg.

* Removed whitespace to pass style check.

* Added updated test files from running --live.

* Added simple test creating webapp in different group from plan.

* Loop through existing plans and match name to allow for plan being on a different resource group.

* Fixed small bug.

* Check resource group for plan before looking outside of rg.

* Removed whitespace to pass style check.

* Added updated test files from running --live.

* Reran tests.

* Handle errors, reran failing tests live.

Co-authored-by: Haroon Feisal <haroonfeisal@microsoft.com>
  • Loading branch information
runefa and Haroon Feisal authored Mar 25, 2022
1 parent 25ace8b commit ad14ed5
Show file tree
Hide file tree
Showing 67 changed files with 12,418 additions and 6,912 deletions.
19 changes: 16 additions & 3 deletions src/azure-cli/azure/cli/command_modules/appservice/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def create_webapp(cmd, resource_group_name, name, plan, runtime=None, startup_fi
using_webapp_up=False, language=None, assign_identities=None,
role='Contributor', scope=None, vnet=None, subnet=None, https_only=False):
from azure.mgmt.web.models import Site
from azure.core.exceptions import ResourceNotFoundError as _ResourceNotFoundError
SiteConfig, SkuDescription, NameValuePair = cmd.get_models(
'SiteConfig', 'SkuDescription', 'NameValuePair')

Expand All @@ -101,14 +102,26 @@ def create_webapp(cmd, resource_group_name, name, plan, runtime=None, startup_fi
docker_registry_server_url = parse_docker_image_name(deployment_container_image_name)

client = web_client_factory(cmd.cli_ctx)
plan_info = None
if is_valid_resource_id(plan):
parse_result = parse_resource_id(plan)
plan_info = client.app_service_plans.get(parse_result['resource_group'], parse_result['name'])
else:
plan_info = client.app_service_plans.get(name=plan, resource_group_name=resource_group_name)
try:
plan_info = client.app_service_plans.get(name=plan, resource_group_name=resource_group_name)
except _ResourceNotFoundError:
plan_info = None
if not plan_info:
plans = list(client.app_service_plans.list(detailed=True))
for user_plan in plans:
if user_plan.name.lower() == plan.lower():
if plan_info:
raise InvalidArgumentValueError("There are multiple plans with name {}.".format(plan),
"Try using the plan resource ID instead.")
parse_result = parse_resource_id(user_plan.id)
plan_info = client.app_service_plans.get(parse_result['resource_group'], parse_result['name'])
if not plan_info:
raise ResourceNotFoundError("The plan '{}' doesn't exist in the resource group '{}".format(plan,
resource_group_name))
raise ResourceNotFoundError("The plan '{}' doesn't exist.".format(plan))
is_linux = plan_info.reserved
helper = _StackRuntimeHelper(cmd, linux=is_linux, windows=not is_linux)
location = plan_info.location
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ interactions:
ParameterSetName:
- -g -n --address-prefix --subnet-name --subnet-prefix
User-Agent:
- AZURECLI/2.33.1 azsdk-python-azure-mgmt-resource/20.0.0 Python/3.8.2 (macOS-10.16-x86_64-i386-64bit)
- AZURECLI/2.34.1 azsdk-python-azure-mgmt-resource/20.0.0 Python/3.8.10 (Windows-10-10.0.19044-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001?api-version=2021-04-01
response:
body:
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001","name":"clitest.rg000001","type":"Microsoft.Resources/resourceGroups","location":"japanwest","tags":{"product":"azurecli","cause":"automation","date":"2022-02-24T19:35:25Z"},"properties":{"provisioningState":"Succeeded"}}'
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001","name":"clitest.rg000001","type":"Microsoft.Resources/resourceGroups","location":"japanwest","tags":{"product":"azurecli","cause":"automation","date":"2022-03-23T19:14:32Z"},"properties":{"provisioningState":"Succeeded"}}'
headers:
cache-control:
- no-cache
Expand All @@ -27,7 +27,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Thu, 24 Feb 2022 19:35:27 GMT
- Wed, 23 Mar 2022 19:14:38 GMT
expires:
- '-1'
pragma:
Expand Down Expand Up @@ -62,21 +62,21 @@ interactions:
ParameterSetName:
- -g -n --address-prefix --subnet-name --subnet-prefix
User-Agent:
- AZURECLI/2.33.1 azsdk-python-azure-mgmt-network/19.3.0 Python/3.8.2 (macOS-10.16-x86_64-i386-64bit)
- AZURECLI/2.34.1 azsdk-python-azure-mgmt-network/19.3.0 Python/3.8.10 (Windows-10-10.0.19044-SP0)
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/vnet000005?api-version=2021-05-01
response:
body:
string: "{\r\n \"name\": \"vnet000005\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/vnet000005\",\r\n
\ \"etag\": \"W/\\\"1e0f6676-6456-4922-ab1b-f307f8f53796\\\"\",\r\n \"type\":
\ \"etag\": \"W/\\\"86af37e9-9a3a-40b7-8750-e719d60f2918\\\"\",\r\n \"type\":
\"Microsoft.Network/virtualNetworks\",\r\n \"location\": \"japanwest\",\r\n
\ \"tags\": {},\r\n \"properties\": {\r\n \"provisioningState\": \"Updating\",\r\n
\ \"resourceGuid\": \"d62c63d0-e39e-4d44-9a32-f928b368444e\",\r\n \"addressSpace\":
\ \"resourceGuid\": \"abbca9c7-24b6-4ae4-9300-676cc2f9bd0f\",\r\n \"addressSpace\":
{\r\n \"addressPrefixes\": [\r\n \"10.0.0.0/16\"\r\n ]\r\n
\ },\r\n \"dhcpOptions\": {\r\n \"dnsServers\": []\r\n },\r\n
\ \"subnets\": [\r\n {\r\n \"name\": \"subnet000004\",\r\n \"id\":
\"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/vnet000005/subnets/subnet000004\",\r\n
\ \"etag\": \"W/\\\"1e0f6676-6456-4922-ab1b-f307f8f53796\\\"\",\r\n
\ \"etag\": \"W/\\\"86af37e9-9a3a-40b7-8750-e719d60f2918\\\"\",\r\n
\ \"properties\": {\r\n \"provisioningState\": \"Updating\",\r\n
\ \"addressPrefix\": \"10.0.0.0/24\",\r\n \"delegations\":
[],\r\n \"privateEndpointNetworkPolicies\": \"Enabled\",\r\n \"privateLinkServiceNetworkPolicies\":
Expand All @@ -87,15 +87,15 @@ interactions:
azure-asyncnotification:
- Enabled
azure-asyncoperation:
- https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Network/locations/japanwest/operations/642544c4-fede-48f2-b285-f052d5c1c0e5?api-version=2021-05-01
- https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Network/locations/japanwest/operations/b5e779f1-6659-467c-aa9f-3a3524d2f1bc?api-version=2021-05-01
cache-control:
- no-cache
content-length:
- '1313'
content-type:
- application/json; charset=utf-8
date:
- Thu, 24 Feb 2022 19:35:30 GMT
- Wed, 23 Mar 2022 19:14:47 GMT
expires:
- '-1'
pragma:
Expand All @@ -108,9 +108,9 @@ interactions:
x-content-type-options:
- nosniff
x-ms-arm-service-request-id:
- 66d4f744-c388-471f-852c-3a84682be74d
- 33cb0625-70af-4cbe-8def-525f8121e4ab
x-ms-ratelimit-remaining-subscription-writes:
- '1196'
- '1199'
status:
code: 201
message: Created
Expand All @@ -128,9 +128,9 @@ interactions:
ParameterSetName:
- -g -n --address-prefix --subnet-name --subnet-prefix
User-Agent:
- AZURECLI/2.33.1 azsdk-python-azure-mgmt-network/19.3.0 Python/3.8.2 (macOS-10.16-x86_64-i386-64bit)
- AZURECLI/2.34.1 azsdk-python-azure-mgmt-network/19.3.0 Python/3.8.10 (Windows-10-10.0.19044-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Network/locations/japanwest/operations/642544c4-fede-48f2-b285-f052d5c1c0e5?api-version=2021-05-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Network/locations/japanwest/operations/b5e779f1-6659-467c-aa9f-3a3524d2f1bc?api-version=2021-05-01
response:
body:
string: "{\r\n \"status\": \"Succeeded\"\r\n}"
Expand All @@ -142,7 +142,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Thu, 24 Feb 2022 19:35:34 GMT
- Wed, 23 Mar 2022 19:14:50 GMT
expires:
- '-1'
pragma:
Expand All @@ -159,7 +159,7 @@ interactions:
x-content-type-options:
- nosniff
x-ms-arm-service-request-id:
- b3734020-78d9-4ed9-8fb4-42311eda3c2d
- 3f675fa2-3fe7-4be2-b9e0-2cb4f3256ab2
status:
code: 200
message: OK
Expand All @@ -177,21 +177,21 @@ interactions:
ParameterSetName:
- -g -n --address-prefix --subnet-name --subnet-prefix
User-Agent:
- AZURECLI/2.33.1 azsdk-python-azure-mgmt-network/19.3.0 Python/3.8.2 (macOS-10.16-x86_64-i386-64bit)
- AZURECLI/2.34.1 azsdk-python-azure-mgmt-network/19.3.0 Python/3.8.10 (Windows-10-10.0.19044-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/vnet000005?api-version=2021-05-01
response:
body:
string: "{\r\n \"name\": \"vnet000005\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/vnet000005\",\r\n
\ \"etag\": \"W/\\\"aeefa564-adcd-4361-89cf-ac6dccee8bc4\\\"\",\r\n \"type\":
\ \"etag\": \"W/\\\"67849aab-4186-4e01-a389-0d307fd118af\\\"\",\r\n \"type\":
\"Microsoft.Network/virtualNetworks\",\r\n \"location\": \"japanwest\",\r\n
\ \"tags\": {},\r\n \"properties\": {\r\n \"provisioningState\": \"Succeeded\",\r\n
\ \"resourceGuid\": \"d62c63d0-e39e-4d44-9a32-f928b368444e\",\r\n \"addressSpace\":
\ \"resourceGuid\": \"abbca9c7-24b6-4ae4-9300-676cc2f9bd0f\",\r\n \"addressSpace\":
{\r\n \"addressPrefixes\": [\r\n \"10.0.0.0/16\"\r\n ]\r\n
\ },\r\n \"dhcpOptions\": {\r\n \"dnsServers\": []\r\n },\r\n
\ \"subnets\": [\r\n {\r\n \"name\": \"subnet000004\",\r\n \"id\":
\"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/vnet000005/subnets/subnet000004\",\r\n
\ \"etag\": \"W/\\\"aeefa564-adcd-4361-89cf-ac6dccee8bc4\\\"\",\r\n
\ \"etag\": \"W/\\\"67849aab-4186-4e01-a389-0d307fd118af\\\"\",\r\n
\ \"properties\": {\r\n \"provisioningState\": \"Succeeded\",\r\n
\ \"addressPrefix\": \"10.0.0.0/24\",\r\n \"delegations\":
[],\r\n \"privateEndpointNetworkPolicies\": \"Enabled\",\r\n \"privateLinkServiceNetworkPolicies\":
Expand All @@ -206,9 +206,9 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Thu, 24 Feb 2022 19:35:34 GMT
- Wed, 23 Mar 2022 19:14:50 GMT
etag:
- W/"aeefa564-adcd-4361-89cf-ac6dccee8bc4"
- W/"67849aab-4186-4e01-a389-0d307fd118af"
expires:
- '-1'
pragma:
Expand All @@ -225,7 +225,7 @@ interactions:
x-content-type-options:
- nosniff
x-ms-arm-service-request-id:
- 74b2e305-7a7e-4164-80a6-13416f6234af
- 90e2052f-5aff-4bbf-8cab-0270a89629c3
status:
code: 200
message: OK
Expand All @@ -243,12 +243,12 @@ interactions:
ParameterSetName:
- -g -n --sku
User-Agent:
- AZURECLI/2.33.1 azsdk-python-azure-mgmt-resource/20.0.0 Python/3.8.2 (macOS-10.16-x86_64-i386-64bit)
- AZURECLI/2.34.1 azsdk-python-azure-mgmt-resource/20.0.0 Python/3.8.10 (Windows-10-10.0.19044-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001?api-version=2021-04-01
response:
body:
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001","name":"clitest.rg000001","type":"Microsoft.Resources/resourceGroups","location":"japanwest","tags":{"product":"azurecli","cause":"automation","date":"2022-02-24T19:35:25Z"},"properties":{"provisioningState":"Succeeded"}}'
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001","name":"clitest.rg000001","type":"Microsoft.Resources/resourceGroups","location":"japanwest","tags":{"product":"azurecli","cause":"automation","date":"2022-03-23T19:14:32Z"},"properties":{"provisioningState":"Succeeded"}}'
headers:
cache-control:
- no-cache
Expand All @@ -257,7 +257,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Thu, 24 Feb 2022 19:35:34 GMT
- Wed, 23 Mar 2022 19:14:50 GMT
expires:
- '-1'
pragma:
Expand Down Expand Up @@ -291,13 +291,13 @@ interactions:
ParameterSetName:
- -g -n --sku
User-Agent:
- AZURECLI/2.33.1 azsdk-python-azure-mgmt-web/6.1.0 Python/3.8.2 (macOS-10.16-x86_64-i386-64bit)
- AZURECLI/2.34.1 azsdk-python-azure-mgmt-web/6.1.0 Python/3.8.10 (Windows-10-10.0.19044-SP0)
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Web/serverfarms/vnetplan000003?api-version=2021-03-01
response:
body:
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Web/serverfarms/vnetplan000003","name":"vnetplan000003","type":"Microsoft.Web/serverfarms","kind":"app","location":"japanwest","properties":{"serverFarmId":35356,"name":"vnetplan000003","sku":{"name":"P1v2","tier":"PremiumV2","size":"P1v2","family":"Pv2","capacity":1},"workerSize":"D1","workerSizeId":3,"workerTierName":null,"numberOfWorkers":1,"currentWorkerSize":"D1","currentWorkerSizeId":3,"currentNumberOfWorkers":1,"status":"Ready","webSpace":"clitest.rg000001-JapanWestwebspace","subscription":"e483435e-282d-4ac1-92b5-d6123f2aa360","adminSiteName":null,"hostingEnvironment":null,"hostingEnvironmentProfile":null,"maximumNumberOfWorkers":0,"planName":"VirtualDedicatedPlan","adminRuntimeSiteName":null,"computeMode":"Dedicated","siteMode":null,"geoRegion":"Japan
West","perSiteScaling":false,"elasticScaleEnabled":false,"maximumElasticWorkerCount":1,"numberOfSites":0,"hostingEnvironmentId":null,"isSpot":false,"spotExpirationTime":null,"freeOfferExpirationTime":null,"tags":null,"kind":"app","resourceGroup":"clitest.rg000001","reserved":false,"isXenon":false,"hyperV":false,"mdmId":"waws-prod-os1-027_35356","targetWorkerCount":0,"targetWorkerSizeId":0,"provisioningState":"Succeeded","webSiteId":null,"existingServerFarmIds":null,"kubeEnvironmentProfile":null,"zoneRedundant":false},"sku":{"name":"P1v2","tier":"PremiumV2","size":"P1v2","family":"Pv2","capacity":1}}'
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Web/serverfarms/vnetplan000003","name":"vnetplan000003","type":"Microsoft.Web/serverfarms","kind":"app","location":"japanwest","properties":{"serverFarmId":35106,"name":"vnetplan000003","sku":{"name":"P1v2","tier":"PremiumV2","size":"P1v2","family":"Pv2","capacity":1},"workerSize":"D1","workerSizeId":3,"workerTierName":null,"numberOfWorkers":1,"currentWorkerSize":"D1","currentWorkerSizeId":3,"currentNumberOfWorkers":1,"status":"Ready","webSpace":"clitest.rg000001-JapanWestwebspace","subscription":"9b345226-dedc-4977-baeb-ea15d01b863d","adminSiteName":null,"hostingEnvironment":null,"hostingEnvironmentProfile":null,"maximumNumberOfWorkers":0,"planName":"VirtualDedicatedPlan","adminRuntimeSiteName":null,"computeMode":"Dedicated","siteMode":null,"geoRegion":"Japan
West","perSiteScaling":false,"elasticScaleEnabled":false,"maximumElasticWorkerCount":1,"numberOfSites":0,"hostingEnvironmentId":null,"isSpot":false,"spotExpirationTime":null,"freeOfferExpirationTime":null,"tags":null,"kind":"app","resourceGroup":"clitest.rg000001","reserved":false,"isXenon":false,"hyperV":false,"mdmId":"waws-prod-os1-013_35106","targetWorkerCount":0,"targetWorkerSizeId":0,"provisioningState":"Succeeded","webSiteId":null,"existingServerFarmIds":null,"kubeEnvironmentProfile":null,"zoneRedundant":false},"sku":{"name":"P1v2","tier":"PremiumV2","size":"P1v2","family":"Pv2","capacity":1}}'
headers:
cache-control:
- no-cache
Expand All @@ -306,9 +306,9 @@ interactions:
content-type:
- application/json
date:
- Thu, 24 Feb 2022 19:35:45 GMT
- Wed, 23 Mar 2022 19:15:06 GMT
etag:
- '"1D829B5B68C5860"'
- '"1D83EEA4CAD6E15"'
expires:
- '-1'
pragma:
Expand All @@ -326,7 +326,7 @@ interactions:
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-writes:
- '1196'
- '1199'
x-powered-by:
- ASP.NET
status:
Expand Down
Loading

0 comments on commit ad14ed5

Please sign in to comment.