Skip to content

Websites: Add Multicontainer Capabilities#6255

Merged
yugangw-msft merged 8 commits into
Azure:devfrom
LukaszStem:multicontainer
Apr 30, 2018
Merged

Websites: Add Multicontainer Capabilities#6255
yugangw-msft merged 8 commits into
Azure:devfrom
LukaszStem:multicontainer

Conversation

@LukaszStem
Copy link
Copy Markdown


This checklist is used to make sure that common guidelines for a pull request are followed.

  • The PR has modified HISTORY.rst describing any customer-facing, functional changes. Note that this does not include changes only to help content. (see Modifying change log).

  • I adhere to the Command Guidelines.

@LukaszStem LukaszStem requested a review from yugangw-msft April 28, 2018 18:15
@promptws
Copy link
Copy Markdown

View a preview at https://prompt.ws/r/Azure/azure-cli/6255
This is an experimental preview for @microsoft users.

@LukaszStem LukaszStem changed the title Websites Multicontainer change Websites: Add Multicontainer Capabilities Apr 28, 2018
Copy link
Copy Markdown
Contributor

@yugangw-msft yugangw-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start! Please address my comments

c.argument('docker_registry_server_user', options_list=['--docker-registry-server-user', '-u'], help='the container registry server username')
c.argument('docker_registry_server_password', options_list=['--docker-registry-server-password', '-p'], help='the container registry server password')
c.argument('websites_enable_app_service_storage', options_list=['--enable-app-service-storage', '-t'], help='enables platform storage (custom container only)', arg_type=get_three_state_flag(return_label=True))
c.argument('multicontainer_config_type', options_list=['--multicontainer-config-type'], help='config type', arg_type=get_enum_type(MULTI_CONTAINER_TYPES))
Copy link
Copy Markdown
Contributor

@yugangw-msft yugangw-msft Apr 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this linux only as well like the one used in webapp create? I suggested we could consolidate them to avoid dupes.

if not validate_linux_create_options(runtime, deployment_container_image_name,
multicontainer_config_type, multicontainer_config_file):
raise CLIError("usage error: --runtime | --deployment-container-image-name |"
" --multicontainer-config-type with --multicontainer-config-file")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per convention, you can just say --multicontainer-config-type TYPE --multicontainer-config-file FILE. with is unnecessary

elif runtime: # windows webapp with runtime specified
if startup_file or deployment_container_image_name:
raise CLIError("usage error: --startup-file or --deployment-container-image-name is "
raise CLIError("usage error: --startup-file or --deployment-container-image-name or "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you will need to add new sub-conditions with multicontainer_config_type or multicontainer_config_file

multicontainer_config_type=None, multicontainer_config_file=None):
if bool(multicontainer_config_type) != bool(multicontainer_config_file):
return False
opts = [bool(runtime), bool(deployment_container_image_name), bool(multicontainer_config_type)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: you can remove the bool() to leverage Python's support for True Value testing



def _format_linux_fx_version(custom_image_name):
def _format_linux_fx_version(custom_image_name, custom_prefix=None):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless custom is a agreed-on term, shall we rename to "container_config_type" to make it more explicit?

if file_name:
if url_validator(file_name):
from urllib.request import urlopen
response = urlopen(file_name)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will not work across platform, particularly windows and linux, as you need to set the SSL context. Please check out how acs does
Or, for this version, just pull out the support for opening from url

response = urlopen(file_name)
config_file_bytes = response.read()
else:
with open(file_name) as f:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you will encode back in 2 lines below, you are better off just reading the file in binary mode, so why not with open(file_name, 'rb')?

try:
config_file_bytes = b64decode(linux_fx_version.split('|')[1].encode('utf-8'))
except:
raise CLIError('Could not decode config')
Copy link
Copy Markdown
Contributor

@yugangw-msft yugangw-msft Apr 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest get rid of this if block all together, and just keep an string.
At high level, I suggest make the function do one thing which is to read file content and return a string. No other things. This way the function will have a bit of readability. In details:

  1. please get rid of loops from encoding->decode->encoding again.
  2. get rid of the encoded arguments, and let caller (only once place) to encode if needs

update_app_settings(cmd, resource_group_name, name, settings, slot)
settings = get_app_settings(cmd, resource_group_name, name, slot)

if bool(multicontainer_config_file) != bool(multicontainer_config_type):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the multicontainer_config_file should be used together with multicontainer_config_type, why the opposite?

Copy link
Copy Markdown
Contributor

@yugangw-msft yugangw-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please address my new comments, and also test it well

elif deployment_container_image_name:
site_config.linux_fx_version = _format_linux_fx_version(deployment_container_image_name)
site_config.app_settings.append(NameValuePair("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "false"))
else: # must specify runtime
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you remove this? Now we won't report anything if none of the arguments are supplied

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate_linux_create_options() will catch this right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

elif runtime: # windows webapp with runtime specified
if startup_file or deployment_container_image_name:
raise CLIError("usage error: --startup-file or --deployment-container-image-name is "
if startup_file or deployment_container_image_name or multicontainer_config_file or multicontainer_config_type:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use use any[...], to be consistent with the rest code you wrote?

try:
result = urlparse(url)
return all([result.scheme, result.netloc, result.path])
except:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would fail the pylint. I believe you should only catch ValueError per this API's document

raise CLIError("Cannot decode config that is not one of the"
" following types: {}".form (','(MULTI_CONTAINER_TYPES)))
try:
return b64decode(linux_fx_version.spl('|'[1].encode('utf-8')))
Copy link
Copy Markdown
Contributor

@yugangw-msft yugangw-msft Apr 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this code would work at all. have you tested it?

response = urlopen(file_name, context=_ssl_context())
config_file_bytes = response.read()
else:
with open(file_name) as f:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can read the file as binary, so you don't need to encode again in the 2 line below

update_app_settings(cmd, resource_group_name, name, settings, slot)
settings = get_app_settings(cmd, resource_group_name, name, slot)

if bool(multicontainer_config_file) and bool(multicontainer_config_type):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can simply: multicontainer_config_file and multicontainer_config_type

linux_fx_version = _format_linux_fx_version(encoded_config_file, multicontainer_config_type)
update_site_configs(cmd, resource_group_name, name, linux_fx_version=linux_fx_version)
else:
raise CLIError('Must use --multicontainer-config-file FILE --multicontainer-config-type TYPE')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be very wrong, unless I mis-understood. To me now this command would only succeed with multicontainer_config_file and multicontainer_config_type; while all other settings would not go through

Copy link
Copy Markdown
Contributor

@yugangw-msft yugangw-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better now.
One more comment, and keep on testing it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not this be multicontainer_config_file or multicontainer_config_type? Otherwise, setting an unrelated config like docker_custom_image_name would trigger this warn.

Copy link
Copy Markdown
Contributor

@yugangw-msft yugangw-msft Apr 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you log an issue and assign to yourself, so you can improve the test to create all from the scratch instead of hard-coding the assert?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use from six.moves.urllib.request import urlopen like other command module

elif deployment_container_image_name:
site_config.linux_fx_version = _format_linux_fx_version(deployment_container_image_name)
site_config.app_settings.append(NameValuePair("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "false"))
else: # must specify runtime
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suggest you don't catch, let it throw unless you can make the error specific

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like i said, you will have to fix the else here to avoid impacting common case

Copy link
Copy Markdown
Contributor

@yugangw-msft yugangw-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more comment to revert an relevant change. Also do enough testing. After these, let me know when I should merge

Comment thread scripts/ci/test_integration.sh Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rebase to get rid of the diff on this file

Lukasz Stempniewicz added 2 commits April 30, 2018 14:24
@LukaszStem
Copy link
Copy Markdown
Author

LGTM

@yugangw-msft yugangw-msft merged commit c7641a4 into Azure:dev Apr 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants