Skip to content

Commit 56da217

Browse files
committed
integration test: verify public nics state
1 parent 31bd821 commit 56da217

4 files changed

Lines changed: 192 additions & 0 deletions

File tree

test/integration/component/test_multiple_subnets_in_isolated_network.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,35 @@ def get_router_ips(self, router):
192192
sourcenatIp = nic.ipaddress
193193
return guestIp, controlIp, sourcenatIp
194194

195+
def verify_router_publicnic_state(self, router, host, publicNics):
196+
command = '/opt/cloud/bin/checkrouter.sh | cut -d ":" -f2 |tr -d " "'
197+
self.logger.debug("Executing command '%s'" % command)
198+
result = get_process_status(
199+
host.ipaddress,
200+
host.port,
201+
host.user,
202+
host.password,
203+
router.linklocalip,
204+
command)
205+
self.assertTrue(len(result) > 0, "Cannot get router %s redundant state" % router.name)
206+
redundant_state = result[0]
207+
self.logger.debug("router %s redudnant state is %s" % (router.name, redundant_state))
208+
if redundant_state == "FAULT":
209+
self.logger.debug("Skip as redundant_state is %s" % redundant_state)
210+
return
211+
elif redundant_state == "MASTER":
212+
command = 'ip link show |grep BROADCAST | egrep "%s" |grep "state DOWN" |wc -l' % publicNics
213+
elif redundant_state == "BACKUP":
214+
command = 'ip link show |grep BROADCAST | egrep "%s" |grep "state UP" |wc -l' % publicNics
215+
result = get_process_status(
216+
host.ipaddress,
217+
host.port,
218+
host.user,
219+
host.password,
220+
router.linklocalip,
221+
command)
222+
self.assertTrue(len(result) > 0 and result[0] == "0", "Expected result is 0 but actual result is %s" % result[0])
223+
195224
def verify_network_interfaces_in_router(self, router, host, expectedNics):
196225
command = 'ip link show |grep BROADCAST | cut -d ":" -f2 |tr -d " "|tr "\n" ","'
197226
self.logger.debug("Executing command '%s'" % command)
@@ -338,6 +367,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
338367
self.verify_ip_address_in_router(router, host, guestIp, "eth0", True)
339368
self.verify_ip_address_in_router(router, host, controlIp, "eth1", True)
340369
self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True)
370+
self.verify_router_publicnic_state(router, host, "eth2")
341371

342372
# 4. get a free public ip, assign to network, and create port forwarding rules (ssh) to the vm
343373
ipaddress = PublicIPAddress.create(
@@ -363,6 +393,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
363393
self.verify_ip_address_in_router(router, host, controlIp, "eth1", True)
364394
self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True)
365395
self.verify_ip_address_in_router(router, host, ipaddress.ipaddress.ipaddress, "eth2", True)
396+
self.verify_router_publicnic_state(router, host, "eth2")
366397

367398
# 5. release the new ip
368399
ipaddress.delete(self.apiclient)
@@ -378,6 +409,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
378409
self.verify_ip_address_in_router(router, host, controlIp, "eth1", True)
379410
self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True)
380411
self.verify_ip_address_in_router(router, host, ipaddress.ipaddress.ipaddress, "eth2", False)
412+
self.verify_router_publicnic_state(router, host, "eth2")
381413

382414
# 6. create new public ip range 1
383415
self.services["publiciprange"]["zoneid"] = self.zone.id
@@ -423,6 +455,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
423455
self.verify_ip_address_in_router(router, host, controlIp, "eth1", True)
424456
self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True)
425457
self.verify_ip_address_in_router(router, host, ipaddress_1.ipaddress.ipaddress, "eth3", True)
458+
self.verify_router_publicnic_state(router, host, "eth2|eth3")
426459

427460
# 8. get a free ip in new ip range, assign to network, and create port forwarding rules (ssh) to the vm
428461
# verify the available nics in VR should be "eth0,eth1,eth2,eth3"
@@ -452,6 +485,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
452485
self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True)
453486
self.verify_ip_address_in_router(router, host, ipaddress_1.ipaddress.ipaddress, "eth3", True)
454487
self.verify_ip_address_in_router(router, host, ipaddress_2.ipaddress.ipaddress, "eth3", True)
488+
self.verify_router_publicnic_state(router, host, "eth2|eth3")
455489

456490
# 9. get a free ip in new ip range, assign to network, and create port forwarding rules (ssh) to the vm
457491
# verify the available nics in VR should be "eth0,eth1,eth2,eth3"
@@ -482,6 +516,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
482516
self.verify_ip_address_in_router(router, host, ipaddress_1.ipaddress.ipaddress, "eth3", True)
483517
self.verify_ip_address_in_router(router, host, ipaddress_2.ipaddress.ipaddress, "eth3", True)
484518
self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True)
519+
self.verify_router_publicnic_state(router, host, "eth2|eth3")
485520

486521
# 10. release new ip 2
487522
# verify the available nics in VR should be "eth0,eth1,eth2,eth3"
@@ -499,6 +534,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
499534
self.verify_ip_address_in_router(router, host, ipaddress_1.ipaddress.ipaddress, "eth3", True)
500535
self.verify_ip_address_in_router(router, host, ipaddress_2.ipaddress.ipaddress, "eth3", False)
501536
self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True)
537+
self.verify_router_publicnic_state(router, host, "eth2|eth3")
502538

503539
# 11. release new ip 1
504540
# verify the available nics in VR should be "eth0,eth1,eth2,eth3"
@@ -515,6 +551,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
515551
self.verify_ip_address_in_router(router, host, ipaddress_1.ipaddress.ipaddress, "eth3", False)
516552
self.verify_ip_address_in_router(router, host, ipaddress_2.ipaddress.ipaddress, "eth3", False)
517553
self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True)
554+
self.verify_router_publicnic_state(router, host, "eth2|eth3")
518555

519556
# 12. create new public ip range 2
520557
self.services["publiciprange"]["zoneid"] = self.zone.id
@@ -562,6 +599,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
562599
self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True)
563600
self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True)
564601
self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", True)
602+
self.verify_router_publicnic_state(router, host, "eth2|eth3|eth4")
565603

566604
# 14. get a free ip 5 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm
567605
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,"
@@ -592,6 +630,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
592630
self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True)
593631
self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", True)
594632
self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth4", True)
633+
self.verify_router_publicnic_state(router, host, "eth2|eth3|eth4")
595634

596635
# 15. get a free ip 6 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm
597636
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,"
@@ -623,6 +662,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
623662
self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", True)
624663
self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth4", True)
625664
self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth4", True)
665+
self.verify_router_publicnic_state(router, host, "eth2|eth3|eth4")
626666

627667
# 16. release new ip 5
628668
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,"
@@ -641,6 +681,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
641681
self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", True)
642682
self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth4", False)
643683
self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth4", True)
684+
self.verify_router_publicnic_state(router, host, "eth2|eth3|eth4")
644685

645686
# 17. release new ip 4
646687
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,"
@@ -658,6 +699,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
658699
self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", False)
659700
self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth4", False)
660701
self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth4", True)
702+
self.verify_router_publicnic_state(router, host, "eth2|eth3|eth4")
661703

662704
# 18. release new ip 3
663705
# verify the available nics in VR should be "eth0,eth1,eth2,eth4,"
@@ -674,6 +716,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
674716
self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", False)
675717
self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth4", False)
676718
self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth4", True)
719+
self.verify_router_publicnic_state(router, host, "eth2|eth4")
677720

678721
# 19. restart network
679722
self.network1.restart(self.apiclient)
@@ -688,6 +731,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
688731
self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", False)
689732
self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth4", False)
690733
self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth4", True)
734+
self.verify_router_publicnic_state(router, host, "eth2|eth4")
691735

692736
# reboot router
693737
for router in routers:
@@ -704,6 +748,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
704748
self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth3", False)
705749
self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth3", False)
706750
self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth3", True)
751+
self.verify_router_publicnic_state(router, host, "eth2|eth3")
707752

708753
# 20. restart network with cleanup
709754
self.network1.restart(self.apiclient, cleanup=True)
@@ -732,3 +777,4 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
732777
self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth3", False)
733778
self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth3", False)
734779
self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth3", True)
780+
self.verify_router_publicnic_state(router, host, "eth2|eth3")

0 commit comments

Comments
 (0)