Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

appservice: support to create plan when create a webapp #2550

Merged
merged 2 commits into from
Mar 20, 2017

Conversation

yugangw-msft
Copy link
Contributor

@yugangw-msft yugangw-msft commented Mar 18, 2017

Fix #1369

1.	az group create -n myRG -l eastus
2.	az webapp create -g myRG -n myWeb1 
(this should automatically create a plan named ‘myWeb1_Plan’. CLI will output a warning to communicate)
3.	az webapp create -g myRG -n myWeb2
(CLI will detect whether there is a plan in myRG to use, and then create myWeb2 into ‘myWeb1_Plan’)
4.	az webapp create -g myRG -n myWeb3 –plan myWeb1_Plan
(You can always call out the plan name and CLI will use it if exists; otherwise it will create one)
5.	az group create -n myRG2 -l estsus
6.	az webapp create -g myRG2 -n myWeb4 –plan /subscriptions/…/resourceGroups/myRG/providers/Microsoft.Web/serverfarms/ myWeb1_Plan
(If you create a web in a different group, you can always reference an existing plan by using full id)

@codecov-io
Copy link

codecov-io commented Mar 18, 2017

Codecov Report

Merging #2550 into master will increase coverage by 0.15%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #2550      +/-   ##
==========================================
+ Coverage   72.13%   72.29%   +0.15%     
==========================================
  Files         362      363       +1     
  Lines       19776    19832      +56     
  Branches     2920     2923       +3     
==========================================
+ Hits        14266    14338      +72     
+ Misses       4589     4584       -5     
+ Partials      921      910      -11
Impacted Files Coverage Δ
...ce/azure/cli/command_modules/appservice/_params.py 94.39% <100%> (+0.45%) ⬆️
...ice/azure/cli/command_modules/appservice/custom.py 72.92% <100%> (+0.27%) ⬆️
...zure/cli/command_modules/appservice/_validators.py 100% <100%> (ø)
src/azure-cli-core/azure/cli/core/_output.py 61.4% <0%> (-1.17%) ⬇️
...li-core/azure/cli/core/test_utils/vcr_test_base.py 73.68% <0%> (-0.62%) ⬇️
...-cli-role/azure/cli/command_modules/role/custom.py 17.89% <0%> (ø) ⬆️
...dback/azure/cli/command_modules/feedback/custom.py 34.69% <0%> (ø) ⬆️
...-cli-sql/azure/cli/command_modules/sql/commands.py 100% <0%> (ø) ⬆️
...e-cli-acs/azure/cli/command_modules/acs/_params.py 69.09% <0%> (ø) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 232beb7...910fd65. Read the comment docs.

@lostintangent
Copy link
Member

@yugangw-msft You are my hero! This looks awesome.

sku_arg_type = CliArgumentType(help='The pricing tiers, e.g., F1(Free), D1(Shared), B1(Basic Small), B2(Basic Medium), B3(Basic Large), S1(Standard Small), P1(Premium Small), etc',
**enum_choice_list(['F1', 'FREE', 'D1', 'SHARED', 'B1', 'B2', 'B3', 'S1', 'S2', 'S3', 'P1', 'P2', 'P3']))
_SKU_HELP = 'The pricing tiers, e.g., F1(Free), D1(Shared), B1(Basic Small), B2(Basic Medium), B3(Basic Large), S1(Standard Small), P1(Premium Small), etc'
_SKU_LIST = ['F1', 'FREE', 'D1', 'SHARED', 'B1', 'B2', 'B3', 'S1', 'S2', 'S3', 'P1', 'P2', 'P3']
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get this metadata from SDK? It doesn't feel right for SDK to hard-code service options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, it is not right. But it is a known webapp api pattern, that offers no enum or choices. Yep, this makes lives a bit harder for client apps

'plan {}. Please use --plan to specify a new plan'.format(namespace.plan))



Copy link
Contributor

Choose a reason for hiding this comment

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

Extra empty line. Didn't pylint complain?

Copy link
Member

Choose a reason for hiding this comment

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

Apparently not or it would not have passed CI 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will not be a pylint error, rather PEP 8 style check should catch it. I have opened #2562 to get that done.

from azure.cli.core._util import CLIError
from azure.cli.command_modules.appservice._validators import process_webapp_create_namespace

class TestValidators(unittest.TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

Two empty lines between top level structures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This style check error will be fixed through #2562.

JMESPathCheck('length(@)', 0)
])

class WebappSimpleCreateTest(ResourceGroupVCRTestBase):
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest write new tests using ScenarioTest base class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

from azure.cli.core._util import CLIError
from azure.cli.core.commands.validators import get_default_location_from_resource_group

def _validate_plan_arg(namespace):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is necessary to initial the function name with an underline. The module name itself already indicate its a private module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

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

Want to review this before merged.

Copy link
Member

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

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

Overall, looks good. A couple questions and I would suggest you implement Troy's recommendations before merging.

register_cli_argument('appservice web create', 'create_plan', ignore_type)
register_cli_argument('appservice web create', 'plan', arg_group='AppService Plan',
options_list=('--plan', '-p'), completer=get_resource_name_completion_list('Microsoft.Web/serverFarms'),
help='Appservice plan name. Can also reference an existing subnet by ID. If omitted, an appropriate plan in the same resource group will be selected automatically, or a new one will be created.')
Copy link
Member

Choose a reason for hiding this comment

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

Copy/paste error? "Can also reference an existing subnet by ID"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

'plan {}. Please use --plan to specify a new plan'.format(namespace.plan))



Copy link
Member

Choose a reason for hiding this comment

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

Apparently not or it would not have passed CI 😁

def _match_plan_location(plan, location):
# the problem with appservice is it uses display name, rather canonical name
# so we have to hack it
return plan.location.replace(' ', '').lower() == location.lower()
Copy link
Member

Choose a reason for hiding this comment

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

Is this because of a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would say, not a bug, but another anti-pattern in webapp's service.

webapp_def = Site(server_farm_id=plan, location=location)
plan_id = plan
if create_plan:
logger.warning("Create appservice plan: '%s'", plan)
Copy link
Member

Choose a reason for hiding this comment

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

Why are we issuing a warning? We don't do this for other creates (VM/VMSS/LB/AG) that create extra resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it before put in a warning. The situation here is a bit different, that we are creating a parent like resource which contains the webapp, and sooner or later users will need to know the existence of the plan for scenarios like scale up/down. This is different with vnet, subnet, etc, which would be mostly transparent to users.

Copy link
Member

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

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

LGTM

@yugangw-msft
Copy link
Contributor Author

@lostintangent, I am merging this one. Please note, I decided to make a separate PR for the command renaming we chatted in #2325. The Webapp team is circulating the naming change and will confirm it no later than this Wednesday.

@yugangw-msft yugangw-msft merged commit 316c37f into Azure:master Mar 20, 2017
@yugangw-msft yugangw-msft deleted the simpleweb branch March 20, 2017 19:50
thegalah pushed a commit to thegalah/azure-cli that referenced this pull request Mar 21, 2017
* Azure/master: (478 commits)
  vm live test: allow more valid power states on vmss test verifications (Azure#2564)
  rbac:catch more graph error (Azure#2567)
  appservice: support to create plan when create a webapp (Azure#2550)
  Update storage tests (Azure#2556)
  Change PEP8 check filter from whitelist to blacklist (Azure#2557)
  Add scenario tests documentation (Azure#2555)
  [ACS] Adding support for configuring a default ACS cluster (Azure#2554)
  [ACS] Provide a short name alias for the orchestrator type flag (Azure#2553)
  Sql Import/Export CLI commands and test (Azure#2538)
  Fix format bug. (Azure#2549)
  [VM/VMSS] Improved disk caching support (Azure#2522)
  VM/VMSS: incorporate credentials validation logic used by portal (Azure#2537)
  Script that creates packaged releases package archive (Azure#2508)
  Adding alias for defaults flag (Azure#2540)
  Add wait commands and --no-wait support (Azure#2524)
  choice list outside of named arguments (Azure#2521)
  Fixed test failure in test_sql_db_mgmt. (Azure#2530)
  core: support login using service principal with a cert (Azure#2457)
  Add note about being in preview (Azure#2512)
  vm:fix distro check mechanism used by disk encryption (Azure#2511)
  ...
@yugangw-msft yugangw-msft restored the simpleweb branch March 28, 2017 19:43
@yugangw-msft yugangw-msft deleted the simpleweb branch March 30, 2017 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants