Skip to content

Commit

Permalink
add prop value, norm type value and ignore add type (#418)
Browse files Browse the repository at this point in the history
* add prop value, norm type value and ignore add type

---------

Co-authored-by: Li Wang <[email protected]>
  • Loading branch information
AllyW and Li Wang authored Aug 10, 2023
1 parent 64f4b0f commit d4e9490
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 107 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion azdev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# license information.
# -----------------------------------------------------------------------------

__VERSION__ = '0.1.58'
__VERSION__ = '0.1.59'
22 changes: 22 additions & 0 deletions azdev/operations/command_change/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down
28 changes: 0 additions & 28 deletions azdev/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
11 changes: 0 additions & 11 deletions azdev/utilities/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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")
48 changes: 0 additions & 48 deletions azdev/utilities/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
5 changes: 5 additions & 0 deletions azure-cli-diff-tool/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion azure-cli-diff-tool/azure_cli_diff_tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
12 changes: 6 additions & 6 deletions azure-cli-diff-tool/azure_cli_diff_tool/_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
12 changes: 8 additions & 4 deletions azure-cli-diff-tool/azure_cli_diff_tool/meta_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,21 @@ 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"
self.is_ignore = 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:
Expand All @@ -200,19 +202,21 @@ 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"
self.is_ignore = 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:
Expand Down
10 changes: 6 additions & 4 deletions azure-cli-diff-tool/azure_cli_diff_tool/meta_change_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions azure-cli-diff-tool/tests/jsons/az_monitor_meta_after.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 3 additions & 1 deletion azure-cli-diff-tool/tests/test_break_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d4e9490

Please sign in to comment.