Skip to content

Conversation

@jorgecotillo
Copy link
Contributor

@jorgecotillo jorgecotillo commented May 19, 2020

Description

  • Add --skip-resource-name-params argument which removes the use of parameters from name properties
  • Add --skip-all-params argument which removes the use of all parameters from the response
  • Add

--resource-ids argument to filter the results based on a string containing whitespace-separated

Testing Guide

  • To export all resource templates from a resource group without resource name parameterization: az group export --name contoso_rg --skip-resource-name-params --resource-ids "*"
  • To export all resource templates from a resource group without parameters: az group export --name contoso_rg --skip-all-params --resource-ids "*"

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

@yonzhan yonzhan added this to the S170 milestone May 19, 2020
@yonzhan
Copy link
Collaborator

yonzhan commented May 19, 2020

add to S170

@anthony-c-martin
Copy link
Member

LGTM!

@zhoxing-ms
Copy link
Contributor

zhoxing-ms commented May 21, 2020

@jorgecotillo Hi, I suggest that it might be better to change the PR title, like:
[ARM] az group export: Add new parameters `--skip-resource-name-parameterization` and `--skip-all-parameterization` to support skip parameterization

Please refer to the document when writing PR title: doc link

@zhoxing-ms
Copy link
Contributor

Testing Guide

To export all resource templates from a resource group without resource name parameterization: az resource group export --name contoso_rg --skip-resource-name-parameterization --resource-ids "*"
To export all resource templates from a resource group without parameters: az resource group export --name contoso_rg --skip-all-parameterization --resource-ids "*"

This command should actually be az group export, right?

"type": "python",
"request": "launch",
"pythonPath": "${config:python.pythonPath}",
"pythonPath": "${config:python.interpreterPath}",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it modified here?


def export_group_as_template(
cmd, resource_group_name, include_comments=False, include_parameter_default_value=False):
cmd, resource_group_name, resource_ids=None, include_comments=False, include_parameter_default_value=False, skip_resource_name_parameterization=False, skip_all_parameterization=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

resource_ids=None It is recommended to put the new parameters after the existing parameter of the method

Copy link
Contributor

Choose a reason for hiding this comment

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

--skip-all-parameterization and --skip-resource-name-parameterization are too long for the customers to input. Could you make them shorter?

Copy link

@azcloudfarmer azcloudfarmer May 22, 2020

Choose a reason for hiding this comment

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

How about --skip-all-params and --skip-resource-name-params? @jorgecotillo

Comment on lines 1057 to 1058
raise CLIError('az resource: error: argument --resource_ids: invalid ResourceId value: \'%s\'' % i)

Copy link
Contributor

Choose a reason for hiding this comment

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

--resource_ids --> --resource-ids


self.cmd('network vnet create -g {rg} -n {vnet}')
self.kwargs['vnet_id'] = self.cmd('network vnet show -g {rg} -n {vnet}').get_output_in_json()['id']
result = self.cmd('group export --name {rg} --resource-ids "{vnet_id}" --skip-all-parameterization --query "contentVersion"')
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add checks to this test to confirm whether the --skip-all-parameterization is effective?


self.cmd('network vnet create -g {rg} -n {vnet}')
self.kwargs['vnet_id'] = self.cmd('network vnet show -g {rg} -n {vnet}').get_output_in_json()['id']
result = self.cmd('group export --name {rg} --resource-ids "{vnet_id}" --skip-resource-name-parameterization --query "contentVersion"')
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add checks to this test to confirm whether the --skip-resource-name-parameterization is effective?

@jorgecotillo jorgecotillo changed the title [ARM] Add new options to az resource group export [ARM] az group export: Add new parameters --skip-resource-name-parameterization and --skip-all-parameterization to support skip parameterization May 22, 2020
@jorgecotillo jorgecotillo changed the title [ARM] az group export: Add new parameters --skip-resource-name-parameterization and --skip-all-parameterization to support skip parameterization [ARM] az group export: Add new parameters --skip-resource-name-params and --skip-all-params to support skip parameterization May 22, 2020
@jorgecotillo
Copy link
Contributor Author

Can someone give me a hint on how to solve the following issue:

AssertionError: No match for the request (<Request (PUT) https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_rg_scenario000001/providers/Microsoft.Network/virtualNetworks/vnet1?api-version=2020-04-01>) was found. Can't overwrite existing cassette ('/home/vsts/work/1/s/src/azure-cli/azure/cli/command_modules/resource/tests/latest/recordings/test_resource_group_export_skip_all_params.yaml') in your current record mode ('once').

When I run the test locally, I get vnet api-version 2020-03-01, I just merged the latest from master and still seeing the same api-version and an additional error: test_resource_scenario is also complaining.

Can I get some assistance please?

@zhoxing-ms
Copy link
Contributor

Can someone give me a hint on how to solve the following issue:
AssertionError: No match for the request (<Request (PUT) https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_rg_scenario000001/providers/Microsoft.Network/virtualNetworks/vnet1?api-version=2020-04-01>) was found. Can't overwrite existing cassette ('/home/vsts/work/1/s/src/azure-cli/azure/cli/command_modules/resource/tests/latest/recordings/test_resource_group_export_skip_all_params.yaml') in your current record mode ('once').
When I run the test locally, I get vnet api-version 2020-03-01, I just merged the latest from master and still seeing the same api-version and an additional error: test_resource_scenario is also complaining.
Can I get some assistance please?

@jorgecotillo Hi, this problem is because the version of ResourceType.MGMT_NETWORK was upgraded in the dev branch at 05-21. You need to merge with dev branch and retest locally for record.

@jorgecotillo
Copy link
Contributor Author

jorgecotillo commented May 26, 2020

@zhoxing-ms merged from dev and now seeing different errors ...

env/lib/python3.8/site-packages/_pytest/junitxml.py:417
/home/vsts/work/1/s/env/lib/python3.8/site-packages/_pytest/junitxml.py:417: PytestDeprecationWarning: The 'junit_family' default value will change to 'xunit2' in pytest 6.0.
Add 'junit_family=xunit1' to your pytest.ini file to keep the current format in future versions of pytest and silence this warning.
_issue_warning_captured(deprecated.JUNIT_XML_DEFAULT_FAMILY, config.hook, 2)

-- Docs: https://docs.pytest.org/en/latest/warnings.html

  • generated xml file: /home/vsts/.azdev/env_config/home/vsts/work/1/s/env/test_results.xml -
    =========================== short test summary info ============================
    FAILED src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_cli_version.py::VersionTest::test_version
    !!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
    ==================== 1 failed, 6 passed, 1 warning in 1.47s ====================

@zhoxing-ms
Copy link
Contributor

zhoxing-ms commented May 26, 2020

@jorgecotillo This is a known issue: the problem is caused by an incompatibility with Python 3.8 in the azure-python-devtools project on which azure-cli-testsdk is dependent

self = <contextlib.ExitStack object at 0x7f4b609ab070>, exc_details = ()
    def __exit__(self, *exc_details):
>       received_exc = exc_details[0] is not None
E       IndexError: tuple index out of range

We already have a PR follow-up to solve this problem: #13661


def export_group_as_template(
cmd, resource_group_name, include_comments=False, include_parameter_default_value=False):
cmd, resource_group_name, include_comments=False, include_parameter_default_value=False, resource_ids=None, skip_resource_name_params=False, skip_all_params=False):
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 register all new arguments in _params.py? Especially for --resource-ids, which should be an array, right?

Copy link
Contributor Author

@jorgecotillo jorgecotillo May 27, 2020

Choose a reason for hiding this comment

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

Done, had to add nargs to the param.

Comment on lines +1034 to +1035
:param bool skip_resource_name_params: export template and skip resource name parameterization.
:param bool skip_all_params: export template parameter and skip all parameterization.
Copy link
Contributor

Choose a reason for hiding this comment

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

For these parameters, I will recommend you to add them as storage_true and give short name for them.

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.

@yonzhan yonzhan modified the milestones: S170, S171 May 31, 2020
@yonzhan
Copy link
Collaborator

yonzhan commented May 31, 2020

add to S171

@jorgecotillo
Copy link
Contributor Author

@Juliehzl can you please confirm the recent updates? Let me know if they look ok to you or if additional updates are needed.

@zhoxing-ms zhoxing-ms self-requested a review June 2, 2020 02:43
Copy link
Contributor

@zhoxing-ms zhoxing-ms left a comment

Choose a reason for hiding this comment

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

LGTM

@jorgecotillo
Copy link
Contributor Author

@qianwens please let me know if the PR looks good or if updates are required.

@azcloudfarmer
Copy link

@qianwens please let us know if the PR is good to go or if there are any other updates we need to make. Thanks!

self.assertEqual('"1.0.0.0"\n', result.output)

@ResourceGroupPreparer(name_prefix='cli_test_rg_scenario')
def test_resource_group_export_skip_all_params(self, resource_group):
Copy link
Member

Choose a reason for hiding this comment

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

test_resource_group_export_skip_all_params [](start = 8, length = 42)

please also add test case for parameter --resource-ids

export_options.append('SkipAllParameterization')

resources = []
if resource_ids is None or resource_ids == "*":
Copy link
Member

Choose a reason for hiding this comment

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

resource_ids [](start = 31, length = 12)

just to confirm here if it should be resource_ids[0] == "*"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the code.

@jorgecotillo
Copy link
Contributor Author

@Juliehzl @qianwens @zhoxing-ms if the PR looks good, is it possible to merge it please? Otherwise, let me know if there are additional updates required.

@zhoxing-ms zhoxing-ms merged commit d780bb4 into Azure:dev Jun 12, 2020
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.

9 participants