Skip to content

Commit a0ad836

Browse files
Gaurav AradhyeAbhinandan Prateek
authored andcommitted
CLOUDSTACK-6758: [Marvin] Detect failed job and throw exception
Signed-off-by: Abhinandan Prateek <aprateek@apache.org>
1 parent 8b39e2f commit a0ad836

18 files changed

Lines changed: 105 additions & 159 deletions

test/integration/component/test_accounts.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""
1919
#Import Local Modules
2020
from marvin.cloudstackTestCase import cloudstackTestCase
21+
#from marvin.cloudstackAPI import *
2122
from marvin.lib.utils import (random_gen,
2223
cleanup_resources)
2324
from marvin.lib.base import (Domain,
@@ -40,7 +41,7 @@
4041
get_builtin_template_info,
4142
wait_for_cleanup)
4243
from nose.plugins.attrib import attr
43-
from marvin.codes import ERROR_CODE_530
44+
from marvin.cloudstackException import CloudstackAPIException
4445
import time
4546

4647
class Services:
@@ -1672,18 +1673,16 @@ def test_forceDeleteDomain(self):
16721673
" to cleanup any remaining resouces")
16731674
# Sleep 3*account.gc to ensure that all resources are deleted
16741675
wait_for_cleanup(self.apiclient, ["account.cleanup.interval"]*3)
1675-
response = Domain.list(
1676+
with self.assertRaises(CloudstackAPIException):
1677+
Domain.list(
16761678
self.apiclient,
16771679
id=domain.id,
16781680
listall=True
16791681
)
1680-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
1681-
have failed with error code %s, instead got response \
1682-
%s" % (ERROR_CODE_530, str(response)))
16831682

16841683
self.debug("Checking if the resources in domain are deleted")
1685-
with self.assertRaises(Exception):
1686-
response = Account.list(
1684+
with self.assertRaises(CloudstackAPIException):
1685+
Account.list(
16871686
self.apiclient,
16881687
name=self.account_1.name,
16891688
domainid=self.account_1.domainid,
@@ -1833,8 +1832,6 @@ def test_DeleteDomain(self):
18331832
)
18341833

18351834
self.debug("Deleting domain without force option")
1836-
response = domain.delete(self.apiclient, cleanup=False)
1837-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
1838-
have failed with error code %s, instead got response \
1839-
%s" % (ERROR_CODE_530, str(response)))
1835+
with self.assertRaises(Exception):
1836+
domain.delete(self.apiclient, cleanup=False)
18401837
return

test/integration/component/test_add_remove_network.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
removeNicFromVirtualMachine,
5959
updateDefaultNicForVirtualMachine)
6060

61-
from marvin.codes import PASS, ERROR_CODE_530
61+
from marvin.codes import PASS
6262
import random
6363
import time
6464

@@ -466,10 +466,8 @@ def test_05_add_vpc_nw_stopped_vm(self, value):
466466
self.cleanup.append(vpc)
467467
self.cleanup.append(vpc_off)
468468
self.debug("Trying to add VPC to vm belonging to isolated network, this should fail")
469-
response = self.virtual_machine.add_nic(self.apiclient, vpc.id)
470-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
471-
have failed with error code %s, instead got response \
472-
%s" % (ERROR_CODE_530, str(response)))
469+
with self.assertRaises(Exception):
470+
self.virtual_machine.add_nic(self.apiclient, vpc.id)
473471
self.debug("Starting virtual machine")
474472
self.virtual_machine.start(self.apiclient)
475473
self.debug("Disabling vpc offering: %s" % vpc_off.id)
@@ -827,10 +825,9 @@ def test_08_remove_default_nic(self):
827825
self.assertEqual(len(vm_list[0].nic), 1, "There should only be default nic present in the vm")
828826
self.debug("Trying to remove the default nic of vm : %s, this should fail" %
829827
self.virtual_machine.id)
830-
response = self.virtual_machine.remove_nic(self.apiclient, vm_list[0].nic[0].id)
831-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
832-
have failed with error code %s, instead got response \
833-
%s" % (ERROR_CODE_530, str(response)))
828+
with self.assertRaises(Exception):
829+
self.virtual_machine.remove_nic(self.apiclient, vm_list[0].nic[0].id)
830+
self.debug("Removing default nic of vm failed")
834831
return
835832

836833
@attr(tags = ["advanced"])

test/integration/component/test_affinity_groups.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
get_template,
3030
list_virtual_machines,
3131
wait_for_cleanup)
32-
from marvin.codes import ERROR_CODE_530
3332
from nose.plugins.attrib import attr
3433

3534
class Services:
@@ -1087,10 +1086,9 @@ def test_05_update_aff_grp_on_running_vm(self):
10871086
vm1, hostid1 = self.create_vm_in_aff_grps([self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id)
10881087

10891088
aff_grps = [self.aff_grp[0], self.aff_grp[1]]
1090-
response = vm1.update_affinity_group(self.api_client, affinitygroupnames=[])
1091-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
1092-
have failed with error code %s, instead got response \
1093-
%s" % (ERROR_CODE_530, str(response)))
1089+
with self.assertRaises(Exception):
1090+
vm1.update_affinity_group(self.api_client, affinitygroupnames=[])
1091+
10941092
vm1.delete(self.api_client)
10951093
#Wait for expunge interval to cleanup VM
10961094
wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])

test/integration/component/test_assign_vm.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
list_snapshots,
3939
list_virtual_machines)
4040
from marvin.lib.utils import cleanup_resources
41-
from marvin.codes import ERROR_CODE_530
4241

4342
def log_test_exceptions(func):
4443
def test_wrap_exception_log(self, *args, **kwargs):
@@ -370,14 +369,7 @@ def test_10_move_across_subdomain_vm_running(self):
370369
# 1. deploy VM in sub subdomain1
371370
# 3. assignVirtualMachine to subdomain2
372371
self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'],isRunning=True)
373-
response = self.virtual_machine.assign_virtual_machine(
374-
self.apiclient,
375-
self.sdomain_account_user2['account'].name,
376-
self.sdomain_account_user2['domain'].id)
377-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
378-
have failed with error code %s, instead got response \
379-
%s" % (ERROR_CODE_530, str(response)))
380-
return
372+
self.assertRaises(Exception, self.virtual_machine.assign_virtual_machine, self.apiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id)
381373

382374
@attr(tags = ["advanced"])
383375
@log_test_exceptions
@@ -388,14 +380,7 @@ def test_11_move_across_subdomain_vm_pfrule(self):
388380
# 1. deploy VM in sub subdomain1 with PF rule set.
389381
# 3. assignVirtualMachine to subdomain2
390382
self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'],pfrule=True)
391-
response = self.virtual_machine.assign_virtual_machine(
392-
self.apiclient,
393-
self.sdomain_account_user2['account'].name,
394-
self.sdomain_account_user2['domain'].id)
395-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
396-
have failed with error code %s, instead got response \
397-
%s" % (ERROR_CODE_530, str(response)))
398-
return
383+
self.assertRaises(Exception, self.virtual_machine.assign_virtual_machine, self.apiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id)
399384

400385
@attr(tags = ["advanced"])
401386
@log_test_exceptions

test/integration/component/test_ip_reservation.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
createNetworkRulesForVM,
3939
verifyNetworkState)
4040
from marvin.codes import (PASS, FAIL, FAILED, UNKNOWN, FAULT, MASTER,
41-
NAT_RULE, STATIC_NAT_RULE, ERROR_CODE_530)
41+
NAT_RULE, STATIC_NAT_RULE)
4242
import netaddr
4343

4444
import random
@@ -270,10 +270,8 @@ def test_update_cidr_multiple_vms_not_all_inclusive(self):
270270
except Exception as e:
271271
self.fail("VM creation failed: %s" % e)
272272

273-
response = isolated_network.update(self.apiclient, guestvmcidr=guest_vm_cidr)
274-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
275-
have failed with error code %s, instead got response \
276-
%s" % (ERROR_CODE_530, str(response)))
273+
with self.assertRaises(Exception):
274+
isolated_network.update(self.apiclient, guestvmcidr=guest_vm_cidr)
277275
return
278276

279277
@attr(tags=["advanced"])
@@ -302,10 +300,8 @@ def test_update_cidr_single_vm_not_inclusive(self):
302300
except Exception as e:
303301
self.fail("VM creation failed: %s" % e)
304302

305-
response = isolated_network.update(self.apiclient, guestvmcidr=guest_vm_cidr)
306-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
307-
have failed with error code %s, instead got response \
308-
%s" % (ERROR_CODE_530, str(response)))
303+
with self.assertRaises(Exception):
304+
isolated_network.update(self.apiclient, guestvmcidr=guest_vm_cidr)
309305
return
310306

311307
@data(NAT_RULE, STATIC_NAT_RULE)
@@ -1083,10 +1079,8 @@ def test_network_not_implemented(self):
10831079
else:
10841080
isolated_network = resultSet[1]
10851081

1086-
response = isolated_network.update(self.apiclient, guestvmcidr="10.1.1.0/26")
1087-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
1088-
have failed with error code %s, instead got response \
1089-
%s" % (ERROR_CODE_530, str(response)))
1082+
with self.assertRaises(Exception):
1083+
response = isolated_network.update(self.apiclient, guestvmcidr="10.1.1.0/26")
10901084
return
10911085

10921086
@attr(tags=["advanced", "selfservice"])

test/integration/component/test_non_contiguous_vlan.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#Import local modules
2828

2929

30-
from marvin.cloudstackTestCase import (cloudstackTestCase)
30+
from marvin.cloudstackTestCase import (cloudstackTestCase,unittest)
3131
from marvin.lib.base import (Account,
3232
ServiceOffering,
3333
PhysicalNetwork,
@@ -40,7 +40,6 @@
4040
setNonContiguousVlanIds)
4141
from marvin.lib.utils import (cleanup_resources,
4242
xsplit)
43-
from marvin.codes import ERROR_CODE_530
4443

4544
from nose.plugins.attrib import attr
4645

@@ -318,11 +317,12 @@ def test_05_remove_used_range(self):
318317
self.debug("Deployed instance in account: %s" % account.name)
319318
self.debug("Trying to remove vlan range : %s , This should fail" % self.vlan["partial_range"][0])
320319

321-
response = self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = self.vlan["partial_range"][0])
322-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
323-
have failed with error code %s, instead got response \
324-
%s" % (ERROR_CODE_530, str(response)))
320+
with self.assertRaises(Exception) as e:
321+
self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = self.vlan["partial_range"][0])
322+
323+
self.debug("operation failed with exception: %s" % e.exception)
325324
account.delete(self.apiclient)
325+
326326
except Exception as e:
327327
self.fail("Exception in test case: %s" % e)
328328

test/integration/component/test_projects.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
""" P1 tests for Project
1818
"""
1919
#Import Local Modules
20+
import marvin
2021
from nose.plugins.attrib import attr
2122
from marvin.cloudstackTestCase import *
2223
from marvin.cloudstackAPI import *
2324
from marvin.lib.utils import *
2425
from marvin.lib.base import *
2526
from marvin.lib.common import *
26-
from marvin.codes import ERROR_CODE_530
27+
from marvin.sshClient import SshClient
28+
import datetime
2729

2830

2931
class Services:
@@ -428,14 +430,13 @@ def test_02_cross_domain_account_add(self):
428430
self.user.domainid,
429431
project.id
430432
))
431-
# Add user to the project from different domain
432-
response = project.addAccount(
433+
with self.assertRaises(Exception):
434+
# Add user to the project from different domain
435+
project.addAccount(
433436
self.apiclient,
434437
self.user.name
435438
)
436-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
437-
have failed with error code %s, instead got response \
438-
%s" % (ERROR_CODE_530, str(response)))
439+
self.debug("User add to project failed!")
439440
return
440441

441442

@@ -541,10 +542,10 @@ def test_03_delete_account_with_project(self):
541542
"Check project name from list response"
542543
)
543544
# Deleting account who is owner of the project
544-
response = self.account.delete(self.apiclient)
545-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
546-
have failed with error code %s, instead got response \
547-
%s" % (ERROR_CODE_530, str(response)))
545+
with self.assertRaises(Exception):
546+
self.account.delete(self.apiclient)
547+
self.debug("Deleting account %s failed!" %
548+
self.account.name)
548549
return
549550

550551

test/integration/component/test_volumes.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
get_zone,
3737
get_template,
3838
get_pod)
39-
from marvin.codes import ERROR_CODE_530
4039
#Import System modules
4140
import time
4241

@@ -342,17 +341,16 @@ def test_02_volume_attach_max(self):
342341
True,
343342
"Check list volumes response for valid list"
344343
)
345-
self.debug("Trying to Attach volume: %s to VM: %s" % (
344+
# Attach volume to VM
345+
with self.assertRaises(Exception):
346+
self.debug("Trying to Attach volume: %s to VM: %s" % (
346347
volume.id,
347348
self.virtual_machine.id
348349
))
349-
response = self.virtual_machine.attach_volume(
350+
self.virtual_machine.attach_volume(
350351
self.apiclient,
351352
volume
352353
)
353-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
354-
have failed with error code %s, instead got response \
355-
%s" % (ERROR_CODE_530, str(response)))
356354
return
357355

358356
class TestAttachDetachVolume(cloudstackTestCase):

test/integration/component/test_vpc.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from marvin.lib.utils import *
2626
from marvin.lib.base import *
2727
from marvin.lib.common import *
28-
from marvin.codes import ERROR_CODE_530
2928

3029

3130
class Services:
@@ -700,10 +699,8 @@ def test_05_delete_vpc_with_networks(self):
700699
self.debug("Created network with ID: %s" % network_2.id)
701700

702701
self.debug("Deleting the VPC with no network")
703-
response = vpc.delete(self.apiclient)
704-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
705-
have failed with error code %s, instead got response \
706-
%s" % (ERROR_CODE_530, str(response)))
702+
with self.assertRaises(Exception):
703+
vpc.delete(self.apiclient)
707704
self.debug("Delete VPC failed as there are still networks in VPC")
708705
self.debug("Deleting the networks in the VPC")
709706

test/integration/component/test_vpc_network.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
# For more info on ddt refer to http://ddt.readthedocs.org/en/latest/api.html#module-ddt
4545
from ddt import ddt, data
4646
import time
47-
from marvin.codes import PASS, ERROR_CODE_530
47+
from marvin.codes import PASS
4848

4949
class Services:
5050
"""Test VPC network services
@@ -2107,14 +2107,12 @@ def test_02_network_vpcvr2vr_upgrade(self):
21072107
self.fail("Failed to stop VMs, %s" % e)
21082108

21092109
self.debug("Upgrading network offering to support PF services")
2110-
response = network_1.update(
2110+
with self.assertRaises(Exception):
2111+
network_1.update(
21112112
self.apiclient,
21122113
networkofferingid=nw_off_vr.id,
21132114
changecidr=True
21142115
)
2115-
self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \
2116-
have failed with error code %s, instead got response \
2117-
%s" % (ERROR_CODE_530, str(response)))
21182116
return
21192117

21202118
class TestVPCNetworkGc(cloudstackTestCase):

0 commit comments

Comments
 (0)