Skip to content

Commit

Permalink
added integration tests for rendered and gathered
Browse files Browse the repository at this point in the history
  • Loading branch information
AAYUSH2091 committed Nov 15, 2024
1 parent 5041054 commit 20ae6c0
Showing 1 changed file with 142 additions and 0 deletions.
142 changes: 142 additions & 0 deletions tests/unit/modules/network/ios/test_ios_vrf_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,145 @@ def test_ios_vrf_interfaces_overridden(self):
]
result = self.execute_module(changed=True)
self.assertEqual(sorted(result["commands"]), sorted(commands))

def test_ios_vrf_interfaces_replaced_idempotent(self):
self.maxDiff = None
run_cfg = dedent(
"""\
interface GigabitEthernet1
ip address dhcp
no shutdown
!
interface GigabitEthernet2
no ip address
shutdown
!
interface GigabitEthernet3
vrf forwarding testvrf2
no ip address
shutdown
!
interface GigabitEthernet4
vrf forwarding testvrf1
no ip address
shutdown
!
""",
)
self.get_config.return_value = run_cfg
set_module_args(
dict(
config=[
{"name": "GigabitEthernet1"},
{"name": "GigabitEthernet2"},
{"name": "GigabitEthernet3", "vrf_name": "testvrf2"},
{"name": "GigabitEthernet4", "vrf_name": "testvrf1"},
],
state="replaced",
),
)
result = self.execute_module(changed=False)
self.assertEqual(result["commands"], [])

def test_ios_vrf_interfaces_overridden_idempotent(self):
self.maxDiff = None
run_cfg = dedent(
"""\
interface GigabitEthernet1
ip address dhcp
no shutdown
!
interface GigabitEthernet2
no ip address
shutdown
!
interface GigabitEthernet3
vrf forwarding testvrf2
no ip address
shutdown
!
interface GigabitEthernet4
vrf forwarding testvrf1
no ip address
shutdown
!
""",
)
self.get_config.return_value = run_cfg
set_module_args(
dict(
config=[
{"name": "GigabitEthernet1"},
{"name": "GigabitEthernet2"},
{"name": "GigabitEthernet3", "vrf_name": "testvrf2"},
{"name": "GigabitEthernet4", "vrf_name": "testvrf1"},
],
state="overridden",
),
)
result = self.execute_module(changed=False)
self.assertEqual(result["commands"], [])

def test_ios_vrf_interfaces_gathered(self):
self.maxDiff = None
run_cfg = dedent(
"""\
interface GigabitEthernet1
ip address dhcp
no shutdown
!
interface GigabitEthernet2
vrf forwarding vrf_1
shutdown
!
interface GigabitEthernet3
vrf forwarding vrf_2
no ip address
shutdown
!
interface GigabitEthernet4
no shutdown
!
""",
)
self.get_config.return_value = run_cfg
set_module_args(dict(state="gathered"))
gathered_list = [
{"name": "GigabitEthernet1"},
{"name": "GigabitEthernet2", "vrf_name": "vrf_1"},
{"name": "GigabitEthernet3", "vrf_name": "vrf_2"},
{"name": "GigabitEthernet4"},
]
result = self.execute_module(changed=False)
self.assertEqual(result["gathered"], gathered_list)

def test_ios_vrf_interfaces_rendered(self):
self.maxDiff = None
set_module_args(
dict(
config=[
{"name": "GigabitEthernet1"},
{"name": "GigabitEthernet2", "vrf_name": "vrf_1"},
{"name": "GigabitEthernet3", "vrf_name": "vrf_2"},
{"name": "GigabitEthernet4"},
],
state="rendered",
),
)
commands = [
"interface GigabitEthernet2",
"vrf forwarding vrf_1",
"interface GigabitEthernet3",
"vrf forwarding vrf_2",
]
result = self.execute_module(changed=False)
self.assertEqual(sorted(result["rendered"]), sorted(commands))

0 comments on commit 20ae6c0

Please sign in to comment.