Skip to content

Commit 322b0af

Browse files
committed
Addressing review comments
1 parent ae49831 commit 322b0af

File tree

9 files changed

+67
-64
lines changed

9 files changed

+67
-64
lines changed

plugins/module_utils/msd/query_child_fab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import logging
2121

2222
from ..common.results import Results
23-
from ..msd.Fabric_associations import FabricAssociations
23+
from ..msd.fabric_associations import FabricAssociations
2424

2525

2626
class childFabricQuery():

plugins/modules/dcnm_child_fabric.py renamed to plugins/modules/dcnm_fabric_member.py

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
DOCUMENTATION = """
2222
---
23-
module: dcnm_child_fabric
23+
module: dcnm_fabric_member
2424
short_description: Manage addition and deletion of NDFC fabrics to MSD.
2525
version_added: "3.5.0"
2626
author: Prabahal (@prabahal)
@@ -63,7 +63,7 @@
6363
EXAMPLES = """
6464
6565
- name: add child fabrics to MSD
66-
cisco.dcnm.dcnm_child_fabric:
66+
cisco.dcnm.dcnm_fabric_member:
6767
state: merged
6868
config:
6969
- FABRIC_NAME: MSD_Parent1
@@ -79,7 +79,7 @@
7979
# Query the child fabrics of a MSD Fabric.
8080
8181
- name: Query the child fabrics of MSD fabrics.
82-
cisco.dcnm.dcnm_child_fabric:
82+
cisco.dcnm.dcnm_fabric_member:
8383
state: query
8484
config:
8585
- FABRIC_NAME: MSD_Fabric1
@@ -123,9 +123,9 @@
123123
from ..module_utils.msd.query_child_fab import childFabricQuery
124124
from ..module_utils.msd.delete_child_fab import childFabricDelete
125125
from ..module_utils.msd.add_child_fab import childFabricAdd
126-
from ..module_utils.msd.Fabric_associations import FabricAssociations
126+
from ..module_utils.msd.fabric_associations import FabricAssociations
127127
from ..module_utils.fabric.verify_playbook_params import VerifyPlaybookParams
128-
128+
from ..module_utils.network.dcnm.dcnm import validate_list_of_dicts
129129

130130
@Properties.add_rest_send
131131
class childCommon():
@@ -151,7 +151,6 @@ def __init__(self, params):
151151
self.results = Results()
152152
self.results.state = self.state
153153
self.results.check_mode = self.check_mode
154-
self._verify_playbook_params = VerifyPlaybookParams()
155154
self.conversion = ConversionUtils()
156155
self.payloads = []
157156
self.want = []
@@ -218,36 +217,54 @@ def verify_child_fabric_is_already_member(self, item) -> bool:
218217
if (self.data[fabric]['fabricParent'] == item["destFabric"]):
219218
return True
220219
return False
221-
222-
def get_want(self):
223-
method_name = inspect.stack()[0][3]
220+
221+
def validate_input(self):
222+
if self.state != "query":
223+
fab_member_spec = dict(
224+
FABRIC_NAME=dict(required=True, type="str"),
225+
CHILD_FABRIC_NAME=dict(required=True, type="str"),
226+
DEPLOY=dict(type="bool", default=False),
227+
)
228+
else:
229+
fab_member_spec = dict(
230+
FABRIC_NAME=dict(type="str"),
231+
)
232+
fab_mem_info, invalid_params = validate_list_of_dicts(self.config, fab_member_spec, None)
233+
if invalid_params:
234+
mesg = "Invalid parameters in playbook: {0}".format(
235+
"while processing config "
236+
+ "\n".join(invalid_params)
237+
)
238+
raise ValueError(mesg)
224239
for config in self.config:
225-
msg = f"payload: {config}"
226-
self.log.debug(msg)
227-
228240
if not isinstance(config, dict):
229241
msg = f"{self.class_name}.{method_name}: "
230-
msg += "Playbook configuration for fabrics must be a dict. "
242+
msg += "Playbook configuration for fabric_member must be a dict. "
231243
msg += f"Got type {type(config).__name__}, "
232244
msg += f"value {config}."
233245
raise ValueError(msg)
246+
msd_fabric = config.get("FABRIC_NAME", None)
247+
child_fabric = config.get("CHILD_FABRIC_NAME", None)
234248
try:
235-
msd_fabric = config.get("FABRIC_NAME", None)
236-
child_fabric = config.get("CHILD_FABRIC_NAME", None)
237-
deploy = config.get("DEPLOY", None)
238-
try:
239-
self.conversion.validate_fabric_name(msd_fabric)
240-
self.conversion.validate_fabric_name(child_fabric)
241-
except (TypeError, ValueError) as error:
242-
msg = f"{self.class_name}: "
243-
msg += "Playbook configuration for FABRIC_NAME or CHILD_FABRIC_NAME "
244-
msg += "contains an invalid FABRIC_NAME. "
245-
# error below already contains a period "." at the end
246-
msg += f"Error detail: {error} "
247-
msg += f"Bad configuration: {config}."
248-
raise ValueError(msg) from error
249-
except ValueError as error:
250-
raise ValueError(f"{error}") from error
249+
self.conversion.validate_fabric_name(msd_fabric)
250+
self.conversion.validate_fabric_name(child_fabric)
251+
except (TypeError, ValueError) as error:
252+
msg = f"{self.class_name}: "
253+
msg += "Playbook configuration for FABRIC_NAME or CHILD_FABRIC_NAME "
254+
msg += "contains an invalid FABRIC_NAME. "
255+
# error below already contains a period "." at the end
256+
msg += f"Error detail: {error} "
257+
msg += f"Bad configuration: {config}."
258+
raise ValueError(msg) from error
259+
260+
def get_want(self):
261+
method_name = inspect.stack()[0][3]
262+
for config in self.config:
263+
msg = f"{method_name} payload: {config}"
264+
self.log.debug(msg)
265+
msd_fabric = config.get("FABRIC_NAME", None)
266+
child_fabric = config.get("CHILD_FABRIC_NAME", None)
267+
deploy = config.get("DEPLOY", None)
251268
config_payload = {'destFabric': msd_fabric, 'sourceFabric': child_fabric, 'DEPLOY': deploy}
252269
self.payloads.append(copy.deepcopy(config_payload))
253270

@@ -315,24 +332,7 @@ def populate_state(self):
315332
msg += f"Expected one of: {','.join(valid_states)}."
316333
raise ValueError(msg)
317334

318-
def get_want_query(self) -> None:
319-
"""
320-
### Summary
321-
- Validate the playbook configs.
322-
- Update self.want with the playbook configs.
323-
324-
### Raises
325-
- ``ValueError`` if the playbook configs are invalid.
326-
"""
327-
merged_configs = []
328-
for config in self.config:
329-
merged_configs.append(copy.deepcopy(config))
330-
331-
self.want = []
332-
for config in merged_configs:
333-
self.want.append(copy.deepcopy(config))
334-
335-
# Keeping this function to check lower NDFC version support. yet to get data
335+
# Keeping this function to check lower NDFC version support. yet to get data from Mike
336336
def get_controller_version(self):
337337
"""
338338
### Summary
@@ -389,7 +389,8 @@ def commit(self) -> None:
389389

390390
msg = f"ENTERED: {self.class_name}.{method_name}"
391391
self.log.debug(msg)
392-
392+
393+
self.validate_input()
393394
self.get_want()
394395

395396
self.fab_association = FabricAssociations()
@@ -480,7 +481,9 @@ def commit(self) -> None:
480481

481482
msg = f"ENTERED: {self.class_name}.{method_name}"
482483
self.log.debug(msg)
483-
484+
self.get_controller_version()
485+
### Version validation needs to be added
486+
self.validate_input()
484487
self.get_want()
485488

486489
self.add.results = self.results
@@ -582,14 +585,14 @@ def commit(self) -> None:
582585
query the fabrics.
583586
"""
584587
self.verify_payload()
585-
self.get_want_query()
588+
self.get_want()
586589
fabric_query = childFabricQuery()
587590
fabric_query.rest_send = self.rest_send
588591
fabric_query.results = self.results
589592

590593
fabric_names_to_query = []
591-
for want in self.want:
592-
fabric_names_to_query.append(want["FABRIC_NAME"])
594+
for item in self.payloads:
595+
fabric_names_to_query.append(item["destFabric"])
593596
try:
594597
fabric_query.fabric_names = copy.copy(fabric_names_to_query)
595598
except ValueError as error:

tests/integration/targets/dcnm_child_fabric/tests/dcnm_child_fabric.yaml renamed to tests/integration/targets/dcnm_fabric_member/tests/dcnm_fabric_member.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
# Example vars:
7070
#
7171
# vars:
72-
# testcase: dcnm_child_fabric_merged
72+
# testcase: dcnm_fabric_member_merged
7373
# msd_fabric_name_1: MSD_1
7474
# MSD_fabric_type: VXLAN_EVPN_MSD
7575
# child_fabric_name_11: child_11
@@ -562,7 +562,7 @@
562562

563563
################################################################################
564564
- name: MERGED - TEST - Merge child fabrics into MSD Fabric
565-
cisco.dcnm.dcnm_child_fabric:
565+
cisco.dcnm.dcnm_fabric_member:
566566
state: merged
567567
config:
568568
- FABRIC_NAME: "{{ msd_fabric_name_1 }}"
@@ -685,7 +685,7 @@
685685
#}
686686
#######################################################################################
687687
- name: MERGED - TEST - Merge additional fabric child_fabric_name_13 into MSD Fabric
688-
cisco.dcnm.dcnm_child_fabric: &merge_child_fabric
688+
cisco.dcnm.dcnm_fabric_member: &merge_child_fabric
689689
state: merged
690690
config:
691691
- FABRIC_NAME: "{{ msd_fabric_name_1 }}"
@@ -728,7 +728,7 @@
728728
#-name QUERY - TEST - Query child fabrics of MSD Fabric
729729
###################################################################################################
730730
- name: QUERY - TEST - Query child fabrics of MSD Fabric
731-
cisco.dcnm.dcnm_child_fabric:
731+
cisco.dcnm.dcnm_fabric_member:
732732
state: query
733733
config:
734734
- FABRIC_NAME: "{{ msd_fabric_name_1 }}"
@@ -831,7 +831,7 @@
831831
#}
832832
#################################################################################
833833
- name: MERGED - TEST - Merge additional config into MSD fabric - idempotence
834-
cisco.dcnm.dcnm_child_fabric: *merge_child_fabric
834+
cisco.dcnm.dcnm_fabric_member: *merge_child_fabric
835835
register: result
836836
- debug:
837837
var: result
@@ -945,7 +945,7 @@
945945
#}
946946
################################################################################
947947
- name: DELETED - SETUP - Delete child fabrics from MSD fabric
948-
cisco.dcnm.dcnm_child_fabric: &delete_child_fabric
948+
cisco.dcnm.dcnm_fabric_member: &delete_child_fabric
949949
state: deleted
950950
config:
951951
- FABRIC_NAME: "{{ msd_fabric_name_1 }}"
@@ -1132,7 +1132,7 @@
11321132
#}
11331133
###############################################################################################
11341134
- name: MERGED - TEST - Delete child Fabrics into MSD fabric - idempotence
1135-
cisco.dcnm.dcnm_child_fabric: *delete_child_fabric
1135+
cisco.dcnm.dcnm_fabric_member: *delete_child_fabric
11361136
register: result
11371137
- debug:
11381138
var: result
@@ -1214,7 +1214,7 @@
12141214
#- name: MERGED - TEST - ADD child Fabrics into MSD fabric with Deploy
12151215
################################################################################################
12161216
- name: Merged - TEST - Merge child fabrics into MSD Fabric with Deploy flag - To save the config
1217-
cisco.dcnm.dcnm_child_fabric:
1217+
cisco.dcnm.dcnm_fabric_member:
12181218
state: merged
12191219
config:
12201220
- FABRIC_NAME: "{{ msd_fabric_name_1 }}"
@@ -1361,7 +1361,7 @@
13611361
#- name: DELETED - TEST - Delete child Fabrics from MSD fabric with Deploy
13621362
################################################################################################
13631363
- name: Deleted - TEST - Delete child fabrics from MSD Fabric with Deploy flag - To save the config
1364-
cisco.dcnm.dcnm_child_fabric:
1364+
cisco.dcnm.dcnm_fabric_member:
13651365
state: deleted
13661366
config:
13671367
- FABRIC_NAME: "{{ msd_fabric_name_1 }}"

tests/sanity/ignore-2.15.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ plugins/httpapi/dcnm.py import-3.10!skip
2424
plugins/module_utils/common/sender_requests.py import-3.9 # TODO remove this if/when requests is added to the standard library
2525
plugins/module_utils/common/sender_requests.py import-3.10 # TODO remove this if/when requests is added to the standard library
2626
plugins/module_utils/common/sender_requests.py import-3.11 # TODO remove this if/when requests is added to the standard library
27-
plugins/modules/dcnm_child_fabric.py validate-modules:missing-gplv3-license # GPLv3 license header not found in the first 20 lines of the module
27+
plugins/modules/dcnm_fabric_member.py validate-modules:missing-gplv3-license # GPLv3 license header not found in the first 20 lines of the module

tests/sanity/ignore-2.16.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ plugins/modules/dcnm_bootflash.py validate-modules:missing-gplv3-license # GPLv3
2121
plugins/modules/dcnm_log.py validate-modules:missing-gplv3-license # GPLv3 license header not found in the first 20 lines of the module
2222
plugins/module_utils/common/sender_requests.py import-3.10 # TODO remove this if/when requests is added to the standard library
2323
plugins/module_utils/common/sender_requests.py import-3.11 # TODO remove this if/when requests is added to the standard library
24-
plugins/modules/dcnm_child_fabric.py validate-modules:missing-gplv3-license # GPLv3 license header not found in the first 20 lines of the module
24+
plugins/modules/dcnm_fabric_member.py validate-modules:missing-gplv3-license # GPLv3 license header not found in the first 20 lines of the module

0 commit comments

Comments
 (0)