From d4e9490071a5161c3f663e41a99f16b7a091feea Mon Sep 17 00:00:00 2001 From: AllyW Date: Thu, 10 Aug 2023 13:57:09 +0800 Subject: [PATCH] add prop value, norm type value and ignore add type (#418) * add prop value, norm type value and ignore add type --------- Co-authored-by: Li Wang --- HISTORY.rst | 4 ++ azdev/__init__.py | 2 +- azdev/operations/command_change/custom.py | 22 +++++++++ azdev/utilities/__init__.py | 28 ----------- azdev/utilities/config.py | 11 ----- azdev/utilities/const.py | 48 ------------------- azure-cli-diff-tool/HISTORY.rst | 5 ++ .../azure_cli_diff_tool/__init__.py | 2 +- .../azure_cli_diff_tool/_const.py | 12 ++--- .../azure_cli_diff_tool/meta_change.py | 12 +++-- .../azure_cli_diff_tool/meta_change_detect.py | 10 ++-- .../tests/jsons/az_monitor_meta_after.json | 6 +-- .../tests/test_break_change.py | 4 +- 13 files changed, 59 insertions(+), 107 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 6cbe16639..bed28f527 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,10 @@ Release History =============== +0.1.59 +++++++ +* `azdev command-change meta-export`: Normalize basic cmd types: str, bool, int, float + 0.1.58 ++++++ * Fix cmdcov issue(#417): Any name of a parameter has been tested, the parameter should be considered as passing the parameter test coverage. diff --git a/azdev/__init__.py b/azdev/__init__.py index 2671cf5b8..27f13c164 100644 --- a/azdev/__init__.py +++ b/azdev/__init__.py @@ -4,4 +4,4 @@ # license information. # ----------------------------------------------------------------------------- -__VERSION__ = '0.1.58' +__VERSION__ = '0.1.59' diff --git a/azdev/operations/command_change/custom.py b/azdev/operations/command_change/custom.py index 6350f2433..42a8b041b 100644 --- a/azdev/operations/command_change/custom.py +++ b/azdev/operations/command_change/custom.py @@ -67,6 +67,27 @@ def process_arg_type(argument_settings, para): para["type"] = raw_type if raw_type in ["str", "int", "float", "bool", "file_type"] else "custom_type" +def normalize_para_types(para): + type_string_opts = ["string", "str", "aazstrarg", + "aazresourcelocationarg", "aazresourcegroupnamearg", "aazresourceidarg", + "aazpaginationtokenarg", "aazfilearg"] + + type_int_opts = ["int", "aazintarg", "aazpaginationlimitarg"] + type_float_opts = ["float", "aazfloatarg"] + type_bool_opts = ["boolean", "bool", "aazboolarg", "aazgenericupdateforcestringarg"] + + def normalize_para_type(type_opts, value): + if para.get("type", None) and para["type"].lower() in type_opts: + para["type"] = value + if para.get("aaz_type", None) and para["aaz_type"].lower() in type_opts: + para["aaz_type"] = value + + normalize_para_type(type_string_opts, "string") + normalize_para_type(type_int_opts, "int") + normalize_para_type(type_float_opts, "float") + normalize_para_type(type_bool_opts, "bool") + + def gen_command_meta(command_info, with_help=False, with_example=False): stored_property_when_exist = ["confirmation", "supports_no_wait", "is_preview"] command_meta = { @@ -118,6 +139,7 @@ def gen_command_meta(command_info, with_help=False, with_example=False): para["desc"] = settings["help"] if command_info["is_aaz"] and command_info["az_arguments_schema"]: process_aaz_argument(command_info["az_arguments_schema"], settings, para) + normalize_para_types(para) parameters.append(para) command_meta["parameters"] = parameters return command_meta diff --git a/azdev/utilities/__init__.py b/azdev/utilities/__init__.py index ad1aa52d4..e00924255 100644 --- a/azdev/utilities/__init__.py +++ b/azdev/utilities/__init__.py @@ -9,8 +9,6 @@ get_azure_config_dir, get_azdev_config, get_azdev_config_dir, - get_change_rule_template, - get_change_suggest_template ) from .command import ( call, @@ -20,18 +18,6 @@ CommandError ) from .const import ( - BREAKING_CHANE_RULE_LINK_URL_PREFIX, - BREAKING_CHANE_RULE_LINK_URL_SUFFIX, - CMD_PROPERTY_ADD_BREAK_LIST, - CMD_PROPERTY_REMOVE_BREAK_LIST, - CMD_PROPERTY_UPDATE_BREAK_LIST, - CMD_PROPERTY_IGNORED_LIST, - PARA_PROPERTY_ADD_BREAK_LIST, - PARA_PROPERTY_REMOVE_BREAK_LIST, - PARA_PROPERTY_UPDATE_BREAK_LIST, - PARA_NAME_IGNORED_LIST, - PARA_PROPERTY_IGNORED_LIST, - PARA_VALUE_IGNORED_LIST, COMMAND_MODULE_PREFIX, EXTENSION_PREFIX, IS_WINDOWS, @@ -73,18 +59,6 @@ __all__ = [ 'COMMAND_MODULE_PREFIX', 'EXTENSION_PREFIX', - 'BREAKING_CHANE_RULE_LINK_URL_PREFIX', - 'BREAKING_CHANE_RULE_LINK_URL_SUFFIX', - 'CMD_PROPERTY_ADD_BREAK_LIST', - 'CMD_PROPERTY_REMOVE_BREAK_LIST', - 'CMD_PROPERTY_UPDATE_BREAK_LIST', - 'CMD_PROPERTY_IGNORED_LIST', - 'PARA_PROPERTY_ADD_BREAK_LIST', - 'PARA_PROPERTY_REMOVE_BREAK_LIST', - 'PARA_PROPERTY_UPDATE_BREAK_LIST', - 'PARA_NAME_IGNORED_LIST', - 'PARA_PROPERTY_IGNORED_LIST', - 'PARA_VALUE_IGNORED_LIST', 'display', 'output', 'heading', @@ -102,8 +76,6 @@ 'get_azure_config', 'get_azdev_config_dir', 'get_azdev_config', - 'get_change_rule_template', - 'get_change_suggest_template', 'ENV_VAR_TEST_MODULES', 'ENV_VAR_TEST_LIVE', 'ENV_VAR_VIRTUAL_ENV', diff --git a/azdev/utilities/config.py b/azdev/utilities/config.py index d5dbb864d..69a5d0e39 100644 --- a/azdev/utilities/config.py +++ b/azdev/utilities/config.py @@ -7,7 +7,6 @@ import os from knack.config import CLIConfig -from .const import CHANGE_RULE_MESSAGE_MAPPING, CHANGE_SUGGEST_MESSAGE_MAPPING def get_azdev_config(): @@ -32,13 +31,3 @@ def get_azdev_config_dir(): def get_azure_config_dir(): """ Returns the user's Azure directory. """ return os.getenv('AZURE_CONFIG_DIR', None) or os.path.expanduser(os.path.join('~', '.azure')) - - -def get_change_rule_template(rule_id="1000"): - """ Return the rule message template""" - return CHANGE_RULE_MESSAGE_MAPPING.get(rule_id, "Non applicable") - - -def get_change_suggest_template(rule_id="1000"): - """ Return the change suggest message template""" - return CHANGE_SUGGEST_MESSAGE_MAPPING.get(rule_id, "Non applicable") diff --git a/azdev/utilities/const.py b/azdev/utilities/const.py index 7412175a4..d0db79008 100644 --- a/azdev/utilities/const.py +++ b/azdev/utilities/const.py @@ -14,51 +14,3 @@ ENV_VAR_TEST_MODULES = 'AZDEV_TEST_TESTS' # comma-separated list of modules to test ENV_VAR_VIRTUAL_ENV = ['VIRTUAL_ENV', 'CONDA_PREFIX'] # used by system to identify virtual environment ENV_VAR_TEST_LIVE = 'AZURE_TEST_RUN_LIVE' # denotes that tests should be run live instead of played back - -BREAKING_CHANE_RULE_LINK_URL_PREFIX = "https://github.com/Azure/azure-cli/blob/dev/doc/breaking_change_rules/" -BREAKING_CHANE_RULE_LINK_URL_SUFFIX = ".md" - -CMD_PROPERTY_REMOVE_BREAK_LIST = [] -CMD_PROPERTY_ADD_BREAK_LIST = ["confirmation"] -CMD_PROPERTY_UPDATE_BREAK_LIST = [] -CMD_PROPERTY_IGNORED_LIST = ["is_aaz", "supports_no_wait"] - -PARA_PROPERTY_REMOVE_BREAK_LIST = ["options", "id_part", "nargs"] -PARA_PROPERTY_ADD_BREAK_LIST = ["required", "choices", "type"] -PARA_PROPERTY_UPDATE_BREAK_LIST = ["default", "aaz_default", "type"] -PARA_NAME_IGNORED_LIST = ["force_string"] -PARA_PROPERTY_IGNORED_LIST = [] -PARA_VALUE_IGNORED_LIST = ["generic_update_set", "generic_update_add", "generic_update_remove", - "generic_update_force_string"] - -CHANGE_RULE_MESSAGE_MAPPING = { - "1000": "default Message", - "1001": "cmd `{0}` added", - "1002": "cmd `{0}` removed", - "1003": "cmd `{0}` added property `{1}`", - "1004": "cmd `{0}` removed property `{1}`", - "1005": "cmd `{0}` updated property `{1}` from `{2}` to `{3}`", - "1006": "cmd `{0}` added parameter `{1}`", - "1007": "cmd `{0}` removed parameter `{1}`", - "1008": "cmd `{0}` update parameter `{1}`: added property `{2}`", - "1009": "cmd `{0}` update parameter `{1}`: removed property `{2}`", - "1010": "cmd `{0}` update parameter `{1}`: updated property `{2}` from `{3}` to `{4}`", - "1011": "sub group `{0}` added", - "1012": "sub group `{0}` removed", -} - -CHANGE_SUGGEST_MESSAGE_MAPPING = { - "1000": "default Message", - "1001": "please confirm cmd `{0}` added", - "1002": "please confirm cmd `{0}` removed", - "1003": "please remove property `{0}` for cmd `{1}`", - "1004": "please add back property `{0}` for cmd `{1}`", - "1005": "please change property `{0}` from `{1}` to `{2}` for cmd `{3}`", - "1006": "please remove parameter `{0}` for cmd `{1}`", - "1007": "please add back parameter `{0}` for cmd `{1}`", - "1008": "please remove property `{0}` for parameter `{1}` for cmd `{2}`", - "1009": "please add back property `{0}` for parameter {1}` for cmd `{2}`", - "1010": "please change property `{0}` from `{1}` to `{2}` for parameter `{3}` of cmd `{4}`", - "1011": "please confirm sub group `{0}` added", - "1012": "please confirm sub group `{0}` removed", -} diff --git a/azure-cli-diff-tool/HISTORY.rst b/azure-cli-diff-tool/HISTORY.rst index 37eba3ce5..e0ea97320 100644 --- a/azure-cli-diff-tool/HISTORY.rst +++ b/azure-cli-diff-tool/HISTORY.rst @@ -2,6 +2,11 @@ Release History =============== +0.0.3 +++++++ +* Add prop value for parameter add/remove property +* Remove type add break justification + 0.0.2 ++++++ * Change time consuming into info log level diff --git a/azure-cli-diff-tool/azure_cli_diff_tool/__init__.py b/azure-cli-diff-tool/azure_cli_diff_tool/__init__.py index 97f48140a..17644980a 100644 --- a/azure-cli-diff-tool/azure_cli_diff_tool/__init__.py +++ b/azure-cli-diff-tool/azure_cli_diff_tool/__init__.py @@ -18,7 +18,7 @@ extract_module_name_from_meta_file, export_meta_changes_to_csv, export_meta_changes_to_json, \ export_meta_changes_to_dict -__VERSION__ = '0.0.2' +__VERSION__ = '0.0.3' logger = logging.getLogger(__name__) diff --git a/azure-cli-diff-tool/azure_cli_diff_tool/_const.py b/azure-cli-diff-tool/azure_cli_diff_tool/_const.py index edafd36b5..28c260073 100644 --- a/azure-cli-diff-tool/azure_cli_diff_tool/_const.py +++ b/azure-cli-diff-tool/azure_cli_diff_tool/_const.py @@ -23,8 +23,8 @@ CMD_PROPERTY_IGNORED_LIST = ["is_aaz", "supports_no_wait"] PARA_PROPERTY_REMOVE_BREAK_LIST = ["options", "id_part", "nargs"] -PARA_PROPERTY_ADD_BREAK_LIST = ["required", "choices", "type"] -PARA_PROPERTY_UPDATE_BREAK_LIST = ["default", "aaz_default", "type"] +PARA_PROPERTY_ADD_BREAK_LIST = ["required", "choices"] +PARA_PROPERTY_UPDATE_BREAK_LIST = ["default", "aaz_default", "type", "aaz_type"] PARA_NAME_IGNORED_LIST = ["force_string"] PARA_PROPERTY_IGNORED_LIST = [] PARA_VALUE_IGNORED_LIST = ["generic_update_set", "generic_update_add", "generic_update_remove", @@ -42,8 +42,8 @@ "1005": "cmd `{0}` updated property `{1}` from `{2}` to `{3}`", "1006": "cmd `{0}` added parameter `{1}`", "1007": "cmd `{0}` removed parameter `{1}`", - "1008": "cmd `{0}` update parameter `{1}`: added property `{2}`", - "1009": "cmd `{0}` update parameter `{1}`: removed property `{2}`", + "1008": "cmd `{0}` update parameter `{1}`: added property `{2}={3}`", + "1009": "cmd `{0}` update parameter `{1}`: removed property `{2}={3}`", "1010": "cmd `{0}` update parameter `{1}`: updated property `{2}` from `{3}` to `{4}`", "1011": "sub group `{0}` added", "1012": "sub group `{0}` removed", @@ -58,8 +58,8 @@ "1005": "please change property `{0}` from `{1}` to `{2}` for cmd `{3}`", "1006": "please remove parameter `{0}` for cmd `{1}`", "1007": "please add back parameter `{0}` for cmd `{1}`", - "1008": "please remove property `{0}` for parameter `{1}` for cmd `{2}`", - "1009": "please add back property `{0}` for parameter {1}` for cmd `{2}`", + "1008": "please remove property `{0}={1}` for parameter `{2}` of cmd `{3}`", + "1009": "please add back property `{0}={1}` for parameter `{2}` of cmd `{3}`", "1010": "please change property `{0}` from `{1}` to `{2}` for parameter `{3}` of cmd `{4}`", "1011": "please confirm sub group `{0}` added", "1012": "please confirm sub group `{0}` removed", diff --git a/azure-cli-diff-tool/azure_cli_diff_tool/meta_change.py b/azure-cli-diff-tool/azure_cli_diff_tool/meta_change.py index 583648b20..ddd123e37 100644 --- a/azure-cli-diff-tool/azure_cli_diff_tool/meta_change.py +++ b/azure-cli-diff-tool/azure_cli_diff_tool/meta_change.py @@ -178,7 +178,7 @@ def __init__(self, cmd_name, para_name, is_break=False): class ParaPropAdd(MetaChange): - def __init__(self, cmd_name, para_name, para_property, is_break=False): + def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break=False): if not cmd_name or not para_name or not para_property: raise Exception("cmd name, parameter name and parameter property needed") self.rule_id = "1008" @@ -186,11 +186,13 @@ def __init__(self, cmd_name, para_name, para_property, is_break=False): self.cmd_name = cmd_name self.para_name = para_name self.para_prop = para_property + self.para_prop_value = para_prop_value self.is_break = is_break self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.para_name, - self.para_prop) + self.para_prop, self.para_prop_value) self.suggest_message = get_change_suggest_template(self.rule_id).format(self.para_prop, + self.para_prop_value, self.para_name, self.cmd_name) if self.is_break else "" if para_property in PARA_PROPERTY_IGNORED_LIST or para_name in PARA_NAME_IGNORED_LIST: @@ -200,7 +202,7 @@ def __init__(self, cmd_name, para_name, para_property, is_break=False): class ParaPropRemove(MetaChange): - def __init__(self, cmd_name, para_name, para_property, is_break=False): + def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break=False): if not cmd_name or not para_name or not para_property: raise Exception("cmd name, parameter name and parameter property needed") self.rule_id = "1009" @@ -208,11 +210,13 @@ def __init__(self, cmd_name, para_name, para_property, is_break=False): self.cmd_name = cmd_name self.para_name = para_name self.para_prop = para_property + self.para_prop_value = para_prop_value self.is_break = is_break self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.para_name, - self.para_prop) + self.para_prop, self.para_prop_value) self.suggest_message = get_change_suggest_template(self.rule_id).format(self.para_prop, + self.para_prop_value, self.para_name, self.cmd_name) if self.is_break else "" if para_property in PARA_PROPERTY_IGNORED_LIST or para_name in PARA_NAME_IGNORED_LIST: diff --git a/azure-cli-diff-tool/azure_cli_diff_tool/meta_change_detect.py b/azure-cli-diff-tool/azure_cli_diff_tool/meta_change_detect.py index c609a8b82..2ae01a5f2 100644 --- a/azure-cli-diff-tool/azure_cli_diff_tool/meta_change_detect.py +++ b/azure-cli-diff-tool/azure_cli_diff_tool/meta_change_detect.py @@ -209,18 +209,20 @@ def check_cmd_parameter_diff(self, cmd_name, base_parameters, cmp_parameters): continue if prop in base_para_obj and prop not in cmp_para_obj: # prop dropped in new para obj + prop_value = base_para_obj[prop] if prop in PARA_PROPERTY_REMOVE_BREAK_LIST: - diff_obj = ParaPropRemove(cmd_name, base_para_obj["name"], prop, True) + diff_obj = ParaPropRemove(cmd_name, base_para_obj["name"], prop, prop_value, True) else: - diff_obj = ParaPropRemove(cmd_name, base_para_obj["name"], prop, False) + diff_obj = ParaPropRemove(cmd_name, base_para_obj["name"], prop, prop_value, False) self.diff_objs.append(diff_obj) continue if prop not in base_para_obj and prop in cmp_para_obj: # prop added in new para obj + prop_value = cmp_para_obj[prop] if prop in PARA_PROPERTY_ADD_BREAK_LIST: - diff_obj = ParaPropAdd(cmd_name, base_para_obj["name"], prop, True) + diff_obj = ParaPropAdd(cmd_name, base_para_obj["name"], prop, prop_value, True) else: - diff_obj = ParaPropAdd(cmd_name, base_para_obj["name"], prop, False) + diff_obj = ParaPropAdd(cmd_name, base_para_obj["name"], prop, prop_value, False) self.diff_objs.append(diff_obj) continue # prop exists in both new and old para obj, value needs to be checked diff --git a/azure-cli-diff-tool/tests/jsons/az_monitor_meta_after.json b/azure-cli-diff-tool/tests/jsons/az_monitor_meta_after.json index 52fbee5d0..3090c9fd2 100644 --- a/azure-cli-diff-tool/tests/jsons/az_monitor_meta_after.json +++ b/azure-cli-diff-tool/tests/jsons/az_monitor_meta_after.json @@ -106,12 +106,12 @@ "parameters": [{ "name": "resource_group_name", "options": ["--resource-group", "-g"], - "required": true, - "id_part": "resource_group" + "required": true }, { "name": "scope_name", "options": ["--scope-name"], - "required": true + "required": true, + "type": "string" }, { "name": "cmd", "options": ["--cmd"], diff --git a/azure-cli-diff-tool/tests/test_break_change.py b/azure-cli-diff-tool/tests/test_break_change.py index d61e4b25e..8826e3f61 100644 --- a/azure-cli-diff-tool/tests/test_break_change.py +++ b/azure-cli-diff-tool/tests/test_break_change.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # ----------------------------------------------------------------------------- - +# pylint: disable=line-too-long import unittest import os @@ -52,6 +52,8 @@ def test_diff_meta(self): target_message = [ "please confirm cmd `monitor private-link-scope scoped-resource show` removed", "sub group `monitor private-link-scope private-endpoint-connection cust` removed", + "cmd `monitor private-link-scope private-link-resource list` update parameter `scope_name`: added property `type=string`", + "cmd `monitor private-link-scope private-link-resource list` update parameter `resource_group_name`: removed property `id_part=resource_group`" ] for mes in target_message: found = False