Skip to content

Commit e7fe391

Browse files
Gaurav AradhyeGirish Shilamkar
authored andcommitted
CLOUDSTACK-1466: Automatiion - Primary Storage Limits test cases
1 parent 942fc98 commit e7fe391

8 files changed

Lines changed: 2341 additions & 7 deletions

File tree

test/integration/component/test_ps_domain_limits.py

Lines changed: 690 additions & 0 deletions
Large diffs are not rendered by default.

test/integration/component/test_ps_limits.py

Lines changed: 588 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
""" Tests for praimary storage - Maximum Limits
19+
20+
Test Plan: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Limit+Resources+to+domain+or+accounts
21+
22+
Issue Link: https://issues.apache.org/jira/browse/CLOUDSTACK-1466
23+
24+
Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Limit+Resources+to+domains+and+accounts
25+
"""
26+
# Import Local Modules
27+
from nose.plugins.attrib import attr
28+
from marvin.cloudstackTestCase import cloudstackTestCase, unittest
29+
from marvin.lib.base import (Account,
30+
ServiceOffering,
31+
VirtualMachine,
32+
Resources,
33+
Domain,
34+
Project,
35+
Volume,
36+
DiskOffering)
37+
from marvin.lib.common import (get_domain,
38+
get_zone,
39+
get_template)
40+
from marvin.lib.utils import (cleanup_resources,
41+
validateList)
42+
from marvin.codes import PASS, FAIL
43+
44+
class TestMaxPrimaryStorageLimits(cloudstackTestCase):
45+
46+
@classmethod
47+
def setUpClass(cls):
48+
cloudstackTestClient = super(TestMaxPrimaryStorageLimits,
49+
cls).getClsTestClient()
50+
cls.api_client = cloudstackTestClient.getApiClient()
51+
# Fill services from the external config file
52+
cls.services = cloudstackTestClient.getParsedTestDataConfig()
53+
# Get Zone, Domain and templates
54+
cls.domain = get_domain(cls.api_client)
55+
cls.zone = get_zone(cls.api_client, cloudstackTestClient.getZoneForTests())
56+
cls.services["mode"] = cls.zone.networktype
57+
58+
cls.template = get_template(
59+
cls.api_client,
60+
cls.zone.id,
61+
cls.services["ostype"]
62+
)
63+
64+
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
65+
cls.services["virtual_machine"]["template"] = cls.template.id
66+
cls.services["volume"]["zoneid"] = cls.zone.id
67+
cls._cleanup = []
68+
try:
69+
cls.service_offering = ServiceOffering.create(cls.api_client, cls.services["service_offering"])
70+
cls._cleanup.append(cls.service_offering)
71+
except Exception as e:
72+
cls.tearDownClass()
73+
raise unittest.SkipTest("Exception in setUpClass: %s" % e)
74+
return
75+
76+
@classmethod
77+
def tearDownClass(cls):
78+
try:
79+
# Cleanup resources used
80+
cleanup_resources(cls.api_client, cls._cleanup)
81+
except Exception as e:
82+
raise Exception("Warning: Exception during cleanup : %s" % e)
83+
return
84+
85+
def setUp(self):
86+
self.apiclient = self.testClient.getApiClient()
87+
self.dbclient = self.testClient.getDbConnection()
88+
self.cleanup = []
89+
try:
90+
response = self.setupAccounts()
91+
if response[0] == FAIL:
92+
self.skipTest("Failure while setting up accounts: %s" % response[1])
93+
self.services["disk_offering"]["disksize"] = 2
94+
self.disk_offering = DiskOffering.create(self.apiclient, self.services["disk_offering"])
95+
self.cleanup.append(self.disk_offering)
96+
except Exception as e:
97+
self.tearDown()
98+
self.skipTest("Failure in setup: %s" % e)
99+
return
100+
101+
def tearDown(self):
102+
try:
103+
# Clean up, terminate the created instance, volumes and snapshots
104+
cleanup_resources(self.apiclient, self.cleanup)
105+
except Exception as e:
106+
raise Exception("Warning: Exception during cleanup : %s" % e)
107+
return
108+
109+
def setupAccounts(self):
110+
111+
try:
112+
self.child_domain = Domain.create(self.apiclient,services=self.services["domain"],
113+
parentdomainid=self.domain.id)
114+
115+
self.child_do_admin = Account.create(self.apiclient, self.services["account"], admin=True,
116+
domainid=self.child_domain.id)
117+
118+
# Create project as a domain admin
119+
self.project = Project.create(self.apiclient, self.services["project"],
120+
account=self.child_do_admin.name,
121+
domainid=self.child_do_admin.domainid)
122+
123+
# Cleanup created project at end of test
124+
self.cleanup.append(self.project)
125+
126+
# Cleanup accounts created
127+
self.cleanup.append(self.child_do_admin)
128+
self.cleanup.append(self.child_domain)
129+
except Exception as e:
130+
return [FAIL, e]
131+
return [PASS, None]
132+
133+
def updatePrimaryStorageLimits(self, accountLimit=None, domainLimit=None,
134+
projectLimit=None):
135+
136+
try:
137+
# Update resource limits for account
138+
if accountLimit:
139+
Resources.updateLimit(self.apiclient, resourcetype=10,
140+
max=accountLimit, account=self.child_do_admin.name,
141+
domainid=self.child_do_admin.domainid)
142+
143+
if projectLimit:
144+
Resources.updateLimit(self.apiclient, resourcetype=10,
145+
max=projectLimit, projectid=self.project.id)
146+
147+
if domainLimit:
148+
Resources.updateLimit(self.apiclient, resourcetype=10,
149+
max=domainLimit, domainid=self.child_domain.id)
150+
except Exception as e:
151+
return [FAIL, e]
152+
return [PASS, None]
153+
154+
@attr(tags=["advanced","selfservice"])
155+
def test_01_deploy_vm_domain_limit_reached(self):
156+
"""Test Try to deploy VM with admin account where account has not used
157+
the resources but @ domain they are not available
158+
159+
# Validate the following
160+
# 1. Try to deploy VM with admin account where account has not used the
161+
# resources but @ domain they are not available
162+
# 2. Deploy VM should error out saying ResourceAllocationException
163+
# with "resource limit exceeds"""
164+
165+
self.virtualMachine = VirtualMachine.create(self.api_client, self.services["virtual_machine"],
166+
accountid=self.child_do_admin.name, domainid=self.child_do_admin.domainid,
167+
serviceofferingid=self.service_offering.id)
168+
169+
accounts = Account.list(self.apiclient, id=self.child_do_admin.id)
170+
self.assertEqual(validateList(accounts)[0], PASS,
171+
"accounts list validation failed")
172+
173+
self.initialResourceCount = int(accounts[0].primarystoragetotal)
174+
domainLimit = self.initialResourceCount + 3
175+
176+
self.debug("Setting up account and domain hierarchy")
177+
response = self.updatePrimaryStorageLimits(domainLimit=domainLimit)
178+
self.assertEqual(response[0], PASS, response[1])
179+
180+
self.services["volume"]["size"] = self.services["disk_offering"]["disksize"] = 2
181+
182+
try:
183+
disk_offering = DiskOffering.create(self.apiclient,
184+
services=self.services["disk_offering"])
185+
self.cleanup.append(disk_offering)
186+
Volume.create(self.apiclient,
187+
self.services["volume"],
188+
zoneid=self.zone.id,
189+
account=self.child_do_admin.name,
190+
domainid=self.child_do_admin.domainid,
191+
diskofferingid=disk_offering.id)
192+
except Exception as e:
193+
self.fail("Exception occured: %s" % e)
194+
195+
with self.assertRaises(Exception):
196+
Volume.create(self.apiclient,
197+
self.services["volume"],
198+
zoneid=self.zone.id,
199+
account=self.child_do_admin.name,
200+
domainid=self.child_do_admin.domainid,
201+
diskofferingid=disk_offering.id)
202+
return
203+
204+
@attr(tags=["advanced","selfservice"])
205+
def test_02_deploy_vm_account_limit_reached(self):
206+
"""Test Try to deploy VM with admin account where account has used
207+
the resources but @ domain they are available"""
208+
209+
self.virtualMachine = VirtualMachine.create(self.api_client, self.services["virtual_machine"],
210+
accountid=self.child_do_admin.name, domainid=self.child_do_admin.domainid,
211+
diskofferingid=self.disk_offering.id,
212+
serviceofferingid=self.service_offering.id)
213+
214+
accounts = Account.list(self.apiclient, id=self.child_do_admin.id)
215+
self.assertEqual(validateList(accounts)[0], PASS,
216+
"accounts list validation failed")
217+
218+
self.initialResourceCount = int(accounts[0].primarystoragetotal)
219+
accountLimit = self.initialResourceCount + 3
220+
221+
self.debug("Setting up account and domain hierarchy")
222+
response = self.updatePrimaryStorageLimits(accountLimit=accountLimit)
223+
self.assertEqual(response[0], PASS, response[1])
224+
225+
self.services["volume"]["size"] = self.services["disk_offering"]["disksize"] = 2
226+
227+
try:
228+
disk_offering = DiskOffering.create(self.apiclient,
229+
services=self.services["disk_offering"])
230+
self.cleanup.append(disk_offering)
231+
Volume.create(self.apiclient,
232+
self.services["volume"],
233+
zoneid=self.zone.id,
234+
account=self.child_do_admin.name,
235+
domainid=self.child_do_admin.domainid,
236+
diskofferingid=disk_offering.id)
237+
except Exception as e:
238+
self.fail("failed to create volume: %s" % e)
239+
240+
with self.assertRaises(Exception):
241+
Volume.create(self.apiclient,
242+
self.services["volume"],
243+
zoneid=self.zone.id,
244+
account=self.child_do_admin.name,
245+
domainid=self.child_do_admin.domainid,
246+
diskofferingid=disk_offering.id)
247+
return
248+
249+
@attr(tags=["advanced","selfservice"])
250+
def test_03_deploy_vm_project_limit_reached(self):
251+
"""Test TTry to deploy VM with admin account where account has not used
252+
the resources but @ project they are not available
253+
254+
# Validate the following
255+
# 1. Try to deploy VM with admin account where account has not used the
256+
# resources but @ project they are not available
257+
# 2. Deploy VM should error out saying ResourceAllocationException
258+
# with "resource limit exceeds"""
259+
260+
self.virtualMachine = VirtualMachine.create(self.api_client, self.services["virtual_machine"],
261+
projectid=self.project.id,
262+
diskofferingid=self.disk_offering.id,
263+
serviceofferingid=self.service_offering.id)
264+
265+
try:
266+
projects = Project.list(self.apiclient, id=self.project.id, listall=True)
267+
except Exception as e:
268+
self.fail("failed to get projects list: %s" % e)
269+
270+
self.assertEqual(validateList(projects)[0], PASS,
271+
"projects list validation failed")
272+
self.initialResourceCount = int(projects[0].primarystoragetotal)
273+
274+
projectLimit = self.initialResourceCount + 3
275+
276+
self.debug("Setting up account and domain hierarchy")
277+
response = self.updatePrimaryStorageLimits(projectLimit=projectLimit)
278+
self.assertEqual(response[0], PASS, response[1])
279+
280+
self.services["volume"]["size"] = self.services["disk_offering"]["disksize"] = 2
281+
282+
try:
283+
disk_offering = DiskOffering.create(self.apiclient,
284+
services=self.services["disk_offering"])
285+
self.cleanup.append(disk_offering)
286+
Volume.create(self.apiclient,
287+
self.services["volume"],
288+
zoneid=self.zone.id,
289+
projectid=self.project.id,
290+
diskofferingid=disk_offering.id)
291+
except Exception as e:
292+
self.fail("Exception occured: %s" % e)
293+
294+
with self.assertRaises(Exception):
295+
Volume.create(self.apiclient,
296+
self.services["volume"],
297+
zoneid=self.zone.id,
298+
projectid=self.project.id,
299+
diskofferingid=disk_offering.id)
300+
return

0 commit comments

Comments
 (0)