Skip to content

Commit

Permalink
Fix style warnings in the webapp extension
Browse files Browse the repository at this point in the history
- This commit primarily fixes the style warnings (azdev style webapp)
- upload_source_code parameter list was missing the command param. This commit fixes that.
- Another change to functionality is that OneDeploy async deployments don't poll for the operation completion now. This behavior can be toggled for development purposes using the poll_async_deployment_for_debugging flag in code
  • Loading branch information
shrishrirang committed Dec 21, 2020
1 parent cea479f commit 6f02bb7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/webapp/azext_webapp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-import,ungrouped-imports
# pylint: disable=unused-import,ungrouped-imports,import-outside-toplevel,super-with-arguments
from azure.cli.core import AzCommandsLoader
from azure.cli.command_modules.appservice.commands import ex_handler_factory
from knack.arguments import CLIArgumentType
Expand Down Expand Up @@ -68,12 +68,12 @@ def load_arguments(self, _):
c.argument('name', options_list=['--name'], help='Name of the webapp to connect to')
c.argument('src_path', options_list=['--src-path'], help='Path of the file to be deployed. Example: /mnt/apps/myapp.war')
c.argument('src_url', options_list=['--src-url'], help='url to download the package from. Example: http://mysite.com/files/myapp.war?key=123')
c.argument('type', options_list=['--type'], help='Type of deployment requested')
c.argument('async', options_list=['--async'], help='Asynchronous deployment', type=bool)
c.argument('target_path', options_list=['--target-path'], help='Target path relative to wwwroot to which the file will be deployed to.')
c.argument('restart', options_list=['--restart'], help='restart or not. default behavior is to restart.', type=bool)
c.argument('clean', options_list=['--clean'], help='clean or not. default is target-type specific.', type=bool)
c.argument('ignore_stack', options_list=['--ignore-stack'], help='should override the default stack check', type=bool)
c.argument('artifact_type', options_list=['--type'], help='Type of deployment requested')
c.argument('is_async', options_list=['--async'], help='Asynchronous deployment', choices=['true', 'false'])
c.argument('restart', options_list=['--restart'], help='restart or not. default behavior is to restart.', choices=['true', 'false'])
c.argument('clean', options_list=['--clean'], help='clean or not. default is target-type specific.', choices=['true', 'false'])
c.argument('ignore_stack', options_list=['--ignore-stack'], help='should override the default stack check', choices=['true', 'false'])
c.argument('timeout', options_list=['--timeout'], help='Timeout for operation in milliseconds')
c.argument('slot', help="Name of the deployment slot to use")

Expand Down
2 changes: 2 additions & 0 deletions src/webapp/azext_webapp/acr_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
VERSION_2019_06_01_PREVIEW = "2019-06-01-preview"


# pylint:disable=import-outside-toplevel
def queue_acr_build(cmd, registry_rg, registry_name, img_name, src_dir):
import os
client_registries = get_acr_service_client(cmd.cli_ctx, VERSION_2019_06_01_PREVIEW).registries
Expand All @@ -38,6 +39,7 @@ def queue_acr_build(cmd, registry_rg, registry_name, img_name, src_dir):
tar_file_path = os.path.join(tempfile.gettempdir(), 'build_archive_{}.tar.gz'.format(uuid.uuid4().hex))

source_location = upload_source_code(
cmd,
client_registries, registry_name, registry_rg,
src_dir, tar_file_path,
docker_file_path, docker_file_in_tar)
Expand Down
53 changes: 35 additions & 18 deletions src/webapp/azext_webapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
logger = get_logger(__name__)


# pylint:disable=no-member,too-many-lines,too-many-locals,too-many-statements,too-many-branches,line-too-long
# pylint:disable=no-member,too-many-lines,too-many-locals,too-many-statements,too-many-branches,line-too-long,import-outside-toplevel
def create_deploy_container_app(cmd, name, source_location=None, docker_custom_image_name=None, dryrun=False, registry_rg=None, registry_name=None): # pylint: disable=too-many-statements
import os
import json
Expand Down Expand Up @@ -318,9 +318,9 @@ def perform_onedeploy(cmd,
name,
src_path=None,
src_url=None,
type=None,
async=None,
target_path=None,
artifact_type=None,
is_async=None,
restart=None,
clean=None,
ignore_stack=None,
Expand All @@ -333,9 +333,9 @@ def perform_onedeploy(cmd,
params.webapp_name = name
params.src_path = src_path
params.src_url = src_url
params.artifact_type = type
params.is_async_deployment = async
params.target_path = target_path
params.artifact_type = artifact_type
params.is_async_deployment = is_async
params.should_restart = restart
params.is_clean_deployment = clean
params.should_ignore_stack = ignore_stack
Expand All @@ -346,8 +346,23 @@ def perform_onedeploy(cmd,


# Class for OneDeploy parameters
# pylint: disable=too-many-instance-attributes,too-few-public-methods
class OneDeployParams(object):
pass
def __init__(self):
self.cmd = None
self.resource_group_name = None
self.webapp_name = None
self.src_path = None
self.src_url = None
self.artifact_type = None
self.is_async_deployment = None
self.target_path = None
self.should_restart = None
self.is_clean_deployment = None
self.should_ignore_stack = None
self.timeout = None
self.slot = None
# pylint: enable=too-many-instance-attributes,too-few-public-methods


def _validate_onedeploy_params(params):
Expand Down Expand Up @@ -391,8 +406,7 @@ def _get_onedeploy_status_url(params):
def _get_basic_headers(params):
import urllib3
from azure.cli.core.util import (
should_disable_connection_verify,
get_az_user_agent
get_az_user_agent,
)

user_name, password = _get_site_credential(params.cmd.cli_ctx, params.resource_group_name, params.webapp_name, params.slot)
Expand All @@ -417,14 +431,14 @@ def _get_onedeploy_request_body(params):
import json

if params.src_path:
logger.info('Deploying from local path: ' + params.src_path)
logger.info('Deploying from local path: %s', params.src_path)
try:
with open(os.path.realpath(os.path.expanduser(params.src_path)), 'rb') as fs:
body = fs.read()
except Exception as e:
raise CLIError("Either '{}' is not a valid local file path or you do not have permissions to access it".format(params.src_path)) from e
elif params.src_url:
logger.info('Deploying from URL: ' + params.src_url)
logger.info('Deploying from URL: %s', params.src_url)
body = json.dumps({
"packageUri": params.src_url
})
Expand All @@ -449,7 +463,7 @@ def _update_artifact_type(params):
params.artifact_type = 'startup'
else:
params.artifact_type = 'static'
logger.warning("Deployment type: %s. To override deloyment type, please specify the --type parameter. " +
logger.warning("Deployment type: %s. To override deloyment type, please specify the --type parameter. "
"Possible values: war, jar, ear, zip, startup, script, static", params.artifact_type)


Expand All @@ -466,14 +480,19 @@ def _make_onedeploy_request(params):
deploy_url = _build_onedeploy_url(params)
deployment_status_url = _get_onedeploy_status_url(params)

logger.info("Deployment API: " + deploy_url)
logger.info("Deployment API: %s", deploy_url)
response = requests.post(deploy_url, data=body, headers=headers, verify=not should_disable_connection_verify())

# For debugging purposes only, you can change the async deployment into a sync deployment by polling the API status
# For that, set poll_async_deployment_for_debugging=True
poll_async_deployment_for_debugging = False

# check the status of async deployment
if response.status_code == 202:
logger.info("Asynchronous deployment request completed")
response_body = _check_zip_deployment_status(params.cmd, params.resource_group_name, params.webapp_name, deployment_status_url, headers, params.timeout)
logger.info(response_body)
if poll_async_deployment_for_debugging:
logger.info('Polloing the status of async deployment')
response_body = _check_zip_deployment_status(params.cmd, params.resource_group_name, params.webapp_name, deployment_status_url, headers, params.timeout)
logger.info('Async deployment complete. Server response: %s', response_body)
return

if response.status_code == 200:
Expand All @@ -485,9 +504,7 @@ def _make_onedeploy_request(params):

# check if there's an ongoing process
if response.status_code == 409:
raise CLIError("There may be an ongoing deployment or your app setting has WEBSITE_RUN_FROM_PACKAGE. "
"Please track your deployment in {} and ensure the WEBSITE_RUN_FROM_PACKAGE app setting "
"is removed.".format(deployment_status_url))
raise CLIError("Another deployment is in progress. You can track the ongoing deployment at {}".format(deployment_status_url))

# check if an error occured during deployment
if response.status_code:
Expand Down
2 changes: 1 addition & 1 deletion src/webapp/azext_webapp/tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=import-error,unused-import
# pylint: disable=import-error,unused-import,import-outside-toplevel,super-with-arguments
import sys
import ssl
import socket
Expand Down

0 comments on commit 6f02bb7

Please sign in to comment.