Skip to content

Commit

Permalink
Appease linters
Browse files Browse the repository at this point in the history
1. test_dcnm_vrf.py

Fix black whitespace on blank line.

2. dcnm_vrf.py

Fix pylint unused-import

3. module_utils/network/dcnm/dcnm.py

1. Run through black
2. Fix pep8 expected 2 blank lines, found 1
  • Loading branch information
allenrobel committed Jan 19, 2025
1 parent f6e6712 commit 2d7c3c3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 60 deletions.
88 changes: 34 additions & 54 deletions plugins/module_utils/network/dcnm/dcnm.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"boolean": "bool",
"enum": "str",
"ipV4AddressWithSubnet": "ipv4_subnet",
"ipV6AddressWithSubnet": "ipv6_subnet"
"ipV6AddressWithSubnet": "ipv6_subnet",
}


Expand All @@ -73,15 +73,11 @@ def validate_ip_address_format(type, item, invalid_params):
subnet = item.split("/")[1]
if not subnet or int(subnet) > mask_len:
invalid_params.append(
"{0} : Invalid {1} gw/subnet syntax".format(
item, addr_type
)
"{0} : Invalid {1} gw/subnet syntax".format(item, addr_type)
)
else:
invalid_params.append(
"{0} : Invalid {1} gw/subnet syntax".format(
item, addr_type
)
"{0} : Invalid {1} gw/subnet syntax".format(item, addr_type)
)
try:
socket.inet_pton(addr_family, address)
Expand Down Expand Up @@ -176,9 +172,7 @@ def validate_list_of_dicts(param_list, spec, module=None):
module.no_log_values.add(item)
else:
msg = "\n\n'{0}' is a no_log parameter".format(param)
msg += (
"\nAnsible module object must be passed to this "
)
msg += "\nAnsible module object must be passed to this "
msg += "\nfunction to ensure it is not logged\n\n"
raise Exception(msg)

Expand Down Expand Up @@ -283,6 +277,7 @@ def get_ip_sn_fabric_dict(inventory_data):

return ip_fab, sn_fab


def get_ip_fabric_dict(inventory_data):
"""
Maps the switch IP Address/Serial No. in the multisite inventory
Expand All @@ -304,6 +299,7 @@ def get_ip_fabric_dict(inventory_data):

return ip_fab


def get_sn_fabric_dict(inventory_data):
"""
Maps the switch IP Address/Serial No. in the multisite inventory
Expand All @@ -325,6 +321,7 @@ def get_sn_fabric_dict(inventory_data):

return sn_fab


# sw_elem can be ip_addr, hostname, dns name or serial number. If the given
# sw_elem is ip_addr, then it is returned as is. If DNS or hostname then a DNS
# lookup is performed to get the IP address to be returned. If not ip_sn
Expand All @@ -334,7 +331,9 @@ def dcnm_get_ip_addr_info(module, sw_elem, ip_sn, hn_sn):

msg_dict = {"Error": ""}
msg = 'Given switch elem = "{}" is not a valid one for this fabric\n'
msg1 = 'Given switch elem = "{}" cannot be validated, provide a valid ip_sn object\n'
msg1 = (
'Given switch elem = "{}" cannot be validated, provide a valid ip_sn object\n'
)

# Check if the given sw_elem is a v4 ip_addr
try:
Expand Down Expand Up @@ -462,9 +461,7 @@ def dcnm_reset_connection(module):

conn = Connection(module._socket_path)

return conn.login(
conn.get_option("remote_user"), conn.get_option("password")
)
return conn.login(conn.get_option("remote_user"), conn.get_option("password"))


def dcnm_version_supported(module):
Expand Down Expand Up @@ -567,16 +564,14 @@ def dcnm_get_url(module, fabric, path, items, module_name):
elif iter != (send_count - 1):
itemstr = ",".join(
itemlist[
(iter * (len(itemlist) // send_count)):(
(iter * (len(itemlist) // send_count)) : (
(iter + 1) * (len(itemlist) // send_count)
)
]
)
url = path.format(fabric, itemstr)
else:
itemstr = ",".join(
itemlist[iter * (len(itemlist) // send_count):]
)
itemstr = ",".join(itemlist[iter * (len(itemlist) // send_count) :])
url = path.format(fabric, itemstr)

att_objects = dcnm_send(module, method, url)
Expand Down Expand Up @@ -623,12 +618,7 @@ def dcnm_get_template_details(module, version, name):
module, "GET", dcnm_paths[version]["TEMPLATE_WITH_NAME"].format(name)
)

if (
resp
and resp["RETURN_CODE"] == 200
and resp["MESSAGE"] == "OK"
and resp["DATA"]
):
if resp and resp["RETURN_CODE"] == 200 and resp["MESSAGE"] == "OK" and resp["DATA"]:
if resp["DATA"]["name"] == name:
return resp["DATA"]
else:
Expand Down Expand Up @@ -658,20 +648,12 @@ def dcnm_update_arg_specs(mspec, arg_specs):
# Given key is included in the mspec. So mark this a 'true' in the aspec. Final 'eval'
# on the item["required"] will yield the desired bool value.
item["required"] = item["required"].replace("true", "True")
item["required"] = item["required"].replace(
"false", "False"
)
item["required"] = eval(
item["required"].replace(key, "True")
)
item["required"] = item["required"].replace("false", "False")
item["required"] = eval(item["required"].replace(key, "True"))
else:
item["required"] = item["required"].replace("true", "True")
item["required"] = item["required"].replace(
"false", "False"
)
item["required"] = eval(
item["required"].replace(key, "False")
)
item["required"] = item["required"].replace("false", "False")
item["required"] = eval(item["required"].replace(key, "False"))


def dcnm_get_template_specs(module, name, version):
Expand All @@ -697,12 +679,12 @@ def dcnm_get_template_specs(module, name, version):
)

if "IsShow" in p["annotations"]:
pb_template[name][p["name"]] += ", Mandatory: " + p[
"annotations"
]["IsShow"].replace('"', "")
pb_template[name + "_spec"][p["name"]]["required"] = p[
"annotations"
]["IsShow"].replace('"', "")
pb_template[name][p["name"]] += ", Mandatory: " + p["annotations"][
"IsShow"
].replace('"', "")
pb_template[name + "_spec"][p["name"]]["required"] = p["annotations"][
"IsShow"
].replace('"', "")
else:
# If 'defaultValue' is included, then the object can be marked as optional.
if p["metaProperties"].get("defaultValue", None) is not None:
Expand Down Expand Up @@ -755,14 +737,14 @@ def dcnm_get_template_specs(module, name, version):
pb_template[name][p["name"]] += (
", Type: " + dcnm_template_type_xlations[str(p["parameterType"])]
)
pb_template[name + "_spec"][p["name"]]["type"] = dcnm_template_type_xlations[
p["parameterType"]
]
pb_template[name + "_spec"][p["name"]]["type"] = (
dcnm_template_type_xlations[p["parameterType"]]
)
if p.get("parameterType") == "string[]":
pb_template[name][p["name"]] += ", elements: " + "str"
pb_template[name + "_spec"][p["name"]]["type"] = dcnm_template_type_xlations[
p["parameterType"]
]
pb_template[name + "_spec"][p["name"]]["type"] = (
dcnm_template_type_xlations[p["parameterType"]]
)
pb_template[name + "_spec"][p["name"]]["elements"] = "str"

if p["metaProperties"].get("defaultValue", None) is not None:
Expand All @@ -775,9 +757,9 @@ def dcnm_get_template_specs(module, name, version):
"metaProperties"
]["defaultValue"].replace('""', "")
else:
pb_template[name + "_spec"][p["name"]][
"default"
] = int(p["metaProperties"]["defaultValue"])
pb_template[name + "_spec"][p["name"]]["default"] = int(
p["metaProperties"]["defaultValue"]
)
else:
pb_template[name + "_spec"][p["name"]]["default"] = p[
"metaProperties"
Expand Down Expand Up @@ -810,9 +792,7 @@ def dcnm_get_auth_token(module):

def dcnm_post_request(path, hdrs, verify_flag, upload_files):

resp = requests.post(
path, headers=hdrs, verify=verify_flag, files=upload_files
)
resp = requests.post(path, headers=hdrs, verify=verify_flag, files=upload_files)
json_resp = resp.json()
if json_resp:
json_resp["RETURN_CODE"] = resp.status_code
Expand Down
7 changes: 2 additions & 5 deletions plugins/modules/dcnm_vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,8 @@
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.cisco.dcnm.plugins.module_utils.network.dcnm.dcnm import (
dcnm_get_ip_addr_info, dcnm_get_url, dcnm_send, dcnm_version_supported,
get_fabric_details, get_fabric_inventory_details, get_ip_fabric_dict,
get_ip_sn_dict, get_ip_sn_fabric_dict, get_sn_fabric_dict,
validate_list_of_dicts)
get_fabric_details, get_fabric_inventory_details, get_ip_sn_dict,
get_sn_fabric_dict, validate_list_of_dicts)

from ..module_utils.common.log_v2 import Log

Expand Down Expand Up @@ -662,8 +661,6 @@ def __init__(self, module):
self.sn_ip = {value: key for (key, value) in self.ip_sn.items()}
self.fabric_data = get_fabric_details(self.module, self.fabric)
self.fabric_type = self.fabric_data.get("fabricType")
# self.ip_fab, self.sn_fab = get_ip_sn_fabric_dict(self.inventory_data)
self.ip_fab = get_ip_fabric_dict(self.inventory_data)
self.sn_fab = get_sn_fabric_dict(self.inventory_data)
if self.dcnm_version > 12:
self.paths = dcnm_vrf_paths[12]
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/dcnm/test_dcnm_vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TestDcnmVrfModule(TestDcnmModule):
fabric_details = test_data.get("fabric_details")
fabric_details_mfd = test_data.get("fabric_details_mfd")
fabric_details_vxlan = test_data.get("fabric_details_vxlan")

mock_vrf_attach_object_del_not_ready = test_data.get(
"mock_vrf_attach_object_del_not_ready"
)
Expand Down

0 comments on commit 2d7c3c3

Please sign in to comment.