Skip to content

Commit cc9c868

Browse files
manasaveloorisanjeev
authored andcommitted
verify that when createTemplate is ued to create templates with same name, all of them fet unique_name under vm_template table so that templates with same name does not get deleted during template sync
This closes #688
1 parent 5f04aa5 commit cc9c868

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

test/integration/smoke/test_templates.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,54 @@
3434
import urllib
3535
#Import System modules
3636
import time
37+
from marvin.cloudstackAPI import (createTemplate, listOsTypes)
3738

3839
_multiprocess_shared_ = True
3940

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+
4085
class TestCreateTemplate(cloudstackTestCase):
4186

4287
def setUp(self):
@@ -147,6 +192,46 @@ def tearDownClass(cls):
147192

148193
return
149194

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+
150235
@attr(tags = ["advanced", "advancedns", "smoke"], required_hardware="false")
151236
def test_01_create_template(self):
152237
"""Test create public & private template

0 commit comments

Comments
 (0)