def setUpClass(cls): testClient = super(TestScaleVm, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = testClient.getParsedTestDataConfig() cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][ 0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__ cls._cleanup = [] cls.unsupportedHypervisor = False cls.hypervisor = cls.testClient.getHypervisorInfo() if cls.hypervisor.lower() in ('kvm', 'hyperv', 'lxc'): cls.unsupportedHypervisor = True return # Get Zone, Domain and templates domain = get_domain(cls.apiclient) cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype if cls.hypervisor.lower() in ['simulator', 'vmware']: cls.template = get_template(cls.apiclient, cls.zone.id, cls.services["ostype"]) if cls.template == FAILED: assert False, "get_template() failed to return template\ with description %s" % cls.services["ostype"] cls.template = Template.update(cls.template, cls.apiclient, isdynamicallyscalable='true') else: cls.template = Template.register(cls.apiclient, cls.services["CentOS7template"], zoneid=cls.zone.id) cls._cleanup.append(cls.template) cls.template.download(cls.apiclient) time.sleep(60) # Set Zones and disk offerings cls.services["small"]["zoneid"] = cls.zone.id cls.services["small"]["template"] = cls.template.id # Create account, service offerings, vm. cls.account = Account.create(cls.apiclient, cls.services["account"], domainid=domain.id) cls._cleanup.append(cls.account) cls.small_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"]) cls._cleanup.append(cls.small_offering) cls.big_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["big"]) cls._cleanup.append(cls.big_offering) Configurations.update(cls.apiclient, name="enable.dynamic.scale.vm", value="true") cls.small_offering_dynamic_scaling_disabled = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"], dynamicscalingenabled=False) cls.big_offering_dynamic_scaling_disabled = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"], dynamicscalingenabled=False) # create a virtual machine cls.virtual_machine = VirtualMachine.create( cls.apiclient, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.small_offering.id, mode=cls.services["mode"]) # create a virtual machine which cannot be dynamically scalable cls.virtual_machine_with_service_offering_dynamic_scaling_disabled = VirtualMachine.create( cls.apiclient, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.small_offering_dynamic_scaling_disabled.id, mode=cls.services["mode"]) # create a virtual machine which cannot be dynamically scalable cls.virtual_machine_not_dynamically_scalable = VirtualMachine.create( cls.apiclient, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.small_offering.id, mode=cls.services["mode"], dynamicscalingenabled=False) cls._cleanup = [ cls.small_offering, cls.big_offering, cls.small_offering_dynamic_scaling_disabled, cls.big_offering_dynamic_scaling_disabled, cls.account ]
def test_03_edit_template_details(self): """ @Desc: Test to Edit Template name, displaytext, OSType @steps: Step1: Listing all the Templates for a user Step2: Verifying that no Templates are listed Step3: Creating a Templates Step4: Listing all the Templates again for a user Step5: Verifying that list size is 1 Step6: Verifying if the template is in ready state. If yes the continuing If not waiting and checking for template to be ready till timeout Step7: Editing the template name Step8: Verifying that Template name is edited Step9: Editing the template displaytext Step10: Verifying that Template displaytext is edited Step11: Editing the template ostypeid Step12: Verifying that Template ostypeid is edited Step13: Editing the template name, displaytext Step14: Verifying that Template name, displaytext are edited Step15: Editing the template name, displaytext, ostypeid Step16: Verifying that Template name, displaytext and ostypeid are edited """ # Listing all the Templates for a User list_templates_before = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"] ) # Verifying that no Templates are listed self.assertIsNone( list_templates_before, "Templates listed for newly created User" ) self.services["privatetemplate"]["ostype"] = self.services["ostype"] # Creating aTemplate template_created = Template.register( self.userapiclient, self.services["privatetemplate"], self.zone.id, hypervisor=self.hypervisor ) self.assertIsNotNone( template_created, "Template creation failed" ) # Listing all the Templates for a User list_templates_after = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"] ) status = validateList(list_templates_after) self.assertEquals( PASS, status[0], "Templates creation failed" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_templates_after), "Failed to create a Template" ) # Verifying the state of the template to be ready. If not waiting for # state to become ready till time out template_ready = False count = 0 while template_ready is False: list_template = Template.list( self.userapiclient, id=template_created.id, listall=self.services["listall"], templatefilter=self.services["templatefilter"], ) status = validateList(list_template) self.assertEquals( PASS, status[0], "Failed to list Templates by Id" ) if list_template[0].isready is True: template_ready = True elif (str(list_template[0].status) == "Error"): self.fail("Created Template is in Errored state") break elif count > 10: self.fail("Timed out before Template came into ready state") break else: time.sleep(self.services["sleep"]) count = count + 1 # Editing the Template name edited_template = Template.update( template_created, self.userapiclient, name="NewTemplateName" ) self.assertIsNotNone( edited_template, "Editing Template failed" ) # Verifying the details of edited template expected_dict = { "id": template_created.id, "name": "NewTemplateName", "displaytest": template_created.displaytext, "account": template_created.account, "domainid": template_created.domainid, "format": template_created.format, "ostypeid": template_created.ostypeid, "templatetype": template_created.templatetype, } actual_dict = { "id": edited_template.id, "name": edited_template.name, "displaytest": edited_template.displaytext, "account": edited_template.account, "domainid": edited_template.domainid, "format": edited_template.format, "ostypeid": edited_template.ostypeid, "templatetype": edited_template.templatetype, } edit_template_status = self.__verify_values( expected_dict, actual_dict ) self.assertEqual( True, edit_template_status, "Edited Template details are not as expected" ) # Editing the Template displaytext edited_template = Template.update( template_created, self.userapiclient, displaytext="TemplateDisplaytext" ) self.assertIsNotNone( edited_template, "Editing Template failed" ) # Verifying the details of edited template expected_dict = { "id": template_created.id, "name": "NewTemplateName", "displaytest": "TemplateDisplaytext", "account": template_created.account, "domainid": template_created.domainid, "format": template_created.format, "ostypeid": template_created.ostypeid, "templatetype": template_created.templatetype, } actual_dict = { "id": edited_template.id, "name": edited_template.name, "displaytest": edited_template.displaytext, "account": edited_template.account, "domainid": edited_template.domainid, "format": edited_template.format, "ostypeid": edited_template.ostypeid, "templatetype": edited_template.templatetype, } edit_template_status = self.__verify_values( expected_dict, actual_dict ) self.assertEqual( True, edit_template_status, "Edited Template details are not as expected" ) # Editing the Template ostypeid ostype_list = list_os_types(self.userapiclient) status = validateList(ostype_list) self.assertEquals( PASS, status[0], "Failed to list OS Types" ) for i in range(0, len(ostype_list)): if ostype_list[i].id != template_created.ostypeid: newostypeid = ostype_list[i].id break edited_template = Template.update( template_created, self.userapiclient, ostypeid=newostypeid ) self.assertIsNotNone( edited_template, "Editing Template failed" ) # Verifying the details of edited template expected_dict = { "id": template_created.id, "name": "NewTemplateName", "displaytest": "TemplateDisplaytext", "account": template_created.account, "domainid": template_created.domainid, "format": template_created.format, "ostypeid": newostypeid, "templatetype": template_created.templatetype, } actual_dict = { "id": edited_template.id, "name": edited_template.name, "displaytest": edited_template.displaytext, "account": edited_template.account, "domainid": edited_template.domainid, "format": edited_template.format, "ostypeid": edited_template.ostypeid, "templatetype": edited_template.templatetype, } edit_template_status = self.__verify_values( expected_dict, actual_dict ) self.assertEqual( True, edit_template_status, "Edited Template details are not as expected" ) # Editing the Template name, displaytext edited_template = Template.update( template_created, self.userapiclient, name=template_created.name, displaytext=template_created.displaytext ) self.assertIsNotNone( edited_template, "Editing Template failed" ) # Verifying the details of edited template expected_dict = { "id": template_created.id, "name": template_created.name, "displaytest": template_created.displaytext, "account": template_created.account, "domainid": template_created.domainid, "format": template_created.format, "ostypeid": newostypeid, "templatetype": template_created.templatetype, } actual_dict = { "id": edited_template.id, "name": edited_template.name, "displaytest": edited_template.displaytext, "account": edited_template.account, "domainid": edited_template.domainid, "format": edited_template.format, "ostypeid": edited_template.ostypeid, "templatetype": edited_template.templatetype, } edit_template_status = self.__verify_values( expected_dict, actual_dict ) self.assertEqual( True, edit_template_status, "Edited Template details are not as expected" ) # Editing the Template name, displaytext, ostypeid edited_template = Template.update( template_created, self.userapiclient, name="NewTemplateName", displaytext="TemplateDisplaytext", ostypeid=template_created.ostypeid ) self.assertIsNotNone( edited_template, "Editing Template failed" ) # Verifying the details of edited template expected_dict = { "id": template_created.id, "name": "NewTemplateName", "displaytest": "TemplateDisplaytext", "account": template_created.account, "domainid": template_created.domainid, "format": template_created.format, "ostypeid": template_created.ostypeid, "templatetype": template_created.templatetype, } actual_dict = { "id": edited_template.id, "name": edited_template.name, "displaytest": edited_template.displaytext, "account": edited_template.account, "domainid": edited_template.domainid, "format": edited_template.format, "ostypeid": edited_template.ostypeid, "templatetype": edited_template.templatetype, } edit_template_status = self.__verify_values( expected_dict, actual_dict ) self.assertEqual( True, edit_template_status, "Edited Template details are not as expected" ) del self.services["privatetemplate"]["ostype"] return