|
34 | 34 | import urllib |
35 | 35 | #Import System modules |
36 | 36 | import time |
| 37 | +from marvin.cloudstackAPI import (createTemplate, listOsTypes) |
37 | 38 |
|
38 | 39 | _multiprocess_shared_ = True |
39 | 40 |
|
| 41 | +# Function to create template with name existing in test_data without any extensions |
| 42 | + |
| 43 | + |
| 44 | +def create(apiclient, services, volumeid=None, account=None, domainid=None, projectid=None): |
| 45 | + cmd = createTemplate.createTemplateCmd() |
| 46 | + cmd.displaytext = services["displaytext"] |
| 47 | + cmd.name = services["name"] |
| 48 | + if "ostypeid" in services: |
| 49 | + cmd.ostypeid = services["ostypeid"] |
| 50 | + elif "ostype" in services: |
| 51 | + sub_cmd = listOsTypes.listOsTypesCmd() |
| 52 | + sub_cmd.description = services["ostype"] |
| 53 | + ostypes = apiclient.listOsTypes(sub_cmd) |
| 54 | + |
| 55 | + if not isinstance(ostypes, list): |
| 56 | + raise Exception( |
| 57 | + "Unable to find Ostype id with desc: %s" % services["ostype"] |
| 58 | + ) |
| 59 | + cmd.ostypeid = ostypes[0].id |
| 60 | + else: |
| 61 | + raise Exception( |
| 62 | + "Unable to find Ostype is required for creating template") |
| 63 | + |
| 64 | + cmd.isfeatured = services[ |
| 65 | + "isfeatured"] if "isfeatured" in services else False |
| 66 | + |
| 67 | + cmd.ispublic = services[ |
| 68 | + "ispublic"] if "ispublic" in services else False |
| 69 | + cmd.isextractable = services[ |
| 70 | + "isextractable"] if "isextractable" in services else False |
| 71 | + cmd.passwordenabled = services[ |
| 72 | + "passwordenabled"] if "passwordenabled" in services else False |
| 73 | + |
| 74 | + if volumeid: |
| 75 | + cmd.volumeid = volumeid |
| 76 | + if account: |
| 77 | + cmd.account = account |
| 78 | + if domainid: |
| 79 | + cmd.domainid = domainid |
| 80 | + if projectid: |
| 81 | + cmd.projectid = projectid |
| 82 | + return apiclient.createTemplate(cmd) |
| 83 | + |
| 84 | + |
40 | 85 | class TestCreateTemplate(cloudstackTestCase): |
41 | 86 |
|
42 | 87 | def setUp(self): |
@@ -147,6 +192,46 @@ def tearDownClass(cls): |
147 | 192 |
|
148 | 193 | return |
149 | 194 |
|
| 195 | + @attr(tags = ["advanced", "advancedns", "smoke"], required_hardware="false") |
| 196 | + def test_CreateTemplateWithDuplicateName(self): |
| 197 | + """Test when createTemplate is used to create templates having the same name all of them get |
| 198 | + different unique names so that the templates with same name does not get deleted during template sync""" |
| 199 | + |
| 200 | + #1. Create 2 templates with same name |
| 201 | + #2. check the db that the templates with same name have different unique_name |
| 202 | + |
| 203 | + #Create templates from Virtual machine and Volume ID |
| 204 | + template1 = create(self.apiclient, |
| 205 | + self.services["template"], |
| 206 | + self.volume.id, |
| 207 | + account=self.account.name) |
| 208 | + template2 = create(self.apiclient, |
| 209 | + self.services["template"], |
| 210 | + self.volume.id, |
| 211 | + account=self.account.name) |
| 212 | + |
| 213 | + self.debug("Created template with ID: %s" % template1.id) |
| 214 | + self.debug("Created template with ID: %s" % template2.id) |
| 215 | + |
| 216 | + self.assertEqual( |
| 217 | + template1.name, template2.name, "Created templates with same name") |
| 218 | + |
| 219 | + self.debug("select unique_name from vm_template where name='%s';" |
| 220 | + % template1.name) |
| 221 | + |
| 222 | + #Db query to check for unique_name for the templates with same name |
| 223 | + |
| 224 | + qresultset = self.dbclient.execute("select unique_name from vm_template where name='%s' and removed is NULL ;" |
| 225 | + % template1.name) |
| 226 | + |
| 227 | + |
| 228 | + self.debug("unique_name of template1 is '%s' and unique_name of template2 is '%s'", qresultset[0], |
| 229 | + qresultset[1]) |
| 230 | + |
| 231 | + self.assertNotEqual(qresultset[0], qresultset[1], |
| 232 | + "unique names are different") |
| 233 | + |
| 234 | + |
150 | 235 | @attr(tags = ["advanced", "advancedns", "smoke"], required_hardware="false") |
151 | 236 | def test_01_create_template(self): |
152 | 237 | """Test create public & private template |
|
0 commit comments