Websites: Add Multicontainer Capabilities#6255
Conversation
|
View a preview at https://prompt.ws/r/Azure/azure-cli/6255 |
129d739 to
d238802
Compare
c5da61f to
68e0227
Compare
yugangw-msft
left a comment
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 " |
There was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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:
- please get rid of loops from encoding->decode->encoding again.
- get rid of the
encodedarguments, 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): |
There was a problem hiding this comment.
I thought the multicontainer_config_file should be used together with multicontainer_config_type, why the opposite?
yugangw-msft
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
why you remove this? Now we won't report anything if none of the arguments are supplied
There was a problem hiding this comment.
validate_linux_create_options() will catch this right?
| 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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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'))) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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
yugangw-msft
left a comment
There was a problem hiding this comment.
Looks much better now.
One more comment, and keep on testing it
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
bc8cf61 to
e0b0e99
Compare
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
i suggest you don't catch, let it throw unless you can make the error specific
There was a problem hiding this comment.
like i said, you will have to fix the else here to avoid impacting common case
a16701c to
87bd7fc
Compare
yugangw-msft
left a comment
There was a problem hiding this comment.
One more comment to revert an relevant change. Also do enough testing. After these, let me know when I should merge
There was a problem hiding this comment.
please rebase to get rid of the diff on this file
1519908 to
b192243
Compare
4fb1872 to
b3bd113
Compare
|
LGTM |
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.