Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Port Cfg - VS test #12

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 81 additions & 1 deletion tests/test_port_add_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
from dvslib.dvs_common import PollingConfig

# the port to be removed and add
PORT = "Ethernet0"
PORT = "Ethernet64"

"""
DELETE_CREATE_ITERATIONS defines the number of iteration of delete and create to ports,
we add different timeouts between delete/create to catch potential race condition that can lead to system crush.
"""
DELETE_CREATE_ITERATIONS = 10

@pytest.mark.usefixtures('dvs_port_manager')
class TestPortAddRemove(object):

def test_remove_port_with_buffer_cfg(self, dvs, testlog):
Expand Down Expand Up @@ -54,3 +61,76 @@ def test_remove_port_with_buffer_cfg(self, dvs, testlog):

# verify that the port was removed properly since all buffer configuration was removed also
assert len(num) == num_of_ports - 1

config_db.create_entry("PORT", PORT, port_info)

@pytest.mark.parametrize("scenario", ["one_port", "all_ports"])
def test_add_remove_all_the_ports(self, dvs, testlog, scenario):
config_db = dvs.get_config_db()
asic_db = dvs.get_asic_db()

# get the number of ports before removal
num_of_ports = len(asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT"))

# remove buffer pg cfg for the port
if scenario == "all_ports":
ports = config_db.get_keys('PORT')
elif scenario == "one_port":
ports = [PORT]
else:
assert False

ports_info = {}

for i in range(DELETE_CREATE_ITERATIONS):
# remove ports
for key in ports:
# read port info and save it
ports_info[key] = config_db.get_entry("PORT", key)

# remove a port
self.dvs_port.remove_port(key)

# verify remove port
num = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT",
num_of_ports-len(ports))
assert len(num) == num_of_ports-len(ports)

# add port
time.sleep(i%3)
for key in ports:
config_db.create_entry("PORT", key, ports_info[key])

# verify add port
num = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT",
num_of_ports)
assert len(num) == num_of_ports

time.sleep((i%2)+1)

# run ping
dvs.setup_db()
dvs.create_vlan("6")
dvs.create_vlan_member("6", PORT)
dvs.create_vlan_member("6", "Ethernet68")
dvs.set_interface_status("Vlan6", "up")
dvs.add_ip_address("Vlan6", "6.6.6.1/24")
dvs.set_interface_status("Ethernet68", "up")
dvs.set_interface_status(PORT, "up")

dvs.servers[16].runcmd("ifconfig eth0 6.6.6.6/24 up")
dvs.servers[16].runcmd("ip route add default via 6.6.6.1")
dvs.servers[17].runcmd("ifconfig eth0 6.6.6.7/24 up")
dvs.servers[17].runcmd("ip route add default via 6.6.6.1")

time.sleep(2)

rc = dvs.servers[16].runcmd("ping -c 1 6.6.6.7")
assert rc == 0

rc = dvs.servers[17].runcmd("ping -c 1 6.6.6.6")
assert rc == 0

dvs.remove_vlan_member("6", "Ethernet68")
dvs.remove_vlan_member("6", PORT)
dvs.remove_vlan("6")