Skip to content

verify that when createTemplate is ued to create templates with same … #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions test/integration/smoke/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,54 @@
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):
Expand Down Expand Up @@ -147,6 +192,46 @@ def tearDownClass(cls):

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
Expand Down