Skip to content

Commit a07e958

Browse files
Fix vlans context gathered operation (#1151)
* Fix vlans context gathered operation Signed-off-by: rohitthakur2590 <rohitthakur2590@outlook.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: rohitthakur2590 <rohitthakur2590@outlook.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent eefccd0 commit a07e958

File tree

3 files changed

+22
-35
lines changed

3 files changed

+22
-35
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
bugfixes:
3+
- Fixed an issue with VLAN configuration gathering where pre-filled data was blocking proper fetching of dynamic VLAN details. Now VLAN facts are populated correctly for all cases.
4+
- Cleaned up unit tests that were passing for the wrong reasons. The updated tests now ensure the right config sections are verified for VLAN configurations.
5+
- Added a test to validate the gathered state for VLAN configuration context, improving reliability.
6+
- Made improvements to ensure VLAN facts are gathered properly, both for specific configurations and general VLAN settings.

plugins/module_utils/network/ios/facts/vlans/vlans.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,13 @@ def populate_facts(self, connection, ansible_facts, data=None):
9292
remote_objs = []
9393
final_objs = []
9494
pvlan_objs = []
95-
conf_data = {}
96-
97-
if not data:
98-
data = self.get_vlans_data(connection)
99-
100-
# deals with vlan configuration config only
101-
conf_data = self.populate_vlans_config_facts(connection, data)
102-
95+
# Determine if we need to collect vlan data or config data
96+
vlan_data = data if data else self.get_vlans_data(connection)
97+
vlan_conf_data = None
98+
vlan_conf_data = self.populate_vlans_config_facts(connection, data)
10399
# operate on a collection of resource x
104-
config = data.split("\n")
105-
# Get individual vlan configs separately
100+
config = vlan_data.split("\n") if vlan_data else []
101+
106102
vlan_info = ""
107103
temp = ""
108104
vlan_name = True
@@ -190,14 +186,14 @@ def populate_facts(self, connection, ansible_facts, data=None):
190186

191187
facts = {}
192188

193-
if conf_data:
189+
if vlan_conf_data:
194190
for vlan in objs:
195-
if conf_data.get(vlan.get("vlan_id")):
196-
member_data = conf_data.pop(vlan.get("vlan_id"))
191+
if vlan_conf_data.get(vlan.get("vlan_id")):
192+
member_data = vlan_conf_data.pop(vlan.get("vlan_id"))
197193
vlan.update(member_data)
198194

199-
if conf_data: # if any vlan configuration data is pending add it to facts
200-
for vlanid, conf in conf_data.items():
195+
if vlan_conf_data: # if any vlan configuration data is pending add it to facts
196+
for vlanid, conf in vlan_conf_data.items():
201197
objs.append(conf)
202198

203199
if objs:

tests/unit/modules/network/ios/test_ios_vlans.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,23 +1113,8 @@ def test_ios_vlans_config_merged(self):
11131113

11141114
def test_ios_vlans_config_merged_idempotent(self):
11151115
self.mock_l2_device_command.side_effect = True
1116-
self.mock_execute_show_command_conf.side_effect = dedent(
1117-
"""\
1118-
vlan configuration 101
1119-
member evpn-instance 101 vni 10101
1120-
vlan configuration 102
1121-
member evpn-instance 102 vni 10102
1122-
vlan configuration 201
1123-
member evpn-instance 201 vni 10201
1124-
vlan configuration 202
1125-
member evpn-instance 202 vni 10202
1126-
vlan configuration 901
1127-
member vni 50901
1128-
vlan configuration 902
1129-
member vni 50902
1130-
""",
1131-
)
1132-
self.execute_show_command.return_value = dedent(
1116+
self.mock_execute_show_command_conf.side_effect = ""
1117+
self.execute_show_command_conf.return_value = dedent(
11331118
"""\
11341119
vlan configuration 101
11351120
member evpn-instance 101 vni 10101
@@ -1164,7 +1149,7 @@ def test_ios_vlans_config_merged_idempotent(self):
11641149
def test_ios_vlans_config_overridden(self):
11651150
self.mock_l2_device_command.side_effect = True
11661151
self.mock_execute_show_command_conf.side_effect = ""
1167-
self.execute_show_command.return_value = dedent(
1152+
self.execute_show_command_conf.return_value = dedent(
11681153
"""\
11691154
vlan configuration 101
11701155
member evpn-instance 101 vni 10101
@@ -1221,7 +1206,7 @@ def test_ios_vlans_config_overridden(self):
12211206
def test_ios_delete_vlans_config_2(self):
12221207
self.mock_l2_device_command.side_effect = True
12231208
self.mock_execute_show_command_conf.side_effect = ""
1224-
self.execute_show_command.return_value = dedent(
1209+
self.execute_show_command_conf.return_value = dedent(
12251210
"""\
12261211
vlan configuration 101
12271212
member evpn-instance 101 vni 10101
@@ -1252,7 +1237,7 @@ def test_ios_delete_vlans_config_2(self):
12521237
def test_ios_purged_vlans_config(self):
12531238
self.mock_l2_device_command.side_effect = True
12541239
self.mock_execute_show_command_conf.side_effect = ""
1255-
self.execute_show_command.return_value = dedent(
1240+
self.execute_show_command_conf.return_value = dedent(
12561241
"""\
12571242
vlan configuration 101
12581243
member evpn-instance 101 vni 10101

0 commit comments

Comments
 (0)