Skip to content

Commit 9499fa6

Browse files
authored
Merge pull request #310 from CiscoDevNet/dcnm_fabric_v2
dcnm_fabric v2. Ready for review.
2 parents c59ee67 + dfc1a72 commit 9499fa6

File tree

61 files changed

+10703
-11223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+10703
-11223
lines changed

playbooks/roles/dcnm_fabric/dcnm_tests.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---
22
# This playbook can be used to execute integration tests for
3-
# the role located in:
3+
# the roles located in:
44
#
5-
# Modify the vars section with details for testing setup.
5+
# ./tests/integration/targets/dcnm_fabric/tests/*.yaml
6+
#
7+
# Modify the vars section with details for your testing setup.
68
#
79
# NOTES:
810
# 1. For the IPFM test cases (dcnm_*_ipfm), ensure that the controller
@@ -17,17 +19,23 @@
1719
connection: ansible.netcommon.httpapi
1820

1921
vars:
20-
# This testcase field can run any test in the tests directory for the role
22+
# Uncomment ONE of the following testcases
2123
# testcase: dcnm_fabric_deleted_basic
2224
# testcase: dcnm_fabric_deleted_basic_ipfm
25+
# testcase: dcnm_fabric_deleted_basic_lan_classic
26+
# testcase: dcnm_fabric_deleted_basic_msd
27+
# testcase: dcnm_fabric_deleted_basic_vxlan
2328
# testcase: dcnm_fabric_merged_basic
2429
# testcase: dcnm_fabric_merged_basic_ipfm
2530
# testcase: dcnm_fabric_merged_save_deploy
2631
# testcase: dcnm_fabric_merged_save_deploy_ipfm
2732
# testcase: dcnm_fabric_replaced_basic
33+
# testcase: dcnm_fabric_replaced_basic_vxlan
34+
# testcase: dcnm_fabric_replaced_basic_vxlan_site_id
2835
# testcase: dcnm_fabric_replaced_basic_ipfm
2936
# testcase: dcnm_fabric_replaced_save_deploy
3037
# testcase: dcnm_fabric_replaced_save_deploy_ipfm
38+
# testcase: dcnm_fabric_query_basic.yaml
3139
fabric_name_1: VXLAN_EVPN_Fabric
3240
fabric_type_1: VXLAN_EVPN
3341
fabric_name_2: VXLAN_EVPN_MSD_Fabric

plugins/module_utils/common/maintenance_mode_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __init__(self, params):
130130

131131
self.params = params
132132
self.conversion = ConversionUtils()
133-
self.fabric_details = FabricDetailsByName(self.params)
133+
self.fabric_details = FabricDetailsByName()
134134
self.switch_details = SwitchDetails()
135135

136136
self._config = None

plugins/module_utils/common/results.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ def did_anything_change(self) -> bool:
232232
Return True if there were any changes
233233
Otherwise, return False
234234
"""
235-
msg = f"{self.class_name}.did_anything_change(): ENTERED: "
235+
method_name = inspect.stack()[0][3]
236+
237+
msg = f"{self.class_name}.{method_name}: ENTERED: "
236238
msg += f"self.action: {self.action}, "
237239
msg += f"self.state: {self.state}, "
238240
msg += f"self.result_current: {self.result_current}, "
@@ -248,12 +250,17 @@ def did_anything_change(self) -> bool:
248250
return True
249251
if self.result_current.get("changed", None) is False:
250252
return False
253+
if "changed" not in self.result_current:
254+
return False
251255
for diff in self.diff:
252256
something_changed = False
253257
test_diff = copy.deepcopy(diff)
254258
test_diff.pop("sequence_number", None)
255259
if len(test_diff) != 0:
256260
something_changed = True
261+
msg = f"{self.class_name}.{method_name}: "
262+
msg += f"something_changed: {something_changed}"
263+
self.log.debug(msg)
257264
return something_changed
258265

259266
def register_task_result(self):

plugins/module_utils/fabric/common.py

Lines changed: 30 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
from ansible_collections.cisco.dcnm.plugins.module_utils.common.conversion import \
2424
ConversionUtils
25+
from ansible_collections.cisco.dcnm.plugins.module_utils.common.properties import \
26+
Properties
2527
from ansible_collections.cisco.dcnm.plugins.module_utils.fabric.config_deploy import \
2628
FabricConfigDeploy
2729
from ansible_collections.cisco.dcnm.plugins.module_utils.fabric.config_save import \
@@ -30,45 +32,34 @@
3032
FabricTypes
3133

3234

35+
@Properties.add_rest_send
36+
@Properties.add_results
3337
class FabricCommon:
3438
"""
39+
### Summary
3540
Common methods used by the other classes supporting
3641
the dcnm_fabric module
3742
38-
Usage (where params is AnsibleModule.params)
43+
### Usage
3944
4045
class MyClass(FabricCommon):
41-
def __init__(self, params):
42-
super().__init__(params)
46+
def __init__(self):
47+
super().__init__()
4348
...
4449
"""
4550

46-
def __init__(self, params):
51+
def __init__(self):
4752
self.class_name = self.__class__.__name__
48-
self.params = params
53+
self.action = None
4954

5055
self.log = logging.getLogger(f"dcnm.{self.class_name}")
5156

52-
self.check_mode = self.params.get("check_mode", None)
53-
if self.check_mode is None:
54-
msg = f"{self.class_name}.__init__(): "
55-
msg += "check_mode is required"
56-
raise ValueError(msg)
57-
58-
self.state = self.params.get("state", None)
59-
if self.state is None:
60-
msg = f"{self.class_name}.__init__(): "
61-
msg += "state is required"
62-
raise ValueError(msg)
63-
6457
self.conversion = ConversionUtils()
65-
self.config_save = FabricConfigSave(params)
66-
self.config_deploy = FabricConfigDeploy(params)
58+
self.config_save = FabricConfigSave()
59+
self.config_deploy = FabricConfigDeploy()
6760
self.fabric_types = FabricTypes()
6861

69-
msg = "ENTERED FabricCommon(): "
70-
msg += f"check_mode: {self.check_mode}, "
71-
msg += f"state: {self.state}"
62+
msg = "ENTERED FabricCommon()"
7263
self.log.debug(msg)
7364

7465
# key: fabric_name, value: boolean
@@ -105,19 +96,13 @@ def __init__(self, params):
10596
self.path = None
10697
self.verb = None
10798

108-
self._init_properties()
109-
self._init_key_translations()
99+
self._fabric_details = None
100+
self._fabric_summary = None
101+
self._fabric_type = "VXLAN_EVPN"
102+
self._rest_send = None
103+
self._results = None
110104

111-
def _init_properties(self) -> None:
112-
"""
113-
Initialize the properties dictionary.
114-
"""
115-
self._properties: dict = {}
116-
self._properties["fabric_details"] = None
117-
self._properties["fabric_summary"] = None
118-
self._properties["fabric_type"] = "VXLAN_EVPN"
119-
self._properties["rest_send"] = None
120-
self._properties["results"] = None
105+
self._init_key_translations()
121106

122107
def _init_key_translations(self):
123108
"""
@@ -166,6 +151,7 @@ def _config_save(self, payload):
166151
return
167152

168153
self.config_save.payload = payload
154+
# pylint: disable=no-member
169155
self.config_save.rest_send = self.rest_send
170156
self.config_save.results = self.results
171157
try:
@@ -196,6 +182,7 @@ def _config_deploy(self, payload):
196182
self.config_deploy.fabric_details = self.fabric_details
197183
self.config_deploy.payload = payload
198184
self.config_deploy.fabric_summary = self.fabric_summary
185+
# pylint: disable=no-member
199186
self.config_deploy.rest_send = self.rest_send
200187
self.config_deploy.results = self.results
201188
except TypeError as error:
@@ -240,6 +227,7 @@ def translate_anycast_gw_mac(self, fabric_name, mac_address):
240227
try:
241228
mac_address = self.conversion.translate_mac_address(mac_address)
242229
except ValueError as error:
230+
# pylint: disable=no-member
243231
self.results.failed = True
244232
self.results.changed = False
245233
self.results.register_task_result()
@@ -270,6 +258,7 @@ def _fixup_payloads_to_commit(self) -> None:
270258
self._fixup_anycast_gw_mac()
271259
self._fixup_bgp_as()
272260
except ValueError as error:
261+
# pylint: disable=no-member
273262
self.results.failed = True
274263
self.results.changed = False
275264
self.results.register_task_result()
@@ -324,7 +313,7 @@ def _verify_payload(self, payload) -> None:
324313
- raise ``ValueError`` if the payload is missing mandatory keys
325314
"""
326315
method_name = inspect.stack()[0][3]
327-
if self.state not in {"merged", "replaced"}:
316+
if self.action not in {"fabric_create", "fabric_replace", "fabric_update"}:
328317
return
329318
msg = f"{self.class_name}.{method_name}: "
330319
msg += f"payload: {payload}"
@@ -393,22 +382,22 @@ def fabric_details(self):
393382
"""
394383
An instance of the FabricDetails class.
395384
"""
396-
return self._properties["fabric_details"]
385+
return self._fabric_details
397386

398387
@fabric_details.setter
399388
def fabric_details(self, value):
400-
self._properties["fabric_details"] = value
389+
self._fabric_details = value
401390

402391
@property
403392
def fabric_summary(self):
404393
"""
405394
An instance of the FabricSummary class.
406395
"""
407-
return self._properties["fabric_summary"]
396+
return self._fabric_summary
408397

409398
@fabric_summary.setter
410399
def fabric_summary(self, value):
411-
self._properties["fabric_summary"] = value
400+
self._fabric_summary = value
412401

413402
@property
414403
def fabric_type(self):
@@ -419,7 +408,7 @@ def fabric_type(self):
419408
420409
See ``FabricTypes().valid_fabric_types`` for valid values
421410
"""
422-
return self._properties["fabric_type"]
411+
return self._fabric_type
423412

424413
@fabric_type.setter
425414
def fabric_type(self, value):
@@ -430,26 +419,4 @@ def fabric_type(self, value):
430419
msg += f"{self.fabric_types.valid_fabric_types}. "
431420
msg += f"Got {value}"
432421
raise ValueError(msg)
433-
self._properties["fabric_type"] = value
434-
435-
@property
436-
def rest_send(self):
437-
"""
438-
An instance of the RestSend class.
439-
"""
440-
return self._properties["rest_send"]
441-
442-
@rest_send.setter
443-
def rest_send(self, value):
444-
self._properties["rest_send"] = value
445-
446-
@property
447-
def results(self):
448-
"""
449-
An instance of the Results class.
450-
"""
451-
return self._properties["results"]
452-
453-
@results.setter
454-
def results(self, value):
455-
self._properties["results"] = value
422+
self._fabric_type = value

0 commit comments

Comments
 (0)