def setUpClass(cls):
        cls.testClient = super(TestHostHighAvailability, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())

        cls.template = get_template(
            cls.api_client,
            cls.zone.id,
            cls.services["ostype"]
        )
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering_with_ha = ServiceOffering.create(
            cls.api_client,
            cls.services["service_offering_with_ha"],
            offerha=True
        )

        cls.service_offering_without_ha = ServiceOffering.create(
            cls.api_client,
            cls.services["service_offering_without_ha"],
            offerha=False
        )

        cls._cleanup = [
            cls.service_offering_with_ha,
            cls.service_offering_without_ha,
        ]
        return
    def setUpClass(cls):
        cls.testClient = super(TestUpdateResourceCount, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        cls.template = get_template(
            cls.api_client,
            cls.zone.id,
            cls.services["ostype"]
        )
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering_custom = ServiceOffering.create(
            cls.api_client,
            cls.services["service_offering_custom"]
        )
        cls.service_offering_normal = ServiceOffering.create(
            cls.api_client,
            cls.services["service_offering_normal"]
        )
        cls._cleanup = [cls.service_offering_custom, cls.service_offering_normal]
        return
    def setUpClass(cls):
        cls.testClient = super(TestMultipleChildDomains, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()
        cls.testdata = cls.testClient.getParsedTestDataConfig()

        #cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.testdata["mode"] = cls.zone.networktype

        cls.template = get_template(
            cls.api_client,
            cls.zone.id,
            cls.testdata["ostype"]
        )

        # Create service, disk offerings  etc
        cls.service_offering = ServiceOffering.create(
            cls.api_client,
            cls.testdata["service_offering_multiple_cores"]
        )
        cls.testdata["virtual_machine"]["zoneid"] = cls.zone.id

        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.testdata["service_offering_multiple_cores"]
                                            )
        cls._cleanup = []
        return
    def setUpClass(cls):
        testClient = super(TestScaleVm, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        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)
        zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = zone.networktype

        template = get_template(
            cls.apiclient,
            zone.id,
            cls.services["ostype"]
        )
        if template == FAILED:
            assert False, "get_template() failed to return template\
                    with description %s" % cls.services["ostype"]

        # Set Zones and disk offerings ??
        cls.services["small"]["zoneid"] = zone.id
        cls.services["small"]["template"] = template.id

        # Create account, service offerings, vm.
        cls.account = Account.create(
            cls.apiclient,
            cls.services["account"],
            domainid=domain.id
        )

        cls.small_offering = ServiceOffering.create(
            cls.apiclient,
            cls.services["service_offerings"]["small"]
        )

        cls.big_offering = ServiceOffering.create(
            cls.apiclient,
            cls.services["service_offerings"]["big"]
        )

        # 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"]
        )
        cls._cleanup = [
            cls.small_offering,
            cls.account
        ]
    def test_02_failure_to_create_service_offering_with_customized_iops(self):
        try:
            ServiceOffering.create(
                self.apiClient,
                self.testdata[TestData.systemOfferingFailure]
            )
        except:
            return

        self.assert_(False, "The service offering was created, but should not have been.")
 def setUpClass(cls):
     try:
         cls._cleanup = []
         cls.testClient = super(TestChangeServiceOfferingForVmWithSnapshots, cls).getClsTestClient()
         cls.api_client = cls.testClient.getApiClient()
         cls.services = cls.testClient.getParsedTestDataConfig()
         cls.hypervisor = cls.testClient.getHypervisorInfo()
         cls.unsupportedHypervisor = False
         if cls.hypervisor.lower() in (KVM.lower(), "hyperv", "lxc"):
             cls.unsupportedHypervisor = True
             return
         
         cls.domain = get_domain(cls.api_client)
         cls.zone = get_zone(
             cls.api_client,
             cls.testClient.getZoneForTests()
         )
         cls.services["small"]["zoneid"] = cls.zone.id
         cls.template = get_template(
             cls.api_client,
             cls.zone.id,
             cls.services["ostype"]
         )
         if cls.template == FAILED:
             assert False, "get_template() failed to return template\
                 with description %s" % cls.services["ostype"]
         
         test_offerings = Utils().added_service_offerings
         for offering in test_offerings:
             cls.services["service_offerings"][offering] = test_offerings[offering]
             
         # Create 2 different service offerings
         cls.service_offering_1 = ServiceOffering.create(
             cls.api_client,
             cls.services["service_offerings"]["testOffering1"]
         )
         cls._cleanup.append(cls.service_offering_1)
         
         cls.service_offering_2 = ServiceOffering.create(
             cls.api_client,
             cls.services["service_offerings"]["testOffering2"]
         )
         cls._cleanup.append(cls.service_offering_2)
         
         cls.account = Account.create(
             cls.api_client,
             cls.services["account"],
             domainid=cls.domain.id
         )
         cls._cleanup.append(cls.account)
         
     except Exception as e:
         cls.tearDownClass()
         raise Exception("Warning: Exception in setup : %s" % e)
     return
    def setUpClass(cls):
        cls.testClient = super(TestCreateSnapshot, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        if cls.hypervisor.lower() in ['hyperv', 'lxc']:
            raise unittest.SkipTest("Snapshots feature is not supported on %s" % cls.hypervisor.lower())
        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())

        cls.template = get_template(
                            cls.api_client,
                            cls.zone.id,
                            cls.services["ostype"]
                            )

        cls.services["virtual_machine"]["zoneid"] = cls.zone.id

        # Create VMs, NAT Rules etc
        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering"]
                                            )
        cls._cleanup = [
                        cls.service_offering,
                        ]
        return
    def setUpClass(cls):
        cls.testClient = super(TestRedundantRouterNetworkCleanups, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.template = get_template(
                            cls.api_client,
                            cls.zone.id,
                            cls.services["ostype"]
                            )
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering"]
                                            )
        cls.network_offering = NetworkOffering.create(
                                            cls.api_client,
                                            cls.services["network_offering"],
                                            conservemode=True
                                            )
        # Enable Network offering
        cls.network_offering.update(cls.api_client, state='Enabled')

        cls._cleanup = [
                        cls.service_offering,
                        cls.network_offering,
                        ]
        return
    def setUpClass(cls):
        cls.testClient = super(TestMemoryLimits, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())

        cls.services["mode"] = cls.zone.networktype

        cls.template = get_template(
                            cls.api_client,
                            cls.zone.id,
                            cls.services["ostype"]
                            )

        cls.services["virtual_machine"]["zoneid"] = cls.zone.id

        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering"]
                                            )

        cls._cleanup = [cls.service_offering, ]
        return
    def setUpClass(cls):
        cloudstackTestClient = super(TestSecondaryStorageLimits, cls).getClsTestClient()
        cls.api_client = cloudstackTestClient.getApiClient()
        cls.hypervisor = cloudstackTestClient.getHypervisorInfo()
        # Fill services from the external config file
        cls.services = cloudstackTestClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cloudstackTestClient.getZoneForTests())
        cls.services["mode"] = cls.zone.networktype
        cls.hypervisor = cloudstackTestClient.getHypervisorInfo()

        cls.template = get_template(cls.api_client, cls.zone.id, cls.services["ostype"])

        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id
        cls.services["volume"]["zoneid"] = cls.zone.id
        cls._cleanup = []
        try:
            cls.service_offering = ServiceOffering.create(cls.api_client, cls.services["service_offering"])
            if cls.service_offering == FAILED:
                raise Exception("Creating service offering failed")
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest("Exception in setup class: %s" % e)
        return
Exemple #11
0
    def setUpClass(cls):
        testClient = super(TestCreateVolume, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services["mode"] = cls.zone.networktype
        cls.disk_offering = DiskOffering.create(cls.apiclient, cls.services["disk_offering"])
        cls.sparse_disk_offering = DiskOffering.create(cls.apiclient, cls.services["sparse_disk_offering"])
        cls.custom_disk_offering = DiskOffering.create(cls.apiclient, cls.services["disk_offering"], custom=True)
        template = get_template(cls.apiclient, cls.zone.id, cls.services["ostype"])
        if template == FAILED:
            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]

        cls.services["domainid"] = cls.domain.id
        cls.services["zoneid"] = cls.zone.id
        cls.services["template"] = template.id
        cls.services["customdiskofferingid"] = cls.custom_disk_offering.id
        cls.services["diskname"] = cls.services["volume"]["diskname"]
        # Create VMs, NAT Rules etc
        cls.account = Account.create(cls.apiclient, cls.services["account"], domainid=cls.domain.id)
        cls.service_offering = ServiceOffering.create(cls.apiclient, cls.services["service_offerings"])
        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient,
            cls.services,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            mode=cls.services["mode"],
        )
        cls._cleanup = [cls.service_offering, cls.disk_offering, cls.custom_disk_offering, cls.account]
    def setUp(self):
        self.testdata = TestData().testdata
        self.apiclient = self.testClient.getApiClient()
        self.hypervisor = self.testClient.getHypervisorInfo()

        # Get Zone, Domain and Default Built-in template
        self.domain = get_domain(self.apiclient)
        self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
        self.testdata["mode"] = self.zone.networktype
        self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"])
        if self.template == FAILED:
            assert False, "get_template() failed to return template "
#       for testing with specific template
#        self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"], templatetype='USER', services = {"template":'31f52a4d-5681-43f7-8651-ad4aaf823618'})
        

        #create a user account
        self.account = Account.create(
            self.apiclient,
            self.testdata["account"],
            domainid=self.domain.id
        )
        #create a service offering
        self.service_offering = ServiceOffering.create(
            self.apiclient,
            self.testdata["service_offering"]["small"]
        )
        #build cleanup list
        self.cleanup = [
            self.service_offering,
            self.account
        ]
    def setUpClass(cls):
        # We want to fail quicker if it's failure
        socket.setdefaulttimeout(60)

        cls.testClient = super(TestVPCRedundancy, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.template = get_template(
            cls.api_client,
            cls.zone.id,
            cls.services["ostype"])
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
            cls.api_client,
            cls.services["service_offering"])
        cls._cleanup = [cls.service_offering]

        cls.logger = logging.getLogger('TestVPCRedundancy')
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        return
    def setUpClass(cls):
        cls.testClient = super(TestCreateTemplate, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id

        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering"]
                                            )
        cls.account = Account.create(
                            cls.api_client,
                            cls.services["account"],
                            domainid=cls.domain.id
                            )
        cls.services["account"] = cls.account.name

        cls._cleanup = [
                        cls.account,
                        cls.service_offering
                        ]
        return
    def setUpClass(cls):
        cls.testClient = super(TestCreateTemplate, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        cls._cleanup = []
        cls.unsupportedHypervisor = False
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        if cls.hypervisor.lower() in ['lxc']:
            cls.unsupportedHypervisor = True
            return
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id

        cls.service_offering = ServiceOffering.create(
            cls.api_client,
            cls.services["service_offering"]
        )
        cls._cleanup.append(cls.service_offering)
        cls.account = Account.create(
            cls.api_client,
            cls.services["account"],
            domainid=cls.domain.id
        )
        cls._cleanup.append(cls.account)
        cls.services["account"] = cls.account.name
        return
Exemple #16
0
    def setUpClass(cls):
        cls.testClient = super(TestCreateTemplate, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        if cls.hypervisor.lower() in ['lxc']:
            raise unittest.SkipTest("Template creation from root volume is not supported in LXC")
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id

        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering"]
                                            )
        cls.account = Account.create(
                            cls.api_client,
                            cls.services["account"],
                            domainid=cls.domain.id
                            )
        cls.services["account"] = cls.account.name

        cls._cleanup = [
                        cls.account,
                        cls.service_offering
                        ]
        return
    def setUpClass(cls):
        cloudstackTestClient = super(TestVolumeLimits,
                               cls).getClsTestClient()
        cls.api_client = cloudstackTestClient.getApiClient()
        cls.hypervisor = cloudstackTestClient.getHypervisorInfo()
        # Fill services from the external config file
        cls.services = cloudstackTestClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cloudstackTestClient.getZoneForTests())
        cls.services["mode"] = cls.zone.networktype
        cls._cleanup = []
        cls.unsupportedStorageType = False
        if cls.hypervisor.lower() == 'lxc':
            if not find_storage_pool_type(cls.api_client, storagetype='rbd'):
                cls.unsupportedStorageType = True
                return

        cls.template = get_template(
                            cls.api_client,
                            cls.zone.id,
                            cls.services["ostype"]
                            )

        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id
        cls.services["volume"]["zoneid"] = cls.zone.id

        try:
            cls.service_offering = ServiceOffering.create(cls.api_client, cls.services["service_offering"])
            cls._cleanup.append(cls.service_offering)
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest("Exception in setUpClass: %s" % e)
        return
    def setUpClass(cls):

        cls.testClient = super(TestAffinityRules, cls).getClsTestClient()
        if cls.testClient.getHypervisorInfo().lower() != "vmware":
            raise unittest.SkipTest("VMWare tests only valid on VMWare hypervisor")
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.template = get_template(
                                    cls.api_client,
                                    cls.zone.id,
                                    cls.services["ostype"]
                            )

        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering"],
                                            offerha=True
                                            )

        cls.account = Account.create(
                                     cls.api_client,
                                     cls.services["account"],
                                     domainid=cls.domain.id
                                     )
        cls._cleanup = [cls.account]
        return
    def setUpClass(cls):
        cls.testClient = super(TestMaxProjectNetworks, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.domain = get_domain(cls.api_client)
        cls.services['mode'] = cls.zone.networktype
        cls.template = get_template(
                            cls.api_client,
                            cls.zone.id,
                            cls.services["ostype"]
                            )
        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering"]
                                            )
        cls.network_offering = NetworkOffering.create(
                                            cls.api_client,
                                            cls.services["network_offering"],
                                            conservemode=True
                                            )
        # Enable Network offering
        cls.network_offering.update(cls.api_client, state='Enabled')

        cls._cleanup = [
                        cls.service_offering,
                        cls.network_offering
                        ]
        return
    def setUpClass(cls):
        testClient = super(TestDeployVmWithUserData, cls).getClsTestClient()
        cls.apiClient = testClient.getApiClient() 
        cls.services = testClient.getParsedTestDataConfig()

        cls.zone = get_zone(cls.apiClient, testClient.getZoneForTests())
        if cls.zone.localstorageenabled:
            #For devcloud since localstroage is enabled
            cls.services["service_offerings"]["storagetype"] = "local"
        cls.service_offering = ServiceOffering.create(
            cls.apiClient,
            cls.services["service_offerings"]
        )
        cls.account = Account.create(cls.apiClient, services=cls.services["account"])
        cls.cleanup = [cls.account]
        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.debug("Successfully created account: %s, id: \
                   %s" % (cls.account.name,\
                          cls.account.id))


        # Generate userdata of 2500 bytes. This is larger than the 2048 bytes limit.
        # CS however allows for upto 4K bytes in the code. So this must succeed.
        # Overall, the query length must not exceed 4K, for then the json decoder
        # will fail this operation at the marvin client side itcls.
        user_data = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(2500))
        cls.services["virtual_machine"]["userdata"] = user_data
    def setUp(self):
        self.testdata = TestData().testdata
        self.apiclient = self.testClient.getApiClient()

        # Get Zone, Domain and Default Built-in template
        self.domain = get_domain(self.apiclient)
        self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
        self.testdata["mode"] = self.zone.networktype
        self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"])

        #create a user account
        self.account = Account.create(
            self.apiclient,
            self.testdata["account"],
            domainid=self.domain.id
        )
        #create a service offering
        self.service_offering = ServiceOffering.create(
            self.apiclient,
            self.testdata["service_offering"]["small"]
        )
        #build cleanup list
        self.cleanup = [
            self.service_offering,
            self.account
        ]
    def setUpClass(cls):
        testClient = super(TestSameVMName, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.testdata = testClient.getParsedTestDataConfig()

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())

        cls.template = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.testdata["ostype"])

        cls._cleanup = []

        cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__
        try:
            cls.skiptest = False

            if cls.hypervisor.lower() not in ['vmware']:
                cls.skiptest = True

            # Create an account
            cls.account_1 = Account.create(
                cls.apiclient,
                cls.testdata["account"],
                domainid=cls.domain.id
            )
            cls.account_2 = Account.create(
                cls.apiclient,
                cls.testdata["account"],
                domainid=cls.domain.id
            )

            # Create user api client of the account
            cls.userapiclient_1 = testClient.getUserApiClient(
                UserName=cls.account_1.name,
                DomainName=cls.account_1.domain
            )

            cls.userapiclient_2 = testClient.getUserApiClient(
                UserName=cls.account_2.name,
                DomainName=cls.account_2.domain
            )
           # Create Service offering
            cls.service_offering = ServiceOffering.create(
                cls.apiclient,
                cls.testdata["service_offering"],
            )

            cls._cleanup = [
                cls.account_1,
                cls.account_2,
                cls.service_offering,
            ]
        except Exception as e:
            cls.tearDownClass()
            raise e
        return
Exemple #23
0
    def setUpClass(cls):
        cls.testClient = super(TestVPC, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__
        cls.unsupportedHypervisor = False
        if cls.hypervisor.lower() == 'hyperv':
            cls._cleanup = []
            cls.unsupportedHypervisor = True
            return
        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.template = get_template(
            cls.api_client,
            cls.zone.id,
            cls.services["ostype"]
        )
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
            cls.api_client,
            cls.services["service_offering"]
        )
        cls.vpc_off = VpcOffering.create(
            cls.api_client,
            cls.services["vpc_offering"]
        )
        cls.vpc_off.update(cls.api_client, state='Enabled')
        cls._cleanup = [
            cls.service_offering,
        ]
        return
    def setUpClass(cls):

        cls.testClient = super(TestHighAvailability, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.pod = get_pod(
            cls.api_client,
            zone_id=cls.zone.id
        )
        cls.template = get_template(
            cls.api_client,
            cls.zone.id,
            cls.services["ostype"]
        )
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        if cls.hypervisor.lower() in ['lxc']:
            raise unittest.SkipTest("Template creation from root volume is not supported in LXC")
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
            cls.api_client,
            cls.services["service_offering"],
            offerha=True
        )
        cls._cleanup = [
            cls.service_offering,
        ]
        return
    def setUpClass(cls):
        # We want to fail quicker if it's failure
        socket.setdefaulttimeout(60)

        cls.testClient = super(TestVPCNetworkPFRules, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.template = get_template(
                                    cls.api_client,
                                    cls.zone.id,
                                    cls.services["ostype"]
                                    )
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
                                                        cls.api_client,
                                                        cls.services["service_offering"]
                                                        )
        cls._cleanup = [cls.service_offering]
        return
    def setUpClass(cls):
        cloudstackTestClient = super(TestProjectsVolumeLimits,
                               cls).getClsTestClient()
        cls.api_client = cloudstackTestClient.getApiClient()
        # Fill services from the external config file
        cls.services = cloudstackTestClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cloudstackTestClient.getZoneForTests())
        cls.services["mode"] = cls.zone.networktype

        cls.template = get_template(
                            cls.api_client,
                            cls.zone.id,
                            cls.services["ostype"]
                            )

        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["volume"]["zoneid"] = cls.zone.id
        cls._cleanup = []
        try:
            cls.service_offering = ServiceOffering.create(cls.api_client, cls.services["service_offering"])
            cls._cleanup.append(cls.service_offering)
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest("Exception in setUpClass: %s" % e)
        return
    def setUpClass(cls):

        cls.testClient = super(TestAffinityRules, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.template = get_template(
                                    cls.api_client,
                                    cls.zone.id,
                                    cls.services["ostype"]
                            )

        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering"],
                                            offerha=True
                                            )

        cls.account = Account.create(
                                     cls.api_client,
                                     cls.services["account"],
                                     domainid=cls.domain.id
                                     )
        cls._cleanup = [cls.account]
        return
    def test_03_deploy_vm_project_limit_reached(self):
        """Test TTry to deploy VM with admin account where account has not used
        the resources but @ project they are not available"""

        # Validate the following
        # 1. Try to deploy VM with admin account where account has not used the
        #    resources but @ project they are not available
        # 2. Deploy VM should error out saying  ResourceAllocationException
        #    with "resource limit exceeds"

        self.debug("Creating service offering with 3 CPU cores")

        so = self.testdata["service_offering"]
        so["cpunumber"] = 3
        self.service_offering = ServiceOffering.create(
            self.apiclient,
            so
        )
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts(account_limit=4, domain_limit=4, project_limit=2)

        api_client_admin = self.testClient.getUserApiClient(
            UserName=self.child_do_admin.name,
            DomainName=self.child_do_admin.domain)

        self.debug("Deploying instance in account 2 when CPU limit is reached")

        with self.assertRaises(Exception):
            self.createInstance(project=self.project,
                service_off=self.service_offering, api_client=api_client_admin)
        return
    def setUpClass(cls):
        testClient = super(TestConcurrentSnapshotLimit, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.testdata = testClient.getParsedTestDataConfig()
        cls.hypervisor = cls.testClient.getHypervisorInfo()

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())

        cls.template = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.testdata["ostype"])

        cls._cleanup = []
        cls.supportedHypervisor = True

        if cls.hypervisor.lower() in [
                "hyperv",
                "lxc"]:
            cls.supportedHypervisor = False
            return

        # Create Service offering
        cls.service_offering = ServiceOffering.create(
            cls.apiclient,
            cls.testdata["service_offering"],
        )
        cls._cleanup.append(cls.service_offering)
        return
    def setUp(self):
        self.apiclient = self.testClient.getApiClient()

        self.testdata = self.testClient.getParsedTestDataConfig()
        # Get Zone, Domain and Default Built-in template
        self.domain = get_domain(self.apiclient)
        self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
        self.testdata["mode"] = self.zone.networktype
        self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"])

        if self.template == FAILED:
            self.fail("get_template() failed to return template with description %s" % self.testdata["ostype"])

        #create a user account
        self.account = Account.create(
            self.apiclient,
            self.testdata["account"],
            domainid=self.domain.id
        )
        #create a service offering
        self.service_offering = ServiceOffering.create(
            self.apiclient,
            self.testdata["service_offerings"]["small"]
        )
        #build cleanup list
        self.cleanup = [
            self.service_offering,
            self.account
        ]
Exemple #31
0
    def test_04_resource_count_vm_with_dynamic_offering_in_running_state(self):
        """Create VM with dynamic service offering. Take resources of vm in running state into calculation of resource count.

            Steps:
            # 1. update resource.count.running.vms.only to true
            # 2. create dynamic service offering
            # 3. deploy vm, resource count of cpu/ram increases
            # 4. stop vm, resource count of cpu/ram decreases
            # 5. start vm, resource count of cpu/ram increases
            # 6. reboot vm, resource count of cpu/ram is not changed
            # 7. destroy vm, resource count of cpu/ram decreases
            # 8. recover vm, resource count of cpu/ram is not changed
            # 9. update vm with displayvm=false, resource count of cpu/ram is not changed
            # 10. destroy vm with expunge = true, resource count of cpu/ram is not changed
        """
        Configurations.update(self.apiclient,
                              name="resource.count.running.vms.only",
                              value="true")

        # Create dynamic service offering
        self.services["service_offering"]["cpunumber"] = ""
        self.services["service_offering"]["cpuspeed"] = ""
        self.services["service_offering"]["memory"] = ""

        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offering"])
        self.cleanup.append(self.service_offering)

        # deploy vm
        try:
            virtual_machine_4 = VirtualMachine.create(
                self.apiclient,
                self.services["virtual_machine"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                customcpunumber=1,
                customcpuspeed=100,
                custommemory=256,
                templateid=self.template.id,
                zoneid=self.zone.id,
                mode=self.zone.networktype)
        except Exception as e:
            self.fail("Exception while deploying virtual machine: %s" % e)

        self.expectedCpu = self.expectedCpu + virtual_machine_4.cpunumber
        self.expectedMemory = self.expectedMemory + virtual_machine_4.memory
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # stop vm
        virtual_machine_4.stop(self.apiclient)
        self.expectedCpu = self.expectedCpu - virtual_machine_4.cpunumber
        self.expectedMemory = self.expectedMemory - virtual_machine_4.memory
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # start vm
        virtual_machine_4.start(self.apiclient)
        self.expectedCpu = self.expectedCpu + virtual_machine_4.cpunumber
        self.expectedMemory = self.expectedMemory + virtual_machine_4.memory
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # reboot vm
        virtual_machine_4.reboot(self.apiclient)
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # destroy vm
        virtual_machine_4.delete(self.apiclient, expunge=False)
        self.expectedCpu = self.expectedCpu - virtual_machine_4.cpunumber
        self.expectedMemory = self.expectedMemory - virtual_machine_4.memory
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # recover vm
        virtual_machine_4.recover(self.apiclient)
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # update vm with displayvm=false
        virtual_machine_4.update(self.apiclient, displayvm=False)
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # expunge vm
        virtual_machine_4.delete(self.apiclient, expunge=True)
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)
Exemple #32
0
    def setUpClass(cls):
        cls.testClient = super(TestKubernetesCluster, cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.services = cls.testClient.getParsedTestDataConfig()
        cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__
        cls.cks_template_name_key = "cloud.kubernetes.cluster.template.name." + cls.hypervisor.lower()

        cls.hypervisorNotSupported = False
        if cls.hypervisor.lower() not in ["kvm", "vmware", "xenserver"]:
            cls.hypervisorNotSupported = True
        cls.setup_failed = False
        cls._cleanup = []
        cls.kubernetes_version_ids = []

        if cls.hypervisorNotSupported == False:
            cls.initial_configuration_cks_enabled = Configurations.list(cls.apiclient,
                                                                        name="cloud.kubernetes.service.enabled")[0].value
            if cls.initial_configuration_cks_enabled not in ["true", True]:
                cls.debug("Enabling CloudStack Kubernetes Service plugin and restarting management server")
                Configurations.update(cls.apiclient,
                                      "cloud.kubernetes.service.enabled",
                                      "true")
                cls.restartServer()
            cls.updateVmwareSettings(False)
            cls.cks_template = None
            cls.initial_configuration_cks_template_name = None
            cls.cks_service_offering = None

            if cls.setup_failed == False:
                try:
                    cls.kubernetes_version_1 = cls.addKubernetesSupportedVersion(cls.services["cks_kubernetes_versions"]["1.14.9"])
                    cls.kubernetes_version_ids.append(cls.kubernetes_version_1.id)
                except Exception as e:
                    cls.setup_failed = True
                    cls.debug("Failed to get Kubernetes version ISO in ready state, version=%s, url=%s, %s" %
                        (cls.services["cks_kubernetes_versions"]["1.14.9"]["semanticversion"], cls.services["cks_kubernetes_versions"]["1.14.9"]["url"], e))
            if cls.setup_failed == False:
                try:
                    cls.kubernetes_version_2 = cls.addKubernetesSupportedVersion(cls.services["cks_kubernetes_versions"]["1.15.0"])
                    cls.kubernetes_version_ids.append(cls.kubernetes_version_2.id)
                except Exception as e:
                    cls.setup_failed = True
                    cls.debug("Failed to get Kubernetes version ISO in ready state, version=%s, url=%s, %s" %
                        (cls.services["cks_kubernetes_versions"]["1.15.0"]["semanticversion"], cls.services["cks_kubernetes_versions"]["1.15.0"]["url"], e))
            if cls.setup_failed == False:
                try:
                    cls.kubernetes_version_3 = cls.addKubernetesSupportedVersion(cls.services["cks_kubernetes_versions"]["1.16.0"])
                    cls.kubernetes_version_ids.append(cls.kubernetes_version_3.id)
                except Exception as e:
                    cls.setup_failed = True
                    cls.debug("Failed to get Kubernetes version ISO in ready state, version=%s, url=%s, %s" %
                        (cls.services["cks_kubernetes_versions"]["1.16.0"]["semanticversion"], cls.services["cks_kubernetes_versions"]["1.16.0"]["url"], e))
            if cls.setup_failed == False:
                try:
                    cls.kubernetes_version_4 = cls.addKubernetesSupportedVersion(cls.services["cks_kubernetes_versions"]["1.16.3"])
                    cls.kubernetes_version_ids.append(cls.kubernetes_version_4.id)
                except Exception as e:
                    cls.setup_failed = True
                    cls.debug("Failed to get Kubernetes version ISO in ready state, version=%s, url=%s, %s" %
                        (cls.services["cks_kubernetes_versions"]["1.16.3"]["semanticversion"], cls.services["cks_kubernetes_versions"]["1.16.3"]["url"], e))

            if cls.setup_failed == False:
                cls.cks_template, existAlready = cls.getKubernetesTemplate()
                if cls.cks_template == FAILED:
                    assert False, "getKubernetesTemplate() failed to return template for hypervisor %s" % cls.hypervisor
                    cls.setup_failed = True
                else:
                    if not existAlready:
                        cls._cleanup.append(cls.cks_template)

            if cls.setup_failed == False:
                cls.initial_configuration_cks_template_name = Configurations.list(cls.apiclient,
                                                                                  name=cls.cks_template_name_key)[0].value
                Configurations.update(cls.apiclient,
                                      cls.cks_template_name_key,
                                      cls.cks_template.name)

                cks_offering_data = cls.services["cks_service_offering"]
                cks_offering_data["name"] = 'CKS-Instance-' + random_gen()
                cls.cks_service_offering = ServiceOffering.create(
                                                                  cls.apiclient,
                                                                  cks_offering_data
                                                                 )
                cls._cleanup.append(cls.cks_service_offering)
                cls.domain = get_domain(cls.apiclient)
                cls.account = Account.create(
                    cls.apiclient,
                    cls.services["account"],
                    domainid=cls.domain.id
                )
                cls._cleanup.append(cls.account)
        return
    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"]
        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")

        # 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"])
Exemple #34
0
    def setUpCloudStack(cls):
        super(TestMigrationFromUuidToGlobalId, cls).setUpClass()

        cls._cleanup = []

        cls.helper = HelperUtil(cls)
        cls.helper.build_commit(cls.ARGS.uuid, cls.ARGS)
        cfg.logger.info("Starting CloudStack")
        cls.mvn_proc = subprocess.Popen(
            ['mvn', '-pl', ':cloud-client-ui', 'jetty:run'],
            cwd=cls.ARGS.forked,
            preexec_fn=os.setsid,
            stdout=cfg.misc,
            stderr=subprocess.STDOUT,
        )
        cls.mvn_proc_grp = os.getpgid(cls.mvn_proc.pid)
        cfg.logger.info("Started CloudStack in process group %d",
                        cls.mvn_proc_grp)
        cfg.logger.info("Waiting for a while to give it a chance to start")
        proc = subprocess.Popen(["tail", "-f", cfg.misc_name],
                                shell=False,
                                bufsize=0,
                                stdout=subprocess.PIPE)
        while True:
            line = proc.stdout.readline()
            if not line:
                cfg.logger.info("tail ended, was this expected?")
                cfg.logger.info("Stopping CloudStack")
                os.killpg(cls.mvn_proc_grp, signal.SIGTERM)
                break
            if "[INFO] Started Jetty Server" in line:
                cfg.logger.info("got it!")
                break
        proc.terminate()
        proc.wait()
        time.sleep(15)
        cfg.logger.info("Processing with the setup")

        cls.obj_marvininit = cls.helper.marvin_init(cls.ARGS.cfg)
        cls.testClient = cls.obj_marvininit.getTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        dbclient = cls.testClient.getDbConnection()
        v = dbclient.execute(
            "select * from configuration where name='sp.migration.to.global.ids.completed'"
        )
        cfg.logger.info("Configuration setting for update of db is %s", v)
        if len(v) > 0:
            update = dbclient.execute(
                "update configuration set value='false' where name='sp.migration.to.global.ids.completed'"
            )
            cfg.logger.info("DB configuration table was updated %s", update)

        cls.spapi = spapi.Api.fromConfig(multiCluster=True)

        td = TestData()
        cls.testdata = td.testdata

        cls.services = cls.testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.cluster = list_clusters(cls.apiclient)[0]
        cls.hypervisor = get_hypervisor_type(cls.apiclient)

        #The version of CentOS has to be supported
        cls.template = get_template(cls.apiclient,
                                    cls.zone.id,
                                    account="system")

        if cls.template == FAILED:
            assert False, "get_template() failed to return template\
                    with description %s" % cls.services["ostype"]

        cls.services["domainid"] = cls.domain.id
        cls.services["small"]["zoneid"] = cls.zone.id
        cls.services["templates"]["ostypeid"] = cls.template.ostypeid
        cls.services["zoneid"] = cls.zone.id
        primarystorage = cls.testdata[TestData.primaryStorage]

        serviceOffering = cls.testdata[TestData.serviceOffering]
        storage_pool = list_storage_pools(cls.apiclient,
                                          name=primarystorage.get("name"))
        cls.primary_storage = storage_pool[0]

        disk_offering = list_disk_offering(cls.apiclient, name="Small")

        assert disk_offering is not None

        service_offering = list_service_offering(cls.apiclient, name="ssd")
        if service_offering is not None:
            cls.service_offering = service_offering[0]
        else:
            cls.service_offering = ServiceOffering.create(
                cls.apiclient, serviceOffering)
        assert cls.service_offering is not None

        cls.disk_offering = disk_offering[0]

        account = list_accounts(cls.apiclient, name="admin")
        cls.account = account[0]

        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=cls.zone.id,
            templateid=cls.template.id,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            rootdisksize=10)
        cls._cleanup.append(cls.virtual_machine)

        cls.virtual_machine2 = VirtualMachine.create(
            cls.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=cls.zone.id,
            templateid=cls.template.id,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            rootdisksize=10)
        cls._cleanup.append(cls.virtual_machine2)

        cls.virtual_machine3 = VirtualMachine.create(
            cls.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=cls.zone.id,
            templateid=cls.template.id,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            rootdisksize=10)
        cls._cleanup.append(cls.virtual_machine3)

        #check that ROOT disk is created with uuid
        root_volume = list_volumes(cls.apiclient,
                                   virtualmachineid=cls.virtual_machine3.id,
                                   type="ROOT")
        try:
            spvolume = cls.spapi.volumeList(volumeName=root_volume[0].id)

        except spapi.ApiError as err:
            cfg.logger.info("Root volume is not created with UUID")
            raise Exception(err)

        cls.volume = Volume.create(cls.apiclient,
                                   cls.testdata[TestData.volume_1],
                                   account=cls.account.name,
                                   domainid=cls.domain.id,
                                   zoneid=cls.zone.id,
                                   diskofferingid=cls.disk_offering.id)
        cls._cleanup.append(cls.volume)

        cls.random_data_vm_snapshot1 = random_gen(size=100)
        cls.test_dir = "/tmp"
        cls.random_data = "random.data"

        volume_attached = cls.virtual_machine.attach_volume(
            cls.apiclient, cls.volume)

        cls.helper.write_on_disks(cls.random_data_vm_snapshot1,
                                  cls.virtual_machine, cls.test_dir,
                                  cls.random_data)

        MemorySnapshot = False
        cls.vm_snapshot1 = cls.helper.create_vm_snapshot(
            MemorySnapshot, cls.virtual_machine)
        cls.helper.delete_random_data_after_vmsnpashot(cls.vm_snapshot1,
                                                       cls.virtual_machine,
                                                       cls.test_dir,
                                                       cls.random_data)

        cls.random_data_vm_snapshot2 = random_gen(size=100)
        cls.helper.write_on_disks(cls.random_data_vm_snapshot2,
                                  cls.virtual_machine, cls.test_dir,
                                  cls.random_data)

        cls.vm_snapshot2 = cls.helper.create_vm_snapshot(
            MemorySnapshot, cls.virtual_machine)
        cls.helper.delete_random_data_after_vmsnpashot(cls.vm_snapshot2,
                                                       cls.virtual_machine,
                                                       cls.test_dir,
                                                       cls.random_data)

        #vm snapshot to be deleted without revert
        cls.random_data_vm_snapshot3 = random_gen(size=100)
        cls.helper.write_on_disks(cls.random_data_vm_snapshot3,
                                  cls.virtual_machine, cls.test_dir,
                                  cls.random_data)

        cls.vm_snapshot_for_delete = cls.helper.create_vm_snapshot(
            MemorySnapshot, cls.virtual_machine)
        cls.helper.delete_random_data_after_vmsnpashot(
            cls.vm_snapshot_for_delete, cls.virtual_machine, cls.test_dir,
            cls.random_data)

        cls.snapshot_on_secondary = cls.helper.create_snapshot(
            False, cls.virtual_machine2)
        cls._cleanup.append(cls.snapshot_on_secondary)

        cls.template_on_secondary = cls.helper.create_template_from_snapshot(
            cls.services, snapshotid=cls.snapshot_on_secondary.id)
        cls._cleanup.append(cls.template_on_secondary)

        cls.snapshot_bypassed = cls.helper.create_snapshot(
            True, cls.virtual_machine2)
        cls._cleanup.append(cls.snapshot_bypassed)

        cls.template_bypased = cls.helper.create_template_from_snapshot(
            cls.services, snapshotid=cls.snapshot_bypassed.id)
        cls._cleanup.append(cls.template_bypased)

        #change to latest commit with globalId implementation
        cls.helper.switch_to_globalid_commit(cls.ARGS.globalid, cls.ARGS)
        cfg.logger.info("The setup is done, proceeding with the tests")
    def setUpClass(cls):
        testClient = super(TestMultipleVolumeAttach, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        cls._cleanup = []
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        cls.hypervisor = testClient.getHypervisorInfo()
        cls.invalidStoragePoolType = False

        cls.disk_offering = DiskOffering.create(cls.apiclient,
                                                cls.services["disk_offering"])

        template = get_template(cls.apiclient, cls.zone.id,
                                cls.services["ostype"])
        if template == FAILED:
            assert False, "get_template() failed to return template with description %s" % cls.services[
                "ostype"]

        cls.services["domainid"] = cls.domain.id
        cls.services["zoneid"] = cls.zone.id
        cls.services["template"] = template.id
        cls.services["diskofferingid"] = cls.disk_offering.id

        # Create VMs, VMs etc
        cls.account = Account.create(cls.apiclient,
                                     cls.services["account"],
                                     domainid=cls.domain.id)
        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.services["service_offering"])
        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient,
            cls.services,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            mode=cls.services["mode"])

        #Create volumes (data disks)
        cls.volume1 = Volume.create(cls.apiclient,
                                    cls.services,
                                    account=cls.account.name,
                                    domainid=cls.account.domainid)

        cls.volume2 = Volume.create(cls.apiclient,
                                    cls.services,
                                    account=cls.account.name,
                                    domainid=cls.account.domainid)

        cls.volume3 = Volume.create(cls.apiclient,
                                    cls.services,
                                    account=cls.account.name,
                                    domainid=cls.account.domainid)

        cls.volume4 = Volume.create(cls.apiclient,
                                    cls.services,
                                    account=cls.account.name,
                                    domainid=cls.account.domainid)
        cls._cleanup = [cls.service_offering, cls.disk_offering, cls.account]
    def setUpClass(cls):
        cls.testClient = super(TestVMLifeCycleHostmaintenance,
                               cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.template = get_template(cls.api_client, cls.zone.id,
                                    cls.services["ostype"])
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        clusterWithSufficientHosts = None
        clusters = Cluster.list(cls.api_client, zoneid=cls.zone.id)
        for cluster in clusters:
            cls.hosts = Host.list(cls.api_client, clusterid=cluster.id)
            if len(cls.hosts) >= 2:
                clusterWithSufficientHosts = cluster

        if clusterWithSufficientHosts is None:
            raise unittest.SkipTest("No Cluster with 2 hosts found")

        Host.update(cls.api_client, id=cls.hosts[0].id, hosttags="hosttag1")
        Host.update(cls.api_client, id=cls.hosts[1].id, hosttags="hosttag2")

        cls.service_offering_1 = ServiceOffering.create(
            cls.api_client, cls.services["service_offering_1"])
        cls.service_offering_2 = ServiceOffering.create(
            cls.api_client, cls.services["service_offering_2"])
        cls.vpc_off = VpcOffering.create(cls.api_client,
                                         cls.services["vpc_offering"])
        cls.vpc_off.update(cls.api_client, state='Enabled')

        cls.account = Account.create(cls.api_client,
                                     cls.services["account"],
                                     admin=True,
                                     domainid=cls.domain.id)

        cls.vpc_off = VpcOffering.create(cls.api_client,
                                         cls.services["vpc_offering"])

        cls.vpc_off.update(cls.api_client, state='Enabled')

        cls.services["vpc"]["cidr"] = '10.1.1.1/16'
        cls.vpc = VPC.create(cls.api_client,
                             cls.services["vpc"],
                             vpcofferingid=cls.vpc_off.id,
                             zoneid=cls.zone.id,
                             account=cls.account.name,
                             domainid=cls.account.domainid)

        cls.nw_off = NetworkOffering.create(cls.api_client,
                                            cls.services["network_offering"],
                                            conservemode=False)
        # Enable Network offering
        cls.nw_off.update(cls.api_client, state='Enabled')

        # Creating network using the network offering created
        cls.network_1 = Network.create(cls.api_client,
                                       cls.services["network"],
                                       accountid=cls.account.name,
                                       domainid=cls.account.domainid,
                                       networkofferingid=cls.nw_off.id,
                                       zoneid=cls.zone.id,
                                       gateway='10.1.1.1',
                                       vpcid=cls.vpc.id)
        cls.nw_off_no_lb = NetworkOffering.create(
            cls.api_client,
            cls.services["network_offering_no_lb"],
            conservemode=False)
        # Enable Network offering
        cls.nw_off_no_lb.update(cls.api_client, state='Enabled')

        # Creating network using the network offering created
        cls.network_2 = Network.create(cls.api_client,
                                       cls.services["network"],
                                       accountid=cls.account.name,
                                       domainid=cls.account.domainid,
                                       networkofferingid=cls.nw_off_no_lb.id,
                                       zoneid=cls.zone.id,
                                       gateway='10.1.2.1',
                                       vpcid=cls.vpc.id)
        # Spawn an instance in that network
        cls.vm_1 = VirtualMachine.create(
            cls.api_client,
            cls.services["virtual_machine"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering_1.id,
            networkids=[str(cls.network_1.id)])
        # Spawn an instance in that network
        cls.vm_2 = VirtualMachine.create(
            cls.api_client,
            cls.services["virtual_machine"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering_1.id,
            networkids=[str(cls.network_1.id)])
        cls.vm_3 = VirtualMachine.create(
            cls.api_client,
            cls.services["virtual_machine"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering_2.id,
            networkids=[str(cls.network_2.id)])
        routers = Router.list(cls.api_client,
                              account=cls.account.name,
                              domainid=cls.account.domainid,
                              listall=True)
        if isinstance(routers, list):
            cls.vpcvr = routers[0]

        cls._cleanup = [
            cls.service_offering_1,
            cls.service_offering_2,
            cls.nw_off,
            cls.nw_off_no_lb,
        ]
        return
Exemple #37
0
    def setUpClass(cls):
        cls.testClient = super(TestResizeVolume, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()
        cls.hypervisor = (cls.testClient.getHypervisorInfo()).lower()
        cls.storageID = None
        # Fill services from the external config file
        cls.services = cls.testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.services["mode"] = cls.zone.networktype
        cls._cleanup = []
        cls.unsupportedStorageType = False
        cls.unsupportedHypervisorType = False
        cls.updateclone = False
        if cls.hypervisor not in ['xenserver', "kvm", "vmware"]:
            cls.unsupportedHypervisorType = True
            return
        cls.template = get_template(cls.api_client, cls.zone.id)
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id
        cls.services["volume"]["zoneid"] = cls.zone.id
        try:
            cls.parent_domain = Domain.create(cls.api_client,
                                              services=cls.services["domain"],
                                              parentdomainid=cls.domain.id)
            cls.parentd_admin = Account.create(cls.api_client,
                                               cls.services["account"],
                                               admin=True,
                                               domainid=cls.parent_domain.id)
            cls._cleanup.append(cls.parentd_admin)
            cls._cleanup.append(cls.parent_domain)
            list_pool_resp = list_storage_pools(cls.api_client,
                                                account=cls.parentd_admin.name,
                                                domainid=cls.parent_domain.id)
            res = validateList(list_pool_resp)
            if res[2] == INVALID_INPUT:
                raise Exception(
                    "Failed to  list storage pool-no storagepools found ")
            #Identify the storage pool type  and set vmware fullclone to true if storage is VMFS
            if cls.hypervisor == 'vmware':
                for strpool in list_pool_resp:
                    if strpool.type.lower() == "vmfs" or strpool.type.lower(
                    ) == "networkfilesystem":
                        list_config_storage_response = list_configurations(
                            cls.api_client,
                            name="vmware.create.full.clone",
                            storageid=strpool.id)
                        res = validateList(list_config_storage_response)
                        if res[2] == INVALID_INPUT:
                            raise Exception("Failed to  list configurations ")
                        if list_config_storage_response[0].value == "false":
                            Configurations.update(cls.api_client,
                                                  "vmware.create.full.clone",
                                                  value="true",
                                                  storageid=strpool.id)
                            cls.updateclone = True
                            StoragePool.update(cls.api_client,
                                               id=strpool.id,
                                               tags="scsi")
                            cls.storageID = strpool.id
                            cls.unsupportedStorageType = False
                            break
                    else:
                        cls.unsupportedStorageType = True
            # Creating service offering with normal config
            cls.service_offering = ServiceOffering.create(
                cls.api_client, cls.services["service_offering"])
            cls.services_offering_vmware = ServiceOffering.create(
                cls.api_client, cls.services["service_offering"], tags="scsi")
            cls._cleanup.extend(
                [cls.service_offering, cls.services_offering_vmware])

        except Exception as e:
            cls.tearDownClass()
        return
Exemple #38
0
    def test_04_deploy_multiple_vm_with_multiple_cpus(self):
        """Test Deploy multiple VM with 4 core CPU & verify the usage"""
        #keep the configuration value - max.account.cpus number = 16
        # Validate the following
        # 1. Create compute offering with 4 core CPU
        # 2. Deploy multiple VMs with this service offering
        # 3. List Resource count for the root admin CPU usage
        # 4. CPU usage should list properly

        self.debug("Creating service offering with 4 CPU cores")
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.testdata["service_offering_multiple_cores"])
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {
            self.child_domain_1: self.child_do_admin_1,
            self.child_domain_2: self.child_do_admin_2
        }
        for domain, admin in list(users.items()):
            self.account = admin
            self.domain = domain

            cpu_account_gc = Resources.list(
                self.apiclient,
                resourcetype=8,  #CPU
                account=self.account.name,
                domainid=self.domain.id)

            if cpu_account_gc[0].max != 16:
                self.skipTest(
                    "This test case requires configuration value max.account.cpus to be 16"
                )

            api_client = self.testClient.getUserApiClient(
                UserName=self.account.name, DomainName=self.account.domain)

            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)
            vm_1 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            vm_2 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            self.createInstance(service_off=self.service_offering,
                                api_client=api_client)
            self.createInstance(service_off=self.service_offering,
                                api_client=api_client)

            self.debug("Deploying instance - CPU capacity is fully utilized")
            with self.assertRaises(Exception):
                self.createInstance(service_off=self.service_offering,
                                    api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count = account_list[0].cputotal

            expected_resource_count = int(
                self.service_offering.cpunumber) * 4  #Total 4 vms

            self.assertEqual(
                resource_count, expected_resource_count,
                "Initial resource count should with the expected resource count"
            )

            self.debug("Destroying instance: %s" % vm_1.name)
            try:
                vm_1.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_delete = account_list[0].cputotal

            expected_resource_count -= int(self.service_offering.cpunumber)

            self.assertEqual(
                resource_count_after_delete, expected_resource_count,
                "Resource count should be less than before after deleting the instance"
            )

            host = findSuitableHostForMigration(self.apiclient, vm_2.id)
            if host is None:
                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
            self.debug("Migrating instance: %s to host: %s" %
                       (vm_2.name, host.name))
            try:
                vm_2.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_migrate = account_list[0].cputotal

            self.debug(resource_count_after_migrate)
            self.assertEqual(
                resource_count_after_delete, resource_count_after_migrate,
                "Resource count should be same after migrating the instance")
    def setUpClass(cls):

        cls.testClient = super(TestTemplates, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        cls._cleanup = []
        cls.unsupportedHypervisor = False
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        if cls.hypervisor.lower() in ['lxc']:
            cls.unsupportedHypervisor = True
            return
        # populate second zone id for iso copy
        cmd = listZones.listZonesCmd()
        zones = cls.api_client.listZones(cmd)
        if not isinstance(zones, list):
            raise Exception("Failed to find zones.")
        if len(zones) >= 2:
            cls.services["destzoneid"] = zones[1].id

        template = get_template(cls.api_client, cls.zone.id,
                                cls.services["ostype"])
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        try:
            cls.account = Account.create(cls.api_client,
                                         cls.services["account"],
                                         domainid=cls.domain.id)
            cls._cleanup.append(cls.account)

            cls.services["account"] = cls.account.name
            cls.service_offering = ServiceOffering.create(
                cls.api_client, cls.services["service_offering"])
            cls._cleanup.append(cls.service_offering)

            # create virtual machine
            cls.virtual_machine = VirtualMachine.create(
                cls.api_client,
                cls.services["virtual_machine"],
                templateid=template.id,
                accountid=cls.account.name,
                domainid=cls.account.domainid,
                serviceofferingid=cls.service_offering.id,
            )
            # Stop virtual machine
            cls.virtual_machine.stop(cls.api_client)

            timeout = cls.services["timeout"]

            while True:
                list_volume = Volume.list(
                    cls.api_client,
                    virtualmachineid=cls.virtual_machine.id,
                    type='ROOT',
                    listall=True)
                if isinstance(list_volume, list):
                    break
                elif timeout == 0:
                    raise Exception("List volumes failed.")

                time.sleep(5)
                timeout = timeout - 1

            cls.volume = list_volume[0]

            # Create template from volume
            cls.template = Template.create(cls.api_client,
                                           cls.services["template"],
                                           cls.volume.id)
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest("Failure in setUpClass: %s" % e)
    def setUpClass(cls):
        testClient = super(TestAdvancedZoneStoppedVM, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.testdata = testClient.getParsedTestDataConfig()
        cls.hypervisor = testClient.getHypervisorInfo()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient)
        cls._cleanup = []

        try:
            # Create an account
            cls.account = Account.create(
                cls.apiclient,
                cls.testdata["account"],
                domainid=cls.domain.id
            )
            cls._cleanup.append(cls.account)

            # If local storage is enabled, alter the offerings to use
            # localstorage
            if cls.zone.localstorageenable:
                cls.testdata["service_offering"]["storagetype"] = 'local'

            # Create 2 service offerings with different values for
            # for cpunumber, cpuspeed, and memory

            cls.testdata["service_offering"]["cpunumber"] = 1
            cls.testdata["service_offering"]["cpuspeed"] = 128
            cls.testdata["service_offering"]["memory"] = 256

            if cls.hypervisor.lower() == "hyperv":
                cls.testdata["service_offering"]["cpuspeed"] = 1024
                cls.testdata["service_offering"]["memory"] = 1024

            cls.service_offering = ServiceOffering.create(
                cls.apiclient,
                cls.testdata["service_offering"]
            )
            cls._cleanup.append(cls.service_offering)

            cls.testdata["service_offering"]["cpunumber"] = 2

            cls.service_offering_2 = ServiceOffering.create(
                cls.apiclient,
                cls.testdata["service_offering"]
            )
            cls._cleanup.append(cls.service_offering_2)

            # Create isolated network offering
            cls.isolated_network_offering = CreateEnabledNetworkOffering(
                cls.apiclient,
                cls.testdata["isolated_network_offering"]
            )
            cls._cleanup.append(cls.isolated_network_offering)

            cls.networkid = None
            if str(cls.zone.networktype).lower() == "advanced":
                cls.network = Network.create(
                    cls.apiclient, cls.testdata["isolated_network"],
                    networkofferingid=cls.isolated_network_offering.id,
                    accountid=cls.account.name,
                    domainid=cls.account.domainid,
                    zoneid=cls.zone.id)
                cls.networkid = cls.network.id

            # Create user api client of the account
            cls.userapiclient = testClient.getUserApiClient(
                UserName=cls.account.name,
                DomainName=cls.account.domain
            )

            template = get_template(
                cls.apiclient,
                cls.zone.id,
                cls.testdata["ostype"])
            cls.defaultTemplateId = template.id
            # Set Zones and disk offerings

            # Check that we are able to login to the created account
            respose = User.login(
                cls.apiclient,
                username=cls.account.name,
                password=cls.testdata["account"]["password"]
            )

            assert respose.sessionkey is not None,\
                "Login to the CloudStack should be successful\
                            response shall have non Null key"

        except Exception as e:
            cls.tearDownClass()
            raise e
        return
Exemple #41
0
    def setUp(self):

        self.apiclient = self.testClient.getApiClient()
        self.services = self.testClient.getParsedTestDataConfig()

        # Get Zone, Domain and templates
        self.domain = get_domain(self.apiclient)
        self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
        self.hypervisor = self.testClient.getHypervisorInfo()
        template = get_test_template(self.apiclient, self.zone.id,
                                     self.hypervisor)
        if template == FAILED:
            self.fail("get_test_template() failed to return template")

        self.services["virtual_machine"]["zoneid"] = self.zone.id

        # Create an account, network, VM and IP addresses
        self.account = Account.create(self.apiclient,
                                      self.services["account"],
                                      admin=True,
                                      domainid=self.domain.id)
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offerings"]["tiny"])
        self.vm_1 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            templateid=template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id)

        # Wait for VM to come up
        time.sleep(120)

        src_nat_ip_addrs = list_publicIP(self.apiclient,
                                         account=self.account.name,
                                         domainid=self.account.domainid)
        try:
            src_nat_ip_addr = src_nat_ip_addrs[0]
        except Exception as e:
            raise Exception(
                "Warning: Exception during fetching source NAT: %s" % e)

        self.public_ip = PublicIPAddress.create(
            self.apiclient, self.vm_1.account, self.vm_1.zoneid,
            self.vm_1.domainid, self.services["virtual_machine"])
        # Open up firewall port for SSH
        FireWallRule.create(self.apiclient,
                            ipaddressid=self.public_ip.ipaddress.id,
                            protocol=self.services["lbrule"]["protocol"],
                            cidrlist=['0.0.0.0/0'],
                            startport=self.services["lbrule"]["publicport"],
                            endport=self.services["lbrule"]["publicport"])

        lb_rule = LoadBalancerRule.create(self.apiclient,
                                          self.services["lbrule"],
                                          src_nat_ip_addr.id,
                                          self.account.name)
        lb_rule.assign(self.apiclient, [self.vm_1])
        self.nat_rule = NATRule.create(self.apiclient,
                                       self.vm_1,
                                       self.services["natrule"],
                                       ipaddressid=self.public_ip.ipaddress.id)
        self.cleanup = [
            self.nat_rule,
            lb_rule,
            self.vm_1,
            self.service_offering,
            self.account,
        ]
        return
    def setUpClass(cls):
        testClient = super(TestServiceOfferings, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()

        domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype

        cls.service_offering_1 = ServiceOffering.create(
            cls.apiclient,
            cls.services["service_offerings"]
        )
        cls.service_offering_2 = ServiceOffering.create(
            cls.apiclient,
            cls.services["service_offerings"]
        )
        template = get_template(
                            cls.apiclient,
                            cls.zone.id,
                            cls.services["ostype"]
                            )
        if template == FAILED:
            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]

        # Set Zones and disk offerings
        cls.services["small"]["zoneid"] = cls.zone.id
        cls.services["small"]["template"] = template.id

        cls.services["medium"]["zoneid"] = cls.zone.id
        cls.services["medium"]["template"] = template.id

        # Create VMs, NAT Rules etc
        cls.account = Account.create(
                            cls.apiclient,
                            cls.services["account"],
                            domainid=domain.id
                            )

        cls.small_offering = ServiceOffering.create(
                                    cls.apiclient,
                                    cls.services["service_offerings"]["small"]
                                    )

        cls.medium_offering = ServiceOffering.create(
                                    cls.apiclient,
                                    cls.services["service_offerings"]["medium"]
                                    )
        cls.medium_virtual_machine = VirtualMachine.create(
                                       cls.apiclient,
                                       cls.services["medium"],
                                       accountid=cls.account.name,
                                       domainid=cls.account.domainid,
                                       serviceofferingid=cls.medium_offering.id,
                                       mode=cls.services["mode"]
                                    )
        cls._cleanup = [
                        cls.small_offering,
                        cls.medium_offering,
                        cls.account
                        ]
        return
Exemple #43
0
    def test_01_multiple_child_domains(self):
        """Test CPU limits with multiple child domains"""

        # Validate the following
        # 1. Create Domain1 with 10 core CPU and 2 child domains with 4 core
        #    each.Assign 2 cores for Domain1 admin1 & Domain1 User1 .Assign 2
        #    cores for Domain2 admin1 & Domain2 User1
        # 2. Deploy VM's by Domain1 admin1/user1/ Domain2 user1/Admin1 account
        #    and verify the resource updates
        # 3. Deploy VM by admin account after reaching max parent domain limit
        # 4. Deploy VM with child account after reaching max child domain limit
        # 5. Destroy user/admin account VM's and verify the child & Parent
        #    domain resource updates

        self.debug("Creating service offering with 2 CPU cores")
        self.services["service_offering"]["cpunumber"] = 2
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offering"])
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()

        api_client_cadmin_1 = self.testClient.getUserApiClient(
            UserName=self.cadmin_1.name, DomainName=self.cadmin_1.domain)

        api_client_cadmin_2 = self.testClient.getUserApiClient(
            UserName=self.cadmin_2.name, DomainName=self.cadmin_2.domain)

        self.debug("Creating an instance with service offering: %s" %
                   self.service_offering.name)
        vm_1 = self.createInstance(account=self.cadmin_1,
                                   service_off=self.service_offering,
                                   api_client=api_client_cadmin_1)

        vm_2 = self.createInstance(account=self.cadmin_2,
                                   service_off=self.service_offering,
                                   api_client=api_client_cadmin_2)

        self.debug("Checking resource count for account: %s" %
                   self.cadmin_1.name)

        account_list = Account.list(self.apiclient, id=self.cadmin_1.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_cadmin_1 = account_list[0].cputotal

        self.debug(resource_count_cadmin_1)

        self.debug("Checking resource count for account: %s" %
                   self.cadmin_2.name)
        account_list = Account.list(self.apiclient, id=self.cadmin_2.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_cadmin_2 = account_list[0].cputotal

        self.debug(resource_count_cadmin_2)

        self.debug(
            "Creating instance when CPU limit is fully used in child domain 1")
        with self.assertRaises(Exception):
            self.createInstance(account=self.cadmin_1,
                                service_off=self.service_offering,
                                api_client=api_client_cadmin_1)

        self.debug(
            "Creating instance when CPU limit is fully used in child domain 2")
        with self.assertRaises(Exception):
            self.createInstance(account=self.cadmin_2,
                                service_off=self.service_offering,
                                api_client=api_client_cadmin_2)
        self.debug("Destroying instances: %s, %s" % (vm_1.name, vm_2.name))
        try:
            vm_1.delete(self.apiclient)
            vm_2.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete instance: %s" % e)

        self.debug("Checking resource count for account: %s" %
                   self.cadmin_1.name)

        account_list = Account.list(self.apiclient, id=self.cadmin_1.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_cadmin_1 = account_list[0].cputotal

        self.debug(resource_count_cadmin_1)
        self.assertEqual(resource_count_cadmin_1, 0,
                         "Resource count for %s should be 0" %
                         get_resource_type(resource_id=8))  # CPU

        self.debug("Checking resource count for account: %s" %
                   self.cadmin_2.name)
        account_list = Account.list(self.apiclient, id=self.cadmin_2.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_cadmin_2 = account_list[0].cputotal

        self.debug(resource_count_cadmin_2)
        self.assertEqual(resource_count_cadmin_2, 0,
                         "Resource count for %s should be 0" %
                         get_resource_type(resource_id=8))  # CPU
        return
Exemple #44
0
    def setUpClass(cls):
        testClient = super(TestPublicIP, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        # Create Accounts & networks
        cls.account = Account.create(cls.apiclient,
                                     cls.services["account"],
                                     admin=True,
                                     domainid=cls.domain.id)

        cls.user = Account.create(cls.apiclient,
                                  cls.services["account"],
                                  domainid=cls.domain.id)
        cls.services["network"]["zoneid"] = cls.zone.id

        cls.network_offering = NetworkOffering.create(
            cls.apiclient,
            cls.services["network_offering"],
        )
        # Enable Network offering
        cls.network_offering.update(cls.apiclient, state='Enabled')

        cls.services["network"]["networkoffering"] = cls.network_offering.id
        cls.account_network = Network.create(cls.apiclient,
                                             cls.services["network"],
                                             cls.account.name,
                                             cls.account.domainid)
        cls.user_network = Network.create(cls.apiclient,
                                          cls.services["network"],
                                          cls.user.name, cls.user.domainid)

        cls.service_offering = ServiceOffering.create(
            cls.apiclient,
            cls.services["service_offerings"]["tiny"],
        )

        cls.hypervisor = testClient.getHypervisorInfo()
        cls.template = get_test_template(cls.apiclient, cls.zone.id,
                                         cls.hypervisor)
        if cls.template == FAILED:
            assert False, "get_test_template() failed to return template"

        cls.services["virtual_machine"]["zoneid"] = cls.zone.id

        cls.account_vm = VirtualMachine.create(
            cls.apiclient,
            cls.services["virtual_machine"],
            templateid=cls.template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            networkids=cls.account_network.id,
            serviceofferingid=cls.service_offering.id)

        cls.user_vm = VirtualMachine.create(
            cls.apiclient,
            cls.services["virtual_machine"],
            templateid=cls.template.id,
            accountid=cls.user.name,
            domainid=cls.user.domainid,
            networkids=cls.user_network.id,
            serviceofferingid=cls.service_offering.id)

        # Create Source NAT IP addresses
        PublicIPAddress.create(cls.apiclient, cls.account.name, cls.zone.id,
                               cls.account.domainid)
        PublicIPAddress.create(cls.apiclient, cls.user.name, cls.zone.id,
                               cls.user.domainid)
        cls._cleanup = [
            cls.account_vm, cls.user_vm, cls.account_network, cls.user_network,
            cls.account, cls.user, cls.network_offering
        ]
        return
Exemple #45
0
    def test_01_resource_count_vm_with_normal_offering_in_all_states(self):
        """Create VM with normal offering. Take resources of vm in all states into calculation of resource count.

            Steps:
            # 1. update resource.count.running.vms.only to false
            # 2. create normal service offering
            # 3. deploy vm, resource count of cpu/ram increases
            # 4. stop vm, resource count of cpu/ram is not changed
            # 5. update vm with displayvm=false, resource count decreases
            # 6. update vm with displayvm=true, resource count increases
            # 7. start vm, resource count of cpu/ram is not changed
            # 8. reboot vm, resource count of cpu/ram is not changed
            # 9. destroy vm, resource count of cpu/ram decreases
            # 10. expunge vm, resource count of cpu/ram is not changed
        """

        Configurations.update(self.apiclient,
                              name="resource.count.running.vms.only",
                              value="false")

        # Create small service offering
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offerings"]["small"])
        self.cleanup.append(self.service_offering)

        # deploy vm
        try:
            virtual_machine_1 = VirtualMachine.create(
                self.apiclient,
                self.services["virtual_machine"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                templateid=self.template.id,
                zoneid=self.zone.id,
                mode=self.zone.networktype)
        except Exception as e:
            self.fail("Exception while deploying virtual machine: %s" % e)

        self.expectedCpu = self.expectedCpu + virtual_machine_1.cpunumber
        self.expectedMemory = self.expectedMemory + virtual_machine_1.memory
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # stop vm
        virtual_machine_1.stop(self.apiclient)
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # update vm with displayvm=false
        virtual_machine_1.update(self.apiclient, displayvm=False)
        self.expectedCpu = self.expectedCpu - virtual_machine_1.cpunumber
        self.expectedMemory = self.expectedMemory - virtual_machine_1.memory
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # update vm with displayvm=false
        virtual_machine_1.update(self.apiclient, displayvm=True)
        self.expectedCpu = self.expectedCpu + virtual_machine_1.cpunumber
        self.expectedMemory = self.expectedMemory + virtual_machine_1.memory
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # start vm
        virtual_machine_1.start(self.apiclient)
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # reboot vm
        virtual_machine_1.reboot(self.apiclient)
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # destroy vm
        virtual_machine_1.delete(self.apiclient, expunge=False)
        self.expectedCpu = self.expectedCpu - virtual_machine_1.cpunumber
        self.expectedMemory = self.expectedMemory - virtual_machine_1.memory
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # expunge vm
        virtual_machine_1.expunge(self.apiclient)
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)
    def setUpClass(cls):
        cls.testClient = super(TestDirectDownloadTemplates,
                               cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        cls.dbclient = cls.testClient.getDbConnection()
        cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.pod = get_pod(cls.apiclient, cls.zone.id)
        cls.services = cls.testClient.getParsedTestDataConfig()

        cls._cleanup = []
        cls.hypervisorSupported = False
        cls.nfsStorageFound = False
        cls.localStorageFound = False
        cls.sharedMountPointFound = False

        if cls.hypervisor.lower() in ['kvm', 'lxc']:
            cls.hypervisorSupported = True

        if cls.hypervisorSupported:
            cls.services["test_templates"]["kvm"]["directdownload"] = "true"
            cls.template = Template.register(
                cls.apiclient,
                cls.services["test_templates"]["kvm"],
                zoneid=cls.zone.id,
                hypervisor=cls.hypervisor)
            cls._cleanup.append(cls.template)

            cls.services["virtual_machine"]["zoneid"] = cls.zone.id
            cls.services["virtual_machine"]["template"] = cls.template.id
            cls.services["virtual_machine"]["hypervisor"] = cls.hypervisor
            cls.service_offering = ServiceOffering.create(
                cls.apiclient, cls.services["service_offerings"]["tiny"])
            cls._cleanup.append(cls.service_offering)

            if cls.zone.networktype == 'Basic':
                networks = Network.list(cls.apiclient)
                if len(networks) == 0:
                    self.skipTest(
                        "Skipping test since no network found in basic zone")
                else:
                    cls.network = networks[0]
            else:
                cls.network_offering = NetworkOffering.create(
                    cls.apiclient,
                    cls.services["l2-network_offering"],
                )
                cls._cleanup.append(cls.network_offering)
                cls.network_offering.update(cls.apiclient, state='Enabled')
                cls.services["network"][
                    "networkoffering"] = cls.network_offering.id
                cls.network = Network.create(
                    cls.apiclient,
                    cls.services["l2-network"],
                    zoneid=cls.zone.id,
                    networkofferingid=cls.network_offering.id)
                cls._cleanup.append(cls.network)

            storage_pools = StoragePool.list(cls.apiclient, zoneid=cls.zone.id)
            for pool in storage_pools:
                if not cls.nfsStorageFound and pool.type == "NetworkFilesystem":
                    cls.nfsStorageFound = True
                    cls.nfsPoolId = pool.id
                elif not cls.localStorageFound and pool.type == "Filesystem":
                    cls.localStorageFound = True
                    cls.localPoolId = pool.id
                elif not cls.sharedMountPointFound and pool.type == "SharedMountPoint":
                    cls.sharedMountPointFound = True
                    cls.sharedPoolId = pool.id

        cls.nfsKvmNotAvailable = not cls.hypervisorSupported or not cls.nfsStorageFound
        cls.localStorageKvmNotAvailable = not cls.hypervisorSupported or not cls.localStorageFound
        cls.sharedMountPointKvmNotAvailable = not cls.hypervisorSupported or not cls.sharedMountPointFound
        return
    def setUpClass(cls):
        testClient = super(TestCpuCapServiceOfferings, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        cls.hypervisor = testClient.getHypervisorInfo()
        cls._cleanup = []
        cls.hypervisorNotSupported = False
        if cls.hypervisor.lower() not in ["kvm"]:
            cls.hypervisorNotSupported = True
            return

        domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype

        template = get_template(cls.apiclient, cls.zone.id, cls.hypervisor)
        if template == FAILED:
            assert False, "get_template() failed to return template"

        cls.services["small"]["zoneid"] = cls.zone.id
        cls.services["small"]["template"] = template.id
        cls.services["small"]["hypervisor"] = cls.hypervisor
        cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][
            0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__

        cls.account = Account.create(cls.apiclient,
                                     cls.services["account"],
                                     domainid=domain.id)

        offering_data = {
            'displaytext': 'TestOffering',
            'cpuspeed': 512,
            'cpunumber': 2,
            'name': 'TestOffering',
            'memory': 1024
        }

        cls.offering = ServiceOffering.create(cls.apiclient,
                                              offering_data,
                                              limitcpuuse=True)

        def getHost(self, hostId=None):
            response = list_hosts(self.apiclient,
                                  type='Routing',
                                  hypervisor='kvm',
                                  id=hostId)
            # Check if more than one kvm hosts are available in order to successfully configure host-ha
            if response and len(response) > 0:
                self.host = response[0]
                return self.host
            raise self.skipTest(
                "Not enough KVM hosts found, skipping host-ha test")

        cls.host = getHost(cls)

        cls.vm = VirtualMachine.create(cls.apiclient,
                                       cls.services["small"],
                                       accountid=cls.account.name,
                                       domainid=cls.account.domainid,
                                       serviceofferingid=cls.offering.id,
                                       mode=cls.services["mode"],
                                       hostid=cls.host.id)
        cls._cleanup = [cls.offering, cls.account]
Exemple #48
0
    def test_04_deploy_multiple_vm_with_multiple_core(self):
        """Test Deploy multiple VM with 4 core CPU & verify the usage"""

        # Validate the following
        # 1. Create compute offering with 4 core CPU
        # 2. Deploy multiple VMs within domain with this service offering
        # 3. Update Resource count for the domain
        # 4. CPU usage should list properly

        self.debug("Creating service offering with 4 CPU cores")
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offering"])
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {
            self.domain: self.admin,
            self.child_domain: self.child_do_admin
        }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            api_client = self.testClient.getUserApiClient(
                UserName=self.account.name, DomainName=self.account.domain)

            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)
            vm_1 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            vm_2 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            self.createInstance(service_off=self.service_offering,
                                api_client=api_client)
            self.createInstance(service_off=self.service_offering,
                                api_client=api_client)

            self.debug("Deploying instance - CPU capacity is fully utilized")
            with self.assertRaises(Exception):
                self.createInstance(service_off=self.service_offering,
                                    api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count = account_list[0].cputotal

            expected_resource_count = int(self.services["service_offering"]
                                          ["cpunumber"]) * 4  # Total 4 VMs

            self.assertEqual(resource_count, expected_resource_count,
                             "Initial resource count should be 4")

            self.debug("Destroying instance: %s" % vm_1.name)
            try:
                vm_1.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_delete = account_list[0].cputotal

            expected_resource_count -= int(
                self.services["service_offering"]["cpunumber"])

            self.assertEqual(
                resource_count_after_delete, expected_resource_count,
                "Resource count should match with the expected count")
            host = findSuitableHostForMigration(self.apiclient, vm_2.id)
            if host is None:
                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
            self.debug("Migrating instance: %s to host: %s" %
                       (vm_2.name, host.name))
            try:
                vm_2.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_migrate = account_list[0].cputotal

            self.assertEqual(
                resource_count_after_migrate, resource_count_after_delete,
                "Resource count should not change after migrating the instance"
            )
        return
Exemple #49
0
    def setUpClass(cls):
        cls.testClient = super(TestMulipleNicSupport, cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.testdata = cls.testClient.getParsedTestDataConfig()
        cls.services = cls.testClient.getParsedTestDataConfig()
        zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.zone = Zone(zone.__dict__)
        cls._cleanup = []

        cls.skip = False
        if str(cls.zone.securitygroupsenabled) != "True":
            cls.skip = True
            return

        cls.logger = logging.getLogger("TestMulipleNicSupport")
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        # Get Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.services['mode'] = cls.zone.networktype

        cls.template = get_template(cls.apiclient,
                                    cls.zone.id,
                                    hypervisor="KVM")
        if cls.template == FAILED:
            cls.skip = True
            return

        # Create new domain, account, network and VM
        cls.user_domain = Domain.create(
            cls.apiclient,
            services=cls.testdata["acl"]["domain2"],
            parentdomainid=cls.domain.id)

        # Create account
        cls.account1 = Account.create(cls.apiclient,
                                      cls.testdata["acl"]["accountD2"],
                                      admin=True,
                                      domainid=cls.user_domain.id)

        # Create small service offering
        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.testdata["service_offerings"]["small"])

        cls._cleanup.append(cls.service_offering)
        cls.services["network"]["zoneid"] = cls.zone.id
        cls.network_offering = NetworkOffering.create(
            cls.apiclient,
            cls.services["network_offering"],
        )
        # Enable Network offering
        cls.network_offering.update(cls.apiclient, state='Enabled')

        cls._cleanup.append(cls.network_offering)
        cls.testdata["virtual_machine"]["zoneid"] = cls.zone.id
        cls.testdata["virtual_machine"]["template"] = cls.template.id

        if cls.zone.securitygroupsenabled:
            # Enable networking for reaching to VM thorugh SSH
            security_group = SecurityGroup.create(
                cls.apiclient,
                cls.testdata["security_group"],
                account=cls.account1.name,
                domainid=cls.account1.domainid)

            # Authorize Security group to SSH to VM
            ingress_rule = security_group.authorize(
                cls.apiclient,
                cls.testdata["ingress_rule"],
                account=cls.account1.name,
                domainid=cls.account1.domainid)

            # Authorize Security group to SSH to VM
            ingress_rule2 = security_group.authorize(
                cls.apiclient,
                cls.testdata["ingress_rule_ICMP"],
                account=cls.account1.name,
                domainid=cls.account1.domainid)

        cls.testdata["shared_network_offering_sg"]["specifyVlan"] = 'True'
        cls.testdata["shared_network_offering_sg"]["specifyIpRanges"] = 'True'
        cls.shared_network_offering = NetworkOffering.create(
            cls.apiclient,
            cls.testdata["shared_network_offering_sg"],
            conservemode=False)

        NetworkOffering.update(cls.shared_network_offering,
                               cls.apiclient,
                               id=cls.shared_network_offering.id,
                               state="enabled")

        physical_network, vlan = get_free_vlan(cls.apiclient, cls.zone.id)
        cls.testdata["shared_network_sg"][
            "physicalnetworkid"] = physical_network.id

        random_subnet_number = random.randrange(90, 99)
        cls.testdata["shared_network_sg"][
            "name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number)
        cls.testdata["shared_network_sg"][
            "displaytext"] = "Shared-Network-SG-Test-vlan" + str(
                random_subnet_number)
        cls.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
            random_subnet_number)
        cls.testdata["shared_network_sg"]["startip"] = "192.168." + str(
            random_subnet_number) + ".240"
        cls.testdata["shared_network_sg"]["endip"] = "192.168." + str(
            random_subnet_number) + ".250"
        cls.testdata["shared_network_sg"]["gateway"] = "192.168." + str(
            random_subnet_number) + ".254"
        cls.network1 = Network.create(
            cls.apiclient,
            cls.testdata["shared_network_sg"],
            networkofferingid=cls.shared_network_offering.id,
            zoneid=cls.zone.id,
            accountid=cls.account1.name,
            domainid=cls.account1.domainid)

        random_subnet_number = random.randrange(100, 110)
        cls.testdata["shared_network_sg"][
            "name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number)
        cls.testdata["shared_network_sg"][
            "displaytext"] = "Shared-Network-SG-Test-vlan" + str(
                random_subnet_number)
        cls.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
            random_subnet_number)
        cls.testdata["shared_network_sg"]["startip"] = "192.168." + str(
            random_subnet_number) + ".240"
        cls.testdata["shared_network_sg"]["endip"] = "192.168." + str(
            random_subnet_number) + ".250"
        cls.testdata["shared_network_sg"]["gateway"] = "192.168." + str(
            random_subnet_number) + ".254"
        cls.network2 = Network.create(
            cls.apiclient,
            cls.testdata["shared_network_sg"],
            networkofferingid=cls.shared_network_offering.id,
            zoneid=cls.zone.id,
            accountid=cls.account1.name,
            domainid=cls.account1.domainid)

        random_subnet_number = random.randrange(111, 120)
        cls.testdata["shared_network_sg"][
            "name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number)
        cls.testdata["shared_network_sg"][
            "displaytext"] = "Shared-Network-SG-Test-vlan" + str(
                random_subnet_number)
        cls.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
            random_subnet_number)
        cls.testdata["shared_network_sg"]["startip"] = "192.168." + str(
            random_subnet_number) + ".240"
        cls.testdata["shared_network_sg"]["endip"] = "192.168." + str(
            random_subnet_number) + ".250"
        cls.testdata["shared_network_sg"]["gateway"] = "192.168." + str(
            random_subnet_number) + ".254"
        cls.network3 = Network.create(
            cls.apiclient,
            cls.testdata["shared_network_sg"],
            networkofferingid=cls.shared_network_offering.id,
            zoneid=cls.zone.id,
            accountid=cls.account1.name,
            domainid=cls.account1.domainid)

        try:
            cls.virtual_machine1 = VirtualMachine.create(
                cls.apiclient,
                cls.testdata["virtual_machine"],
                accountid=cls.account1.name,
                domainid=cls.account1.domainid,
                serviceofferingid=cls.service_offering.id,
                templateid=cls.template.id,
                securitygroupids=[security_group.id],
                networkids=cls.network1.id)
            for nic in cls.virtual_machine1.nic:
                if nic.isdefault:
                    cls.virtual_machine1.ssh_ip = nic.ipaddress
                    cls.virtual_machine1.default_network_id = nic.networkid
                    break
        except Exception as e:
            cls.fail("Exception while deploying virtual machine: %s" % e)

        try:
            cls.virtual_machine2 = VirtualMachine.create(
                cls.apiclient,
                cls.testdata["virtual_machine"],
                accountid=cls.account1.name,
                domainid=cls.account1.domainid,
                serviceofferingid=cls.service_offering.id,
                templateid=cls.template.id,
                securitygroupids=[security_group.id],
                networkids=[str(cls.network1.id),
                            str(cls.network2.id)])
            for nic in cls.virtual_machine2.nic:
                if nic.isdefault:
                    cls.virtual_machine2.ssh_ip = nic.ipaddress
                    cls.virtual_machine2.default_network_id = nic.networkid
                    break
        except Exception as e:
            cls.fail("Exception while deploying virtual machine: %s" % e)

        cls._cleanup.append(cls.virtual_machine1)
        cls._cleanup.append(cls.virtual_machine2)
        cls._cleanup.append(cls.network1)
        cls._cleanup.append(cls.network2)
        cls._cleanup.append(cls.network3)
        cls._cleanup.append(cls.shared_network_offering)
        if cls.zone.securitygroupsenabled:
            cls._cleanup.append(security_group)
        cls._cleanup.append(cls.account1)
        cls._cleanup.append(cls.user_domain)
Exemple #50
0
    def setUpClass(cls):

        testClient = super(TestTemplates, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls._cleanup = []
        cls.services = testClient.getParsedTestDataConfig()
        cls.unsupportedHypervisor = False
        cls.hypervisor = testClient.getHypervisorInfo()

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        #populate second zone id for iso copy
        cls.zones = Zone.list(cls.apiclient)
        if not isinstance(cls.zones, list):
            raise Exception("Failed to find zones.")

        cls.disk_offering = DiskOffering.create(
                                    cls.apiclient,
                                    cls.services["disk_offering"]
                                    )
        template = get_template(
                            cls.apiclient,
                            cls.zone.id,
                            cls.services["ostype"]
                            )
        if template == FAILED:
            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]

        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["volume"]["diskoffering"] = cls.disk_offering.id
        cls.services["volume"]["zoneid"] = cls.zone.id
        cls.services["template_2"]["zoneid"] = cls.zone.id
        cls.services["sourcezoneid"] = cls.zone.id

        cls.services["template"]["ostypeid"] = template.ostypeid
        cls.services["template_2"]["ostypeid"] = template.ostypeid
        cls.services["ostypeid"] = template.ostypeid
        cls.account = Account.create(
                            cls.apiclient,
                            cls.services["account"],
                            admin=True,
                            domainid=cls.domain.id
                            )
        cls.user = Account.create(
                            cls.apiclient,
                            cls.services["account"],
                            domainid=cls.domain.id
                            )
        cls.service_offering = ServiceOffering.create(
                                            cls.apiclient,
                                            cls.services["service_offerings"]["tiny"]
                                        )
        #create virtual machine
        cls.virtual_machine = VirtualMachine.create(
                                    cls.apiclient,
                                    cls.services["virtual_machine"],
                                    templateid=template.id,
                                    accountid=cls.account.name,
                                    domainid=cls.account.domainid,
                                    serviceofferingid=cls.service_offering.id,
                                    mode=cls.services["mode"]
                                    )
        #Stop virtual machine
        cls.virtual_machine.stop(cls.apiclient)

        list_volume = Volume.list(
                                   cls.apiclient,
                                   virtualmachineid=cls.virtual_machine.id,
                                   type='ROOT',
                                   listall=True
                                   )
        try:
            cls.volume = list_volume[0]
        except Exception as e:
            raise Exception(
                "Exception: Unable to find root volume foe VM: %s - %s" %
                 (cls.virtual_machine.id, e))

        #Create templates for Edit, Delete & update permissions testcases
        cls.template_1 = Template.create(
                                         cls.apiclient,
                                         cls.services["template"],
                                         cls.volume.id,
                                         account=cls.account.name,
                                         domainid=cls.account.domainid
                                         )
        cls.template_2 = Template.create(
                                         cls.apiclient,
                                         cls.services["template_2"],
                                         cls.volume.id,
                                         account=cls.account.name,
                                         domainid=cls.account.domainid
                                         )
        cls._cleanup = [
                        cls.service_offering,
                        cls.disk_offering,
                        cls.account,
                        cls.user
                        ]
Exemple #51
0
    def test_deployvm_userconcentrated(self):
        """Test deploy VMs using user concentrated planner
        """
        self.service_offering_userconcentrated = ServiceOffering.create(
            self.apiclient,
            self.services["service_offerings"],
            deploymentplanner='UserConcentratedPodPlanner'
        )

        self.virtual_machine_1 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            zoneid=self.zone.id,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_userconcentrated.id,
            templateid=self.template.id
        )
        self.virtual_machine_2 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            zoneid=self.zone.id,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_userconcentrated.id,
            templateid=self.template.id
        )

        list_vm_1 = VirtualMachine.list(self.apiclient, id=self.virtual_machine_1.id)
        list_vm_2 = VirtualMachine.list(self.apiclient, id=self.virtual_machine_2.id)
        self.assertEqual(
            isinstance(list_vm_1, list),
            True,
            "List VM response was not a valid list"
        )
        self.assertEqual(
            isinstance(list_vm_2, list),
            True,
            "List VM response was not a valid list"
        )
        vm1 = list_vm_1[0]
        vm2 = list_vm_2[0]
        self.assertEqual(
            vm1.state,
            "Running",
            msg="VM is not in Running state"
        )
        self.assertEqual(
            vm2.state,
            "Running",
            msg="VM is not in Running state"
        )
        vm1clusterid = filter(lambda c: c.id == vm1.hostid, self.hosts)[0].clusterid
        vm2clusterid = filter(lambda c: c.id == vm2.hostid, self.hosts)[0].clusterid

        vm1podid = filter(lambda p: p.id == vm1clusterid, self.clusters)[0].podid
        vm2podid = filter(lambda p: p.id == vm2clusterid, self.clusters)[0].podid
        self.assertEqual(
            vm1podid,
            vm2podid,
            msg="VMs (%s, %s) meant to be pod concentrated are deployed on different pods (%s, %s)" % (vm1.id, vm2.id, vm1clusterid, vm2clusterid)
        )
Exemple #52
0
    def setUpClass(cls):
        testClient = super(TestKubernetesCluster, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.hypervisor = testClient.getHypervisorInfo()
        cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__

        cls.hypervisorNotSupported = False
        if cls.hypervisor.lower() not in ["kvm", "vmware", "xenserver"]:
            cls.hypervisorNotSupported = True
        cls.setup_failed = False
        cls._cleanup = []
        cls.kubernetes_version_ids = []

        if cls.hypervisorNotSupported == False:
            cls.endpoint_url = Configurations.list(
                cls.apiclient, name="endpoint.url")[0].value
            if "localhost" in cls.endpoint_url:
                endpoint_url = "http://%s:%d/client/api " % (
                    cls.mgtSvrDetails["mgtSvrIp"], cls.mgtSvrDetails["port"])
                cls.debug("Setting endpoint.url to %s" % (endpoint_url))
                Configurations.update(cls.apiclient, "endpoint.url",
                                      endpoint_url)
            cls.initial_configuration_cks_enabled = Configurations.list(
                cls.apiclient,
                name="cloud.kubernetes.service.enabled")[0].value
            if cls.initial_configuration_cks_enabled not in ["true", True]:
                cls.debug(
                    "Enabling CloudStack Kubernetes Service plugin and restarting management server"
                )
                Configurations.update(cls.apiclient,
                                      "cloud.kubernetes.service.enabled",
                                      "true")
                cls.restartServer()
            cls.updateVmwareSettings(False)
            cls.cks_service_offering = None

            if cls.setup_failed == False:
                try:
                    cls.kubernetes_version_1_23_3 = cls.addKubernetesSupportedVersion(
                        cls.services["cks_kubernetes_versions"]["1.23.3"])
                    cls.kubernetes_version_ids.append(
                        cls.kubernetes_version_1_23_3.id)
                except Exception as e:
                    cls.setup_failed = True
                    cls.debug(
                        "Failed to get Kubernetes version ISO in ready state, version=%s, url=%s, %s"
                        % (cls.services["cks_kubernetes_versions"]["1.23.3"]
                           ["semanticversion"],
                           cls.services["cks_kubernetes_versions"]["1.23.3"]
                           ["url"], e))
            if cls.setup_failed == False:
                try:
                    cls.kubernetes_version_1_24_0 = cls.addKubernetesSupportedVersion(
                        cls.services["cks_kubernetes_versions"]["1.24.0"])
                    cls.kubernetes_version_ids.append(
                        cls.kubernetes_version_1_24_0.id)
                except Exception as e:
                    cls.setup_failed = True
                    cls.debug(
                        "Failed to get Kubernetes version ISO in ready state, version=%s, url=%s, %s"
                        % (cls.services["cks_kubernetes_versions"]["1.24.0"]
                           ["semanticversion"],
                           cls.services["cks_kubernetes_versions"]["1.24.0"]
                           ["url"], e))

            if cls.setup_failed == False:
                cks_offering_data = cls.services["cks_service_offering"]
                cks_offering_data["name"] = 'CKS-Instance-' + random_gen()
                cls.cks_service_offering = ServiceOffering.create(
                    cls.apiclient, cks_offering_data)
                cls._cleanup.append(cls.cks_service_offering)
                cls.domain = get_domain(cls.apiclient)
                cls.account = Account.create(cls.apiclient,
                                             cls.services["account"],
                                             domainid=cls.domain.id)
                cls._cleanup.append(cls.account)

        cls.default_network = None
        if str(cls.zone.securitygroupsenabled) == "True":
            networks = Network.list(cls.apiclient, listall=True)
            cls.default_network = networks[0]

        return
    def setUpClass(cls):
        cls._cleanup = []
        cls.testClient = super(TestNuageVsp, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.template = get_template(cls.api_client, cls.zone.id,
                                    cls.services["ostype"])
        #nuage vsp device brings the Nuage virtual service platform into play
        cls.nuage_services = cls.services["nuage_vsp_device"]
        try:

            resp = listPhysicalNetworks.listPhysicalNetworksCmd()
            resp.zoneid = cls.zone.id
            physical_networks = cls.api_client.listPhysicalNetworks(resp)
            if isinstance(physical_networks, list):
                physical_network = physical_networks[1]
            resp = listNetworkServiceProviders.listNetworkServiceProvidersCmd()
            resp.name = 'NuageVsp'
            resp.physicalnetworkid = physical_network.id
            nw_service_providers = cls.api_client.listNetworkServiceProviders(
                resp)
            if isinstance(nw_service_providers, list):
                nuage_provider = nw_service_providers[0]
            else:
                #create network service provider and add nuage vsp device
                resp_add_nsp = addNetworkServiceProvider.addNetworkServiceProviderCmd(
                )
                resp_add_nsp.name = 'NuageVsp'
                resp_add_nsp.physicalnetworkid = physical_network.id
                nuage_provider = cls.api_client.addNetworkServiceProvider(
                    resp_add_nsp)
                resp_add_device = addNuageVspDevice.addNuageVspDeviceCmd()
                resp_add_device.physicalnetworkid = physical_network.id
                resp_add_device.username = cls.nuage_services["username"]
                resp_add_device.password = cls.nuage_services["password"]
                resp_add_device.hostname = cls.nuage_services["hostname"]
                resp_add_device.apiversion = cls.nuage_services["apiversion"]
                resp_add_device.retrycount = cls.nuage_services["retrycount"]
                resp_add_device.retryinterval = cls.nuage_services[
                    "retryinterval"]
                cls.nuage = cls.api_client.addNuageVspDevice(resp_add_device)

            cls.network_offering = NetworkOffering.create(
                cls.api_client,
                cls.services["network_offering"],
                conservemode=True)
            cls._cleanup.append(cls.network_offering)

            cls.network_offering.update(cls.api_client, state='Enabled')
            cls.services["virtual_machine"]["zoneid"] = cls.zone.id
            cls.services["virtual_machine"]["template"] = cls.template.id
            cls.service_offering = ServiceOffering.create(
                cls.api_client, cls.services["service_offering"])
            cls._cleanup.append(cls.service_offering)
        except Exception as e:
            cls.tearDownClass()
            raise Exception("Warning: Exception in setUpClass: %s" % e)
        return
Exemple #54
0
    def setUpClass(cls):
        testClient = super(TestCreateTemplate, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls._cleanup = []
        cls.services = testClient.getParsedTestDataConfig()
        cls.unsupportedHypervisor = False
        cls.hypervisor = testClient.getHypervisorInfo()

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        try:
            cls.disk_offering = DiskOffering.create(
                                    cls.apiclient,
                                    cls.services["disk_offering"]
                                    )
            cls._cleanup.append(cls.disk_offering)
            template = get_template(
                            cls.apiclient,
                            cls.zone.id,
                            cls.services["ostype"]
                            )
            if template == FAILED:
                assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]

            cls.services["template"]["ostypeid"] = template.ostypeid
            cls.services["template_2"]["ostypeid"] = template.ostypeid
            cls.services["ostypeid"] = template.ostypeid

            cls.services["virtual_machine"]["zoneid"] = cls.zone.id
            cls.services["volume"]["diskoffering"] = cls.disk_offering.id
            cls.services["volume"]["zoneid"] = cls.zone.id
            cls.services["sourcezoneid"] = cls.zone.id
            cls.account = Account.create(
                            cls.apiclient,
                            cls.services["account"],
                            domainid=cls.domain.id
                            )
            cls._cleanup.append(cls.account)
            cls.service_offering = ServiceOffering.create(
                                            cls.apiclient,
                                            cls.services["service_offerings"]["tiny"]
                                            )
            cls._cleanup.append(cls.service_offering)
            #create virtual machine
            cls.virtual_machine = VirtualMachine.create(
                                    cls.apiclient,
                                    cls.services["virtual_machine"],
                                    templateid=template.id,
                                    accountid=cls.account.name,
                                    domainid=cls.account.domainid,
                                    serviceofferingid=cls.service_offering.id,
                                    mode=cls.services["mode"]
                                    )
            #Stop virtual machine
            cls.virtual_machine.stop(cls.apiclient)

            list_volume = Volume.list(
                                   cls.apiclient,
                                   virtualmachineid=cls.virtual_machine.id,
                                   type='ROOT',
                                   listall=True
                                   )

            cls.volume = list_volume[0]
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest("Exception in setUpClass: %s" % e)
        return
Exemple #55
0
    def test_08_resource_count_vm_in_all_states_and_move_and_upgrade(self):
        """Create VM with dynamic service offering. Take resources of vm in all states into calculation. Move vm to another account and upgrade it.

            Steps:
            # 1. update resource.count.running.vms.only to true
            # 2. create dynamic service offering
            # 3. deploy vm, resource count of cpu/ram increases
            # 4. stop vm, resource count of cpu/ram is not changed
            # 5. create another account
            # 6. move vm to new account. resource count of cpu/ram of current account decreases. resource count of cpu/ram of new account increases.
            # 7. create another service offering.
            # 8. upgrade vm. resource count of cpu/ram of new account is changed.
            # 9. start vm, resource count of cpu/ram is not changed
            # 10. destroy vm, resource count of cpu/ram decreases
            # 11. expunge vm, resource count of cpu/ram is not changed
        """
        Configurations.update(self.apiclient,
                              name="resource.count.running.vms.only",
                              value="false")

        # Create dynamic service offering
        self.services["service_offering"]["cpunumber"] = ""
        self.services["service_offering"]["cpuspeed"] = ""
        self.services["service_offering"]["memory"] = ""

        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offering"])
        self.cleanup.append(self.service_offering)

        # deploy vm
        try:
            virtual_machine_8 = VirtualMachine.create(
                self.apiclient,
                self.services["virtual_machine"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                customcpunumber=1,
                customcpuspeed=100,
                custommemory=256,
                templateid=self.template.id,
                zoneid=self.zone.id)
        except Exception as e:
            self.fail("Exception while deploying virtual machine: %s" % e)

        self.expectedCpu = self.expectedCpu + virtual_machine_8.cpunumber
        self.expectedMemory = self.expectedMemory + virtual_machine_8.memory
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # stop vm
        virtual_machine_8.stop(self.apiclient)
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # create another account
        self.account2 = Account.create(self.apiclient,
                                       self.services["account2"],
                                       admin=True,
                                       domainid=self.domain.id)
        self.cleanup.append(self.account2)
        accounts = Account.list(self.apiclient, id=self.account2.id)
        self.account2Cpu = int(accounts[0].cputotal)
        self.account2Memory = int(accounts[0].memorytotal)

        # move vm to new account. resource count of cpu/ram of current account decreases. resource count of cpu/ram of new account increases.
        oldcpunumber = virtual_machine_8.cpunumber
        oldmemory = virtual_machine_8.memory
        virtual_machine_8.assign_virtual_machine(self.apiclient,
                                                 self.account2.name,
                                                 self.account2.domainid)

        self.expectedCpu = self.expectedCpu - virtual_machine_8.cpunumber
        self.expectedMemory = self.expectedMemory - virtual_machine_8.memory
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        self.account2Cpu = self.account2Cpu + virtual_machine_8.cpunumber
        self.account2Memory = self.account2Memory + virtual_machine_8.memory
        self.verify_resource_count_cpu_memory(self.account2Cpu,
                                              self.account2Memory,
                                              account=self.account2)

        # create another service offering
        self.service_offering_big = ServiceOffering.create(
            self.apiclient, self.services["service_offerings"]["big"])
        self.cleanup.append(self.service_offering_big)

        # upgrade vm
        virtual_machine_8.change_service_offering(self.apiclient,
                                                  self.service_offering_big.id)
        self.account2Cpu = self.account2Cpu + self.service_offering_big.cpunumber - oldcpunumber
        self.account2Memory = self.account2Memory + self.service_offering_big.memory - oldmemory
        self.verify_resource_count_cpu_memory(self.account2Cpu,
                                              self.account2Memory,
                                              account=self.account2)

        # start vm
        virtual_machine_8.start(self.apiclient)
        self.verify_resource_count_cpu_memory(self.account2Cpu,
                                              self.account2Memory,
                                              account=self.account2)

        # expunge vm
        virtual_machine_8.delete(self.apiclient, expunge=True)
        self.account2Cpu = self.account2Cpu - self.service_offering_big.cpunumber
        self.account2Memory = self.account2Memory - self.service_offering_big.memory
        self.verify_resource_count_cpu_memory(self.account2Cpu,
                                              self.account2Memory,
                                              account=self.account2)
    def setUpClass(cls):
        testClient = super(TestVMLifeCycle, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        cls.hypervisor = testClient.getHypervisorInfo()

        # Get Zone, Domain and templates
        domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype

        # if local storage is enabled, alter the offerings to use localstorage
        # this step is needed for devcloud
        if cls.zone.localstorageenabled == True:
            cls.services["service_offerings"]["tiny"]["storagetype"] = 'local'
            cls.services["service_offerings"]["small"]["storagetype"] = 'local'
            cls.services["service_offerings"]["medium"][
                "storagetype"] = 'local'

        template = get_template(cls.apiclient, cls.zone.id,
                                cls.services["ostype"])
        if template == FAILED:
            assert False, "get_template() failed to return template with description %s" % cls.services[
                "ostype"]

        # Set Zones and disk offerings
        cls.services["small"]["zoneid"] = cls.zone.id
        cls.services["small"]["template"] = template.id

        cls.services["iso1"]["zoneid"] = cls.zone.id

        # Create VMs, NAT Rules etc
        cls.account = Account.create(cls.apiclient,
                                     cls.services["account"],
                                     domainid=domain.id)

        cls.small_offering = ServiceOffering.create(
            cls.apiclient, cls.services["service_offerings"]["small"])

        cls.medium_offering = ServiceOffering.create(
            cls.apiclient, cls.services["service_offerings"]["medium"])
        # create small and large virtual machines
        cls.small_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"])
        cls.medium_virtual_machine = VirtualMachine.create(
            cls.apiclient,
            cls.services["small"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.medium_offering.id,
            mode=cls.services["mode"])
        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"])
        cls._cleanup = [cls.small_offering, cls.medium_offering, cls.account]
Exemple #57
0
    def test_06_resource_count_vm_with_dynamic_offering_in_all_states_failed_cases(
            self):
        """Create VM with dynamic service offering. Take resources of vm in all states into calculation of resource count. Test failed cases

            Steps:
            # 1. update resource.count.running.vms.only to false
            # 2. create dynamic service offering
            # 3. update account cpu/ram limitation to current value
            # 4. deploy vm (startvm=false), it should fail
            # 5. increase cpu limitation, deploy vm, it should fail
            # 6. increase memory limitation, deploy vm, it should succeed. resource count of cpu/ram increases
            # 7. start vm, resource count of cpu/ram is not changed
            # 8. restore vm, it should succeed. resource count of cpu/ram is not changed
            # 9. destroy vm, resource count of cpu/ram decreases
            # 10. expunge vm, resource count of cpu/ram is not changed
        """
        Configurations.update(self.apiclient,
                              name="resource.count.running.vms.only",
                              value="false")

        # Create dynamic service offering
        self.services["service_offering"]["cpunumber"] = ""
        self.services["service_offering"]["cpuspeed"] = ""
        self.services["service_offering"]["memory"] = ""

        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offering"])
        self.cleanup.append(self.service_offering)

        # update resource limitation
        self.update_account_resource_limitation(self.expectedCpu,
                                                self.expectedMemory)

        # deploy vm (startvm=false)
        try:
            virtual_machine_6 = VirtualMachine.create(
                self.apiclient,
                self.services["virtual_machine"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                customcpunumber=1,
                customcpuspeed=100,
                custommemory=256,
                templateid=self.template.id,
                zoneid=self.zone.id,
                startvm=False,
                mode=self.zone.networktype)
            self.fail("Deploy VM should fail as there is not enough cpu")
        except Exception as e:
            self.debug("Deploy VM failed as expected")

        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # increase cpu limitation, and deploy vm
        self.update_account_resource_limitation(self.expectedCpu + 1,
                                                self.expectedMemory)
        try:
            virtual_machine_6 = VirtualMachine.create(
                self.apiclient,
                self.services["virtual_machine"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                customcpunumber=1,
                customcpuspeed=100,
                custommemory=256,
                templateid=self.template.id,
                zoneid=self.zone.id,
                startvm=False,
                mode=self.zone.networktype)
            self.fail("Deploy VM should fail as there is not enough memory")
        except Exception as e:
            self.debug("Deploy VM failed as expected")

        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # increase memory limitation, and deploy vm
        self.update_account_resource_limitation(self.expectedCpu + 1,
                                                self.expectedMemory + 256)
        try:
            virtual_machine_6 = VirtualMachine.create(
                self.apiclient,
                self.services["virtual_machine"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                customcpunumber=1,
                customcpuspeed=100,
                custommemory=256,
                templateid=self.template.id,
                zoneid=self.zone.id,
                startvm=False,
                mode=self.zone.networktype)
            self.debug("Deploy VM succeed as expected")
        except Exception:
            self.fail(
                "Deploy VM should succeed as there is enough cpu and memory")

        self.expectedCpu = self.expectedCpu + virtual_machine_6.cpunumber
        self.expectedMemory = self.expectedMemory + virtual_machine_6.memory
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # start vm
        virtual_machine_6.start(self.apiclient)
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # restore running vm
        virtual_machine_6.restore(self.apiclient)
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)

        # expunge vm
        virtual_machine_6.delete(self.apiclient, expunge=True)
        self.expectedCpu = self.expectedCpu - virtual_machine_6.cpunumber
        self.expectedMemory = self.expectedMemory - virtual_machine_6.memory
        self.verify_resource_count_cpu_memory(self.expectedCpu,
                                              self.expectedMemory)
Exemple #58
0
    def setUpClass(cls):
        # Set up API client
        testclient = super(TestVMMigrationWithStorage, cls).getClsTestClient()

        cls.apiClient = testclient.getApiClient()
        cls.configData = testclient.getParsedTestDataConfig()
        cls.dbConnection = testclient.getDbConnection()

        cls.testdata = TestData().testdata

        xenserver = cls.testdata[TestData.xenServer]

        # Set up xenAPI connection
        host_ip = "https://" + \
                  list_hosts(cls.apiClient, clusterid=cls.testdata[TestData.clusterId1], name=TestData.xen_server_hostname_src)[0].ipaddress

        # Set up XenAPI connection
        cls.xen_session_1 = XenAPI.Session(host_ip)

        cls.xen_session_1.xenapi.login_with_password(
            xenserver[TestData.username], xenserver[TestData.password])

        # Set up xenAPI connection
        host_ip = "https://" + \
                  list_hosts(cls.apiClient, clusterid=cls.testdata[TestData.clusterId2], name=TestData.xen_server_hostname_dest)[0].ipaddress

        # Set up XenAPI connection
        cls.xen_session_2 = XenAPI.Session(host_ip)

        cls.xen_session_2.xenapi.login_with_password(
            xenserver[TestData.username], xenserver[TestData.password])

        # Set up SolidFire connection
        solidfire = cls.testdata[TestData.solidFire]

        cls.sfe = ElementFactory.create(solidfire[TestData.mvip],
                                        solidfire[TestData.username],
                                        solidfire[TestData.password])

        # Get Resources from Cloud Infrastructure
        cls.zone = get_zone(cls.apiClient,
                            zone_id=cls.testdata[TestData.zoneId])
        cls.cluster_1 = list_clusters(cls.apiClient,
                                      id=cls.testdata[TestData.clusterId1])[0]
        cls.cluster_2 = list_clusters(cls.apiClient,
                                      id=cls.testdata[TestData.clusterId2])[0]
        cls.template = get_template(cls.apiClient, cls.zone.id,
                                    cls.configData["ostype"])
        cls.domain = get_domain(cls.apiClient, cls.testdata[TestData.domainId])

        # Create test account
        cls.account = Account.create(cls.apiClient,
                                     cls.testdata["account"],
                                     admin=1)

        # Set up connection to make customized API calls
        cls.user = User.create(cls.apiClient,
                               cls.testdata["user"],
                               account=cls.account.name,
                               domainid=cls.domain.id)

        url = cls.testdata[TestData.url]

        api_url = "http://" + url + ":8080/client/api"
        userkeys = User.registerUserKeys(cls.apiClient, cls.user.id)

        cls.cs_api = SignedAPICall.CloudStack(api_url, userkeys.apikey,
                                              userkeys.secretkey)

        primarystorage = cls.testdata[TestData.primaryStorage]

        cls.primary_storage = StoragePool.create(cls.apiClient, primarystorage)

        cls.compute_offering_1 = ServiceOffering.create(
            cls.apiClient, cls.testdata[TestData.computeOffering1])

        cls.compute_offering_2 = ServiceOffering.create(
            cls.apiClient, cls.testdata[TestData.computeOffering2])

        cls.compute_offering_3 = ServiceOffering.create(
            cls.apiClient, cls.testdata[TestData.computeOffering3])

        cls.disk_offering_1 = DiskOffering.create(
            cls.apiClient, cls.testdata[TestData.diskOffering1])

        cls.disk_offering_2 = DiskOffering.create(
            cls.apiClient, cls.testdata[TestData.diskOffering2])

        # Resources that are to be destroyed
        cls._cleanup = [
            cls.compute_offering_1, cls.compute_offering_2,
            cls.compute_offering_3, cls.disk_offering_1, cls.disk_offering_2,
            cls.user, cls.account
        ]
Exemple #59
0
    def setUpClass(cls):
        cls.testClient = super(TestVPCRouterOneNetwork, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        cls.vpcSupported = True
        cls._cleanup = []
        if cls.hypervisor.lower() == 'hyperv':
            cls.vpcSupported = False
            return
        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.template = get_template(cls.api_client, cls.zone.id,
                                    cls.services["ostype"])
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
            cls.api_client, cls.services["service_offering"])
        cls._cleanup.append(cls.service_offering)
        cls.vpc_off = VpcOffering.create(cls.api_client,
                                         cls.services["vpc_offering"])
        cls.vpc_off.update(cls.api_client, state='Enabled')
        cls._cleanup.append(cls.vpc_off)

        cls.account = Account.create(cls.api_client,
                                     cls.services["account"],
                                     admin=True,
                                     domainid=cls.domain.id)
        cls._cleanup.append(cls.account)

        cls.services["vpc"]["cidr"] = '10.1.1.1/16'
        cls.vpc = VPC.create(cls.api_client,
                             cls.services["vpc"],
                             vpcofferingid=cls.vpc_off.id,
                             zoneid=cls.zone.id,
                             account=cls.account.name,
                             domainid=cls.account.domainid)
        cls._cleanup.append(cls.vpc)

        private_gateway = PrivateGateway.create(cls.api_client,
                                                gateway='10.1.3.1',
                                                ipaddress='10.1.3.100',
                                                netmask='255.255.255.0',
                                                vlan=678,
                                                vpcid=cls.vpc.id)
        cls._cleanup.append(private_gateway)
        cls.gateways = PrivateGateway.list(cls.api_client,
                                           id=private_gateway.id,
                                           listall=True)

        static_route = StaticRoute.create(cls.api_client,
                                          cidr='11.1.1.1/24',
                                          gatewayid=private_gateway.id)
        cls.static_routes = StaticRoute.list(cls.api_client,
                                             id=static_route.id,
                                             listall=True)
        cls._cleanup.append(static_route)

        cls.nw_off = NetworkOffering.create(cls.api_client,
                                            cls.services["network_offering"],
                                            conservemode=False)
        # Enable Network offering
        cls.nw_off.update(cls.api_client, state='Enabled')
        cls._cleanup.append(cls.nw_off)

        # Creating network using the network offering created
        cls.network_1 = Network.create(cls.api_client,
                                       cls.services["network"],
                                       accountid=cls.account.name,
                                       domainid=cls.account.domainid,
                                       networkofferingid=cls.nw_off.id,
                                       zoneid=cls.zone.id,
                                       gateway='10.1.1.1',
                                       vpcid=cls.vpc.id)
        cls._cleanup.append(cls.network_1)

        # Spawn an instance in that network
        vm_1 = VirtualMachine.create(cls.api_client,
                                     cls.services["virtual_machine"],
                                     accountid=cls.account.name,
                                     domainid=cls.account.domainid,
                                     serviceofferingid=cls.service_offering.id,
                                     networkids=[str(cls.network_1.id)])
        cls._cleanup.append(vm_1)
        vm_2 = VirtualMachine.create(cls.api_client,
                                     cls.services["virtual_machine"],
                                     accountid=cls.account.name,
                                     domainid=cls.account.domainid,
                                     serviceofferingid=cls.service_offering.id,
                                     networkids=[str(cls.network_1.id)])
        cls._cleanup.append(vm_2)

        # Spawn an instance in that network
        vm_3 = VirtualMachine.create(cls.api_client,
                                     cls.services["virtual_machine"],
                                     accountid=cls.account.name,
                                     domainid=cls.account.domainid,
                                     serviceofferingid=cls.service_offering.id,
                                     networkids=[str(cls.network_1.id)])
        cls._cleanup.append(vm_3)

        VirtualMachine.list(cls.api_client,
                            account=cls.account.name,
                            domainid=cls.account.domainid,
                            listall=True)

        public_ip_1 = PublicIPAddress.create(cls.api_client,
                                             accountid=cls.account.name,
                                             zoneid=cls.zone.id,
                                             domainid=cls.account.domainid,
                                             networkid=cls.network_1.id,
                                             vpcid=cls.vpc.id)
        cls._cleanup.append(public_ip_1)

        NATRule.create(cls.api_client,
                       vm_1,
                       cls.services["natrule"],
                       ipaddressid=public_ip_1.ipaddress.id,
                       openfirewall=False,
                       networkid=cls.network_1.id,
                       vpcid=cls.vpc.id)

        NetworkACL.create(cls.api_client,
                          networkid=cls.network_1.id,
                          services=cls.services["natrule"],
                          traffictype='Ingress')

        public_ip_2 = PublicIPAddress.create(cls.api_client,
                                             accountid=cls.account.name,
                                             zoneid=cls.zone.id,
                                             domainid=cls.account.domainid,
                                             networkid=cls.network_1.id,
                                             vpcid=cls.vpc.id)
        cls._cleanup.append(public_ip_2)

        try:
            StaticNATRule.enable(cls.api_client,
                                 ipaddressid=public_ip_2.ipaddress.id,
                                 virtualmachineid=vm_2.id,
                                 networkid=cls.network_1.id)
        except Exception as e:
            cls.fail("Failed to enable static NAT on IP: %s - %s" %
                     (public_ip_2.ipaddress.ipaddress, e))

        PublicIPAddress.list(cls.api_client,
                             networkid=cls.network_1.id,
                             listall=True,
                             isstaticnat=True,
                             account=cls.account.name,
                             domainid=cls.account.domainid)
        public_ip_3 = PublicIPAddress.create(cls.api_client,
                                             accountid=cls.account.name,
                                             zoneid=cls.zone.id,
                                             domainid=cls.account.domainid,
                                             networkid=cls.network_1.id,
                                             vpcid=cls.vpc.id)
        cls._cleanup.append(public_ip_3)

        lb_rule = LoadBalancerRule.create(cls.api_client,
                                          cls.services["lbrule"],
                                          ipaddressid=public_ip_3.ipaddress.id,
                                          accountid=cls.account.name,
                                          networkid=cls.network_1.id,
                                          vpcid=cls.vpc.id,
                                          domainid=cls.account.domainid)

        lb_rule.assign(cls.api_client, [vm_3])

        NetworkACL.create(cls.api_client,
                          networkid=cls.network_1.id,
                          services=cls.services["lbrule"],
                          traffictype='Ingress')

        NetworkACL.create(cls.api_client,
                          networkid=cls.network_1.id,
                          services=cls.services["http_rule"],
                          traffictype='Egress')
Exemple #60
0
    def setUpClass(cls):
        # Set up API client
        testclient = super(TestManagedSystemVMs, cls).getClsTestClient()

        cls.apiClient = testclient.getApiClient()
        cls.configData = testclient.getParsedTestDataConfig()
        cls.dbConnection = testclient.getDbConnection()

        cls.testdata = TestData().testdata

        # Set up xenAPI connection
        host_ip = "https://" + \
                  list_hosts(cls.apiClient, clusterid=cls.testdata[TestData.clusterId], name="XenServer-6.5-1")[0].ipaddress

        # Set up XenAPI connection
        cls.xen_session = XenAPI.Session(host_ip)

        xenserver = cls.testdata[TestData.xenServer]

        cls.xen_session.xenapi.login_with_password(xenserver[TestData.username], xenserver[TestData.password])

        # Set up SolidFire connection
        solidfire = cls.testdata[TestData.solidFire]

        cls.sfe = ElementFactory.create(solidfire[TestData.mvip], solidfire[TestData.username], solidfire[TestData.password])

        # Get Resources from Cloud Infrastructure
        cls.zone = Zone(get_zone(cls.apiClient, zone_id=cls.testdata[TestData.zoneId]).__dict__)
        cls.cluster = list_clusters(cls.apiClient)[0]
        cls.template = get_template(cls.apiClient, cls.zone.id, cls.configData["ostype"])
        cls.domain = get_domain(cls.apiClient, cls.testdata[TestData.domainId])

        # Create test account
        cls.account = Account.create(
            cls.apiClient,
            cls.testdata["account"],
            admin=1
        )

        # Set up connection to make customized API calls
        cls.user = User.create(
            cls.apiClient,
            cls.testdata["user"],
            account=cls.account.name,
            domainid=cls.domain.id
        )

        url = cls.testdata[TestData.url]

        api_url = "http://" + url + ":8080/client/api"
        userkeys = User.registerUserKeys(cls.apiClient, cls.user.id)

        cls.cs_api = SignedAPICall.CloudStack(api_url, userkeys.apikey, userkeys.secretkey)

        cls.compute_offering = ServiceOffering.create(
            cls.apiClient,
            cls.testdata[TestData.computeOffering]
        )

        systemoffering = cls.testdata[TestData.systemOffering]

        systemoffering[TestData.name] = "Managed SSVM"
        systemoffering['systemvmtype'] = "secondarystoragevm"

        cls.secondary_storage_offering = ServiceOffering.create(
            cls.apiClient,
            systemoffering
        )

        systemoffering[TestData.name] = "Managed CPVM"
        systemoffering['systemvmtype'] = "consoleproxy"

        cls.console_proxy_offering = ServiceOffering.create(
            cls.apiClient,
            systemoffering
        )

        systemoffering[TestData.name] = "Managed VR"
        systemoffering['systemvmtype'] = "domainrouter"

        cls.virtual_router_offering = ServiceOffering.create(
            cls.apiClient,
            systemoffering
        )

        # Resources that are to be destroyed
        cls._cleanup = [
            cls.secondary_storage_offering,
            cls.console_proxy_offering,
            cls.virtual_router_offering,
            cls.compute_offering,
            cls.user,
            cls.account
        ]