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

sf ARM cli #4132

Merged
merged 2 commits into from
Aug 28, 2017
Merged

sf ARM cli #4132

merged 2 commits into from
Aug 28, 2017

Conversation

QingChenmsft
Copy link
Contributor

@QingChenmsft QingChenmsft commented Aug 3, 2017


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

General Guidelines

  • The PR has modified HISTORY.rst with an appropriate description of the change (see Modifying change log).

Command Guidelines

  • Each command and parameter has a meaningful description.
  • Each new command has a test.

(see Authoring Command Modules)

@msftclas
Copy link

msftclas commented Aug 3, 2017

@QingChenmsft,
Thanks for your contribution as a Microsoft full-time employee or intern. You do not need to sign a CLA.
Thanks,
Microsoft Pull Request Bot

@@ -14,8 +14,7 @@
<LaunchProvider>Standard Python launcher</LaunchProvider>
<InterpreterId>MSBuild|{54f4b6dc-0859-46dc-99bb-b275c9d0aca3}|$(MSBuildProjectFullPath)</InterpreterId>
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
<CommandLineArguments>
</CommandLineArguments>
<CommandLineArguments>sf cluster new -g tcli5 -l westus --cluster-size 1 --certificate-subject-name test.com --certificate-output-folder c:\test --vm-password User@123456789</CommandLineArguments>
Copy link
Member

Choose a reason for hiding this comment

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

Remove this from the project file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay.

@@ -378,7 +378,7 @@ def get_command_table(module_name=None):
If the module is not found, all commands are loaded.
'''
loaded = False
if module_name and module_name not in BLACKLISTED_MODS:
if module_name and module_name not in BLACKLISTED_MODS and module_name != 'sf':
Copy link
Member

Choose a reason for hiding this comment

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

Add a TODO to remove this later.
Would you remove once the old module has been deprecated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.

- name: Specify an existing Certificate resource in a key vault and a custom template to deploy a cluster
text: >
az sf cluster new -g group-name -n cluster1 -l westus --template-file c:\\template.json --parameter-file c:\\parameter.json
--secret-identifier https://chackokv1.vault.azure.net:443/secrets/chackdantestcertificate4/56ec774dc61a462bbc645ffc9b4b225f
Copy link
Member

Choose a reason for hiding this comment

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

This points to a real keyvault... would suggest something else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed.

Copy link
Member

Choose a reason for hiding this comment

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

This still looks like real data rather than example data.

help='The password of the certificate file.')
register_cli_argument('sf', 'certificate_subject_name',options_list=('--certificate-subject-name', '-sn','-csn'),
help='The subject name of the certificate to be created.')
register_cli_argument('sf', 'vault_resource_group_name',options_list=('--vault-resource-group', '-vg','-vrg'),
Copy link
Member

Choose a reason for hiding this comment

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

This looks really strange. 3 options for the same argument?
Also, in the CLI I've only seen short form options that have a single char not 2 or 3.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, short options must only be a single character. If they are multi-character, they should be preceded by --. And it is highly unusually to have multiple long-options in the CLI. Only when one is going to be deprecated in a future release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove other 2.


from os.path import exists, join
from OpenSSL import crypto

Copy link
Member

Choose a reason for hiding this comment

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

Nothing in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed.

class ServiceFabricTest(ScenarioTest):
def test_list_storage_account(self):
cluster_list = self.cmd('az sf cluster list').get_output_in_json()
assert len(cluster_list) > 0
Copy link
Member

Choose a reason for hiding this comment

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

Need more tests than this.
There are several new commands added and lots of custom logic to be tested.

Copy link
Member

Choose a reason for hiding this comment

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

Not only should you cover all of your new commands, you should exercise as many of your parameters as possible. There are many parameter registrations that have nothing more than help='Text..'. Usually more kwargs are necessary to support relevant scenarios.

'azure.cli.command_modules.servicefabric'
],
install_requires=DEPENDENCIES,
)
Copy link
Member

Choose a reason for hiding this comment

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

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.

Test coverage is inadequate. We need to see the <command> -h output for each of the "interesting" commands (creates, updates, adds). I would recommend setting up a quick meeting to go over your command tree structure.

@@ -529,7 +547,6 @@
<Compile Include="command_modules\azure-cli-component\azure\cli\command_modules\component\custom.py" />
<Compile Include="command_modules\azure-cli-component\azure\cli\command_modules\component\commands.py" />
<Compile Include="command_modules\azure-cli-component\azure\cli\command_modules\component\_params.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\custom.py" />
Copy link
Member

Choose a reason for hiding this comment

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

Revert this change.

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

Choose a reason for hiding this comment

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

This still is showing as being removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, should be fixed now.

type: command
short-summary: Add a secondary cluster certificate to the cluster.
examples:
- name: Example1
Copy link
Member

Choose a reason for hiding this comment

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

Needs more descriptive name than "Example1" "Example2"...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed.

Copy link
Member

Choose a reason for hiding this comment

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

Still says Example1, Example2...

# PARAMETER REGISTRATIONS

register_cli_argument('sf cluster list', 'resource_group_name', resource_group_name_type,
id_part=None, required=False, help='The resouce group name')
Copy link
Member

Choose a reason for hiding this comment

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

"requiredness" is inferred from the SDK or custom command signature and does not usually need to be specified here unless the SDK is wrong for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed.


register_cli_argument('sf', 'resource_group_name', resource_group_name_type,
id_part=None, required=True, help='The resouce group name')
register_cli_argument('sf', 'cluster_name',options_list=('--name', '--cluster-name','-n'),
Copy link
Member

Choose a reason for hiding this comment

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

This should be registered as name_type. I'm okay with having both --name and --cluster-name, although that is uncommon in the CLI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

keep it same as our powershell

register_cli_argument('sf', 'location',
validator=get_default_location_from_resource_group)

register_cli_argument('sf', 'secret_identifier',options_list=('--secret-identifier', '-si'),
Copy link
Member

Choose a reason for hiding this comment

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

Short options must be a single letter. Err on the side of no short 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.

removed.


cli_command(__name__, 'sf cluster reliability update', custom_path.format('update_cluster_reliability_level'), factory, no_wait_param=False)

cli_command(__name__, 'sf cluster durability update', custom_path.format('update_cluster_durability'), factory, no_wait_param=False)
Copy link
Member

Choose a reason for hiding this comment

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

You should not have groups (reliability/durability) with only a single command. These could easily be folded into parameters for a sf cluster update command (which is missing BTW) as --reliability-level and --durability-level respectively.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all the command are related to cluster update, we think keeping them this way, which makes user more clear.


cli_command(__name__, 'sf cluster durability update', custom_path.format('update_cluster_durability'), factory, no_wait_param=False)

cli_command(__name__, 'sf cluster node-type add', custom_path.format('add_cluster_node_type'), factory, no_wait_param=False)
Copy link
Member

Choose a reason for hiding this comment

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

There is no node-type remove command.

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 is a bug in our service, we can't have this command ready for now. we will add when we have resolved the issue.


cli_command(__name__, 'sf cluster node remove', custom_path.format('remove_cluster_node'), factory, no_wait_param=False)

cli_command(__name__, 'sf cluster upgrade-type set', custom_path.format('update_cluster_upgrade_type'), factory, no_wait_param=False)
Copy link
Member

Choose a reason for hiding this comment

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

This should also be folded into a sf cluster update command as a parameter. Additionally, whatever parameters are exposed on update should (if feasible) be supported on create as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do not understand, do you mean "'sf cluster upgrade-type set'" should be "sf cluster update upgrade-type"?

Copy link
Member

Choose a reason for hiding this comment

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

I would need more context on your service, but this looks like an entire command to update one parameter, which should not be done. If upgrade-type is a property of a cluster, then there should be a sf cluster update command with --upgrade-type as a parameter.


cli_command(__name__, 'sf cluster upgrade-type set', custom_path.format('update_cluster_upgrade_type'), factory, no_wait_param=False)

cli_command(__name__, 'sf application certificate add', custom_path.format('add_app_cert'), factory, no_wait_param=False)
Copy link
Member

Choose a reason for hiding this comment

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

This is a subcommand with a single subcommand with a single command! Are there going to be more sf application commands? Are there going to be more sf application certificate commands? Why are there no plain sf commands?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, there will be more for application commands.

class ServiceFabricTest(ScenarioTest):
def test_list_storage_account(self):
cluster_list = self.cmd('az sf cluster list').get_output_in_json()
assert len(cluster_list) > 0
Copy link
Member

Choose a reason for hiding this comment

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

Not only should you cover all of your new commands, you should exercise as many of your parameters as possible. There are many parameter registrations that have nothing more than help='Text..'. Usually more kwargs are necessary to support relevant scenarios.

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.

There still seem to be numerous issues.

@@ -529,7 +547,6 @@
<Compile Include="command_modules\azure-cli-component\azure\cli\command_modules\component\custom.py" />
<Compile Include="command_modules\azure-cli-component\azure\cli\command_modules\component\commands.py" />
<Compile Include="command_modules\azure-cli-component\azure\cli\command_modules\component\_params.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\custom.py" />
Copy link
Member

Choose a reason for hiding this comment

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

This still is showing as being removed.

@@ -0,0 +1,4 @@
0.0.1 (2017-8-23)
Copy link
Member

Choose a reason for hiding this comment

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

Should just say "unreleased"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.

short-summary: List all the cluster resource in the same subscription
"""

helps["sf cluster new"] = """
Copy link
Member

Choose a reason for hiding this comment

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

This should be sf cluster create not new.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we want to keep aligned with PowerShell which is New

Copy link
Member

Choose a reason for hiding this comment

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

This will not be accepted. There are 0 "new" commands in the CLI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, i will update, yesterday, i forgot to push the change, you can take a look, i just pushed.

- name: Specify an existing Certificate resource in a key vault and a custom template to deploy a cluster
text: >
az sf cluster new -g group-name -n cluster1 -l westus --template-file c:\\template.json --parameter-file c:\\parameter.json
--secret-identifier https://chackokv1.vault.azure.net:443/secrets/chackdantestcertificate4/56ec774dc61a462bbc645ffc9b4b225f
Copy link
Member

Choose a reason for hiding this comment

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

This still looks like real data rather than example data.

type: command
short-summary: Add a secondary cluster certificate to the cluster.
examples:
- name: Example1
Copy link
Member

Choose a reason for hiding this comment

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

Still says Example1, Example2...

from azure.cli.testsdk.vcr_test_base import (ResourceGroupVCRTestBase,
JMESPathCheck, NoneCheck)

class ServiceFabricNewClusterTest(ResourceGroupVCRTestBase):
Copy link
Member

Choose a reason for hiding this comment

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

This is an older test base--these should really use the ScenarioTest base. Don't change them for this PR, but FYI for the future.

checks=[JMESPathCheck('clientCertificateThumbprints[0].certificateThumbprint', test_thumbprint),
JMESPathCheck('clientCertificateThumbprints[0].isAdmin', False)])

self.cmd('sf cluster client-certificate remove --resource-group {} --name {} --thumbprints {}'.format(rg,name,test_thumbprint),
Copy link
Member

Choose a reason for hiding this comment

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

This needs to test the multi-thumbprint scenario, as I have doubts that it will work the way you have things registered.

self.cmd('sf application certificate add --resource-group {} --cluster-name {} --certificate-subject-name test2.com'.format(rg,name),
checks=NoneCheck())

if __name__ == '__main__':
Copy link
Member

Choose a reason for hiding this comment

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

I might have missed some, but it looks like tests are missing for the following commands:
sf cluster setting remove, sf cluster durability update, sf cluster node-type add, sf cluster node add/remove

register_cli_argument('sf cluster client-certificate', 'certificate_common_name',
help='Specify client certificate common name.')
register_cli_argument('sf cluster client-certificate', 'admin_client_thumbprints',
help='Specify client certificate thumbprint that only has admin permission.')
Copy link
Member

Choose a reason for hiding this comment

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

Remove "Specify..." from these entries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove.

register_cli_argument('sf client certificate', 'certificate_common_name',
help='Specify client certificate common name.')
register_cli_argument('sf client certificate', 'admin_client_thumbprints',
help='Specify list of client certificate thumbprint that only has admin permission.')
Copy link
Member

Choose a reason for hiding this comment

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

How do you specify the list? The only valid lists in the CLI are space-separated lists, and the help should call this out.

from ._client_factory import keyvault_client_factory
from ._client_factory import compute_client_factory
from ._client_factory import storage_client_factory
from ._client_factory import network_client_factory
Copy link
Member

Choose a reason for hiding this comment

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

from ._client_factory import (resource_client_factory, keyvault_client_factory, ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will update.

@lmazuel
Copy link
Member

lmazuel commented Aug 24, 2017

@tjprescott @QingChenmsft https://pypi.python.org/pypi/azure-mgmt-servicefabric/0.1.0

register_cli_argument('sf cluster client-certificate remove', 'thumbprint',
help='a single or list of client certificate thumbprint(s) to be remove.')
register_cli_argument('sf cluster client-certificate remove', 'thumbprints', nargs='+',
help='A single or Space separated list of client certificate thumbprint(s) to be remove.')
Copy link
Member

Choose a reason for hiding this comment

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

You can just say "Space separated list of ...". That's the common pattern in the CLI and no one has ever complained that the didn't realize they could use just one. :)

"""for example: [{"section": "NamingService","parameter": "MaxOperationTimeout","value": 1000},{"section": "MaxFileOperationTimeout","parameter": "Max2","value": 1000]""")
register_cli_argument('sf cluster setting set', 'settings_section_description', type=get_json_object,
help='JSON encoded parameters configuration. Use @{file} to load from a file.'
"""for example: [{"section": "NamingService","parameter": "MaxOperationTimeout","value": 1000},{"section": "MaxFileOperationTimeout","parameter": "Max2","value": 1000]""") # pylint: disable=line-too-long
Copy link
Member

Choose a reason for hiding this comment

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

This would be more appropriate for the parameter long-summary in the helps.py file.


self.cmd('sf cluster list', checks=[JMESPathCheck('type(@)', 'array')])
print('####testing list####')
Copy link
Member

Choose a reason for hiding this comment

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

Please remove these print statements.

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.

Much closer. Still a few commands missing tests, and please remove the print statements in the tests. Otherwise it's little help doc nits that can easily be done in follow-up PRs.

"""for example: [{"section": "NamingService","parameter": "MaxOperationTimeout"}]""")
register_cli_argument('sf cluster setting remove', 'settings_section_description', type=get_json_object,
help='JSON encoded parameters configuration. Use @{file} to load from a file.'
"""for example: [{"section": "NamingService","parameter": "MaxOperationTimeout"}]""")
Copy link
Member

Choose a reason for hiding this comment

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

Why is a JSON object needed for a remove operation?

checks=[JMESPathCheck('nodeTypes[0].durabilityLevel', durability_level)])

print('####testing add app cert###')
self.cmd('sf application certificate add --resource-group {} --cluster-name {} --certificate-subject-name test2.com'.format(rg, name),
Copy link
Member

Choose a reason for hiding this comment

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

Looks like node-type add and node add/remove are still missing.

@derekbekoe
Copy link
Member

** Please check this:

The .json files you've included, should they be shipped as part of your package or are they only for tests? (e.g. azure/cli/command_modules/servicefabric/template/linux/template.json).

If they are required as part of the shipped package, include them e.g. https://github.com/Azure/azure-cli/blob/master/src/command_modules/azure-cli-acr/setup.py#L61.

To verify, run python setup.py bdist_wheel from the directory of your command module. Then open/extract the generated .whl file and confirm that your JSON files are in there.

@QingChenmsft
Copy link
Contributor Author

Hi Derek,
Thanks, can you give me a example how to add this in setup.py ? then I will try to verify it laster.

@derekbekoe
Copy link
Member

@QingChenmsft I included an example in my message above. :)

@codecov-io
Copy link

codecov-io commented Aug 26, 2017

Codecov Report

Merging #4132 into master will decrease coverage by 0.96%.
The diff coverage is 43.26%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4132      +/-   ##
==========================================
- Coverage      70%   69.03%   -0.97%     
==========================================
  Files         475      484       +9     
  Lines       29919    31039    +1120     
  Branches     4627     4850     +223     
==========================================
+ Hits        20945    21429     +484     
- Misses       7490     8030     +540     
- Partials     1484     1580      +96
Impacted Files Coverage Δ
...azure-cli-core/azure/cli/core/commands/__init__.py 69.82% <100%> (ø) ⬆️
...c/azure/cli/command_modules/servicefabric/_help.py 100% <100%> (ø)
..._modules/azure-cli-servicefabric/azure/__init__.py 100% <100%> (ø)
...zure/cli/command_modules/servicefabric/__init__.py 100% <100%> (ø)
...zure/cli/command_modules/servicefabric/commands.py 100% <100%> (ø)
...ervicefabric/azure/cli/command_modules/__init__.py 100% <100%> (ø)
...ules/azure-cli-servicefabric/azure/cli/__init__.py 100% <100%> (ø)
...azure/cli/command_modules/servicefabric/_params.py 100% <100%> (ø)
.../azure/cli/command_modules/servicefabric/custom.py 36.1% <36.1%> (ø)
...i/command_modules/servicefabric/_client_factory.py 76.92% <76.92%> (ø)
... and 13 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 4d67155...38e5e6d. Read the comment docs.

@derekbekoe
Copy link
Member

@tjprescott to take a look also.

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.

Approved with outstanding high-priority issues described in #4328. Futures PRs except for bug fixes to the existing commands (i.e. new commands or new features to commands) will be blocked until #4328 is resolved.

@tjprescott tjprescott merged commit 8d24b5a into Azure:master Aug 28, 2017
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.

7 participants