|
16 | 16 | # under the License. |
17 | 17 |
|
18 | 18 | from 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 * |
24 | | -from marvin.lib.utils import is_snapshot_on_nfs |
25 | | - |
| 19 | +from marvin.cloudstackTestCase import cloudstackTestCase, unittest |
| 20 | +#from marvin.cloudstackAPI import * |
| 21 | +from marvin.lib.utils import ( |
| 22 | + is_snapshot_on_nfs, |
| 23 | + cleanup_resources) |
| 24 | +from marvin.lib.base import (Account, |
| 25 | + Snapshot, |
| 26 | + ServiceOffering, |
| 27 | + VirtualMachine) |
| 28 | +from marvin.lib.common import (get_domain, |
| 29 | + get_zone, |
| 30 | + get_template, |
| 31 | + list_volumes, |
| 32 | + list_accounts, |
| 33 | + list_snapshots, |
| 34 | + wait_for_cleanup) |
26 | 35 |
|
27 | 36 | class Services: |
28 | 37 | """Test Snapshots Services |
@@ -177,7 +186,7 @@ def setUpClass(cls): |
177 | 186 | volume = volumes[0] |
178 | 187 |
|
179 | 188 | # Create a snapshot from the ROOTDISK |
180 | | - cls.snapshot = Snapshot.create(cls.api_client, volumes[0].id) |
| 189 | + cls.snapshot = Snapshot.create(cls.api_client, volume.id) |
181 | 190 | except Exception, e: |
182 | 191 | cls.tearDownClass() |
183 | 192 | unittest.SkipTest("setupClass fails for %s" % cls.__name__) |
@@ -223,70 +232,50 @@ def test_02_accountSnapshotClean(self): |
223 | 232 | # b) snapshot image($snapshot_id) should be deleted from the |
224 | 233 | # /secondary/snapshots/$accountid/$volumeid/ |
225 | 234 |
|
226 | | - accounts = list_accounts( |
| 235 | + try: |
| 236 | + accounts = list_accounts( |
227 | 237 | self.apiclient, |
228 | 238 | id=self.account.id |
229 | 239 | ) |
230 | | - self.assertEqual( |
| 240 | + self.assertEqual( |
231 | 241 | isinstance(accounts, list), |
232 | 242 | True, |
233 | 243 | "Check list response returns a valid list" |
234 | 244 | ) |
235 | | - self.assertNotEqual( |
| 245 | + self.assertNotEqual( |
236 | 246 | len(accounts), |
237 | 247 | 0, |
238 | 248 | "Check list Accounts response" |
239 | 249 | ) |
240 | 250 |
|
241 | | - # VM should be in 'Running' state |
242 | | - virtual_machines = list_virtual_machines( |
243 | | - self.apiclient, |
244 | | - id=self.virtual_machine.id |
245 | | - ) |
246 | | - self.assertEqual( |
247 | | - isinstance(virtual_machines, list), |
248 | | - True, |
249 | | - "Check list response returns a valid list" |
250 | | - ) |
251 | | - self.assertNotEqual( |
252 | | - len(virtual_machines), |
253 | | - 0, |
254 | | - "Check list virtual machines response" |
255 | | - ) |
256 | | - for virtual_machine in virtual_machines: |
257 | | - self.debug("VM ID: %s, VM state: %s" % ( |
258 | | - virtual_machine.id, |
259 | | - virtual_machine.state |
260 | | - )) |
261 | | - self.assertEqual( |
262 | | - virtual_machine.state, |
263 | | - 'Running', |
264 | | - "Check list VM response for Running state" |
265 | | - ) |
266 | | - |
267 | | - # Verify the snapshot was created or not |
268 | | - snapshots = list_snapshots( |
| 251 | + # Verify the snapshot was created or not |
| 252 | + snapshots = list_snapshots( |
269 | 253 | self.apiclient, |
270 | 254 | id=self.snapshot.id |
271 | 255 | ) |
272 | | - self.assertEqual( |
| 256 | + self.assertEqual( |
273 | 257 | isinstance(snapshots, list), |
274 | 258 | True, |
275 | 259 | "Check list response returns a valid list" |
276 | 260 | ) |
277 | | - self.assertNotEqual( |
| 261 | + self.assertNotEqual( |
278 | 262 | snapshots, |
279 | 263 | None, |
280 | 264 | "No such snapshot %s found" % self.snapshot.id |
281 | 265 | ) |
282 | | - self.assertEqual( |
| 266 | + self.assertEqual( |
283 | 267 | snapshots[0].id, |
284 | 268 | self.snapshot.id, |
285 | 269 | "Check snapshot id in list resources call" |
286 | 270 | ) |
287 | 271 |
|
288 | | - self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, self.snapshot.id), |
289 | | - "Snapshot was not found on NFS") |
| 272 | + self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, self.snapshot.id), |
| 273 | + "Snapshot was not found on NFS") |
| 274 | + |
| 275 | + raise Exception("self raised exception") |
| 276 | + except Exception as e: |
| 277 | + self._cleanup.append(self.account) |
| 278 | + self.fail("Exception occured: %s" % e) |
290 | 279 |
|
291 | 280 | self.debug("Deleting account: %s" % self.account.name) |
292 | 281 | # Delete account |
|
0 commit comments