@@ -195,7 +195,8 @@ def tearDownClass(cls):
195195
196196 def setUp (self ):
197197 self .apiclient = self .testClient .getApiClient ()
198-
198+ self .hypervisor = self .testClient .getHypervisorInfo ()
199+
199200 self .logger .debug ("Creating Admin Account for Domain ID ==> %s" % self .domain .id )
200201 self .account = Account .create (
201202 self .apiclient ,
@@ -285,7 +286,7 @@ def test_04_rvpc_privategw_static_routes(self):
285286 self .performVPCTests (vpc_off )
286287
287288 @attr (tags = ["advanced" ], required_hardware = "true" )
288- def test_05_rvpc_privategw_check_interface (self ):
289+ def _test_05_rvpc_privategw_check_interface (self ):
289290 self .logger .debug ("Creating a Redundant VPC offering.." )
290291 vpc_off = VpcOffering .create (
291292 self .apiclient ,
@@ -344,8 +345,8 @@ def performVPCTests(self, vpc_off, restart_with_cleanup = False):
344345 self .check_pvt_gw_connectivity (vm1 , public_ip_1 , [vm2 .nic [0 ].ipaddress , vm1 .nic [0 ].ipaddress ])
345346
346347 if restart_with_cleanup :
347- self .reboot_vpc_with_cleanup (vpc_1 , True )
348- self .reboot_vpc_with_cleanup (vpc_2 , True )
348+ self .reboot_vpc_with_cleanup (vpc_1 , cleanup = restart_with_cleanup )
349+ self .reboot_vpc_with_cleanup (vpc_2 , cleanup = restart_with_cleanup )
349350
350351 self .check_pvt_gw_connectivity (vm1 , public_ip_1 , [vm2 .nic [0 ].ipaddress , vm1 .nic [0 ].ipaddress ])
351352
@@ -391,45 +392,54 @@ def performPrivateGWInterfaceTests(self, vpc_off):
391392
392393 public_ip_1 = self .acquire_publicip (vpc_1 , network_1 )
393394 nat_rule_1 = self .create_natrule (vpc_1 , vm1 , public_ip_1 , network_1 )
395+
396+ self .check_private_gateway_interfaces ()
394397
395- routers = list_routers (self .apiclient ,
396- account = self .account .name ,
397- domainid = self .account .domainid )
398+ self .check_pvt_gw_connectivity (vm1 , public_ip_1 , [vm2 .nic [0 ].ipaddress , vm3 .nic [0 ].ipaddress , vm4 .nic [0 ].ipaddress ])
398399
399- self .assertEqual ( isinstance ( routers , list ), True ,
400- "Check for list routers response return valid data" )
400+ self .reboot_vpc_with_cleanup ( vpc_1 , cleanup = True )
401+ self . check_routers_state ( )
401402
402- self .assertEqual (len (routers ), 2 ,
403- "Check for list routers size returned '%s' instead of 2" % len (routers ))
403+ self .check_pvt_gw_connectivity (vm1 , public_ip_1 , [vm2 .nic [0 ].ipaddress , vm3 .nic [0 ].ipaddress , vm4 .nic [0 ].ipaddress ])
404404
405- self .check_private_gateway_interfaces (routers )
405+ self .stop_router_by_type ("MASTER" )
406+ self .check_routers_state ()
406407
408+ self .check_private_gateway_interfaces ()
407409 self .check_pvt_gw_connectivity (vm1 , public_ip_1 , [vm2 .nic [0 ].ipaddress , vm3 .nic [0 ].ipaddress , vm4 .nic [0 ].ipaddress ])
408410
409- self .reboot_vpc_with_cleanup (vpc_1 , True )
410-
411+ self .start_routers ()
412+ self .check_routers_state ()
413+ self .check_private_gateway_interfaces ()
411414 self .check_pvt_gw_connectivity (vm1 , public_ip_1 , [vm2 .nic [0 ].ipaddress , vm3 .nic [0 ].ipaddress , vm4 .nic [0 ].ipaddress ])
412415
413- self .stop_router_by_type ( routers , status_to_check = "MASTER" )
414- self .check_routers_state ( routers )
416+ self .deletePvtGw ( privateGw_1 . id )
417+ self .check_private_gateway_interfaces ( status_to_check = "DOWN" )
415418
416- self .check_private_gateway_interfaces (routers )
417- self .check_pvt_gw_connectivity (vm1 , public_ip_1 , [vm2 .nic [0 ].ipaddress , vm3 .nic [0 ].ipaddress , vm4 .nic [0 ].ipaddress ])
419+ def query_routers (self ):
420+ routers = list_routers (self .apiclient ,
421+ account = self .account .name ,
422+ domainid = self .account .domainid )
418423
419- self .start_routers (routers )
420- self .check_routers_state (routers )
421- self .check_private_gateway_interfaces (routers )
422- self .check_pvt_gw_connectivity (vm1 , public_ip_1 , [vm2 .nic [0 ].ipaddress , vm3 .nic [0 ].ipaddress , vm4 .nic [0 ].ipaddress ])
424+ self .assertEqual (isinstance (routers , list ), True ,
425+ "Check for list routers response return valid data" )
426+
427+ self .assertEqual (len (routers ), 2 ,
428+ "Check for list routers size returned '%s' instead of 2" % len (routers ))
429+
430+ return routers
423431
424- def stop_router_by_type (self , type , routers ):
425- self .logger .debug ('Stopping %s router' % type )
432+ def stop_router_by_type (self , redundant_state ):
433+ self .logger .debug ('Stopping %s router' % redundant_state )
434+ routers = self .query_routers ()
426435 for router in routers :
427- if router .redundantstate == type :
436+ if router .redundantstate == redundant_state :
428437 self .stop_router (router )
429438 break
430439
431- def start_routers (self , routers ):
440+ def start_routers (self ):
432441 self .logger .debug ('Starting stopped routers' )
442+ routers = self .query_routers ()
433443 for router in routers :
434444 self .logger .debug ('Router %s has state %s' % (router .id , router .state ))
435445 if router .state == "Stopped" :
@@ -438,6 +448,12 @@ def start_routers(self, routers):
438448 cmd .id = router .id
439449 self .apiclient .startRouter (cmd )
440450
451+ def stop_router (self , router ):
452+ self .logger .debug ('Stopping router %s' % router .id )
453+ cmd = stopRouter .stopRouterCmd ()
454+ cmd .id = router .id
455+ self .apiclient .stopRouter (cmd )
456+
441457 def createVPC (self , vpc_offering , cidr = '10.1.1.1/16' ):
442458 try :
443459 self .logger .debug ("Creating a VPC network in the account: %s" % self .account .name )
@@ -574,14 +590,27 @@ def createPvtGw(self, vpc, ip_address, gateway, aclId, vlan):
574590 createPrivateGatewayCmd .aclid = aclId
575591
576592 try :
577- privateGw = self .apiclient .createPrivateGateway (createPrivateGatewayCmd )
593+ privateGw = self .apiclient .createPrivateGateway (createPrivateGatewayCmd )
578594 except Exception as e :
579595 self .fail ("Failed to create Private Gateway ==> %s" % e )
580596
581- self .assertIsNotNone (privateGw .id , "Failed to create ACL ." )
597+ self .assertIsNotNone (privateGw .id , "Failed to create Private Gateway ." )
582598
583599 return privateGw
584600
601+ def deletePvtGw (self , private_gw_id ):
602+ deletePrivateGatewayCmd = deletePrivateGateway .deletePrivateGatewayCmd ()
603+ deletePrivateGatewayCmd .id = private_gw_id
604+
605+ privateGwResponse = None
606+ try :
607+ privateGwResponse = self .apiclient .deletePrivateGateway (deletePrivateGatewayCmd )
608+ except Exception as e :
609+ self .fail ("Failed to create Private Gateway ==> %s" % e )
610+
611+ self .assertIsNotNone (privateGwResponse , "Failed to Delete Private Gateway." )
612+ self .assertTrue (privateGwResponse .success , "Failed to Delete Private Gateway." )
613+
585614 def replaceNetworkAcl (self , aclId , network ):
586615 self .logger .debug ("Replacing Network ACL with ACL ID ==> %s" % aclId )
587616
@@ -642,6 +671,9 @@ def create_natrule(self, vpc, virtual_machine, public_ip, network):
642671 return nat_rule
643672
644673 def check_pvt_gw_connectivity (self , virtual_machine , public_ip , vms_ips ):
674+ sleep_time = 5
675+ succeeded_pings = 0
676+ minimum_vms_to_pass = 2
645677 for vm_ip in vms_ips :
646678 ssh_command = "ping -c 3 %s" % vm_ip
647679
@@ -652,22 +684,25 @@ def check_pvt_gw_connectivity(self, virtual_machine, public_ip, vms_ips):
652684
653685 ssh = virtual_machine .get_ssh_client (ipaddress = public_ip .ipaddress .ipaddress )
654686
687+ self .logger .debug ("Sleeping for %s seconds in order to get the firewall applied..." % sleep_time )
688+ time .sleep (sleep_time )
689+ sleep_time += sleep_time
690+
655691 self .logger .debug ("Ping to VM inside another Network Tier" )
656692 result = str (ssh .execute (ssh_command ))
657693
658694 self .logger .debug ("SSH result: %s; COUNT is ==> %s" % (result , result .count ("3 packets received" )))
659695 except Exception as e :
660696 self .fail ("SSH Access failed for %s: %s" % \
661- (vmObj . get_ip () , e )
697+ (virtual_machine , e )
662698 )
663699
664- self .assertEqual (
665- result .count ("3 packets received" ),
666- 1 ,
667- "Ping to VM on Network Tier N from VM in Network Tier A should be successful"
668- )
700+ succeeded_pings += result .count ("3 packets received" )
701+
669702
670- time .sleep (5 )
703+ self .assertTrue (succeeded_pings >= minimum_vms_to_pass ,
704+ "Ping to VM on Network Tier N from VM in Network Tier A should be successful at least for 2 out of 3 VMs"
705+ )
671706
672707 def reboot_vpc_with_cleanup (self , vpc , cleanup = True ):
673708 self .logger .debug ("Restarting VPC %s with cleanup" % vpc .id )
@@ -679,13 +714,20 @@ def reboot_vpc_with_cleanup(self, vpc, cleanup = True):
679714 cmd .makeredundant = False
680715 self .api_client .restartVPC (cmd )
681716
682- def check_private_gateway_interfaces (self , routers ):
717+ def check_private_gateway_interfaces (self , status_to_check = "UP" ):
718+ routers = self .query_routers ()
719+
683720 state_holder = {routers [0 ].linklocalip : {"state" : None , "mac" : None },
684721 routers [1 ].linklocalip : {"state" : None , "mac" : None }}
685722 state = None
686723 mac = None
687724 for router in routers :
688- hosts = list_hosts (self .apiclient , id = router .hostid )
725+ hosts = list_hosts (
726+ self .apiclient ,
727+ zoneid = router .zoneid ,
728+ type = 'Routing' ,
729+ state = 'Up' ,
730+ id = router .hostid )
689731
690732 self .assertEqual (
691733 isinstance (hosts , list ),
@@ -716,17 +758,26 @@ def check_private_gateway_interfaces(self, routers):
716758 except KeyError :
717759 self .skipTest ("Provide a marvin config file with host credentials to run %s" % self ._testMethodName )
718760
761+ state = str (state [0 ])
762+ mac = str (mac [0 ])
763+
719764 self .logger .debug ("Result from the Router on IP '%s' is -> state: '%s', mac: '%s'" % (router .linklocalip , state , mac ))
720765 state_holder [router .linklocalip ]["state" ] = str (state )
721766 state_holder [router .linklocalip ]["mac" ] = str (mac )
722767
723- check_state = state_holder [routers [0 ].linklocalip ]["state" ].count (state_holder [routers [1 ].linklocalip ]["state" ])
724- check_mac = state_holder [routers [0 ].linklocalip ]["mac" ].count (state_holder [routers [1 ].linklocalip ]["mac" ])
725768
726- self .assertTrue (check_state == 0 , "Routers private gateway interface should not be on the same state!" )
727- self .assertTrue (check_mac == 0 , "Routers private gateway interface should not have the same mac address!" )
769+ if status_to_check == "UP" :
770+ check_state = state_holder [routers [0 ].linklocalip ]["state" ].count (state_holder [routers [1 ].linklocalip ]["state" ])
771+ check_mac = state_holder [routers [0 ].linklocalip ]["mac" ].count (state_holder [routers [1 ].linklocalip ]["mac" ])
772+
773+ self .assertTrue (check_state == 0 , "Routers private gateway interface should not be on the same state!" )
774+ self .assertTrue (check_mac == 0 , "Routers private gateway interface should not have the same mac address!" )
775+ else :
776+ self .assertTrue (check_state == 1 , "Routers private gateway interface should should have been removed!" )
777+
778+ def check_routers_state (self , status_to_check = "MASTER" , expected_count = 1 ):
779+ routers = self .query_routers ()
728780
729- def check_routers_state (self , routers , status_to_check = "MASTER" , expected_count = 1 ):
730781 vals = ["MASTER" , "BACKUP" , "UNKNOWN" ]
731782 cnts = [0 , 0 , 0 ]
732783
0 commit comments