From c1cecebe0a29d916b17e2224092e5d050570e843 Mon Sep 17 00:00:00 2001 From: AllyW Date: Tue, 2 Jan 2024 15:38:15 +0800 Subject: [PATCH] add diff level to meta changes (#425) * add diff level to meta changes --- azure-cli-diff-tool/HISTORY.rst | 5 + .../azure_cli_diff_tool/__init__.py | 2 +- .../azure_cli_diff_tool/_const.py | 25 +++-- .../azure_cli_diff_tool/meta_change.py | 69 ++++++++------ .../azure_cli_diff_tool/meta_change_detect.py | 92 +++++++++++++------ .../azure_cli_diff_tool/utils.py | 7 ++ .../tests/test_break_change.py | 2 +- 7 files changed, 139 insertions(+), 63 deletions(-) diff --git a/azure-cli-diff-tool/HISTORY.rst b/azure-cli-diff-tool/HISTORY.rst index 6739d161..02128c3e 100644 --- a/azure-cli-diff-tool/HISTORY.rst +++ b/azure-cli-diff-tool/HISTORY.rst @@ -2,6 +2,11 @@ Release History =============== +0.0.5 +++++++ +* Add `DiffLevel` to meta comparison +* Downgrade change level according to warn list + 0.0.4 ++++++ * Add meta change parameter update warn list 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 7739f308..b80872fc 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.4' +__VERSION__ = '0.0.5' 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 a87cc5bb..04d7f060 100644 --- a/azure-cli-diff-tool/azure_cli_diff_tool/_const.py +++ b/azure-cli-diff-tool/azure_cli_diff_tool/_const.py @@ -17,22 +17,35 @@ 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_REMOVE_SUFFIX_WARN_LIST = ["wait"] + CMD_PROPERTY_REMOVE_BREAK_LIST = [] +CMD_PROPERTY_REMOVE_WARN_LIST = [] + CMD_PROPERTY_ADD_BREAK_LIST = ["confirmation"] +CMD_PROPERTY_ADD_WARN_LIST = [] + CMD_PROPERTY_UPDATE_BREAK_LIST = [] +CMD_PROPERTY_UPDATE_WARN_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"] -PARA_PROPERTY_UPDATE_BREAK_LIST = ["default", "aaz_default", "type", "aaz_type"] -PARA_PROPERTY_UPDATE_WARN_LIST = ["type", "aaz_type"] +PARA_PROPERTY_REMOVE_BREAK_LIST = ["options"] +PARA_PROPERTY_REMOVE_WARN_LIST = ["id_part", "nargs"] + +PARA_PROPERTY_ADD_BREAK_LIST = ["required"] +PARA_PROPERTY_ADD_WARN_LIST = ["choices"] + +PARA_PROPERTY_UPDATE_BREAK_LIST = ["default", "aaz_default"] +PARA_PROPERTY_UPDATE_WARN_LIST = ["type", "aaz_type", "choices", "nargs"] + 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"] -EXPORTED_CSV_META_HEADER = ["module", "cmd_name", "rule_id", "rule_name", "is_break", "rule_link_url", - "rule_message", "suggest_message"] +EXPORTED_CSV_META_HEADER = ["module", "cmd_name", "rule_id", "rule_name", "is_break", "diff_level", + "rule_link_url", "rule_message", "suggest_message"] CHANGE_RULE_MESSAGE_MAPPING = { "1000": "default Message", 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 ddd123e3..24224927 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 @@ -4,17 +4,18 @@ # license information. # ----------------------------------------------------------------------------- -from .utils import get_change_rule_template, get_change_suggest_template +from .utils import get_change_rule_template, get_change_suggest_template, DiffLevel from ._const import BREAKING_CHANE_RULE_LINK_URL_PREFIX, BREAKING_CHANE_RULE_LINK_URL_SUFFIX, \ CMD_PROPERTY_IGNORED_LIST, PARA_NAME_IGNORED_LIST, PARA_PROPERTY_IGNORED_LIST, PARA_VALUE_IGNORED_LIST class MetaChange: - def __init__(self, rule_id="1000", is_break=False, rule_message="", suggest_message="", + def __init__(self, rule_id="1000", is_break=False, diff_level=DiffLevel.INFO, rule_message="", suggest_message="", is_ignore=False, filter_key=None): self.rule_id = rule_id self.is_break = is_break + self.diff_level = diff_level self.rule_message = rule_message self.suggest_message = suggest_message self.rule_link_url = BREAKING_CHANE_RULE_LINK_URL_PREFIX + self.rule_id + BREAKING_CHANE_RULE_LINK_URL_SUFFIX @@ -22,7 +23,7 @@ def __init__(self, rule_id="1000", is_break=False, rule_message="", suggest_mess self.filter_key = filter_key def __str__(self): - res = [self.rule_message] + res = [self.rule_message, "diff_level: " + str(self.diff_level.value)] if self.is_break: res.append("is_break: {0}".format(self.is_break)) res.append(self.suggest_message) @@ -30,57 +31,61 @@ def __str__(self): class SubgroupAdd(MetaChange): - def __init__(self, subgroup_name, is_break=False): + def __init__(self, subgroup_name, is_break=False, diff_level=DiffLevel.INFO): if not subgroup_name: raise Exception("sub group name needed") self.rule_id = "1011" self.subgroup_name = subgroup_name self.is_break = is_break + self.diff_level = diff_level self.rule_message = get_change_rule_template(self.rule_id).format(self.subgroup_name) self.suggest_message = get_change_suggest_template(self.rule_id).format(self.subgroup_name) \ if self.is_break else "" - super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message) + super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message) class SubgroupRemove(MetaChange): - def __init__(self, subgroup_name, is_break=True): + def __init__(self, subgroup_name, is_break=True, diff_level=DiffLevel.BREAK): if not subgroup_name: raise Exception("sub group name needed") self.rule_id = "1012" self.subgroup_name = subgroup_name self.is_break = is_break + self.diff_level = diff_level self.rule_message = get_change_rule_template(self.rule_id).format(self.subgroup_name) self.suggest_message = get_change_suggest_template(self.rule_id).format(self.subgroup_name) \ if self.is_break else "" - super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message) + super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message) class CmdAdd(MetaChange): - def __init__(self, cmd_name, is_break=False): + def __init__(self, cmd_name, is_break=False, diff_level=DiffLevel.INFO): if not cmd_name: raise Exception("cmd name needed") self.rule_id = "1001" self.cmd_name = cmd_name self.is_break = is_break + self.diff_level = diff_level self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name) self.suggest_message = get_change_suggest_template(self.rule_id).format(self.cmd_name) if self.is_break else "" - super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message) + super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message) class CmdRemove(MetaChange): - def __init__(self, cmd_name, is_break=True): + def __init__(self, cmd_name, is_break=True, diff_level=DiffLevel.BREAK): if not cmd_name: raise Exception("cmd name needed") self.cmd_name = cmd_name self.rule_id = "1002" self.is_break = is_break + self.diff_level = diff_level self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name) self.suggest_message = get_change_suggest_template(self.rule_id).format(self.cmd_name) if self.is_break else "" - super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message) + super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message) class CmdPropAdd(MetaChange): - def __init__(self, cmd_name, cmd_property, is_break=False): + def __init__(self, cmd_name, cmd_property, is_break=False, diff_level=DiffLevel.INFO): if not cmd_name or not cmd_property: raise Exception("cmd name needed") self.rule_id = "1003" @@ -88,18 +93,19 @@ def __init__(self, cmd_name, cmd_property, is_break=False): self.cmd_name = cmd_name self.cmd_property = cmd_property self.is_break = is_break + self.diff_level = diff_level self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.cmd_property) self.suggest_message = get_change_suggest_template(self.rule_id).format(self.cmd_property, self.cmd_name) \ if self.is_break else "" if cmd_property in CMD_PROPERTY_IGNORED_LIST: self.is_ignore = True self.filter_key = [self.rule_id, self.cmd_name, self.cmd_property] - super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message, self.is_ignore, + super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message, self.is_ignore, self.filter_key) class CmdPropRemove(MetaChange): - def __init__(self, cmd_name, cmd_property, is_break=False): + def __init__(self, cmd_name, cmd_property, is_break=False, diff_level=DiffLevel.BREAK): if not cmd_name or not cmd_property: raise Exception("cmd name needed") self.rule_id = "1004" @@ -107,25 +113,28 @@ def __init__(self, cmd_name, cmd_property, is_break=False): self.cmd_name = cmd_name self.cmd_property = cmd_property self.is_break = is_break + self.diff_level = diff_level self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.cmd_property) self.suggest_message = get_change_suggest_template(self.rule_id).format(self.cmd_property, self.cmd_name) \ if self.is_break else "" if cmd_property in CMD_PROPERTY_IGNORED_LIST: self.is_ignore = True self.filter_key = [self.rule_id, self.cmd_name, self.cmd_property] - super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message, + super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message, self.is_ignore, self.filter_key) class CmdPropUpdate(MetaChange): - def __init__(self, cmd_name, cmd_property, is_break=False, old_value=None, new_value=None): + def __init__(self, cmd_name, cmd_property, is_break=False, diff_level=DiffLevel.INFO, + old_value=None, new_value=None): if not cmd_name or not cmd_property: raise Exception("cmd name and cmd prop needed") self.rule_id = "1005" self.is_ignore = False self.cmd_name = cmd_name self.is_break = is_break + self.diff_level = diff_level self.cmd_prop_updated = cmd_property self.old_value = "" self.new_value = "" @@ -142,43 +151,45 @@ def __init__(self, cmd_name, cmd_property, is_break=False, old_value=None, new_v if cmd_property in CMD_PROPERTY_IGNORED_LIST: self.is_ignore = True self.filter_key = [self.rule_id, self.cmd_name, self.cmd_prop_updated] - super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message, + super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message, self.is_ignore, self.filter_key) class ParaAdd(MetaChange): - def __init__(self, cmd_name, para_name, is_break=False): + def __init__(self, cmd_name, para_name, is_break=False, diff_level=DiffLevel.INFO): if not cmd_name or not para_name: raise Exception("cmd name, parameter name needed") self.rule_id = "1006" self.cmd_name = cmd_name self.para_name = para_name self.is_break = is_break + self.diff_level = diff_level self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.para_name) self.suggest_message = get_change_suggest_template(self.rule_id).format(self.para_name, self.cmd_name) if self.is_break else "" - super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message) + super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message) class ParaRemove(MetaChange): - def __init__(self, cmd_name, para_name, is_break=False): + def __init__(self, cmd_name, para_name, is_break=False, diff_level=DiffLevel.BREAK): if not cmd_name or not para_name: raise Exception("cmd name, parameter name needed") self.rule_id = "1007" self.cmd_name = cmd_name self.para_name = para_name self.is_break = is_break + self.diff_level = diff_level self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.para_name) self.suggest_message = get_change_suggest_template(self.rule_id).format(self.para_name, self.cmd_name) if self.is_break else "" - super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message) + super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message) class ParaPropAdd(MetaChange): - def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break=False): + def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break=False, diff_level=DiffLevel.INFO): 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" @@ -188,6 +199,7 @@ def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break self.para_prop = para_property self.para_prop_value = para_prop_value self.is_break = is_break + self.diff_level = diff_level self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.para_name, self.para_prop, self.para_prop_value) @@ -197,12 +209,12 @@ def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break self.cmd_name) if self.is_break else "" if para_property in PARA_PROPERTY_IGNORED_LIST or para_name in PARA_NAME_IGNORED_LIST: self.is_ignore = True - super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message, self.is_ignore) + super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message, self.is_ignore) class ParaPropRemove(MetaChange): - def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break=False): + def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break=False, diff_level=DiffLevel.BREAK): 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" @@ -212,6 +224,7 @@ def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break self.para_prop = para_property self.para_prop_value = para_prop_value self.is_break = is_break + self.diff_level = diff_level self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.para_name, self.para_prop, self.para_prop_value) @@ -221,12 +234,13 @@ def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break self.cmd_name) if self.is_break else "" if para_property in PARA_PROPERTY_IGNORED_LIST or para_name in PARA_NAME_IGNORED_LIST: self.is_ignore = True - super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message, self.is_ignore) + super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message, self.is_ignore) class ParaPropUpdate(MetaChange): - def __init__(self, cmd_name, para_name, para_property, is_break=False, old_value=None, new_value=None): + def __init__(self, cmd_name, para_name, para_property, is_break=False, diff_level=DiffLevel.INFO, + old_value=None, new_value=None): 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 = "1010" @@ -235,6 +249,7 @@ def __init__(self, cmd_name, para_name, para_property, is_break=False, old_value self.para_name = para_name self.para_prop_updated = para_property self.is_break = is_break + self.diff_level = diff_level self.old_value = None self.new_value = None if old_value is not None: @@ -254,5 +269,5 @@ def __init__(self, cmd_name, para_name, para_property, is_break=False, old_value if self.new_value in PARA_VALUE_IGNORED_LIST or self.old_value in PARA_VALUE_IGNORED_LIST: self.is_ignore = True self.filter_key = [self.rule_id, self.cmd_name, self.para_name, self.para_prop_updated] - super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message, + super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message, self.is_ignore, self.filter_key) 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 2ae01a5f..dfe23448 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 @@ -7,20 +7,26 @@ import logging import os.path -from .utils import get_command_tree, ChangeType, extract_cmd_name, extract_subgroup_name, extract_cmd_property +from .utils import get_command_tree, ChangeType, extract_cmd_name, extract_subgroup_name, extract_cmd_property, DiffLevel from .meta_change import (CmdAdd, CmdRemove, CmdPropAdd, CmdPropRemove, CmdPropUpdate, ParaAdd, ParaRemove, ParaPropAdd, ParaPropRemove, ParaPropUpdate, SubgroupAdd, SubgroupRemove) -from ._const import (CMD_PROPERTY_ADD_BREAK_LIST, CMD_PROPERTY_REMOVE_BREAK_LIST, - CMD_PROPERTY_UPDATE_BREAK_LIST, PARA_PROPERTY_REMOVE_BREAK_LIST, - PARA_PROPERTY_ADD_BREAK_LIST, PARA_PROPERTY_UPDATE_BREAK_LIST, META_CHANDE_WHITELIST_FILE_PATH) +from ._const import (CMD_PROPERTY_ADD_BREAK_LIST, CMD_PROPERTY_ADD_WARN_LIST, + CMD_PROPERTY_REMOVE_BREAK_LIST, CMD_PROPERTY_REMOVE_WARN_LIST, + CMD_PROPERTY_UPDATE_BREAK_LIST, CMD_PROPERTY_UPDATE_WARN_LIST, + PARA_PROPERTY_REMOVE_BREAK_LIST, PARA_PROPERTY_REMOVE_WARN_LIST, + PARA_PROPERTY_ADD_BREAK_LIST, PARA_PROPERTY_ADD_WARN_LIST, + PARA_PROPERTY_UPDATE_BREAK_LIST, PARA_PROPERTY_UPDATE_WARN_LIST, + CMD_REMOVE_SUFFIX_WARN_LIST, + META_CHANDE_WHITELIST_FILE_PATH) logger = logging.getLogger(__name__) class MetaChangeDetect: - EXPORTED_META_PROPERTY = ["rule_id", "rule_link_url", "is_break", "rule_message", "suggest_message", "cmd_name", "subgroup_name"] + EXPORTED_META_PROPERTY = ["rule_id", "rule_link_url", "is_break", "diff_level", + "rule_message", "suggest_message", "cmd_name", "subgroup_name"] CHECKED_PARA_PROPERTY = ["name", "options", "required", "choices", "id_part", "nargs", "default", "desc", "aaz_type", "type", "aaz_default", "aaz_choices"] @@ -90,20 +96,27 @@ def __iter_dict_items(self, dict_items, diff_type): if cmd_property == "parameters": self.__log_cmd_with_parameter_change(cmd_name) elif diff_type == ChangeType.ADD: - if cmd_property in CMD_PROPERTY_ADD_BREAK_LIST: - diff_obj = CmdPropAdd(cmd_name, cmd_property, True) + if cmd_property in CMD_PROPERTY_ADD_WARN_LIST: + diff_obj = CmdPropAdd(cmd_name, cmd_property, False, DiffLevel.WARN) + elif cmd_property in CMD_PROPERTY_ADD_BREAK_LIST: + diff_obj = CmdPropAdd(cmd_name, cmd_property, True, DiffLevel.BREAK) else: - diff_obj = CmdPropAdd(cmd_name, cmd_property, False) + diff_obj = CmdPropAdd(cmd_name, cmd_property, False, DiffLevel.INFO) self.diff_objs.append(diff_obj) else: - if cmd_property in CMD_PROPERTY_REMOVE_BREAK_LIST: - diff_obj = CmdPropRemove(cmd_name, cmd_property, True) + if cmd_property in CMD_PROPERTY_REMOVE_WARN_LIST: + diff_obj = CmdPropRemove(cmd_name, cmd_property, False, DiffLevel.WARN) + elif cmd_property in CMD_PROPERTY_REMOVE_BREAK_LIST: + diff_obj = CmdPropRemove(cmd_name, cmd_property, True, DiffLevel.BREAK) else: - diff_obj = CmdPropRemove(cmd_name, cmd_property, False) + diff_obj = CmdPropRemove(cmd_name, cmd_property, False, DiffLevel.INFO) self.diff_objs.append(diff_obj) else: if diff_type == ChangeType.REMOVE: - diff_obj = CmdRemove(cmd_name) + if cmd_name.split()[-1] in CMD_REMOVE_SUFFIX_WARN_LIST: + diff_obj = CmdRemove(cmd_name, False, DiffLevel.WARN) + else: + diff_obj = CmdRemove(cmd_name, True, DiffLevel.BREAK) else: diff_obj = CmdAdd(cmd_name) @@ -172,10 +185,12 @@ def check_value_change(self): if cmd_property == "parameters": self.__log_cmd_with_parameter_change(cmd_name) else: - if cmd_property in CMD_PROPERTY_UPDATE_BREAK_LIST: - diff_obj = CmdPropUpdate(cmd_name, cmd_property, True, old_value, new_value) + if cmd_property in CMD_PROPERTY_UPDATE_WARN_LIST: + diff_obj = CmdPropUpdate(cmd_name, cmd_property, False, DiffLevel.WARN, old_value, new_value) + elif cmd_property in CMD_PROPERTY_UPDATE_BREAK_LIST: + diff_obj = CmdPropUpdate(cmd_name, cmd_property, True, DiffLevel.BREAK, old_value, new_value) else: - diff_obj = CmdPropUpdate(cmd_name, cmd_property, False, old_value, new_value) + diff_obj = CmdPropUpdate(cmd_name, cmd_property, False, DiffLevel.INFO, old_value, new_value) self.diff_objs.append(diff_obj) @staticmethod @@ -199,7 +214,7 @@ def check_cmd_parameter_diff(self, cmd_name, base_parameters, cmp_parameters): cmp_para_obj = self.__search_para_with_name_and_options(base_para_obj, cmp_parameters) if cmp_para_obj is None: # cmd lost parameter obj, is break - diff_obj = ParaRemove(cmd_name, base_para_obj["name"], True) + diff_obj = ParaRemove(cmd_name, base_para_obj["name"], True, DiffLevel.BREAK) # add flag to avoid duplicate compare self.diff_objs.append(diff_obj) continue @@ -210,19 +225,29 @@ def check_cmd_parameter_diff(self, cmd_name, base_parameters, cmp_parameters): 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, prop_value, True) + if prop in PARA_PROPERTY_REMOVE_WARN_LIST: + diff_obj = ParaPropRemove(cmd_name, base_para_obj["name"], prop, prop_value, + False, DiffLevel.WARN) + elif prop in PARA_PROPERTY_REMOVE_BREAK_LIST: + diff_obj = ParaPropRemove(cmd_name, base_para_obj["name"], prop, prop_value, + True, DiffLevel.BREAK) else: - diff_obj = ParaPropRemove(cmd_name, base_para_obj["name"], prop, prop_value, False) + diff_obj = ParaPropRemove(cmd_name, base_para_obj["name"], prop, prop_value, + False, DiffLevel.INFO) 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, prop_value, True) + if prop in PARA_PROPERTY_ADD_WARN_LIST: + diff_obj = ParaPropAdd(cmd_name, base_para_obj["name"], prop, prop_value, + False, DiffLevel.WARN) + elif prop in PARA_PROPERTY_ADD_BREAK_LIST: + diff_obj = ParaPropAdd(cmd_name, base_para_obj["name"], prop, prop_value, + True, DiffLevel.BREAK) else: - diff_obj = ParaPropAdd(cmd_name, base_para_obj["name"], prop, prop_value, False) + diff_obj = ParaPropAdd(cmd_name, base_para_obj["name"], prop, prop_value, + False, DiffLevel.INFO) self.diff_objs.append(diff_obj) continue # prop exists in both new and old para obj, value needs to be checked @@ -232,13 +257,24 @@ def check_cmd_parameter_diff(self, cmd_name, base_parameters, cmp_parameters): if base_val != cmp_val: if isinstance(base_val, list) and isinstance(cmp_val, list): if set(base_val).issubset(set(cmp_val)): - diff_obj = ParaPropUpdate(cmd_name, base_para_obj["name"], prop, False, base_val, cmp_val) + diff_obj = ParaPropUpdate(cmd_name, base_para_obj["name"], prop, False, DiffLevel.INFO, + base_val, cmp_val) else: - diff_obj = ParaPropUpdate(cmd_name, base_para_obj["name"], prop, True, base_val, cmp_val) + if prop in PARA_PROPERTY_UPDATE_WARN_LIST: + diff_obj = ParaPropUpdate(cmd_name, base_para_obj["name"], prop, False, DiffLevel.WARN, + base_val, cmp_val) + else: + diff_obj = ParaPropUpdate(cmd_name, base_para_obj["name"], prop, True, DiffLevel.BREAK, + base_val, cmp_val) + elif prop in PARA_PROPERTY_UPDATE_WARN_LIST: + diff_obj = ParaPropUpdate(cmd_name, base_para_obj["name"], prop, False, DiffLevel.WARN, + base_val, cmp_val) elif prop in PARA_PROPERTY_UPDATE_BREAK_LIST: - diff_obj = ParaPropUpdate(cmd_name, base_para_obj["name"], prop, True, base_val, cmp_val) + diff_obj = ParaPropUpdate(cmd_name, base_para_obj["name"], prop, True, DiffLevel.BREAK, + base_val, cmp_val) else: - diff_obj = ParaPropUpdate(cmd_name, base_para_obj["name"], prop, False, base_val, cmp_val) + diff_obj = ParaPropUpdate(cmd_name, base_para_obj["name"], prop, False, DiffLevel.INFO, + base_val, cmp_val) self.diff_objs.append(diff_obj) # check added parameter obj, if obj is required, then is break @@ -248,9 +284,9 @@ def check_cmd_parameter_diff(self, cmd_name, base_parameters, cmp_parameters): para_name = cmp_para_obj["name"] required = cmp_para_obj.get("required", None) if required: - diff_obj = ParaAdd(cmd_name, para_name, True) + diff_obj = ParaAdd(cmd_name, para_name, True, DiffLevel.BREAK) else: - diff_obj = ParaAdd(cmd_name, para_name, False) + diff_obj = ParaAdd(cmd_name, para_name, False, DiffLevel.INFO) self.diff_objs.append(diff_obj) def check_cmds_parameter_diff(self): diff --git a/azure-cli-diff-tool/azure_cli_diff_tool/utils.py b/azure-cli-diff-tool/azure_cli_diff_tool/utils.py index 9ff17f34..0c9f8033 100644 --- a/azure-cli-diff-tool/azure_cli_diff_tool/utils.py +++ b/azure-cli-diff-tool/azure_cli_diff_tool/utils.py @@ -54,6 +54,13 @@ class ChangeType(int, Enum): REMOVE = 3 +class DiffLevel(int, Enum): + DEFAULT = 0 + INFO = 1 + WARN = 2 + BREAK = 3 + + def get_command_tree(command_name): """ input: monitor log-profiles create diff --git a/azure-cli-diff-tool/tests/test_break_change.py b/azure-cli-diff-tool/tests/test_break_change.py index 8826e3f6..412fcc87 100644 --- a/azure-cli-diff-tool/tests/test_break_change.py +++ b/azure-cli-diff-tool/tests/test_break_change.py @@ -53,7 +53,7 @@ def test_diff_meta(self): "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`" + "cmd `monitor private-link-scope private-link-resource list` update parameter `resource_group_name`: removed property `id_part=resource_group` | diff_level: 2" ] for mes in target_message: found = False