From 054a6ebf9089bd9acf17263f5f9c15d6c8abe1d2 Mon Sep 17 00:00:00 2001 From: Vitaliy Senchyshyn Date: Wed, 20 May 2020 19:29:12 -0700 Subject: [PATCH 1/5] [wr_arp] Fixed wr_arp test Signed-off-by: Vitaliy Senchyshyn --- ansible/roles/test/files/ptftests/wr_arp.py | 44 +++++++++++++-------- tests/arp/test_wr_arp.py | 6 +-- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/ansible/roles/test/files/ptftests/wr_arp.py b/ansible/roles/test/files/ptftests/wr_arp.py index 5115c3f72f5..5274e627f8c 100644 --- a/ansible/roles/test/files/ptftests/wr_arp.py +++ b/ansible/roles/test/files/ptftests/wr_arp.py @@ -28,7 +28,7 @@ class ArpTest(BaseTest): def __init__(self): BaseTest.__init__(self) - log_file_name = '/root/wr_arp_test.log' + log_file_name = '/tmp/wr_arp_test.log' self.log_fp = open(log_file_name, 'a') self.log_fp.write("\nNew test:\n") @@ -46,6 +46,7 @@ def log(self, message): current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") print "%s : %s" % (current_time, message) self.log_fp.write("%s : %s\n" % (current_time, message)) + self.log_fp.flush() return @@ -102,6 +103,16 @@ def dut_thr(self, q_from, q_to): self.log("Quiting from dut_thr") return + def test_port_thr(self): + self.log("test_port_thr started") + while time.time() < self.stop_at: + for test in self.tests: + for port in test['acc_ports']: + nr_rcvd = self.testPort(port) + records[port][time.time()] = nr_rcvd + self.log("Quiting from test_port_thr") + return + def readMacs(self): addrs = {} for intf in os.listdir('/sys/class/net'): @@ -242,21 +253,22 @@ def runTest(self): self.assertTrue(False, "DUT returned error for first uptime request") records = defaultdict(dict) - stop_at = time.time() + self.how_long - rebooted = False - while time.time() < stop_at: - for test in self.tests: - for port in test['acc_ports']: - nr_rcvd = self.testPort(port) - records[port][time.time()] = nr_rcvd - if not rebooted: - result = self.req_dut('WR') - if result.startswith('ok'): - rebooted = True - else: - self.log("Error in WR") - self.req_dut('quit') - self.assertTrue(False, "Error in WR") + self.stop_at = time.time() + self.how_long + + test_port_thr = threading.Thread(target=self.test_port_thr) + test_port_thr.setDaemon(True) + test_port_thr.start() + + self.log("Issuing WR command") + result = self.req_dut('WR') + if result.startswith('ok'): + self.log("WR OK!") + else: + self.log("Error in WR") + self.req_dut('quit') + self.assertTrue(False, "Error in WR") + + test_port_thr.join() uptime_after = self.req_dut('uptime') if uptime_after.startswith('error'): diff --git a/tests/arp/test_wr_arp.py b/tests/arp/test_wr_arp.py index 26319a92d13..ebc907c43c4 100644 --- a/tests/arp/test_wr_arp.py +++ b/tests/arp/test_wr_arp.py @@ -57,7 +57,7 @@ def setupFerret(self, duthost, ptfhost): ptfhost.copy(src="arp/files/ferret.py", dest="/opt") result = duthost.shell( - cmd='''ip route show proto zebra type unicast | + cmd='''ip route show proto 186 type unicast | sed -e '/default/d' -ne '/0\//p' | head -n 1 | sed -ne 's/0\/.*$/1/p' @@ -144,7 +144,7 @@ def removePtfhostIp(self, ptfhost): Returns: None ''' - ptfhost.script(src='scripts/remove_ip.sh') + ptfhost.script('./scripts/remove_ip.sh') @pytest.fixture(scope='class', autouse=True) def changePtfhostMacAddresses(self, ptfhost): @@ -157,7 +157,7 @@ def changePtfhostMacAddresses(self, ptfhost): Returns: None ''' - ptfhost.script(src="scripts/change_mac.sh") + ptfhost.script("./scripts/change_mac.sh") @pytest.fixture(scope='class', autouse=True) def prepareSshKeys(self, duthost, ptfhost): From 0b1eaafe00db54f7df63ba2e8b54f30693e793e3 Mon Sep 17 00:00:00 2001 From: Vitaliy Senchyshyn Date: Thu, 21 May 2020 02:44:48 -0700 Subject: [PATCH 2/5] Make show ip protocol command working for different sonic images --- tests/arp/test_wr_arp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/arp/test_wr_arp.py b/tests/arp/test_wr_arp.py index ebc907c43c4..cf2e377c35c 100644 --- a/tests/arp/test_wr_arp.py +++ b/tests/arp/test_wr_arp.py @@ -57,8 +57,8 @@ def setupFerret(self, duthost, ptfhost): ptfhost.copy(src="arp/files/ferret.py", dest="/opt") result = duthost.shell( - cmd='''ip route show proto 186 type unicast | - sed -e '/default/d' -ne '/0\//p' | + cmd='''ip route show type unicast | + sed -e '/proto 186\|proto zebra/!d' -e '/default/d' -ne '/0\//p' | head -n 1 | sed -ne 's/0\/.*$/1/p' ''' From 502e23c2d6ba1e860a50de922097d377edc39366 Mon Sep 17 00:00:00 2001 From: Vitaliy Senchyshyn Date: Thu, 21 May 2020 22:47:44 -0700 Subject: [PATCH 3/5] Fixed review comments --- ansible/roles/test/files/ptftests/wr_arp.py | 2 ++ tests/arp/test_wr_arp.py | 27 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ansible/roles/test/files/ptftests/wr_arp.py b/ansible/roles/test/files/ptftests/wr_arp.py index 5274e627f8c..fff96db9db7 100644 --- a/ansible/roles/test/files/ptftests/wr_arp.py +++ b/ansible/roles/test/files/ptftests/wr_arp.py @@ -268,6 +268,8 @@ def runTest(self): self.req_dut('quit') self.assertTrue(False, "Error in WR") + self.assertTrue(time.time() < self.stop_at, "warm-reboot took to long") + test_port_thr.join() uptime_after = self.req_dut('uptime') diff --git a/tests/arp/test_wr_arp.py b/tests/arp/test_wr_arp.py index cf2e377c35c..83cbf3fea8c 100644 --- a/tests/arp/test_wr_arp.py +++ b/tests/arp/test_wr_arp.py @@ -56,6 +56,33 @@ def setupFerret(self, duthost, ptfhost): ''' ptfhost.copy(src="arp/files/ferret.py", dest="/opt") + ''' + Get the IP which will be used by ferret script from the "ip route show type unicast" + command output. The output looks as follows: + + default proto 186 src 10.1.0.32 metric 20 + nexthop via 10.0.0.57 dev PortChannel0001 weight 1 + nexthop via 10.0.0.59 dev PortChannel0002 weight 1 + nexthop via 10.0.0.61 dev PortChannel0003 weight 1 + nexthop via 10.0.0.63 dev PortChannel0004 weight 1 + 10.0.0.56/31 dev PortChannel0001 proto kernel scope link src 10.0.0.56 + 10.232.24.0/23 dev eth0 proto kernel scope link src 10.232.24.122 + 100.1.0.29 via 10.0.0.57 dev PortChannel0001 proto 186 src 10.1.0.32 metric 20 + 192.168.0.0/21 dev Vlan1000 proto kernel scope link src 192.168.0.1 + 192.168.8.0/25 proto 186 src 10.1.0.32 metric 20 + nexthop via 10.0.0.57 dev PortChannel0001 weight 1 + nexthop via 10.0.0.59 dev PortChannel0002 weight 1 + nexthop via 10.0.0.61 dev PortChannel0003 weight 1 + nexthop via 10.0.0.63 dev PortChannel0004 weight 1 + 192.168.16.0/25 proto 186 src 10.1.0.32 metric 20 + ... + + We'll use the first subnet IP taken from zebra protocol as the base for the host IP. + As in the new SONiC image the proto will look as '186' instead of 'zebra' (like it looks in 201811) + the filtering output command below will pick the first line containing either 'zebra' or '186' + (except the one for the deafult route) and take host IP from the subnet IP. For the output + above 192.168.8.0/25 subnet will be taken and host IP given to ferret script will be 192.168.8.1 + ''' result = duthost.shell( cmd='''ip route show type unicast | sed -e '/proto 186\|proto zebra/!d' -e '/default/d' -ne '/0\//p' | From a061743c04361e2759d9b21f310df2c116967b61 Mon Sep 17 00:00:00 2001 From: Vitaliy Senchyshyn Date: Fri, 22 May 2020 01:26:23 -0700 Subject: [PATCH 4/5] Made records variable a class memeber --- ansible/roles/test/files/ptftests/wr_arp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ansible/roles/test/files/ptftests/wr_arp.py b/ansible/roles/test/files/ptftests/wr_arp.py index fff96db9db7..39240138985 100644 --- a/ansible/roles/test/files/ptftests/wr_arp.py +++ b/ansible/roles/test/files/ptftests/wr_arp.py @@ -109,7 +109,7 @@ def test_port_thr(self): for test in self.tests: for port in test['acc_ports']: nr_rcvd = self.testPort(port) - records[port][time.time()] = nr_rcvd + self.records[port][time.time()] = nr_rcvd self.log("Quiting from test_port_thr") return @@ -252,7 +252,7 @@ def runTest(self): self.req_dut('quit') self.assertTrue(False, "DUT returned error for first uptime request") - records = defaultdict(dict) + self.records = defaultdict(dict) self.stop_at = time.time() + self.how_long test_port_thr = threading.Thread(target=self.test_port_thr) @@ -286,7 +286,7 @@ def runTest(self): # check that every port didn't have pauses more than 25 seconds pauses = defaultdict(list) - for port, data in records.items(): + for port, data in self.records.items(): was_active = True last_inactive = None for t in sorted(data.keys()): From 8ee312ffff0cccece3f800e8b5c0d0a28a726ce1 Mon Sep 17 00:00:00 2001 From: Vitaliy Senchyshyn Date: Fri, 22 May 2020 02:20:35 -0700 Subject: [PATCH 5/5] Fixed DIP taking from ip route show for sonic master --- tests/arp/test_wr_arp.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/arp/test_wr_arp.py b/tests/arp/test_wr_arp.py index 83cbf3fea8c..bfae665c3a4 100644 --- a/tests/arp/test_wr_arp.py +++ b/tests/arp/test_wr_arp.py @@ -78,14 +78,15 @@ def setupFerret(self, duthost, ptfhost): ... We'll use the first subnet IP taken from zebra protocol as the base for the host IP. - As in the new SONiC image the proto will look as '186' instead of 'zebra' (like it looks in 201811) - the filtering output command below will pick the first line containing either 'zebra' or '186' + As in the new SONiC image the proto will look as '186'(201911) or bgp (master) + instead of 'zebra' (like it looks in 201811)the filtering output command below will pick + the first line containing either 'proto zebra' (or 'proto 186' or 'proto bgp') (except the one for the deafult route) and take host IP from the subnet IP. For the output above 192.168.8.0/25 subnet will be taken and host IP given to ferret script will be 192.168.8.1 ''' result = duthost.shell( cmd='''ip route show type unicast | - sed -e '/proto 186\|proto zebra/!d' -e '/default/d' -ne '/0\//p' | + sed -e '/proto 186\|proto zebra\|proto bgp/!d' -e '/default/d' -ne '/0\//p' | head -n 1 | sed -ne 's/0\/.*$/1/p' '''