1616# under the License.
1717""" P1 tests for Storage motion
1818"""
19- #Import Local Modules
20- import marvin
21- from marvin .cloudstackTestCase import *
22- from marvin .cloudstackAPI import *
23- from marvin .sshClient import SshClient
24- from marvin .lib .utils import *
25- from marvin .lib .base import *
26- from marvin .lib .common import *
19+ # Import Local Modules
20+ from marvin .cloudstackTestCase import cloudstackTestCase
21+ from marvin .lib .utils import cleanup_resources
22+ from marvin .cloudstackAPI import dedicateHost , releaseDedicatedHost
23+ from marvin .lib .base import (Account ,
24+ ServiceOffering ,
25+ VirtualMachine ,
26+ AffinityGroup )
27+ from marvin .lib .common import (get_domain ,
28+ get_zone ,
29+ get_template ,
30+ list_hosts ,
31+ list_virtual_machines )
2732from nose .plugins .attrib import attr
28- #Import System modules
29- import time
3033
3134_multiprocess_shared_ = True
35+
36+
3237class Services :
38+
3339 """Test explicit dedication
3440 """
3541
3642 def __init__ (self ):
3743 self .services = {
38- "disk_offering" :{
39- "displaytext" : "Small" ,
40- "name" : "Small" ,
41- "disksize" : 1
42- },
43- "account" : {
44- "email" : "test@test.com" ,
45- "firstname" : "Test" ,
46- "lastname" : "User" ,
47- "username" : "testexplicit" ,
48- # Random characters are appended in create account to
49- # ensure unique username generated each time
50- "password" : "password" ,
51- },
52- "virtual_machine" :
44+ "disk_offering" : {
45+ "displaytext" : "Small" ,
46+ "name" : "Small" ,
47+ "disksize" : 1
48+ },
49+ "account" : {
50+ "email" : "test@test.com" ,
51+ "firstname" : "Test" ,
52+ "lastname" : "User" ,
53+ "username" : "testexplicit" ,
54+ # Random characters are appended in create account to
55+ # ensure unique username generated each time
56+ "password" : "password" ,
57+ },
58+ "virtual_machine" :
5359 {
5460 "affinity" : {
5561 "name" : "explicit" ,
5662 "type" : "ExplicitDedication" ,
5763 },
58- "hypervisor" : "XenServer" ,
59- },
60- "small" :
64+ "hypervisor" : "XenServer" ,
65+ },
66+ "small" :
6167 # Create a small virtual machine instance with disk offering
6268 {
6369 "displayname" : "testserver" ,
64- "username" : "root" , # VM creds for SSH
70+ "username" : "root" , # VM creds for SSH
6571 "password" : "password" ,
6672 "ssh_port" : 22 ,
6773 "hypervisor" : 'XenServer' ,
6874 "privateport" : 22 ,
6975 "publicport" : 22 ,
7076 "protocol" : 'TCP' ,
71- },
72- "service_offerings" :
77+ },
78+ "service_offerings" :
7379 {
74- "for-explicit" :
80+ "for-explicit" :
7581 {
76- # Small service offering ID to for change VM
77- # service offering from medium to small
82+ # Small service offering ID to for change VM
83+ # service offering from medium to small
7884 "name" : "For explicit" ,
7985 "displaytext" : "For explicit" ,
8086 "cpunumber" : 1 ,
8187 "cpuspeed" : 500 ,
8288 "memory" : 512
8389 }
84- },
85- "template" : {
90+ },
91+ "template" : {
8692 "displaytext" : "Cent OS Template" ,
8793 "name" : "Cent OS Template" ,
8894 "passwordenabled" : True ,
89- },
90- "sleep" : 60 ,
95+ },
96+ "sleep" : 60 ,
9197 "timeout" : 10 ,
9298 "ostype" : 'CentOS 5.3 (64-bit)'
9399 }
94100
101+
95102class TestExplicitDedication (cloudstackTestCase ):
96103
97104 @classmethod
@@ -106,37 +113,36 @@ def setUpClass(cls):
106113 cls .services ['mode' ] = cls .zone .networktype
107114
108115 cls .template = get_template (
109- cls .api_client ,
110- cls .zone .id ,
111- cls .services ["ostype" ]
112- )
116+ cls .api_client ,
117+ cls .zone .id ,
118+ cls .services ["ostype" ]
119+ )
113120 # Set Zones and disk offerings
114121 cls .services ["small" ]["zoneid" ] = cls .zone .id
115122 cls .services ["small" ]["template" ] = cls .template .id
116123
117124 # Create VMs, NAT Rules etc
118125 cls .account = Account .create (
119- cls .api_client ,
120- cls .services ["account" ],
121- domainid = cls .domain .id
122- )
126+ cls .api_client ,
127+ cls .services ["account" ],
128+ domainid = cls .domain .id
129+ )
123130
124131 cls .small_offering = ServiceOffering .create (
125- cls .api_client ,
126- cls .services ["service_offerings" ]["for-explicit" ]
127- )
128-
129- #cls.ag = AffinityGroup.create(cls.api_client, cls.services["virtual_machine"]["affinity"],
130- # account=cls.services["account"], domainid=cls.domain.id)
132+ cls .api_client ,
133+ cls .services ["service_offerings" ]["for-explicit" ]
134+ )
131135
132136 cls ._cleanup = [
133- cls .small_offering ,
134- cls .account
135- ]
137+ cls .small_offering ,
138+ cls .account
139+ ]
136140
137141 @classmethod
138142 def tearDownClass (cls ):
139- cls .api_client = super (TestExplicitDedication , cls ).getClsTestClient ().getApiClient ()
143+ cls .api_client = super (
144+ TestExplicitDedication ,
145+ cls ).getClsTestClient ().getApiClient ()
140146 cleanup_resources (cls .api_client , cls ._cleanup )
141147 return
142148
@@ -146,57 +152,58 @@ def setUp(self):
146152 self .cleanup = []
147153
148154 def tearDown (self ):
149- #Clean up, terminate the created ISOs
155+ # Clean up, terminate the created ISOs
150156 cleanup_resources (self .apiclient , self .cleanup )
151157 return
152158
153- # This test requires multi host and at least one host which is empty (no vms should
154- # be running on that host). It explicitly dedicates empty host to an account, deploys
155- # a vm for that account and verifies that the vm gets deployed to the dedicated host.
156- @attr (tags = ["advanced" , "basic" , "multihosts" , "explicitdedication" ], required_hardware = "false" )
159+ # This test requires multi host and at least one host which is empty
160+ # (no vms should be running on that host). It explicitly dedicates
161+ # empty host to an account, deploys a vm for that account and verifies
162+ # that the vm gets deployed to the dedicated host.
163+ @attr (
164+ tags = [
165+ "advanced" ,
166+ "basic" ,
167+ "multihosts" ,
168+ "explicitdedication" ],
169+ required_hardware = "false" )
157170 def test_01_deploy_vm_with_explicit_dedication (self ):
158171 """Test explicit dedication is placing vms of an account on dedicated hosts.
159172 """
160173 # Validate the following
161174 # 1. Find and dedicate an empty host to an account.
162- # 2. Create an affinity group for explicit dedication.
163- # 3. Create a vm deployment by passing the affinity group as a parameter.
164- # 4 . Validate the vm got deployed on the dedicated host.
165- # 5 . Cleanup.
175+ # 2. Create a vm deployment by passing the affinity group as a
176+ # parameter.
177+ # 3 . Validate the vm got deployed on the dedicated host.
178+ # 4 . Cleanup.
166179
167180 # list and find an empty hosts
168181 all_hosts = list_hosts (
169- self .apiclient ,
170- type = 'Routing' ,
171- )
182+ self .apiclient ,
183+ type = 'Routing' ,
184+ )
172185
173186 empty_host = None
174187 for host in all_hosts :
175188 vms_on_host = list_virtual_machines (
176- self .api_client ,
177- hostid = host .id )
189+ self .api_client ,
190+ hostid = host .id )
178191 if not vms_on_host :
179192 empty_host = host
180193 break
181194
182- #If no empty host is found, return
183- if empty_host :
184- self .skipTest ("Did not find any empty hosts, Skipping" )
185-
186- # Create an affinity group for explicit dedication.
187- agCmd = createAffinityGroup .createAffinityGroupCmd ()
188- agCmd .name = "explicit-affinity"
189- agCmd .displayText = "explicit-affinity"
190- agCmd .account = self .account .name
191- agCmd .domainid = self .account .domainid
192- agCmd .type = self .services ['virtual_machine' ]['affinity' ]['type' ]
193- self .apiclient .createAffinityGroup (agCmd )
195+ # If no empty host is found, return
196+ if empty_host is None :
197+ self .skipTest ("Did not find any empty hosts, Skipping" )
194198
195199 # dedicate the empty host to this account.
196200 dedicateCmd = dedicateHost .dedicateHostCmd ()
197201 dedicateCmd .hostid = empty_host .id
198202 dedicateCmd .domainid = self .domain .id
199- self .apiclient .dedicateHost (dedicateCmd )
203+ self .api_client .dedicateHost (dedicateCmd )
204+ affinitygroup = AffinityGroup .list (
205+ self .apiclient ,
206+ type = "ExplicitDedication" )
200207
201208 # deploy vm on the dedicated resource.
202209 vm = VirtualMachine .create (
@@ -205,29 +212,30 @@ def test_01_deploy_vm_with_explicit_dedication(self):
205212 accountid = self .account .name ,
206213 domainid = self .account .domainid ,
207214 serviceofferingid = self .small_offering .id ,
208- affinitygroupnames = [ "explicit-affinity" ] ,
215+ affinitygroupids = affinitygroup [ 0 ]. id ,
209216 mode = self .services ["mode" ]
210217 )
211218
212219 list_vm_response = list_virtual_machines (
213- self .apiclient ,
214- id = vm .id
215- )
220+ self .apiclient ,
221+ id = vm .id
222+ )
216223
217224 vm_response = list_vm_response [0 ]
218225
219226 self .assertEqual (
220- vm_response .hostid ,
221- empty_host .id ,
222- "Check destination hostID of deployed VM"
223- )
227+ vm_response .hostid ,
228+ empty_host .id ,
229+ "Check destination hostID of deployed VM"
230+ )
224231
225232 # release the dedicated host to this account.
226233 releaseCmd = releaseDedicatedHost .releaseDedicatedHostCmd ()
227234 releaseCmd .hostid = empty_host .id
228235 releaseCmd .domainid = self .domain .id
229236 self .apiclient .releaseDedicatedHost (releaseCmd )
230237
231- #Deletion of the created VM and affinity group is taken care as part of account clean
238+ # Deletion of the created VM and affinity group is taken care as part
239+ # of account clean
232240
233241 return
0 commit comments