Skip to content

Commit ae49831

Browse files
committed
UT issues and IT cases addition
1 parent e2e8006 commit ae49831

File tree

5 files changed

+366
-29
lines changed

5 files changed

+366
-29
lines changed

plugins/module_utils/fabric/common.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,25 @@ def _config_save(self, payload):
133133
"""
134134
method_name = inspect.stack()[0][3]
135135

136-
fabric_name = payload.get("FABRIC_NAME", None)
136+
if self.action == "child_fabric_add" or self.action == "child_fabric_delete":
137+
fabric_name = payload.get("destFabric", None)
138+
payload.update({'FABRIC_NAME': fabric_name})
139+
else:
140+
fabric_name = payload.get("FABRIC_NAME", None)
141+
142+
msg = f"{method_name}: action{self.action} payloads {payload} fab {fabric_name}"
143+
self.log.debug(msg)
137144
if fabric_name is None:
138145
msg = f"{self.class_name}.{method_name}: "
139146
msg += "payload is missing mandatory parameter: FABRIC_NAME."
140147
raise ValueError(msg)
141148

142-
if self.send_payload_result[fabric_name] is False:
143-
# Skip config-save if send_payload failed
144-
# Set config_save_result to False so that config_deploy is skipped
145-
self.config_save_result[fabric_name] = False
146-
return
149+
if not (self.action == "child_fabric_add" or self.action == "child_fabric_delete"):
150+
if self.send_payload_result[fabric_name] is False:
151+
# Skip config-save if send_payload failed
152+
# Set config_save_result to False so that config_deploy is skipped
153+
self.config_save_result[fabric_name] = False
154+
return
147155

148156
self.config_save.payload = payload
149157
# pylint: disable=no-member
@@ -164,7 +172,11 @@ def _config_deploy(self, payload):
164172
- Raise ``ValueError`` if the payload is missing the FABRIC_NAME key.
165173
"""
166174
method_name = inspect.stack()[0][3]
167-
fabric_name = payload.get("FABRIC_NAME")
175+
if self.action == "child_fabric_add":
176+
fabric_name = payload.get("destFabric", None)
177+
payload.update({'FABRIC_NAME': fabric_name})
178+
else:
179+
fabric_name = payload.get("FABRIC_NAME", None)
168180
if fabric_name is None:
169181
msg = f"{self.class_name}.{method_name}: "
170182
msg += "payload is missing mandatory parameter: FABRIC_NAME."

plugins/module_utils/msd/add_child_fab.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,24 @@
3131
# in _validate_commit_parameters() so that we can register the failure
3232
# in commit().
3333
from ..common.results import Results
34+
from ...module_utils.fabric.common import FabricCommon
3435

3536

36-
class childFabricAdd():
37+
class childFabricAdd(FabricCommon):
3738
"""
3839
methods and properties for adding Child fabric into MSD:
3940
4041
"""
4142

4243
def __init__(self):
44+
super().__init__()
4345
self.class_name = self.__class__.__name__
4446
self.action = "child_fabric_add"
4547
self.log = logging.getLogger(f"dcnm.{self.class_name}")
4648
self.ep_fabric_add = EpChildFabricAdd()
4749
msg = "ENTERED childFabricAdd()"
4850
self.log.debug(msg)
51+
self.deploy = False
4952

5053
def commit(self, payload):
5154
"""
@@ -57,6 +60,9 @@ def commit(self, payload):
5760
- ``_validate_commit_parameters`` raises ``ValueError``.
5861
5962
"""
63+
if 'DEPLOY' in payload:
64+
self.deploy = payload.pop('DEPLOY')
65+
6066
try:
6167
self._validate_commit_parameters()
6268
except ValueError as error:
@@ -100,6 +106,13 @@ def commit(self, payload):
100106
msg = f"self.results.diff: {json.dumps(self.results.diff, indent=4, sort_keys=True)}"
101107
self.log.debug(msg)
102108

109+
if True in self.results.failed:
110+
return
111+
112+
if self.deploy is True:
113+
payload.update({'DEPLOY': True})
114+
self._config_save(payload)
115+
103116
def _validate_commit_parameters(self):
104117
"""
105118
- validate the parameters for commit

plugins/module_utils/msd/delete_child_fab.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030
# in _validate_commit_parameters() so that we can register the failure
3131
# in commit().
3232
from ..common.results import Results
33+
from ...module_utils.fabric.common import FabricCommon
3334

3435

35-
class childFabricDelete():
36+
class childFabricDelete(FabricCommon):
3637
"""
3738
Delete child fabrics from Parent fabrics
3839
"""
3940

4041
def __init__(self):
42+
super().__init__()
4143
self.class_name = self.__class__.__name__
4244
self.action = "child_fabric_delete"
4345

@@ -51,6 +53,7 @@ def __init__(self):
5153

5254
msg = "ENTERED childFabricDelete()"
5355
self.log.debug(msg)
56+
self.deploy = False
5457

5558
def commit(self, payload):
5659
"""
@@ -62,7 +65,8 @@ def commit(self, payload):
6265
- ``_validate_commit_parameters`` raises ``ValueError``.
6366
6467
"""
65-
68+
if 'DEPLOY' in payload:
69+
self.deploy = payload.pop('DEPLOY')
6670
try:
6771
self._validate_commit_parameters()
6872
except ValueError as error:
@@ -106,6 +110,13 @@ def commit(self, payload):
106110
msg = f"self.results.diff: {json.dumps(self.results.diff, indent=4, sort_keys=True)}"
107111
self.log.debug(msg)
108112

113+
if True in self.results.failed:
114+
return
115+
116+
if self.deploy is True:
117+
payload.update({'DEPLOY': True})
118+
self._config_save(payload)
119+
109120
def _validate_commit_parameters(self):
110121
"""
111122
- validate the parameters for commit

plugins/modules/dcnm_child_fabric.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
type: list
4343
elements: dict
4444
suboptions:
45+
DEPLOY:
46+
default: False
47+
description:
48+
- Save the member fabric configuration.
49+
required: false
50+
type: bool
4551
FABRIC_NAME:
4652
description:
4753
- The name of the MSD fabric.
@@ -228,6 +234,7 @@ def get_want(self):
228234
try:
229235
msd_fabric = config.get("FABRIC_NAME", None)
230236
child_fabric = config.get("CHILD_FABRIC_NAME", None)
237+
deploy = config.get("DEPLOY", None)
231238
try:
232239
self.conversion.validate_fabric_name(msd_fabric)
233240
self.conversion.validate_fabric_name(child_fabric)
@@ -241,7 +248,7 @@ def get_want(self):
241248
raise ValueError(msg) from error
242249
except ValueError as error:
243250
raise ValueError(f"{error}") from error
244-
config_payload = {'destFabric': msd_fabric, 'sourceFabric': child_fabric}
251+
config_payload = {'destFabric': msd_fabric, 'sourceFabric': child_fabric, 'DEPLOY': deploy}
245252
self.payloads.append(copy.deepcopy(config_payload))
246253

247254
def populate_check_mode(self):
@@ -402,7 +409,7 @@ def commit(self) -> None:
402409
if not self.verify_child_fabric_is_already_member(item):
403410
self.results.action = self.action
404411
self.results.result_current = {"success": True, "changed": False}
405-
msg = "Child fabric is not a member of Parent fabric."
412+
msg = "Given child fabric is already not a member of MSD fabric"
406413
self.results.response_current = {"RETURN_CODE": 200, "MESSAGE": msg}
407414
self.results.register_task_result()
408415
else:
@@ -496,7 +503,7 @@ def commit(self) -> None:
496503
if self.verify_child_fabric_is_already_member(item):
497504
self.results.action = self.action
498505
self.results.result_current = {"success": True, "changed": False}
499-
msg = "Child fabric is already member of Parent fabric."
506+
msg = "Child fabric is already member of MSD fabric."
500507
self.results.response_current = {"RETURN_CODE": 200, "MESSAGE": msg}
501508
self.results.register_task_result()
502509
else:

0 commit comments

Comments
 (0)