Skip to content

Commit 25f6d41

Browse files
Added Portchannel test case.
1 parent 72cfd89 commit 25f6d41

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

tests/dhcp_relay_test.py

+43
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
| | 12.0.0.2 |
1717
| | 12.0.0.3 |
1818
+------------------+-----------------------+
19+
| PortChannel0001 | 11.0.0.1 |
20+
| | 11.0.0.2 |
21+
| | 11.0.0.3 |
22+
+------------------+-----------------------+
1923
| Vlan1000 | 192.0.0.1 |
2024
| | 192.0.0.2 |
2125
| | 192.0.0.3 |
@@ -48,6 +52,16 @@
4852
Restarting DHCP relay service...
4953
"""
5054

55+
config_portchannel_add_dhcp_relay_output="""\
56+
Added DHCP relay address 11.0.0.4 to PortChannel0001
57+
Restarting DHCP relay service...
58+
"""
59+
60+
config_portchannel_rem_dhcp_relay_output="""\
61+
Removed DHCP relay address 11.0.0.3 from PortChannel0001
62+
Restarting DHCP relay service...
63+
"""
64+
5165
class TestDhcpRelay(object):
5266
@classmethod
5367
def setup_class(cls):
@@ -114,6 +128,35 @@ def test_config_add_delete_dhcp_server_on_vlan_interface(self):
114128
assert result.output == config_vlan_rem_dhcp_relay_output
115129
assert mock_run_command.call_count == 3
116130

131+
def test_config_add_delete_dhcp_server_on_portchannel_interface(self):
132+
runner = CliRunner()
133+
db = Db()
134+
obj = {'db':db.cfgdb}
135+
136+
with mock.patch("utilities_common.cli.run_command") as mock_run_command:
137+
# add a same dhcp relay server address to PortChannel0001
138+
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["dhcp-relay"].commands["add"], ["PortChannel0001", "11.0.0.3"], obj=obj)
139+
print(result.exit_code)
140+
print(result.output)
141+
assert result.exit_code != 0
142+
assert "Error: IP address 11.0.0.3 is already configured" in result.output
143+
144+
# remove dhcp relay server address from PortChannel0001
145+
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["dhcp-relay"].commands["remove"], ["PortChannel0001", "11.0.0.3"], obj=obj)
146+
print(result.exit_code)
147+
print(result.output)
148+
assert result.exit_code == 0
149+
assert result.output == config_portchannel_rem_dhcp_relay_output
150+
assert mock_run_command.call_count == 3
151+
152+
# add a new dhcp relay server address to PortChannel0001
153+
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["dhcp-relay"].commands["add"], ["PortChannel0001", "11.0.0.4"], obj=obj)
154+
print(result.exit_code)
155+
print(result.output)
156+
assert result.exit_code == 0
157+
assert result.output == config_portchannel_add_dhcp_relay_output
158+
assert mock_run_command.call_count == 6
159+
117160
@classmethod
118161
def teardown_class(cls):
119162
os.environ['UTILITIES_UNIT_TESTING'] = "0"

tests/mock_tables/config_db.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@
520520
},
521521
"PORTCHANNEL_INTERFACE|PortChannel0001": {
522522
"NULL": "NULL",
523-
"dhcp_servers@": "11.0.0.1,11.0.0.2,11.0.0.3",
523+
"dhcp_servers@": "11.0.0.1,11.0.0.2,11.0.0.3"
524524
},
525525
"PORTCHANNEL_INTERFACE|PortChannel0002": {
526526
"NULL": "NULL"

0 commit comments

Comments
 (0)