@@ -2149,211 +2149,4 @@ def test_invalid_parameters(self):
21492149 return
21502150
21512151
2152- class TestEgressAfterHostMaintenance (cloudstackTestCase ):
21532152
2154- def setUp (self ):
2155-
2156- self .apiclient = self .testClient .getApiClient ()
2157- self .dbclient = self .testClient .getDbConnection ()
2158- self .cleanup = []
2159- return
2160-
2161- def tearDown (self ):
2162- try :
2163- #Clean up, terminate the created templates
2164- cleanup_resources (self .apiclient , self .cleanup )
2165-
2166- except Exception as e :
2167- raise Exception ("Warning: Exception during cleanup : %s" % e )
2168- return
2169-
2170- @classmethod
2171- def setUpClass (cls ):
2172- cls .services = Services ().services
2173- cls .api_client = super (
2174- TestEgressAfterHostMaintenance ,
2175- cls
2176- ).getClsTestClient ().getApiClient ()
2177-
2178- # Get Zone, Domain and templates
2179- cls .domain = get_domain (cls .api_client , cls .services )
2180- cls .zone = get_zone (cls .api_client , cls .services )
2181- cls .services ['mode' ] = cls .zone .networktype
2182- cls .pod = get_pod (
2183- cls .api_client ,
2184- zoneid = cls .zone .id
2185- )
2186-
2187- template = get_template (
2188- cls .api_client ,
2189- cls .zone .id ,
2190- cls .services ["ostype" ]
2191- )
2192- cls .services ["domainid" ] = cls .domain .id
2193- cls .services ["virtual_machine" ]["zoneid" ] = cls .zone .id
2194- cls .services ["virtual_machine" ]["template" ] = template .id
2195-
2196- cls .service_offering = ServiceOffering .create (
2197- cls .api_client ,
2198- cls .services ["service_offering" ]
2199- )
2200- cls .account = Account .create (
2201- cls .api_client ,
2202- cls .services ["account" ],
2203- domainid = cls .domain .id
2204- )
2205- cls .services ["account" ] = cls .account .name
2206- cls ._cleanup = [
2207- cls .account ,
2208- cls .service_offering
2209- ]
2210- return
2211-
2212- @classmethod
2213- def tearDownClass (cls ):
2214- try :
2215- #Cleanup resources used
2216- cleanup_resources (cls .api_client , cls ._cleanup )
2217-
2218- except Exception as e :
2219- raise Exception ("Warning: Exception during cleanup : %s" % e )
2220-
2221- return
2222-
2223- @attr (speed = "slow" )
2224- @attr (tags = ["sg" , "eip" , "maintenance" ])
2225- def test_egress_after_host_maintenance (self ):
2226- """Test maintenance case for egress
2227- """
2228-
2229- # Validate the following:
2230- # 1. createaccount of type user
2231- # 2. createsecuritygroup (ssh) for this account
2232- # 3. authorizeSecurityGroupIngress to allow ssh access to the VM
2233- # 4. authorizeSecurityGroupEgress to allow ssh access only out to
2234- # CIDR: 0.0.0.0/0
2235- # 5. deployVirtualMachine into this security group (ssh)
2236- # 6. deployed VM should be Running, ssh should be allowed into the VM
2237- # 7. Enable maintenance mode for host, cance maintenance mode
2238- # 8. User should be able to SSH into VM after maintainace
2239-
2240- security_group = SecurityGroup .create (
2241- self .apiclient ,
2242- self .services ["security_group" ],
2243- account = self .account .name ,
2244- domainid = self .account .domainid
2245- )
2246- self .debug ("Created security group with ID: %s" % security_group .id )
2247-
2248- # Default Security group should not have any ingress rule
2249- sercurity_groups = SecurityGroup .list (
2250- self .apiclient ,
2251- account = self .account .name ,
2252- domainid = self .account .domainid
2253- )
2254- self .assertEqual (
2255- isinstance (sercurity_groups , list ),
2256- True ,
2257- "Check for list security groups response"
2258- )
2259-
2260- self .assertEqual (
2261- len (sercurity_groups ),
2262- 2 ,
2263- "Check List Security groups response"
2264- )
2265- # Authorize Security group to SSH to VM
2266- self .debug (
2267- "Authorizing ingress rule for sec group ID: %s for ssh access"
2268- % security_group .id )
2269- ingress_rule = security_group .authorize (
2270- self .apiclient ,
2271- self .services ["security_group" ],
2272- account = self .account .name ,
2273- domainid = self .account .domainid
2274- )
2275-
2276- self .assertEqual (
2277- isinstance (ingress_rule , dict ),
2278- True ,
2279- "Check ingress rule created properly"
2280- )
2281-
2282- ssh_rule = (ingress_rule ["ingressrule" ][0 ]).__dict__
2283-
2284- # Authorize Security group to SSH to VM
2285- self .debug (
2286- "Authorizing egress rule for sec group ID: %s for ssh access"
2287- % security_group .id )
2288- egress_rule = security_group .authorizeEgress (
2289- self .apiclient ,
2290- self .services ["security_group" ],
2291- account = self .account .name ,
2292- domainid = self .account .domainid
2293- )
2294-
2295- self .assertEqual (
2296- isinstance (egress_rule , dict ),
2297- True ,
2298- "Check egress rule created properly"
2299- )
2300- ssh_egress_rule = (egress_rule ["egressrule" ][0 ]).__dict__
2301-
2302- self .virtual_machine = VirtualMachine .create (
2303- self .apiclient ,
2304- self .services ["virtual_machine" ],
2305- accountid = self .account .name ,
2306- domainid = self .account .domainid ,
2307- serviceofferingid = self .service_offering .id ,
2308- securitygroupids = [security_group .id ]
2309- )
2310- self .debug ("Deploying VM in account: %s" % self .account .name )
2311-
2312- # Should be able to SSH VM
2313- try :
2314- self .debug ("SSH into VM: %s" % self .virtual_machine .id )
2315- ssh = self .virtual_machine .get_ssh_client ()
2316- except Exception as e :
2317- self .fail ("SSH Access failed for %s: %s" % \
2318- (self .virtual_machine .ipaddress , e )
2319- )
2320- vms = VirtualMachine .list (
2321- self .apiclient ,
2322- id = self .virtual_machine .id ,
2323- listall = True
2324- )
2325- self .assertEqual (
2326- isinstance (vms , list ),
2327- True ,
2328- "Check list VMs response for valid host"
2329- )
2330- vm = vms [0 ]
2331-
2332- self .debug ("Enabling host maintenance for ID: %s" % vm .hostid )
2333- cmd = prepareHostForMaintenance .prepareHostForMaintenanceCmd ()
2334- cmd .id = vm .hostid
2335- self .apiclient .prepareHostForMaintenance (cmd )
2336-
2337- self .debug ("Canceling host maintenance for ID: %s" % vm .hostid )
2338- cmd = cancelHostMaintenance .cancelHostMaintenanceCmd ()
2339- cmd .id = vm .hostid
2340- self .apiclient .cancelHostMaintenance (cmd )
2341-
2342- self .debug ("Waiting for SSVMs to come up" )
2343- wait_for_ssvms (
2344- self .apiclient ,
2345- zoneid = self .zone .id ,
2346- podid = self .pod .id ,
2347- )
2348- self .debug ("Starting VM: %s" % self .virtual_machine .id )
2349-
2350- self .virtual_machine .start (self .apiclient )
2351- # Should be able to SSH VM
2352- try :
2353- self .debug ("SSH into VM: %s" % self .virtual_machine .id )
2354- ssh = self .virtual_machine .get_ssh_client (reconnect = True )
2355- except Exception as e :
2356- self .fail ("SSH Access failed for %s: %s" % \
2357- (self .virtual_machine .ipaddress , e )
2358- )
2359- return
0 commit comments