From ab8b2af13cfb93458e77102b4177ffa3e86df146 Mon Sep 17 00:00:00 2001 From: manasaVeloori Date: Thu, 13 Aug 2015 10:56:18 +0530 Subject: [PATCH] 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 --- test/integration/smoke/test_templates.py | 85 ++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/test/integration/smoke/test_templates.py b/test/integration/smoke/test_templates.py index 4d91d5915ca1..145282937ac8 100644 --- a/test/integration/smoke/test_templates.py +++ b/test/integration/smoke/test_templates.py @@ -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): @@ -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