Beispiel #1
0
    def test_instance_name_with_hyphens(self):
        """ Test the instance  name with hyphens
        """

        # Validate the following
        # 1. Set the vm.instancename.flag to true.
        # 2. Add the virtual machine with display name with hyphens

        # Reading display name property
        if not is_config_suitable(apiclient=self.apiclient, name="vm.instancename.flag", value="true"):
            self.skipTest("vm.instancename.flag should be true. skipping")

        self.services["virtual_machine"]["displayname"] = "TestVM-test-name"
        self.services["virtual_machine"]["name"] = "TestVM"

        self.debug("Deploying an instance in account: %s" % self.account.name)

        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.debug("Checking if the virtual machine is created properly or not?")
        vms = VirtualMachine.list(self.apiclient, id=virtual_machine.id, listall=True)

        self.assertEqual(isinstance(vms, list), True, "List vms should retuen a valid name")
        vm = vms[0]
        self.assertEqual(vm.state, "Running", "Vm state should be running after deployment")
        self.debug("Display name: %s" % vm.displayname)
        return
Beispiel #2
0
    def test_03_duplicate_name(self):
        """ Test the duplicate name when old VM is in non-expunged state
        """

        # Validate the following
        # 1. Set the vm.instancename.flag to true.
        # 2. Add the virtual machine with display name same as that of
        #   non-expunged virtual machine. The proper error should pop
        #   out saying the duplicate names are not allowed

        # Reading display name property
        if not is_config_suitable(apiclient=self.apiclient, name='vm.instancename.flag', value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')

        self.services["virtual_machine"]["displayname"] = "TestVM"
        self.services["virtual_machine"]["name"] = "TestVM"

        self.debug("Deploying an instance in account: %s" %
                                        self.account.name)

        virtual_machine = VirtualMachine.create(
                                  self.apiclient,
                                  self.services["virtual_machine"],
                                  accountid=self.account.name,
                                  domainid=self.account.domainid,
                                  serviceofferingid=self.service_offering.id,
                                  )
        self.cleanup.append(virtual_machine)
        self.debug(
            "Checking if the virtual machine is created properly or not?")
        vms = VirtualMachine.list(
                                  self.apiclient,
                                  id=virtual_machine.id,
                                  listall=True
                                  )

        self.assertEqual(
                         isinstance(vms, list),
                         True,
                         "List vms should retuen a valid name"
                         )
        vm = vms[0]
        self.assertEqual(
                         vm.state,
                         "Running",
                         "Vm state should be running after deployment"
                         )
        self.debug("Display name: %s" % vm.displayname)
        self.debug("Deplying another virtual machine with same name")
        with self.assertRaises(Exception):
            VirtualMachine.create(
                                  self.apiclient,
                                  self.services["virtual_machine"],
                                  accountid=self.account.name,
                                  domainid=self.account.domainid,
                                  serviceofferingid=self.service_offering.id,
                                  )
        return
Beispiel #3
0
    def test_es_47_list_os_types_win_2012(self):
        """
        @Desc: Test VM creation while "apply.allocation.algorithm.to.pods"
        is set to true
        @Reference: https://issues.apache.org/jira/browse/CLOUDSTACK-4947
        @Steps:
        Step1: register windows 2012 VM template as windows 8 template
        Step2: deploy a VM with windows2012 template and  Verify
        that VM creation is successful

         """

        if not is_config_suitable(apiclient=self.apiClient,
                                  name='apply.allocation.algorithm.to.pods',
                                  value='true'):
            self.skipTest('apply.allocation.algorithm.to.pods '
                          'should be true. skipping')

        # register windows 2012 VM template as windows 8 template
        self.hypervisor = self.testClient.getHypervisorInfo()
        if self.hypervisor.lower() in ['lxc']:
            self.skipTest(
                "windows VM is not supported on %s" %
                self.hypervisor.lower())
        self.win2012_template = Template.register(
            self.apiClient,
            self.services["win2012template"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.domain.id,
            hypervisor=self.hypervisor
        )
        # Wait for template to download
        self.win2012_template.download(self.apiClient)
        self.cleanup.append(self.win2012_template)
        # Wait for template status to be changed across
        time.sleep(60)
        # Deploy
        self.debug("Deploying win 2012 VM in account: %s" % self.account.name)
        self.services["virtual_machine"]["displayname"] = "win2012"
        self.services["virtual_machine"]["zoneid"] = self.zone.id
        self.services["virtual_machine"]["template"] = self.win2012_template.id
        vm1 = VirtualMachine.create(
            self.apiClient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id
        )
        self.cleanup.append(vm1)
        # Verify VM state
        self.assertEqual(
            vm1.state,
            'Running',
            "Check VM state is Running or not"
        )
        return
    def test_03_duplicate_name(self):
        """ Test the duplicate name when old VM is in non-expunged state
        """

        # Validate the following
        # 1. Set the vm.instancename.flag to true.
        # 2. Add the virtual machine with display name same as that of
        #   non-expunged virtual machine. The proper error should pop
        #   out saying the duplicate names are not allowed

        # Reading display name property
        if not is_config_suitable(apiclient=self.apiclient, name='vm.instancename.flag', value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')

        self.services["virtual_machine"]["displayname"] = "TestVM"
        self.services["virtual_machine"]["name"] = "TestVM"

        self.debug("Deploying an instance in account: %s" %
                                        self.account.name)

        virtual_machine = VirtualMachine.create(
                                  self.apiclient,
                                  self.services["virtual_machine"],
                                  accountid=self.account.name,
                                  domainid=self.account.domainid,
                                  serviceofferingid=self.service_offering.id,
                                  )
        self.debug(
            "Checking if the virtual machine is created properly or not?")
        vms = VirtualMachine.list(
                                  self.apiclient,
                                  id=virtual_machine.id,
                                  listall=True
                                  )

        self.assertEqual(
                         isinstance(vms, list),
                         True,
                         "List vms should retuen a valid name"
                         )
        vm = vms[0]
        self.assertEqual(
                         vm.state,
                         "Running",
                         "Vm state should be running after deployment"
                         )
        self.debug("Display name: %s" % vm.displayname)
        self.debug("Deplying another virtual machine with same name")
        with self.assertRaises(Exception):
            VirtualMachine.create(
                                  self.apiclient,
                                  self.services["virtual_machine"],
                                  accountid=self.account.name,
                                  domainid=self.account.domainid,
                                  serviceofferingid=self.service_offering.id,
                                  )
        return
Beispiel #5
0
    def test_es_47_list_os_types_win_2012(self):
        """
        @Desc: Test VM creation while "apply.allocation.algorithm.to.pods"
        is set to true
        @Reference: https://issues.apache.org/jira/browse/CLOUDSTACK-4947
        @Steps:
        Step1: register windows 2012 VM template as windows 8 template
        Step2: deploy a VM with windows2012 template and  Verify
        that VM creation is successful

         """

        if not is_config_suitable(apiclient=self.apiClient,
                                  name='apply.allocation.algorithm.to.pods',
                                  value='true'):
            self.skipTest('apply.allocation.algorithm.to.pods '
                          'should be true. skipping')

        # register windows 2012 VM template as windows 8 template
        self.hypervisor = self.testClient.getHypervisorInfo()
        if self.hypervisor.lower() in ['lxc']:
            self.skipTest(
                "windows VM is not supported on %s" %
                self.hypervisor.lower())
        self.win2012_template = Template.register(
            self.apiClient,
            self.services["win2012template"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.domain.id,
            hypervisor=self.hypervisor
        )
        # Wait for template to download
        self.win2012_template.download(self.apiClient)
        self.cleanup.append(self.win2012_template)
        # Wait for template status to be changed across
        time.sleep(60)
        # Deploy
        self.debug("Deploying win 2012 VM in account: %s" % self.account.name)
        self.services["virtual_machine"]["displayname"] = "win2012"
        self.services["virtual_machine"]["zoneid"] = self.zone.id
        self.services["virtual_machine"]["template"] = self.win2012_template.id
        vm1 = VirtualMachine.create(
            self.apiClient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id
        )
        self.cleanup.append(vm1)
        # Verify VM state
        self.assertEqual(
            vm1.state,
            'Running',
            "Check VM state is Running or not"
        )
        return
    def test_instance_name_with_hyphens(self):
        """ Test the instance  name with hyphens
        """

        # Validate the following
        # 1. Set the vm.instancename.flag to true.
        # 2. Add the virtual machine with display name with hyphens

        # Reading display name property
        if not is_config_suitable(
                apiclient=self.apiclient,
                name='vm.instancename.flag',
                value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')

        self.services["virtual_machine"]["displayname"] = random_gen(
            chars=string.ascii_uppercase) + "-" + random_gen(
            chars=string.ascii_uppercase)

        self.debug("Deploying an instance in account: %s" %
                   self.account.name)

        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.debug(
            "Checking if the virtual machine is created properly or not?")
        vms = VirtualMachine.list(
            self.apiclient,
            id=virtual_machine.id,
            listall=True
        )

        self.assertEqual(
            isinstance(vms, list),
            True,
            "List vms should retuen a valid name"
        )
        vm = vms[0]
        self.assertEqual(
            vm.state,
            "Running",
            "Vm state should be running after deployment"
        )
        self.debug("Display name: %s" % vm.displayname)
        return
Beispiel #7
0
    def test_es_1223_apply_algo_to_pods(self):
        """
        @Desc: Test VM creation while "apply.allocation.algorithm.to.pods" is
        set to true
        @Reference: https://issues.apache.org/jira/browse/CLOUDSTACK-4947
        @Steps:
        Step1: Set global configuration "apply.allocation.algorithm.to.pods"
        to true
        Step2: Restart management server
        Step3: Verifying that VM creation is successful
        """
        # Step1:  set global configuration
        # "apply.allocation.algorithm.to.pods" to true
        # Configurations.update(self.apiClient,
        # "apply.allocation.algorithm.to.pods", "true")
        # TODO: restart management server
        if not is_config_suitable(apiclient=self.apiClient,
                                  name='apply.allocation.algorithm.to.pods',
                                  value='true'):
            self.skipTest('apply.allocation.algorithm.to.pods '
                          'should be true. skipping')
        # TODO:Step2: Restart management server
        self.services["virtual_machine"]["zoneid"] = self.zone.id
        self.services["virtual_machine"]["template"] = self.template.id
        # Step3: Verifying that VM creation is successful
        virtual_machine = VirtualMachine.create(
            self.apiClient,
            self.services["virtual_machine2"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.cleanup.append(virtual_machine)
        # Verify VM state
        self.assertEqual(
            virtual_machine.state,
            'Running',
            "Check VM state is Running or not"
        )

        # cleanup: set global configuration
        # "apply.allocation.algorithm.to.pods" back to false
        Configurations.update(
            self.apiClient,
            name="apply.allocation.algorithm.to.pods",
            value="false"
        )
        # TODO:cleanup: Restart management server
        return
Beispiel #8
0
    def test_es_1223_apply_algo_to_pods(self):
        """
        @Desc: Test VM creation while "apply.allocation.algorithm.to.pods" is
        set to true
        @Reference: https://issues.apache.org/jira/browse/CLOUDSTACK-4947
        @Steps:
        Step1: Set global configuration "apply.allocation.algorithm.to.pods"
        to true
        Step2: Restart management server
        Step3: Verifying that VM creation is successful
        """
        # Step1:  set global configuration
        # "apply.allocation.algorithm.to.pods" to true
        # Configurations.update(self.apiClient,
        # "apply.allocation.algorithm.to.pods", "true")
        # TODO: restart management server
        if not is_config_suitable(apiclient=self.apiClient,
                                  name='apply.allocation.algorithm.to.pods',
                                  value='true'):
            self.skipTest('apply.allocation.algorithm.to.pods '
                          'should be true. skipping')
        # TODO:Step2: Restart management server
        self.services["virtual_machine"]["zoneid"] = self.zone.id
        self.services["virtual_machine"]["template"] = self.template.id
        # Step3: Verifying that VM creation is successful
        virtual_machine = VirtualMachine.create(
            self.apiClient,
            self.services["virtual_machine2"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.cleanup.append(virtual_machine)
        # Verify VM state
        self.assertEqual(
            virtual_machine.state,
            'Running',
            "Check VM state is Running or not"
        )

        # cleanup: set global configuration
        # "apply.allocation.algorithm.to.pods" back to false
        Configurations.update(
            self.apiClient,
            name="apply.allocation.algorithm.to.pods",
            value="false"
        )
        # TODO:cleanup: Restart management server
        return
    def test_vm_instance_name_duplicate_different_accounts(self):
        """
        @Desc: Test whether cloudstack allows duplicate vm instance
               names in the diff networks
        @Steps:
        Step1: Set the vm.instancename.flag to true.
        Step2: Deploy a VM with name say webserver01 from account1
               Internal name should be i-<userid>-<vmid>-webserver01
        Step3: Now deploy VM with the same name "webserver01" from account2.
        Step4: Deployment of VM with same name should fail
        """

        if not is_config_suitable(
                apiclient=self.apiclient,
                name='vm.instancename.flag',
                value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')
        # Step2: Deploy a VM with name say webserver01 from account1
        self.debug("Deploying VM in account: %s" % self.account.name)
        self.services["virtual_machine2"][
            "displayname"] = random_gen(chars=string.ascii_uppercase)
        self.services["virtual_machine2"]["zoneid"] = self.zone.id
        self.services["virtual_machine2"]["template"] = self.template.id
        vm1 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine2"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.cleanup.append(vm1)

        # Step3: Now deploy VM with the same name "webserver01" from account2.
        self.debug("Deploying VM in account: %s" % self.account_2.name)
        with self.assertRaises(Exception):
            vm2 = VirtualMachine.create(
                self.apiclient,
                self.services["virtual_machine2"],
                accountid=self.account_2.name,
                domainid=self.account_2.domainid,
                serviceofferingid=self.service_offering.id,
            )
            self.cleanup.append(vm2)
        # Step4: Deployment of VM with same name should fail
        return
    def test_vm_instance_name_duplicate_different_accounts(self):
        """
        @Desc: Test whether cloudstack allows duplicate vm instance
               names in the diff networks
        @Steps:
        Step1: Set the vm.instancename.flag to true.
        Step2: Deploy a VM with name say webserver01 from account1
               Internal name should be i-<userid>-<vmid>-webserver01
        Step3: Now deploy VM with the same name "webserver01" from account2.
        Step4: Deployment of VM with same name should fail
        """

        if not is_config_suitable(
                apiclient=self.apiclient,
                name='vm.instancename.flag',
                value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')
        # Step2: Deploy a VM with name say webserver01 from account1
        self.debug("Deploying VM in account: %s" % self.account.name)
        self.services["virtual_machine2"][
            "displayname"] = random_gen(chars=string.ascii_uppercase)
        self.services["virtual_machine2"]["zoneid"] = self.zone.id
        self.services["virtual_machine2"]["template"] = self.template.id
        vm1 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine2"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.cleanup.append(vm1)

        # Step3: Now deploy VM with the same name "webserver01" from account2.
        self.debug("Deploying VM in account: %s" % self.account_2.name)
        with self.assertRaises(Exception):
            vm2 = VirtualMachine.create(
                self.apiclient,
                self.services["virtual_machine2"],
                accountid=self.account_2.name,
                domainid=self.account_2.domainid,
                serviceofferingid=self.service_offering.id,
            )
            self.cleanup.append(vm2)
        # Step4: Deployment of VM with same name should fail
        return
    def test_05_unsupported_chars_in_display_name(self):
        """ Test Unsupported chars in the display name
            (eg: Spaces,Exclamation,yet to get unsupported chars from the dev)
        """

        # Validate the following
        # 1) Set the Global Setting vm.instancename.flag to true
        # 2) While creating VM give a Display name which has unsupported chars
        #    Gives an error message "Instance name can not be longer than 63
        #    characters. Only ASCII letters a~z, A~Z, digits 0~9, hyphen are
        #    allowed. Must start with a letter and end with a letter or digit

        if not is_config_suitable(
                apiclient=self.apiclient,
                name='vm.instancename.flag',
                value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')

        self.debug("Creating VM with unsupported chars in display name")
        display_names = ["!hkzs566", "asdh asd", "!dsf d"]

        for display_name in display_names:
            self.debug("Display name: %s" % display_name)
            self.services["virtual_machine"]["displayname"] = display_name
            self.services["virtual_machine"]["name"] = random_gen(
                chars=string.ascii_uppercase)

            with self.assertRaises(Exception):
                # Spawn an instance in that network
                VirtualMachine.create(
                    self.apiclient,
                    self.services["virtual_machine"],
                    accountid=self.account.name,
                    domainid=self.account.domainid,
                    serviceofferingid=self.service_offering.id,
                )
        return
    def test_05_unsupported_chars_in_display_name(self):
        """ Test Unsupported chars in the display name
            (eg: Spaces,Exclamation,yet to get unsupported chars from the dev)
        """

        # Validate the following
        # 1) Set the Global Setting vm.instancename.flag to true
        # 2) While creating VM give a Display name which has unsupported chars
        #    Gives an error message "Instance name can not be longer than 63
        #    characters. Only ASCII letters a~z, A~Z, digits 0~9, hyphen are
        #    allowed. Must start with a letter and end with a letter or digit

        if not is_config_suitable(
                apiclient=self.apiclient,
                name='vm.instancename.flag',
                value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')

        self.debug("Creating VM with unsupported chars in display name")
        display_names = ["!hkzs566", "asdh asd", "!dsf d"]

        for display_name in display_names:
            self.debug("Display name: %s" % display_name)
            self.services["virtual_machine"]["displayname"] = display_name
            self.services["virtual_machine"]["name"] = random_gen(
                chars=string.ascii_uppercase)

            with self.assertRaises(Exception):
                # Spawn an instance in that network
                VirtualMachine.create(
                    self.apiclient,
                    self.services["virtual_machine"],
                    accountid=self.account.name,
                    domainid=self.account.domainid,
                    serviceofferingid=self.service_offering.id,
                )
        return
Beispiel #13
0
    def test_01_custom_hostname_instancename_false(self):
        """ Verify custom hostname for the instance when
            vm.instancename.flag=false
        """

        # Validate the following
        # 1. Set the vm.instancename.flog to false. Hostname and displayname
        #    should be UUID
        # 2. Give the user provided display name. Internal name should be
        #    i-<userid>-<vmid>-instance name (It should not contain display name)

        if not is_config_suitable(apiclient=self.apiclient, name="vm.instancename.flag", value="false"):
            self.skipTest("vm.instancename.flag should be false. skipping")

        self.debug("Deploying VM in account: %s" % self.account.name)
        # Spawn an instance in that network
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.debug("Checking if the virtual machine is created properly or not?")
        vms = VirtualMachine.list(self.apiclient, id=virtual_machine.id, listall=True)

        self.assertEqual(isinstance(vms, list), True, "List vms should retuen a valid name")
        vm = vms[0]
        self.assertEqual(vm.state, "Running", "Vm state should be running after deployment")
        self.debug(
            "vm.displayname: %s, original: %s" % (vm.displayname, self.services["virtual_machine"]["displayname"])
        )
        self.assertEqual(
            vm.displayname,
            self.services["virtual_machine"]["displayname"],
            "Vm display name should match the given name",
        )

        # Fetch account ID and VMID from database to check internal name
        self.debug("select id from account where uuid = '%s';" % self.account.id)

        qresultset = self.dbclient.execute("select id from account where uuid = '%s';" % self.account.id)
        self.assertEqual(isinstance(qresultset, list), True, "Check DB query result set for valid data")

        self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")
        qresult = qresultset[0]
        account_id = qresult[0]

        self.debug("select id from vm_instance where uuid = '%s';" % vm.id)

        qresultset = self.dbclient.execute("select id from vm_instance where uuid = '%s';" % vm.id)

        self.assertEqual(isinstance(qresultset, list), True, "Check DB query result set for valid data")

        self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")
        qresult = qresultset[0]
        self.debug("Query result: %s" % qresult)
        vmid = qresult[0]

        self.debug("Fetching the global config value for instance.name")
        configs = Configurations.list(self.apiclient, name="instance.name", listall=True)

        config = configs[0]
        self.debug("Config value : %s" % config)
        instance_name = config.value
        self.debug("Instance.name: %s" % instance_name)

        # internal Name = i-<user ID>-<VM ID>-<instance_name>
        # internal_name = "i-" + str(account_id) + "-" + str(vmid) + "-" + instance_name
        internal_name = "i-%s-%s-%s" % (str(account_id), str(vmid), instance_name)
        self.debug("Internal name: %s" % internal_name)
        self.debug("vm instance name : %s" % vm.instancename)
        self.assertEqual(vm.instancename, internal_name, "VM internal name should match with that of the format")
        return
    def test_01_user_provided_hostname(self):
        """ Verify user provided hostname to an instance
        """

        # Validate the following
        # 1. Set the vm.instancename.flag to true. Hostname and displayname
        #    should be user provided display name
        # 2. Give the user provided user name. Internal name should be
        #    i-<userid>-<vmid>-display name
        if not is_config_suitable(apiclient=self.apiclient, name='vm.instancename.flag', value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')

        self.debug("Deploying VM in account: %s" % self.account.name)
        # Spawn an instance in that network
        virtual_machine = VirtualMachine.create(
                                  self.apiclient,
                                  self.services["virtual_machine"],
                                  accountid=self.account.name,
                                  domainid=self.account.domainid,
                                  serviceofferingid=self.service_offering.id,
                                  )
        self.debug(
            "Checking if the virtual machine is created properly or not?")
        vms = VirtualMachine.list(
                                  self.apiclient,
                                  id=virtual_machine.id,
                                  listall=True
                                  )

        self.assertEqual(
                         isinstance(vms, list),
                         True,
                         "List vms should return a valid name"
                         )
        vm = vms[0]
        self.assertEqual(
                         vm.state,
                         "Running",
                         "Vm state should be running after deployment"
                         )
        self.debug("vm.displayname: %s, original: %s" %
                        (vm.displayname,
                        self.services["virtual_machine"]["displayname"]))
        self.assertEqual(
                         vm.displayname,
                         self.services["virtual_machine"]["displayname"],
                         "Vm display name should match the given name"
                         )

        # Fetch account ID and VMID from database to check internal name
        self.debug("select id from account where uuid = '%s';" \
                                            % self.account.id)

        qresultset = self.dbclient.execute(
                                "select id from account where uuid = '%s';" \
                                % self.account.id
                                )
        self.assertEqual(
                         isinstance(qresultset, list),
                         True,
                         "Check DB query result set for valid data"
                         )

        self.assertNotEqual(
                            len(qresultset),
                            0,
                            "Check DB Query result set"
                            )
        qresult = qresultset[0]
        account_id = qresult[0]

        self.debug("select id from vm_instance where uuid = '%s';" % vm.id)

        qresultset = self.dbclient.execute(
                        "select id from vm_instance where uuid = '%s';" %
                        vm.id)

        self.assertEqual(
                         isinstance(qresultset, list),
                         True,
                         "Check DB query result set for valid data"
                         )

        self.assertNotEqual(
                            len(qresultset),
                            0,
                            "Check DB Query result set"
                            )
        qresult = qresultset[0]
        self.debug("Query result: %s" % qresult)
        vmid = qresult[0]

        #internal Name = i-<user ID>-<VM ID>-Display name
        internal_name = "i-" + str(account_id) + "-" + str(vmid) + "-" + vm.displayname
        self.debug("Internal name: %s" % internal_name)
        self.assertEqual(
                        vm.instancename,
                        internal_name,
                        "VM internal name should match with that of the format"
                        )
        return
    def test_01_custom_hostname_instancename_false(self):
        """ Verify custom hostname for the instance when
            vm.instancename.flag=false
        """

        # Validate the following
        # 1. Set the vm.instancename.flog to false. Hostname and displayname
        #    should be UUID
        # 2. Give the user provided display name. Internal name should be
        # i-<userid>-<vmid>-instance name (It should not contain display name)

        if not is_config_suitable(apiclient=self.apiclient,
                                  name='vm.instancename.flag',
                                  value='false'):
            self.skipTest('vm.instancename.flag should be false. skipping')

        self.debug("Deploying VM in account: %s" % self.account.name)
        # Spawn an instance in that network
        self.services["virtual_machine"]["displayname"] = random_gen(
            chars=string.ascii_uppercase)
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.debug(
            "Checking if the virtual machine is created properly or not?")
        vms = VirtualMachine.list(self.apiclient,
                                  id=virtual_machine.id,
                                  listall=True)

        self.assertEqual(isinstance(vms, list), True,
                         "List vms should retuen a valid name")
        vm = vms[0]
        self.assertEqual(vm.state, "Running",
                         "Vm state should be running after deployment")
        self.debug(
            "vm.displayname: %s, original: %s" %
            (vm.displayname, self.services["virtual_machine"]["displayname"]))
        self.assertEqual(vm.displayname,
                         self.services["virtual_machine"]["displayname"],
                         "Vm display name should match the given name")

        # Fetch account ID and VMID from database to check internal name
        self.debug("select id from account where uuid = '%s';" %
                   self.account.id)

        qresultset = self.dbclient.execute(
            "select id from account where uuid = '%s';" % self.account.id)
        self.assertEqual(isinstance(qresultset, list), True,
                         "Check DB query result set for valid data")

        self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")
        qresult = qresultset[0]
        account_id = qresult[0]

        self.debug("select id from vm_instance where uuid = '%s';" % vm.id)

        qresultset = self.dbclient.execute(
            "select id from vm_instance where uuid = '%s';" % vm.id)

        self.assertEqual(isinstance(qresultset, list), True,
                         "Check DB query result set for valid data")

        self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")
        qresult = qresultset[0]
        self.debug("Query result: %s" % qresult)
        vmid = qresult[0]

        self.debug("Fetching the global config value for instance.name")
        configs = Configurations.list(self.apiclient,
                                      name="instance.name",
                                      listall=True)

        config = configs[0]
        self.debug("Config value : %s" % config)
        instance_name = config.value
        self.debug("Instance.name: %s" % instance_name)

        # internal Name = i-<user ID>-<VM ID>-<instance_name>
        # internal_name = "i-" + str(account_id) + "-" + str(vmid) + "-" +
        # instance_name
        internal_name = "i-%s-%s-%s" % (str(account_id), str(vmid),
                                        instance_name)
        self.debug("Internal name: %s" % internal_name)
        self.debug("vm instance name : %s" % vm.instancename)
        self.assertEqual(
            vm.instancename, internal_name,
            "VM internal name should match with that of the format")
        return
    def test_04_edit_display_name(self):
        """ Test Edit the Display name Through the UI.
        """

        # Validate the following
        # 1) Set the Global Setting vm.instancename.flag to true
        # 2) Create a VM give a Display name.
        # 3) Once the VM is created stop the VM.
        # 4) Edit the VM Display name. The Display name will be changed but the
        #    internal name will not be changed. The VM functionality must not
        #    be effected.

        if not is_config_suitable(apiclient=self.apiclient,
                                  name='vm.instancename.flag',
                                  value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')

        # Spawn an instance in that network
        self.debug("Deploying VM in account: %s" % self.account.name)
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.debug(
            "Checking if the virtual machine is created properly or not?")
        vms = VirtualMachine.list(self.apiclient,
                                  id=virtual_machine.id,
                                  listall=True)

        self.assertEqual(isinstance(vms, list), True,
                         "List vms should retuen a valid name")
        vm = vms[0]
        self.assertEqual(vm.state, "Running",
                         "Vm state should be running after deployment")

        self.assertEqual(vm.displayname,
                         self.services["virtual_machine"]["displayname"],
                         "Vm display name should match the given name")

        old_internal_name = vm.instancename
        self.debug("Stopping the instance: %s" % vm.name)
        try:
            virtual_machine.stop(self.apiclient)
        except Exception as e:
            self.fail("Failed to stop instance: %s, %s" % (vm.name, e))

        self.debug("Update the display name of the instance")
        try:
            virtual_machine.update(
                self.apiclient,
                displayname=random_gen(chars=string.ascii_uppercase))
        except Exception as e:
            self.fail("Failed to update the virtual machine name: %s, %s" %
                      (virtual_machine.name, e))

        self.debug("Start the instance: %s" % virtual_machine.name)
        virtual_machine.start(self.apiclient)

        self.debug("Checking if the instance is working properly after update")
        vms = VirtualMachine.list(self.apiclient,
                                  id=virtual_machine.id,
                                  listall=True)

        self.assertEqual(isinstance(vms, list), True,
                         "List vms should retuen a valid name")
        vm = vms[0]
        self.assertEqual(vm.state, "Running",
                         "Vm state should be running after deployment")

        self.assertEqual(
            vm.instancename, old_internal_name,
            "Vm internal name should not be changed after update")
        return
    def test_02_instancename_from_default_configuration(self):
        """ Verify for globally set instancename
        """

        # Validate the following
        # 1. Set the vm.instancename.flag to true. Hostname and displayname
        #    should be user provided display name
        # 2. Dont give the user provided user name. Internal name should be
        #    i-<userid>-<vmid>-<instance.name> in global config
        if not is_config_suitable(apiclient=self.apiclient,
                                  name='vm.instancename.flag',
                                  value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')

        # Removing display name from config
        del self.services["virtual_machine"]["displayname"]
        self.debug("Deploying VM in account: %s" % self.account.name)
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.debug(
            "Checking if the virtual machine is created properly or not?")
        vms = VirtualMachine.list(self.apiclient,
                                  id=virtual_machine.id,
                                  listall=True)

        self.assertEqual(isinstance(vms, list), True,
                         "List vms should retuen a valid name")
        vm = vms[0]
        self.assertEqual(vm.state, "Running",
                         "Vm state should be running after deployment")
        self.assertNotEqual(vm.displayname, vm.id,
                            "Vm display name should not match the given name")
        # Fetch account ID and VMID from database to check internal name
        self.debug("select id from account where uuid = '%s';" %
                   self.account.id)

        qresultset = self.dbclient.execute(
            "select id from account where uuid = '%s';" % self.account.id)
        self.assertEqual(isinstance(qresultset, list), True,
                         "Check DB query result set for valid data")

        self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")
        qresult = qresultset[0]
        account_id = qresult[0]

        self.debug("select id from vm_instance where uuid = '%s';" % vm.id)

        qresultset = self.dbclient.execute(
            "select id from vm_instance where uuid = '%s';" % vm.id)

        self.assertEqual(isinstance(qresultset, list), True,
                         "Check DB query result set for valid data")

        self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")
        qresult = qresultset[0]
        self.debug("Query result: %s" % qresult)
        vmid = qresult[0]

        self.debug("Fetching the global config value for instance.name")
        configs = Configurations.list(self.apiclient,
                                      name="instance.name",
                                      listall=True)

        config = configs[0]
        instance_name = config.value
        self.debug("Instance.name: %s" % instance_name)

        # internal Name = i-<user ID>-<VM ID>- Instance_name
        internal_name = "i-" + \
            str(account_id) + "-" + str(vmid) + "-" + instance_name
        self.assertEqual(
            vm.instancename, internal_name,
            "VM internal name should match with that of the format")
        return
    def test_04_edit_display_name(self):
        """ Test Edit the Display name Through the UI.
        """

        # Validate the following
        # 1) Set the Global Setting vm.instancename.flag to true
        # 2) Create a VM give a Display name.
        # 3) Once the VM is created stop the VM.
        # 4) Edit the VM Display name. The Display name will be changed but the
        #    internal name will not be changed. The VM functionality must not
        #    be effected.

        if not is_config_suitable(
                apiclient=self.apiclient,
                name='vm.instancename.flag',
                value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')

        # Spawn an instance in that network
        self.debug("Deploying VM in account: %s" % self.account.name)
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.debug(
            "Checking if the virtual machine is created properly or not?")
        vms = VirtualMachine.list(
            self.apiclient,
            id=virtual_machine.id,
            listall=True
        )

        self.assertEqual(
            isinstance(vms, list),
            True,
            "List vms should retuen a valid name"
        )
        vm = vms[0]
        self.assertEqual(
            vm.state,
            "Running",
            "Vm state should be running after deployment"
        )

        self.assertEqual(
            vm.displayname,
            self.services["virtual_machine"]["displayname"],
            "Vm display name should match the given name"
        )

        old_internal_name = vm.instancename
        self.debug("Stopping the instance: %s" % vm.name)
        try:
            virtual_machine.stop(self.apiclient)
        except Exception as e:
            self.fail("Failed to stop instance: %s, %s" % (vm.name, e))

        self.debug("Update the display name of the instance")
        try:
            virtual_machine.update(
                self.apiclient,
                displayname=random_gen(
                    chars=string.ascii_uppercase))
        except Exception as e:
            self.fail("Failed to update the virtual machine name: %s, %s" %
                      (virtual_machine.name, e))

        self.debug("Start the instance: %s" % virtual_machine.name)
        virtual_machine.start(self.apiclient)

        self.debug("Checking if the instance is working properly after update")
        vms = VirtualMachine.list(
            self.apiclient,
            id=virtual_machine.id,
            listall=True
        )

        self.assertEqual(
            isinstance(vms, list),
            True,
            "List vms should retuen a valid name"
        )
        vm = vms[0]
        self.assertEqual(
            vm.state,
            "Running",
            "Vm state should be running after deployment"
        )

        self.assertEqual(
            vm.instancename,
            old_internal_name,
            "Vm internal name should not be changed after update"
        )
        return
    def test_02_instancename_from_default_configuration(self):
        """ Verify for globally set instancename
        """

        # Validate the following
        # 1. Set the vm.instancename.flag to true. Hostname and displayname
        #    should be user provided display name
        # 2. Dont give the user provided user name. Internal name should be
        #    i-<userid>-<vmid>-<instance.name> in global config
        if not is_config_suitable(
                apiclient=self.apiclient,
                name='vm.instancename.flag',
                value='true'):
            self.skipTest('vm.instancename.flag should be true. skipping')

        # Removing display name from config
        del self.services["virtual_machine"]["displayname"]
        self.debug("Deploying VM in account: %s" % self.account.name)
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.debug(
            "Checking if the virtual machine is created properly or not?")
        vms = VirtualMachine.list(
            self.apiclient,
            id=virtual_machine.id,
            listall=True
        )

        self.assertEqual(
            isinstance(vms, list),
            True,
            "List vms should retuen a valid name"
        )
        vm = vms[0]
        self.assertEqual(
            vm.state,
            "Running",
            "Vm state should be running after deployment"
        )
        self.assertNotEqual(
            vm.displayname,
            vm.id,
            "Vm display name should not match the given name"
        )
        # Fetch account ID and VMID from database to check internal name
        self.debug("select id from account where uuid = '%s';"
                   % self.account.id)

        qresultset = self.dbclient.execute(
            "select id from account where uuid = '%s';"
            % self.account.id
        )
        self.assertEqual(
            isinstance(qresultset, list),
            True,
            "Check DB query result set for valid data"
        )

        self.assertNotEqual(
            len(qresultset),
            0,
            "Check DB Query result set"
        )
        qresult = qresultset[0]
        account_id = qresult[0]

        self.debug("select id from vm_instance where uuid = '%s';" % vm.id)

        qresultset = self.dbclient.execute(
            "select id from vm_instance where uuid = '%s';" %
            vm.id)

        self.assertEqual(
            isinstance(qresultset, list),
            True,
            "Check DB query result set for valid data"
        )

        self.assertNotEqual(
            len(qresultset),
            0,
            "Check DB Query result set"
        )
        qresult = qresultset[0]
        self.debug("Query result: %s" % qresult)
        vmid = qresult[0]

        self.debug("Fetching the global config value for instance.name")
        configs = Configurations.list(
            self.apiclient,
            name="instance.name",
            listall=True
        )

        config = configs[0]
        instance_name = config.value
        self.debug("Instance.name: %s" % instance_name)

        # internal Name = i-<user ID>-<VM ID>- Instance_name
        internal_name = "i-" + \
            str(account_id) + "-" + str(vmid) + "-" + instance_name
        self.assertEqual(
            vm.instancename,
            internal_name,
            "VM internal name should match with that of the format"
        )
        return