1616# under the License.
1717
1818from nose .plugins .attrib import attr
19- from marvin .cloudstackTestCase import *
20- from marvin .cloudstackAPI import *
21- from marvin .lib .utils import *
22- from marvin .lib .base import *
23- from marvin .lib .common import *
19+ from marvin .cloudstackTestCase import cloudstackTestCase , unittest
20+ from marvin .lib .utils import cleanup_resources
21+ from marvin .lib .base import (Account ,
22+ Host ,
23+ VPC ,
24+ VpcOffering )
25+ from marvin .lib .common import (get_domain ,
26+ get_zone ,
27+ get_template ,
28+ list_configurations )
29+ import time
2430
2531
2632class Services :
33+
2734 """Test VPC services
2835 """
2936
3037 def __init__ (self ):
3138 self .services = {
32- "account" : {
33- "email" : "test@test.com" ,
34- "firstname" : "Test" ,
35- "lastname" : "User" ,
36- "username" : "test" ,
37- # Random characters are appended for unique
38- # username
39- "password" : "password" ,
40- },
41- "service_offering" : {
42- "name" : "Tiny Instance" ,
43- "displaytext" : "Tiny Instance" ,
44- "cpunumber" : 1 ,
45- "cpuspeed" : 100 ,
46- "memory" : 128 ,
47- },
48- "vpc_offering" : {
49- "name" : 'VPC off' ,
50- "displaytext" : 'VPC off' ,
51- "supportedservices" : 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat,NetworkACL' ,
52- },
53- "vpc" : {
54- "name" : "TestVPC" ,
55- "displaytext" : "TestVPC" ,
56- "cidr" : '10.0.0.1/24'
57- },
58- "virtual_machine" : {
59- "displayname" : "Test VM" ,
60- "username" : "root" ,
61- "password" : "password" ,
62- "ssh_port" : 22 ,
63- "hypervisor" : 'XenServer' ,
64- # Hypervisor type should be same as
65- # hypervisor type of cluster
66- "privateport" : 22 ,
67- "publicport" : 22 ,
68- "protocol" : 'TCP' ,
69- },
70- "ostype" : 'CentOS 5.3 (64-bit)' ,
71- # Cent OS 5.3 (64 bit)
72- "sleep" : 60 ,
73- "timeout" : 10
74- }
39+ "account" : {
40+ "email" : "test@test.com" ,
41+ "firstname" : "Test" ,
42+ "lastname" : "User" ,
43+ "username" : "test" ,
44+ # Random characters are appended for unique
45+ # username
46+ "password" : "password" ,
47+ },
48+ "vpc_offering" : {
49+ "name" : 'VPC off' ,
50+ "displaytext" : 'VPC off' ,
51+ "supportedservices" : 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,\
52+ UserData,StaticNat,NetworkACL' ,
53+ },
54+ "vpc" : {
55+ "name" : "TestVPC" ,
56+ "displaytext" : "TestVPC" ,
57+ "cidr" : '10.0.0.1/24'
58+ },
59+ "virtual_machine" : {
60+ "displayname" : "Test VM" ,
61+ "username" : "root" ,
62+ "password" : "password" ,
63+ "ssh_port" : 22 ,
64+ "hypervisor" : 'XenServer' ,
65+ # Hypervisor type should be same as
66+ # hypervisor type of cluster
67+ "privateport" : 22 ,
68+ "publicport" : 22 ,
69+ "protocol" : 'TCP' ,
70+ },
71+ "ostype" : 'CentOS 5.3 (64-bit)' ,
72+ # Cent OS 5.3 (64 bit)
73+ "sleep" : 60 ,
74+ "timeout" : 10
75+ }
76+
7577
7678class TestVPCHostMaintenance (cloudstackTestCase ):
7779
@@ -93,24 +95,20 @@ def setUpClass(cls):
9395 cls .services ["virtual_machine" ]["template" ] = cls .template .id
9496 cls .services ["mode" ] = cls .zone .networktype
9597
96- cls .service_offering = ServiceOffering .create (
97- cls .api_client ,
98- cls .services ["service_offering" ]
99- )
10098 cls .vpc_off = VpcOffering .create (
10199 cls .api_client ,
102100 cls .services ["vpc_offering" ]
103101 )
104102 cls .vpc_off .update (cls .api_client , state = 'Enabled' )
105- hosts = Host .list (
103+ cls . hosts = Host .list (
106104 cls .api_client ,
107105 zoneid = cls .zone .id ,
108106 listall = True ,
109107 type = 'Routing'
110108 )
111109
112- if isinstance (hosts , list ):
113- for host in hosts :
110+ if isinstance (cls . hosts , list ):
111+ for host in cls . hosts :
114112 Host .enableMaintenance (
115113 cls .api_client ,
116114 id = host .id
@@ -124,48 +122,43 @@ def setUpClass(cls):
124122 id = host .id ,
125123 listall = True
126124 )
127- if hosts_states [0 ].resourcestate == 'PrepareForMaintenance' :
125+ if hosts_states [
126+ 0 ].resourcestate == 'PrepareForMaintenance' :
128127 # Wait for sometimetill host goes in maintenance state
129128 time .sleep (cls .services ["sleep" ])
130129 elif hosts_states [0 ].resourcestate == 'Maintenance' :
131130 time .sleep (cls .services ["sleep" ])
132131 break
133132 elif timeout == 0 :
134133 raise unittest .SkipTest (
135- "Failed to enable maintenance mode on %s" % host .name )
134+ "Failed to enable maintenance mode on %s" %
135+ host .name )
136136 timeout = timeout - 1
137137
138138 cls ._cleanup = [
139- cls .service_offering ,
140139 cls .vpc_off
141140 ]
142141 return
143142
144143 @classmethod
145144 def tearDownClass (cls ):
146145 try :
147- #Cleanup resources used
146+ # Cleanup resources used
148147 cleanup_resources (cls .api_client , cls ._cleanup )
149- hosts = Host .list (
150- cls .api_client ,
151- zoneid = cls .zone .id ,
152- listall = True ,
153- type = 'Routing'
154- )
155- if isinstance (hosts , list ):
156- for host in hosts :
157- Host .cancelMaintenance (
158- cls .api_client ,
159- id = host .id
160- )
148+ for host in cls .hosts :
149+ Host .cancelMaintenance (
150+ cls .api_client ,
151+ id = host .id
152+ )
161153 hosts_states = Host .list (
162154 cls .api_client ,
163155 id = host .id ,
164156 listall = True
165157 )
166158 if hosts_states [0 ].resourcestate != 'Enabled' :
167159 raise Exception (
168- "Failed to cancel maintenance mode on %s" % (host .name ))
160+ "Failed to cancel maintenance mode on %s" %
161+ (host .name ))
169162 except Exception as e :
170163 raise Exception ("Warning: Exception during cleanup : %s" % e )
171164 return
@@ -184,18 +177,8 @@ def setUp(self):
184177
185178 def tearDown (self ):
186179 try :
187- #Clean up, terminate the created network offerings
180+ # Clean up, terminate the created network offerings
188181 cleanup_resources (self .apiclient , self .cleanup )
189- interval = list_configurations (
190- self .apiclient ,
191- name = 'network.gc.interval'
192- )
193- wait = list_configurations (
194- self .apiclient ,
195- name = 'network.gc.wait'
196- )
197- # Sleep to ensure that all resources are deleted
198- time .sleep (int (interval [0 ].value ) + int (wait [0 ].value ))
199182 except Exception as e :
200183 raise Exception ("Warning: Exception during cleanup : %s" % e )
201184 return
@@ -243,7 +226,7 @@ def validate_vpc_network(self, network, state=None):
243226 )
244227 if state :
245228 self .assertEqual (
246- vpc_networks [0 ].state ,
229+ vpc_networks [0 ].state . lower () ,
247230 state ,
248231 "VPC state should be '%s'" % state
249232 )
@@ -269,9 +252,10 @@ def test_01_create_vpc_host_maintenance(self):
269252 vpcofferingid = self .vpc_off .id ,
270253 zoneid = self .zone .id ,
271254 account = self .account .name ,
272- domainid = self .account .domainid
255+ domainid = self .account .domainid ,
256+ start = False
273257 )
274- self .validate_vpc_network (vpc , state = 'Disabled ' )
258+ self .validate_vpc_network (vpc , state = 'inactive ' )
275259 return
276260
277261 @attr (tags = ["advanced" , "intervlan" ])
@@ -295,9 +279,10 @@ def test_02_create_vpc_wait_gc(self):
295279 vpcofferingid = self .vpc_off .id ,
296280 zoneid = self .zone .id ,
297281 account = self .account .name ,
298- domainid = self .account .domainid
282+ domainid = self .account .domainid ,
283+ start = False
299284 )
300- self .validate_vpc_network (vpc , state = 'Disabled ' )
285+ self .validate_vpc_network (vpc , state = 'inactive ' )
301286 interval = list_configurations (
302287 self .apiclient ,
303288 name = 'network.gc.interval'
0 commit comments