Skip to content

Commit 23ac896

Browse files
authored
Merge pull request #1322 from pavanb018/cs9217
Automation for CLOUDSTACK-9217 script to test block volume migration to a pool in maintenance mode
2 parents e77a2f8 + f772517 commit 23ac896

1 file changed

Lines changed: 168 additions & 0 deletions

File tree

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
from marvin.cloudstackTestCase import *
19+
from marvin.lib.utils import *
20+
from marvin.lib.base import *
21+
from marvin.lib.common import *
22+
from nose.plugins.attrib import attr
23+
24+
25+
class TestMigrationMaintainedPool(cloudstackTestCase):
26+
27+
@classmethod
28+
def setUpClass(cls):
29+
30+
cls.testClient = super(TestMigrationMaintainedPool, cls).getClsTestClient()
31+
cls.apiclient = cls.testClient.getApiClient()
32+
cls.services = cls.testClient.getParsedTestDataConfig()
33+
34+
# Get Zone, Domain and templates
35+
domain = get_domain(cls.apiclient)
36+
cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
37+
cls.services['mode'] = cls.zone.networktype
38+
cls.hypervisor = cls.testClient.getHypervisorInfo()
39+
40+
cls.pod = get_pod(cls.apiclient, cls.zone.id)
41+
42+
template = get_template(
43+
cls.apiclient,
44+
cls.zone.id,
45+
cls.services["ostype"]
46+
)
47+
# Set Zones and disk offerings
48+
cls.services["small"]["zoneid"] = cls.zone.id
49+
cls.services["small"]["template"] = template.id
50+
51+
cls.account = Account.create(
52+
cls.apiclient,
53+
cls.services["account"],
54+
domainid=domain.id
55+
)
56+
57+
cls.small_offering = ServiceOffering.create(
58+
cls.apiclient,
59+
cls.services["service_offerings"]["small"]
60+
)
61+
62+
#create a virtual machine
63+
cls.virtual_machine = VirtualMachine.create(
64+
cls.apiclient,
65+
cls.services["small"],
66+
accountid=cls.account.name,
67+
domainid=cls.account.domainid,
68+
serviceofferingid=cls.small_offering.id,
69+
mode=cls.services["mode"]
70+
)
71+
cls._cleanup = [
72+
cls.small_offering,
73+
cls.virtual_machine,
74+
cls.account
75+
]
76+
77+
@classmethod
78+
def tearDownClass(cls):
79+
cls.apiclient = super(TestMigrationMaintainedPool, cls).getClsTestClient().getApiClient()
80+
cleanup_resources(cls.apiclient, cls._cleanup)
81+
return
82+
83+
def setUp(self):
84+
self.apiclient = self.testClient.getApiClient()
85+
self.dbclient = self.testClient.getDbConnection()
86+
self.cleanup = []
87+
88+
def tearDown(self):
89+
#Clean up, terminate the created ISOs
90+
cleanup_resources(self.apiclient, self.cleanup)
91+
return
92+
93+
94+
@attr(tags=["advanced", "basic", "multipool", "storagemotion", "xenserver"], required_hardware="false")
95+
def test_02_migrate_volume_to_maintenance_pool(self):
96+
"""
97+
Trying to migrate a volume to a pool in maintenance mode should fail
98+
"""
99+
#List Available Storage pools
100+
storage_pools_response = list_storage_pools(
101+
self.apiclient,
102+
account=self.account.name,
103+
domainid=self.account.domainid
104+
)
105+
self.assertEqual(
106+
isinstance(storage_pools_response, list),
107+
True,
108+
"Check list response returns a valid list"
109+
)
110+
self.assertNotEqual(
111+
len(storage_pools_response),
112+
0,
113+
"Check list Storage pools response"
114+
)
115+
# Check if there are atleast two storage pools , else skip the test
116+
if len(storage_pools_response) < 2 :
117+
self.skipTest("Atleast two storage pools are need to test Storage migration")
118+
119+
list_volumes_response = list_volumes(
120+
self.apiclient,
121+
virtualmachineid=self.virtual_machine.id,
122+
listall=True
123+
)
124+
self.assertEqual(
125+
isinstance(list_volumes_response, list),
126+
True,
127+
"Check list volumes response for valid list"
128+
)
129+
self.assertNotEqual(
130+
list_volumes_response,
131+
None,
132+
"Check if volume exists in ListVolumes"
133+
)
134+
volume = list_volumes_response[0]
135+
136+
# Ge the list of pools suitable for migration for the volume
137+
pools = StoragePool.listForMigration(
138+
self.apiclient,
139+
id=volume.id
140+
)
141+
self.assertEqual(
142+
isinstance(pools, list),
143+
True,
144+
"Check eligible pools for migration returns a valid list"
145+
)
146+
self.assertNotEqual(
147+
len(pools),
148+
0,
149+
"Check if atleast one pool is suitable for migration"
150+
)
151+
pool = pools[0]
152+
self.debug("Migrating Volume-ID: %s to Pool: %s which is in Maintenance mode" % (volume.id, pool.id))
153+
154+
# Enable maintenance mode for one of the suitable pools
155+
StoragePool.enableMaintenance(self.apiclient,id=pool.id)
156+
157+
# Trying to migrate volume should fail , which is caught here
158+
with self.assertRaises(Exception):
159+
Volume.migrate(
160+
self.apiclient,
161+
volumeid=volume.id,
162+
storageid=pool.id,
163+
livemigrate='true'
164+
)
165+
# Cancel the maintenance mode , so that the pool can be cleaned up in teardown
166+
StoragePool.cancelMaintenance(self.apiclient,id=pool.id)
167+
168+
return

0 commit comments

Comments
 (0)