mirror of https://github.com/apache/cloudstack.git
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
This commit is contained in:
parent
5f04aa5687
commit
cc9c868590
|
|
@ -34,9 +34,54 @@ from nose.plugins.attrib import attr
|
|||
import urllib
|
||||
#Import System modules
|
||||
import time
|
||||
from marvin.cloudstackAPI import (createTemplate, listOsTypes)
|
||||
|
||||
_multiprocess_shared_ = True
|
||||
|
||||
# Function to create template with name existing in test_data without any extensions
|
||||
|
||||
|
||||
def create(apiclient, services, volumeid=None, account=None, domainid=None, projectid=None):
|
||||
cmd = createTemplate.createTemplateCmd()
|
||||
cmd.displaytext = services["displaytext"]
|
||||
cmd.name = services["name"]
|
||||
if "ostypeid" in services:
|
||||
cmd.ostypeid = services["ostypeid"]
|
||||
elif "ostype" in services:
|
||||
sub_cmd = listOsTypes.listOsTypesCmd()
|
||||
sub_cmd.description = services["ostype"]
|
||||
ostypes = apiclient.listOsTypes(sub_cmd)
|
||||
|
||||
if not isinstance(ostypes, list):
|
||||
raise Exception(
|
||||
"Unable to find Ostype id with desc: %s" % services["ostype"]
|
||||
)
|
||||
cmd.ostypeid = ostypes[0].id
|
||||
else:
|
||||
raise Exception(
|
||||
"Unable to find Ostype is required for creating template")
|
||||
|
||||
cmd.isfeatured = services[
|
||||
"isfeatured"] if "isfeatured" in services else False
|
||||
|
||||
cmd.ispublic = services[
|
||||
"ispublic"] if "ispublic" in services else False
|
||||
cmd.isextractable = services[
|
||||
"isextractable"] if "isextractable" in services else False
|
||||
cmd.passwordenabled = services[
|
||||
"passwordenabled"] if "passwordenabled" in services else False
|
||||
|
||||
if volumeid:
|
||||
cmd.volumeid = volumeid
|
||||
if account:
|
||||
cmd.account = account
|
||||
if domainid:
|
||||
cmd.domainid = domainid
|
||||
if projectid:
|
||||
cmd.projectid = projectid
|
||||
return apiclient.createTemplate(cmd)
|
||||
|
||||
|
||||
class TestCreateTemplate(cloudstackTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
@ -147,6 +192,46 @@ class TestCreateTemplate(cloudstackTestCase):
|
|||
|
||||
return
|
||||
|
||||
@attr(tags = ["advanced", "advancedns", "smoke"], required_hardware="false")
|
||||
def test_CreateTemplateWithDuplicateName(self):
|
||||
"""Test when createTemplate is used to create templates having the same name all of them get
|
||||
different unique names so that the templates with same name does not get deleted during template sync"""
|
||||
|
||||
#1. Create 2 templates with same name
|
||||
#2. check the db that the templates with same name have different unique_name
|
||||
|
||||
#Create templates from Virtual machine and Volume ID
|
||||
template1 = create(self.apiclient,
|
||||
self.services["template"],
|
||||
self.volume.id,
|
||||
account=self.account.name)
|
||||
template2 = create(self.apiclient,
|
||||
self.services["template"],
|
||||
self.volume.id,
|
||||
account=self.account.name)
|
||||
|
||||
self.debug("Created template with ID: %s" % template1.id)
|
||||
self.debug("Created template with ID: %s" % template2.id)
|
||||
|
||||
self.assertEqual(
|
||||
template1.name, template2.name, "Created templates with same name")
|
||||
|
||||
self.debug("select unique_name from vm_template where name='%s';"
|
||||
% template1.name)
|
||||
|
||||
#Db query to check for unique_name for the templates with same name
|
||||
|
||||
qresultset = self.dbclient.execute("select unique_name from vm_template where name='%s' and removed is NULL ;"
|
||||
% template1.name)
|
||||
|
||||
|
||||
self.debug("unique_name of template1 is '%s' and unique_name of template2 is '%s'", qresultset[0],
|
||||
qresultset[1])
|
||||
|
||||
self.assertNotEqual(qresultset[0], qresultset[1],
|
||||
"unique names are different")
|
||||
|
||||
|
||||
@attr(tags = ["advanced", "advancedns", "smoke"], required_hardware="false")
|
||||
def test_01_create_template(self):
|
||||
"""Test create public & private template
|
||||
|
|
|
|||
Loading…
Reference in New Issue