Skip to content

Commit

Permalink
Address comment: add a flow for port remove/add/remove
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Sun <stephens@nvidia.com>
  • Loading branch information
stephenxs authored and dprital committed May 26, 2022
1 parent 51de623 commit 39aa90a
Showing 1 changed file with 56 additions and 21 deletions.
77 changes: 56 additions & 21 deletions tests/test_port_add_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
"""
DELETE_CREATE_ITERATIONS = 10

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

def test_remove_port_with_buffer_cfg(self, dvs, testlog):
def test_remove_add_remove_port_with_buffer_cfg(self, dvs, testlog):
config_db = dvs.get_config_db()
asic_db = dvs.get_asic_db()

Expand All @@ -25,45 +24,81 @@ def test_remove_port_with_buffer_cfg(self, dvs, testlog):
# get the number of ports before removal
num_of_ports = len(asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT"))

# try to remove this port
config_db.delete_entry('PORT', PORT_A)
num = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT",
num_of_ports-1,
polling_config = PollingConfig(polling_interval = 1, timeout = 5.00, strict = False))

# verify that the port wasn't removed since we still have buffer cfg
assert len(num) == num_of_ports

# remove buffer pg cfg for the port
# record the buffer pgs before removing them
pgs = config_db.get_keys('BUFFER_PG')
buffer_pgs = {}
for key in pgs:
if PORT_A in key:
buffer_pgs[key] = config_db.get_entry('BUFFER_PG', key)
config_db.delete_entry('BUFFER_PG', key)

num = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT",
num_of_ports-1,
polling_config = PollingConfig(polling_interval = 1, timeout = 5.00, strict = False))

# verify that the port wasn't removed since we still have buffer cfg
assert len(num) == num_of_ports

# modify buffer queue entry to egress_lossless_profile instead of egress_lossy_profile
config_db.update_entry("BUFFER_QUEUE", "%s|0-2"%PORT_A, {"profile": "egress_lossless_profile"})

# remove buffer queue cfg for the port
pgs = config_db.get_keys('BUFFER_QUEUE')
for key in pgs:
queues = config_db.get_keys('BUFFER_QUEUE')
buffer_queues = {}
for key in queues:
if PORT_A in key:
buffer_queues[key] = config_db.get_entry('BUFFER_QUEUE', key)
config_db.delete_entry('BUFFER_QUEUE', key)

# try to remove this port
config_db.delete_entry('PORT', PORT_A)
num = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT",
num_of_ports-1,
polling_config = PollingConfig(polling_interval = 1, timeout = 5.00, strict = True))

# 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_A, port_info)
# verify that the port has been readded
num = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT",
num_of_ports,
polling_config = PollingConfig(polling_interval = 1, timeout = 5.00, strict = True))

assert len(num) == num_of_ports

# re-add buffer pg and queue cfg to the port
for key, pg in buffer_pgs.items():
config_db.update_entry("BUFFER_PG", key, pg)

for key, queue in buffer_queues.items():
config_db.update_entry("BUFFER_QUEUE", key, queue)

# Remove the port with buffer configuration
config_db.delete_entry('PORT', PORT_A)
num = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT",
num_of_ports-1,
polling_config = PollingConfig(polling_interval = 1, timeout = 5.00, strict = False))

# verify that the port wasn't removed since we still have buffer cfg
assert len(num) == num_of_ports

# Remove buffer pgs
for key in buffer_pgs.keys():
config_db.delete_entry('BUFFER_PG', key)

num = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT",
num_of_ports-1,
polling_config = PollingConfig(polling_interval = 1, timeout = 5.00, strict = False))

# verify that the port wasn't removed since we still have buffer cfg
assert len(num) == num_of_ports

# Remove buffer queue
for key in buffer_queues.keys():
config_db.delete_entry('BUFFER_QUEUE', key)

num = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT",
num_of_ports-1,
polling_config = PollingConfig(polling_interval = 1, timeout = 5.00, strict = True))

# verify that the port wasn't removed since we still have buffer cfg
assert len(num) == num_of_ports - 1


@pytest.mark.parametrize("scenario", ["one_port", "all_ports"])
def test_add_remove_all_the_ports(self, dvs, testlog, scenario):
Expand Down

0 comments on commit 39aa90a

Please sign in to comment.