@@ -1191,3 +1191,163 @@ def test_09_copy_delete_template(self):
11911191 "Removed state is not correct."
11921192 )
11931193 return
1194+
1195+ class TestCreateTemplateWithDirectDownload (cloudstackTestCase ):
1196+
1197+ @classmethod
1198+ def setUpClass (self ):
1199+ self .testClient = super (TestCreateTemplateWithDirectDownload , self ).getClsTestClient ()
1200+ self .apiclient = self .testClient .getApiClient ()
1201+ self .dbclient = self .testClient .getDbConnection ()
1202+ self ._cleanup = []
1203+ self .templates = []
1204+
1205+ self .services = self .testClient .getParsedTestDataConfig ()
1206+ self .unsupportedHypervisor = False
1207+ self .hypervisor = self .testClient .getHypervisorInfo ()
1208+ if self .hypervisor .lower () not in ['kvm' ]:
1209+ # Direct Download is only available for KVM hypervisor
1210+ self .unsupportedHypervisor = True
1211+ self .skipTest ("Skipping test because unsupported hypervisor\
1212+ %s" % self .hypervisor )
1213+ return
1214+
1215+ # Get Zone, Domain and templates
1216+ self .domain = get_domain (self .apiclient )
1217+ self .zone = get_zone (self .apiclient , self .testClient .getZoneForTests ())
1218+ self .services ["mode" ] = self .zone .networktype
1219+ self .services ["virtual_machine" ]["zoneid" ] = self .zone .id
1220+ self .account = Account .create (
1221+ self .apiclient ,
1222+ self .services ["account" ],
1223+ admin = True ,
1224+ domainid = self .domain .id
1225+ )
1226+ self ._cleanup .append (self .account )
1227+ self .user = Account .create (
1228+ self .apiclient ,
1229+ self .services ["account" ],
1230+ domainid = self .domain .id
1231+ )
1232+ self ._cleanup .append (self .user )
1233+ self .service_offering = ServiceOffering .create (
1234+ self .apiclient ,
1235+ self .services ["service_offerings" ]["tiny" ]
1236+ )
1237+ self ._cleanup .append (self .service_offering )
1238+
1239+ self .template = {
1240+ "name" : "tiny-kvm" ,
1241+ "displaytext" : "tiny kvm" ,
1242+ "format" : "QCOW2" ,
1243+ "url" : "http://dl.openvm.eu/cloudstack/macchinina/x86_64/macchinina-kvm.qcow2.bz2" ,
1244+ "requireshvm" : "True" ,
1245+ "ispublic" : "True" ,
1246+ "isextractable" : "True" ,
1247+ "checksum" : "{SHA-1}" + "6952e58f39b470bd166ace11ffd20bf479bed936" ,
1248+ "hypervisor" : self .hypervisor ,
1249+ "zoneid" : self .zone .id ,
1250+ "ostype" : "Other Linux (64-bit)" ,
1251+ "directdownload" : True
1252+ }
1253+
1254+ return
1255+
1256+ @classmethod
1257+ def tearDownClass (cls ):
1258+ try :
1259+ cleanup_resources (cls .apiclient , cls ._cleanup )
1260+ except Exception as e :
1261+ raise Exception ("Warning: Exception during cleanup : %s" % e )
1262+ return
1263+
1264+ def setUp (self ):
1265+ self .apiclient = self .testClient .getApiClient ()
1266+ self .dbclient = self .testClient .getDbConnection ()
1267+ self .cleanup = []
1268+
1269+ if self .unsupportedHypervisor :
1270+ self .skipTest ("Skipping test because unsupported hypervisor\
1271+ %s" % self .hypervisor )
1272+ return
1273+
1274+ def tearDown (self ):
1275+ try :
1276+ #Clean up, terminate the created templates
1277+ cleanup_resources (self .apiclient , self .cleanup )
1278+
1279+ except Exception as e :
1280+ raise Exception ("Warning: Exception during cleanup : %s" % e )
1281+ return
1282+
1283+ @attr (tags = ["advanced" , "smoke" ], required_hardware = "true" )
1284+ def test_01_register_template_direct_download_flag (self ):
1285+ """
1286+ Register a template using Direct Download flag
1287+ """
1288+ self .bypassed_template = Template .register (self .apiclient , self .template , zoneid = self .zone .id , hypervisor = self .hypervisor , randomize_name = False )
1289+ self ._cleanup .append (self .bypassed_template )
1290+ self .templates .append (self .bypassed_template )
1291+
1292+ tmplt = self .dbclient .execute ("select id, direct_download from vm_template where uuid='%s';" % self .bypassed_template .id )
1293+ det = tmplt [0 ]
1294+
1295+ self .assertEqual (det [1 ],
1296+ 1 ,
1297+ "Template should be marked as Direct Download"
1298+ )
1299+ qresultset = self .dbclient .execute ("select download_state, state from template_store_ref where template_id='%s' and store_id is NULL;"
1300+ % det [0 ])
1301+ ref = qresultset [0 ]
1302+ self .assertEqual (ref [0 ],
1303+ "BYPASSED" ,
1304+ "Template store ref download state should be marked as BYPASSED"
1305+ )
1306+ self .assertEqual (ref [1 ],
1307+ "Ready" ,
1308+ "Template store ref state should be marked as Ready"
1309+ )
1310+ return
1311+
1312+ @attr (tags = ["advanced" , "smoke" ], required_hardware = "true" )
1313+ def test_02_deploy_vm_from_direct_download_template (self ):
1314+ """
1315+ Deploy a VM from a Direct Download registered template
1316+ """
1317+ bp = self .templates [0 ]
1318+ virtual_machine = VirtualMachine .create (
1319+ self .apiclient ,
1320+ self .services ["virtual_machine" ],
1321+ templateid = bp .id ,
1322+ accountid = self .account .name ,
1323+ domainid = self .account .domainid ,
1324+ serviceofferingid = self .service_offering .id
1325+ )
1326+ self .cleanup .append (virtual_machine )
1327+ return
1328+
1329+ @attr (tags = ["advanced" , "smoke" ], required_hardware = "true" )
1330+ def test_03_deploy_vm_wrong_checksum (self ):
1331+ """
1332+ Deploy a VM from a Direct Download registered template with wrong checksum
1333+ """
1334+ self .template ["checksum" ]= "{MD5}XXXXXXX"
1335+ tmpl = Template .register (self .apiclient , self .template , zoneid = self .zone .id , hypervisor = self .hypervisor , randomize_name = False )
1336+
1337+ try :
1338+ virtual_machine = VirtualMachine .create (
1339+ self .apiclient ,
1340+ self .services ["virtual_machine" ],
1341+ templateid = tmpl .id ,
1342+ accountid = self .account .name ,
1343+ domainid = self .account .domainid ,
1344+ serviceofferingid = self .service_offering .id
1345+ )
1346+ self .cleanup .append (tmpl )
1347+ self .fail ("Expected to fail deployment" )
1348+ except Exception as e :
1349+ self .debug ("Expected exception" )
1350+
1351+ self .cleanup .append (virtual_machine )
1352+ self .cleanup .append (tmpl )
1353+ return
0 commit comments