Skip to content

Commit

Permalink
{App Service} Fix az webapp up not getting correct ASP to use (#14673)
Browse files Browse the repository at this point in the history
* fix python quickstart cannot update site error

* Test recordings
  • Loading branch information
calvinsID authored Aug 6, 2020
1 parent 2d39a5e commit 959166f
Show file tree
Hide file tree
Showing 10 changed files with 21,120 additions and 1,547 deletions.
9 changes: 8 additions & 1 deletion src/azure-cli/azure/cli/command_modules/appservice/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3560,7 +3560,14 @@ def webapp_up(cmd, name, resource_group_name=None, plan=None, location=None, sku
rg_name = get_rg_to_use(cmd, user, loc, os_name, resource_group_name)
_is_linux = os_name.lower() == 'linux'
_create_new_rg = should_create_new_rg(cmd, rg_name, _is_linux)
plan = get_plan_to_use(cmd, user, os_name, loc, sku, rg_name, _create_new_rg, plan)
plan = get_plan_to_use(cmd=cmd,
user=user,
os_name=os_name,
loc=loc,
sku=sku,
create_rg=_create_new_rg,
resource_group_name=rg_name,
plan=plan)
dry_run_str = r""" {
"name" : "%s",
"appserviceplan" : "%s",
Expand Down

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 @@ -18,7 +18,7 @@ interactions:
- -n --dryrun
User-Agent:
- python/3.7.2 (Darwin-16.7.0-x86_64-i386-64bit) msrest/0.6.9 msrest_azure/0.6.3
azure-mgmt-web/0.47.0 Azure-SDK-For-Python AZURECLI/2.9.0
azure-mgmt-web/0.47.0 Azure-SDK-For-Python AZURECLI/2.10.0
accept-language:
- en-US
method: POST
Expand All @@ -35,7 +35,7 @@ interactions:
content-type:
- application/json
date:
- Sat, 18 Jul 2020 05:54:12 GMT
- Wed, 05 Aug 2020 03:09:31 GMT
expires:
- '-1'
pragma:
Expand Down Expand Up @@ -76,7 +76,7 @@ interactions:
- -n
User-Agent:
- python/3.7.2 (Darwin-16.7.0-x86_64-i386-64bit) msrest/0.6.9 msrest_azure/0.6.3
azure-mgmt-web/0.47.0 Azure-SDK-For-Python AZURECLI/2.9.0
azure-mgmt-web/0.47.0 Azure-SDK-For-Python AZURECLI/2.10.0
accept-language:
- en-US
method: POST
Expand All @@ -93,7 +93,7 @@ interactions:
content-type:
- application/json
date:
- Sat, 18 Jul 2020 05:54:13 GMT
- Wed, 05 Aug 2020 03:09:31 GMT
expires:
- '-1'
pragma:
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.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class WebAppUpE2ETests(ScenarioTest):
@live_only()
@ResourceGroupPreparer(location=LINUX_ASP_LOCATION_WEBAPP)
@ResourceGroupPreparer(random_name_length=24, name_prefix='clitest', location=LINUX_ASP_LOCATION_WEBAPP)
def test_webapp_up_node_e2e(self, resource_group):
plan = self.create_random_name('up-nodeplan', 24)
webapp_name = self.create_random_name('up-nodeapp', 24)
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_webapp_up_node_e2e(self, resource_group):
shutil.rmtree(temp_dir)

@live_only()
@ResourceGroupPreparer(location=LINUX_ASP_LOCATION_WEBAPP)
@ResourceGroupPreparer(random_name_length=24, name_prefix='clitest', location=LINUX_ASP_LOCATION_WEBAPP)
def test_webapp_up_python_e2e(self, resource_group):
plan = self.create_random_name('up-pythonplan', 24)
webapp_name = self.create_random_name('up-pythonapp', 24)
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_webapp_up_python_e2e(self, resource_group):
shutil.rmtree(temp_dir)

@live_only()
@ResourceGroupPreparer(location=WINDOWS_ASP_LOCATION_WEBAPP)
@ResourceGroupPreparer(random_name_length=24, name_prefix='clitest', location=WINDOWS_ASP_LOCATION_WEBAPP)
def test_webapp_up_dotnetcore_e2e(self, resource_group):
plan = self.create_random_name('up-dotnetcoreplan', 24)
webapp_name = self.create_random_name('up-dotnetcoreapp', 24)
Expand Down Expand Up @@ -225,7 +225,7 @@ def test_webapp_up_dotnetcore_e2e(self, resource_group):
shutil.rmtree(temp_dir)

@live_only()
@ResourceGroupPreparer(location=WINDOWS_ASP_LOCATION_WEBAPP)
@ResourceGroupPreparer(random_name_length=24, name_prefix='clitest', location=WINDOWS_ASP_LOCATION_WEBAPP)
def test_webapp_up_statichtml_e2e(self, resource_group):
plan = self.create_random_name('up-statichtmlplan', 24)
webapp_name = self.create_random_name('up-statichtmlapp', 24)
Expand Down Expand Up @@ -293,7 +293,7 @@ def test_webapp_up_statichtml_e2e(self, resource_group):
import shutil
shutil.rmtree(temp_dir)

@ResourceGroupPreparer(location=LINUX_ASP_LOCATION_WEBAPP)
@ResourceGroupPreparer(random_name_length=24, name_prefix='clitest', location=LINUX_ASP_LOCATION_WEBAPP)
def test_webapp_up_invalid_name(self, resource_group):
webapp_name = self.create_random_name('invalid_name', 40)
zip_file_name = os.path.join(TEST_DIR, 'python-hello-world-up.zip')
Expand Down Expand Up @@ -323,8 +323,54 @@ def test_webapp_up_invalid_name(self, resource_group):
import shutil
shutil.rmtree(temp_dir)

@live_only()
@ResourceGroupPreparer(random_name_length=24, name_prefix='clitest', location=LINUX_ASP_LOCATION_WEBAPP)
def test_webapp_up_different_skus(self, resource_group):
webapp_name = self.create_random_name('up-different-skus', 40)
webapp_name_2 = self.create_random_name('up-different-skus-2', 40)
webapp_name_3 = self.create_random_name('up-different-skus-3', 40)
plan = self.create_random_name('up-different-skus-plan', 40)
plan_2 = self.create_random_name('up-different-skus-plan-2', 40)

zip_file_name = os.path.join(TEST_DIR, 'python-hello-world-up.zip')

# create a temp directory and unzip the code to this folder
import zipfile
import tempfile
temp_dir = tempfile.mkdtemp()
zip_ref = zipfile.ZipFile(zip_file_name, 'r')
zip_ref.extractall(temp_dir)
current_working_dir = os.getcwd()

# change the working dir to the dir where the code has been extracted to
up_working_dir = os.path.join(temp_dir, 'python-docs-hello-world')
os.chdir(up_working_dir)

result = self.cmd(
'webapp up -n {} --sku S1 -g {} --plan {}'.format(webapp_name, resource_group, plan)).get_output_in_json()
self.assertTrue(result['name'] == webapp_name)
self.assertTrue(result['sku'].lower() == 'standard')

# Creating an app with new ASP with free sku should work
result = self.cmd(
'webapp up -n {} --sku F1 -g {} --plan {}'.format(webapp_name_2, resource_group, plan_2)).get_output_in_json()
self.assertTrue(result['name'] == webapp_name_2)
self.assertTrue(result['sku'].lower() == 'free')

# Creating an app with existing ASP that isn't free should not work
from azure.cli.core.util import CLIError
with self.assertRaises(CLIError):
self.cmd('webapp up -n {} --sku F1 -g {} --plan {}'.format(webapp_name_3, resource_group, plan))

# cleanup
# switch back the working dir
os.chdir(current_working_dir)
# delete temp_dir
import shutil
shutil.rmtree(temp_dir)

@AllowLargeResponse()
@ResourceGroupPreparer(location=LINUX_ASP_LOCATION_WEBAPP)
@ResourceGroupPreparer(random_name_length=24, name_prefix='clitest', location=LINUX_ASP_LOCATION_WEBAPP)
def test_webapp_up_name_exists_not_in_subscription(self, resource_group):
# Make sure webapp_name is the name of an existing web app and is not in your subscription
webapp_name = 'helloworld'
Expand Down Expand Up @@ -356,7 +402,7 @@ def test_webapp_up_name_exists_not_in_subscription(self, resource_group):
shutil.rmtree(temp_dir)

@live_only()
@ResourceGroupPreparer(location=LINUX_ASP_LOCATION_WEBAPP)
@ResourceGroupPreparer(random_name_length=24, name_prefix='clitest', location=LINUX_ASP_LOCATION_WEBAPP)
def test_webapp_up_name_exists_in_subscription(self, resource_group):
plan = self.create_random_name('up-name-exists-plan', 40)
webapp_name = self.create_random_name('up-name-exists-app', 40)
Expand Down

0 comments on commit 959166f

Please sign in to comment.