2020# Import Local Modules
2121from nose .plugins .attrib import attr
2222from marvin .cloudstackTestCase import cloudstackTestCase
23- from marvin .lib .utils import cleanup_resources
2423from marvin .lib .base import (Account ,
2524 VirtualMachine ,
2625 ServiceOffering ,
@@ -38,28 +37,28 @@ class TestDeployVMFromISO(cloudstackTestCase):
3837 def setUpClass (cls ):
3938
4039 cls .testClient = super (TestDeployVMFromISO , cls ).getClsTestClient ()
41- cls .api_client = cls .testClient .getApiClient ()
40+ cls .apiclient = cls .testClient .getApiClient ()
4241
4342 cls .testdata = cls .testClient .getParsedTestDataConfig ()
4443 # Get Zone, Domain and templates
45- cls .domain = get_domain (cls .api_client )
46- cls .zone = get_zone (cls .api_client , cls .testClient .getZoneForTests ())
44+ cls .domain = get_domain (cls .apiclient )
45+ cls .zone = get_zone (cls .apiclient , cls .testClient .getZoneForTests ())
4746 cls .hypervisor = cls .testClient .getHypervisorInfo ()
4847
4948 cls .template = get_test_template (
50- cls .api_client ,
49+ cls .apiclient ,
5150 cls .zone .id ,
5251 cls .hypervisor
5352 )
5453
5554 # Create service, disk offerings etc
5655 cls .service_offering = ServiceOffering .create (
57- cls .api_client ,
56+ cls .apiclient ,
5857 cls .testdata ["service_offering" ]
5958 )
6059
6160 cls .disk_offering = DiskOffering .create (
62- cls .api_client ,
61+ cls .apiclient ,
6362 cls .testdata ["disk_offering" ]
6463 )
6564
@@ -69,13 +68,6 @@ def setUpClass(cls):
6968 ]
7069 return
7170
72- @classmethod
73- def tearDownClass (cls ):
74- try :
75- cleanup_resources (cls .api_client , cls ._cleanup )
76- except Exception as e :
77- raise Exception ("Warning: Exception during cleanup : %s" % e )
78-
7971 def setUp (self ):
8072
8173 self .apiclient = self .testClient .getApiClient ()
@@ -92,66 +84,82 @@ def setUp(self):
9284 self .cleanup = [self .account ]
9385 return
9486
95- def tearDown (self ):
96- try :
97- self .debug ("Cleaning up the resources" )
98- cleanup_resources (self .apiclient , self .cleanup )
99- self .debug ("Cleanup complete!" )
100- except Exception as e :
101- self .debug ("Warning! Exception in tearDown: %s" % e )
102-
10387 @attr (
10488 tags = [
10589 "advanced" ,
10690 "eip" ,
10791 "advancedns" ,
10892 "basic" ,
109- "sg" ],
110- required_hardware = "true" )
93+ "sg"
94+ ],
95+ required_hardware = "true"
96+ )
11197 def test_deploy_vm_from_iso (self ):
11298 """Test Deploy Virtual Machine from ISO
11399 """
114100
115101 # Validate the following:
116- # 1. deploy VM using ISO
117- # 2. listVM command should return the deployed VM. State of this VM
118- # should be "Running".
119- self .hypervisor = self .testClient .getHypervisorInfo ()
120- if self .hypervisor .lower () in ['lxc' ]:
121- self .skipTest (
122- "vm deploy from ISO feature is not supported on %s" %
123- self .hypervisor .lower ())
102+ # 1. Create an ISO
103+ # 2. Deploy a VM from the ISO
104+ # 3. VM should be in 'Running' state
124105
125106 self .iso = Iso .create (
126107 self .apiclient ,
127- self .testdata ["configurableData" ][ "bootableIso " ],
108+ self .testdata ["iso " ],
128109 account = self .account .name ,
129- domainid = self .account .domainid ,
130- zoneid = self .zone .id
110+ domainid = self .account .domainid
111+ )
112+ self .cleanup .append (self .iso )
113+
114+ self .debug ("ISO created with ID: %s" % self .iso .id )
115+
116+ list_iso_response = Iso .list (
117+ self .apiclient ,
118+ id = self .iso .id
119+ )
120+ self .assertEqual (
121+ isinstance (list_iso_response , list ),
122+ True ,
123+ "Check list response returns a valid list"
131124 )
132- try :
133- # Download the ISO
134- self .iso .download (self .apiclient )
135- except Exception as e :
136- raise Exception ("Exception while downloading ISO %s: %s"
137- % (self .iso .id , e ))
138-
139- self .debug ("Registered ISO: %s" % self .iso .name )
140- self .debug ("Deploying instance in the account: %s" %
141- self .account .name )
125+
126+ self .iso .download (self .apiclient )
127+
128+ # Deploy Virtual Machine
142129 self .virtual_machine = VirtualMachine .create (
143130 self .apiclient ,
144131 self .testdata ["virtual_machine" ],
145132 accountid = self .account .name ,
146133 domainid = self .account .domainid ,
147- templateid = self .iso .id ,
148134 serviceofferingid = self .service_offering .id ,
149135 diskofferingid = self .disk_offering .id ,
150- hypervisor = self .hypervisor
136+ mode = self .zone . networktype
151137 )
138+ self .cleanup .append (self .virtual_machine )
139+
140+ self .debug ("VM created with ID: %s" % self .virtual_machine .id )
152141
153- response = self . virtual_machine . getState (
142+ list_vm_response = VirtualMachine . list (
154143 self .apiclient ,
155- VirtualMachine .RUNNING )
156- self .assertEqual (response [0 ], PASS , response [1 ])
144+ id = self .virtual_machine .id
145+ )
146+
147+ self .assertEqual (
148+ isinstance (list_vm_response , list ),
149+ True ,
150+ "Check list response returns a valid list"
151+ )
152+ vm_response = list_vm_response [0 ]
153+
154+ self .assertEqual (
155+ vm_response .state ,
156+ "Running" ,
157+ "Check virtual machine is in running state"
158+ )
159+
160+ self .assertEqual (
161+ vm_response .isoid ,
162+ self .iso .id ,
163+ "Check virtual machine is booted from the ISO"
164+ )
157165 return
0 commit comments