Esempio n. 1
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._cleanup = []
        cls.hypervisor = testClient.getHypervisorInfo()
        cls.services['mode'] = cls.zone.networktype
        cls.invalidStoragePoolType = False
        # for LXC if the storage pool of type 'rbd' ex: ceph is not available, skip the test
        if cls.hypervisor.lower() == 'lxc':
            if not find_storage_pool_type(cls.apiclient, storagetype='rbd'):
                # RBD storage type is required for data volumes for LXC
                cls.invalidStoragePoolType = True
                return
        cls.disk_offering = DiskOffering.create(cls.apiclient,
                                                cls.services["disk_offering"])
        cls._cleanup.append(cls.disk_offering)
        cls.sparse_disk_offering = DiskOffering.create(
            cls.apiclient, cls.services["sparse_disk_offering"])
        cls._cleanup.append(cls.sparse_disk_offering)
        cls.custom_disk_offering = DiskOffering.create(
            cls.apiclient, cls.services["disk_offering"], custom=True)
        cls._cleanup.append(cls.custom_disk_offering)

        template = get_suitable_test_template(cls.apiclient, cls.zone.id,
                                              cls.services["ostype"],
                                              cls.hypervisor)
        if template == FAILED:
            assert False, "get_suitable_test_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._cleanup.append(cls.account)
        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.services["service_offerings"]["tiny"])
        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.append(cls.virtual_machine)
    def setUpClass(cls):
        cls.testClient = super(TestHostMaintenanceAgents,
                               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.logger = logging.getLogger('TestHMAgents')
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        cls._cleanup = []
        cls.hypervisorNotSupported = False
        if cls.hypervisor.lower() not in ['kvm', 'lxc']:
            cls.hypervisorNotSupported = True

        if not cls.hypervisorNotSupported:
            cls.initialsshvalue = cls.is_ssh_enabled()

            cls.template = get_suitable_test_template(cls.apiclient,
                                                      cls.zone.id, None,
                                                      cls.hypervisor)
            if cls.template == FAILED:
                assert False, "get_suitable_test_template() failed to return 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)
            cls.network_offering = NetworkOffering.create(
                cls.apiclient,
                cls.services["l2-network_offering"],
            )
            cls.network_offering.update(cls.apiclient, state='Enabled')
            cls.services["network"][
                "networkoffering"] = cls.network_offering.id
            cls.l2_network = Network.create(
                cls.apiclient,
                cls.services["l2-network"],
                zoneid=cls.zone.id,
                networkofferingid=cls.network_offering.id)
            cls._cleanup.append(cls.l2_network)
            cls._cleanup.append(cls.network_offering)

        cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][
            0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__
    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_suitable_test_template(cls.api_client,
                                                      cls.zone.id,
                                                      cls.services["ostype"],
                                                      cls.hypervisor)
            if cls.template == FAILED:
                assert False, "get_suitable_test_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):
        testClient = super(TestVmSnapshot, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls._cleanup = []
        cls.unsupportedHypervisor = False
        cls.hypervisor = testClient.getHypervisorInfo()
        if cls.hypervisor.lower() in ("hyperv", "lxc"):
            cls.unsupportedHypervisor = True
            return

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

        template = get_suitable_test_template(cls.apiclient, cls.zone.id,
                                              cls.services["ostype"],
                                              cls.hypervisor)
        if template == FAILED:
            assert False, "get_suitable_test_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"] = template.ostypeid
        cls.services["zoneid"] = cls.zone.id

        # Create VMs, NAT Rules etc
        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)
        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient,
            cls.services["small"],
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            mode=cls.zone.networktype)
        cls.random_data_0 = random_gen(size=100)
        cls.test_dir = "$HOME"
        cls.random_data = "random.data"
        return
    def createVMs(self, hostId, number, offering_key="tiny"):
        self.template = get_suitable_test_template(self.apiclient,
                                                   self.zone.id, None,
                                                   self.hypervisor)
        if self.template == FAILED:
            assert False, "get_suitable_test_template() failed to return template"

        self.logger.debug("Using template %s " % self.template.id)

        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offerings"][offering_key])
        self.logger.debug("Using service offering %s " %
                          self.service_offering.id)
        self.network_offering = NetworkOffering.create(
            self.apiclient,
            self.services["l2-network_offering"],
        )
        self.network_offering.update(self.apiclient, state='Enabled')
        self.services["network"]["networkoffering"] = self.network_offering.id
        self.l2_network = Network.create(
            self.apiclient,
            self.services["l2-network"],
            zoneid=self.zone.id,
            networkofferingid=self.network_offering.id)

        vms = []
        for i in range(0, number):
            self.services["virtual_machine"]["zoneid"] = self.zone.id
            self.services["virtual_machine"]["template"] = self.template.id
            self.services["virtual_machine"]["displayname"] = 'vm' + str(i)
            self.services["virtual_machine"]["hypervisor"] = self.hypervisor
            vm = VirtualMachine.create(
                self.apiclient,
                self.services["virtual_machine"],
                serviceofferingid=self.service_offering.id,
                networkids=self.l2_network.id,
                hostid=hostId)
            vms.append(vm)
            self.cleanup.append(vm)
            self.logger.debug("VM create = {}".format(vm.id))
        self.cleanup.append(self.l2_network)
        self.cleanup.append(self.network_offering)
        self.cleanup.append(self.service_offering)
        return vms
Esempio n. 6
0
    def setUpClass(cls):
        testClient = super(TestUnmanageVM, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        cls.hypervisor = testClient.getHypervisorInfo()
        cls._cleanup = []

        # 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
        cls.template = get_suitable_test_template(cls.apiclient, cls.zone.id,
                                                  cls.services["ostype"],
                                                  cls.hypervisor)
        if cls.template == FAILED:
            assert False, "get_suitable_test_template() failed to return template with description %s" % cls.services[
                "ostype"]

        cls.hypervisorNotSupported = cls.hypervisor.lower() != "vmware"

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

        cls.account = Account.create(cls.apiclient,
                                     cls.services["account"],
                                     domainid=cls.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.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')
Esempio n. 7
0
    def setUp(self):

        if self.testClient.getHypervisorInfo().lower() != "vmware":
            raise unittest.SkipTest(
                "VMWare tests only valid on VMWare hypervisor")

        self.services = self.testClient.getParsedTestDataConfig()
        self.apiclient = self.testClient.getApiClient()
        self.dbclient = self.testClient.getDbConnection()
        self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
        self.domain = get_domain(self.apiclient)
        self.services['mode'] = self.zone.networktype
        self.hypervisor = self.hypervisor = self.testClient.getHypervisorInfo()

        template = get_suitable_test_template(self.apiclient, self.zone.id,
                                              self.services["ostype"],
                                              self.hypervisor)

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

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

        self.services["small"]["zoneid"] = self.zone.id
        self.services["small"]["template"] = template.id

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

        iso = Iso.create(self.apiclient,
                         self.services["iso1"],
                         account=self.account.name,
                         domainid=self.account.domainid)

        self.cleanup = [self.account]
Esempio n. 8
0
    def setUpClass(cls):
        testClient = super(TestVolumes, 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
        #for LXC if the storage pool of type 'rbd' ex: ceph is not available, skip the test
        if cls.hypervisor.lower() == 'lxc':
            if not find_storage_pool_type(cls.apiclient, storagetype='rbd'):
                # RBD storage type is required for data volumes for LXC
                cls.invalidStoragePoolType = True
                return
        cls.disk_offering = DiskOffering.create(
                                    cls.apiclient,
                                    cls.services["disk_offering"]
                                    )
        cls.resized_disk_offering = DiskOffering.create(
                                    cls.apiclient,
                                    cls.services["resized_disk_offering"]
                                    )
        cls.custom_resized_disk_offering = DiskOffering.create(
                                    cls.apiclient,
                                    cls.services["resized_disk_offering"],
                                    custom=True
                                    )

        cls.template = get_suitable_test_template(
            cls.apiclient,
            cls.zone.id,
            cls.services["ostype"],
            cls.hypervisor
        )
        if cls.template == FAILED:
            assert False, "get_suitable_test_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"] = cls.template.id
        cls.services["diskofferingid"] = cls.disk_offering.id
        cls.services['resizeddiskofferingid'] = cls.resized_disk_offering.id
        cls.services['customresizeddiskofferingid'] = cls.custom_resized_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_offerings"]["tiny"]
                                        )
        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"]
                                )
        pools = StoragePool.list(cls.apiclient)
        # cls.assertEqual(
        #         validateList(pools)[0],
        #         PASS,
        #         "storage pool list validation failed")



        if cls.hypervisor.lower() == 'lxc' and cls.storage_pools.type.lower() != 'rbd':
            raise unittest.SkipTest("Snapshots not supported on Hyper-V or LXC")
        cls.volume = Volume.create(
                                   cls.apiclient,
                                   cls.services,
                                   account=cls.account.name,
                                   domainid=cls.account.domainid
                                   )
        cls._cleanup = [
                        cls.resized_disk_offering,
                        cls.custom_resized_disk_offering,
                        cls.service_offering,
                        cls.disk_offering,
                        cls.volume,
                        cls.account
                        ]
Esempio n. 9
0
    def setUp(self):
        self.cleanup = []
        self.logger = logging.getLogger('TestNIC')
        self.stream_handler = logging.StreamHandler()
        self.logger.setLevel(logging.DEBUG)
        self.logger.addHandler(self.stream_handler)

        def signal_handler(signal, frame):
            self.tearDown()
            sys.exit(0)

        # assign the signal handler immediately
        signal.signal(signal.SIGINT, signal_handler)

        self.hypervisor = self.testClient.getHypervisorInfo()
        if self.hypervisor.lower() == "hyperv":
            self.skipTest("Not supported on Hyper-V")

        try:
            self.apiclient = self.testClient.getApiClient()
            self.dbclient = self.testClient.getDbConnection()
            self.services = self.testClient.getParsedTestDataConfig()

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

            # if local storage is enabled, alter the offerings to use
            # localstorage
            # this step is needed for devcloud
            if self.zone.localstorageenabled:
                self.services["service_offerings"]["tiny"][
                    "storagetype"] = 'local'
            template = get_suitable_test_template(self.apiclient, self.zone.id,
                                                  self.services["ostype"],
                                                  self.hypervisor)
            if template == FAILED:
                assert False, "get_suitable_test_template() failed to return template with description %s" % self.services[
                    "ostype"]
            # Set Zones and disk offerings
            self.services["small"]["zoneid"] = self.zone.id
            self.services["small"]["template"] = template.id

            self.services["iso1"]["zoneid"] = self.zone.id
            self.services["network"]["zoneid"] = self.zone.id

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

            self.service_offering = ServiceOffering.create(
                self.apiclient, self.services["service_offerings"]["tiny"])
            self.cleanup.insert(0, self.service_offering)

            ####################
            # Network offering
            self.network_offering = NetworkOffering.create(
                self.apiclient,
                self.services["network_offering"],
            )
            self.cleanup.insert(0, self.network_offering)
            self.network_offering.update(
                self.apiclient, state='Enabled')  # Enable Network offering
            self.services["network"][
                "networkoffering"] = self.network_offering.id

            self.network_offering_shared = NetworkOffering.create(
                self.apiclient,
                self.services["network_offering_shared"],
            )
            self.cleanup.insert(0, self.network_offering_shared)
            self.network_offering_shared.update(
                self.apiclient, state='Enabled')  # Enable Network offering
            self.services["network2"][
                "networkoffering"] = self.network_offering_shared.id

            ################
            # Test Network
            self.test_network = Network.create(
                self.apiclient,
                self.services["network"],
                self.account.name,
                self.account.domainid,
            )
            self.cleanup.insert(0, self.test_network)
            self.test_network2 = Network.create(
                self.apiclient,
                self.services["network2"],
                self.account.name,
                self.account.domainid,
                zoneid=self.services["network"]["zoneid"])
            self.cleanup.insert(0, self.test_network2)
        except Exception as ex:
            self.debug("Exception during NIC test SETUP!: " + str(ex))
Esempio n. 10
0
    def test_01_events_resource(self):
        """Test Events resources while doing some operation on VM, volume, template, account, etc

        # Validate the following
        # 1. Note start time
        # 2. Deploy VM for a new account
        # 3. Check resource id and resource type of all concerned events during the period
        """
        now = datetime.now()  # current date and time
        start_time = now.strftime("%Y-%m-%d %H:%M:%S")

        template = get_suitable_test_template(self.apiclient, self.zone.id,
                                              self.services["ostype"],
                                              self.hypervisor)
        if template == FAILED:
            self.fail(
                "get_suitable_test_template() failed to return template with description %s"
                % self.services["ostype"])

        self.disk_offering = DiskOffering.create(
            self.apiclient, self.services["disk_offering"])
        self.cleanup.append(self.disk_offering)
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offerings"]["tiny"])
        self.cleanup.append(self.service_offering)
        self.network_offering = NetworkOffering.create(
            self.apiclient,
            self.services["network_offering"],
        )
        self.network_offering.update(self.apiclient, state='Enabled')
        self.services["network"]["networkoffering"] = self.network_offering.id
        self.cleanup.append(self.network_offering)
        self.services["zoneid"] = self.zone.id
        self.services["template"] = template.id
        self.services["network"]["zoneid"] = self.zone.id

        domain1 = Domain.create(self.apiclient,
                                self.services["domain"],
                                parentdomainid=self.domain.id)
        self.services["domainid"] = domain1.id

        account = Account.create(self.apiclient,
                                 self.services["account"],
                                 domainid=domain1.id)

        account_network = Network.create(self.apiclient,
                                         self.services["network"],
                                         account.name, account.domainid)
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services,
            accountid=account.name,
            domainid=account.domainid,
            networkids=account_network.id,
            serviceofferingid=self.service_offering.id)
        volume = Volume.create(self.apiclient,
                               self.services,
                               zoneid=self.zone.id,
                               account=account.name,
                               domainid=account.domainid,
                               diskofferingid=self.disk_offering.id)
        virtual_machine.attach_volume(self.apiclient, volume)
        virtual_machine.stop(self.apiclient)
        account_network.restart(self.apiclient, cleanup=False)
        time.sleep(self.services["sleep"])
        virtual_machine.restore(self.apiclient)
        time.sleep(self.services["sleep"])
        virtual_machine.detach_volume(self.apiclient, volume)
        volume.delete(self.apiclient)
        ts = str(time.time())
        virtual_machine.update(self.apiclient, displayname=ts)
        virtual_machine.delete(self.apiclient)
        account_network.update(self.apiclient, name=account_network.name + ts)
        account_network.delete(self.apiclient)
        account.update(self.apiclient, newname=account.name + ts)
        account.disable(self.apiclient)
        account.delete(self.apiclient)
        domain1.delete(self.apiclient)

        cmd = listEvents.listEventsCmd()
        cmd.startdate = start_time
        cmd.listall = True
        events = self.apiclient.listEvents(cmd)
        self.assertEqual(isinstance(events, list), True,
                         "List Events response was not a valid list")
        self.assertNotEqual(len(events), 0,
                            "List Events returned an empty list")

        for event in events:
            if event.type.startswith("VM.") or (
                    event.type.startswith("NETWORK.")
                    and not event.type.startswith("NETWORK.ELEMENT")
            ) or event.type.startswith("VOLUME.") or event.type.startswith(
                    "ACCOUNT.") or event.type.startswith(
                        "DOMAIN.") or event.type.startswith("TEMPLATE."):
                if event.resourceid is None or event.resourcetype is None:
                    self.debug("Failed event:: %" % event)
                    self.fail(
                        "resourceid or resourcetype for the event not found!")
                else:
                    self.debug(
                        "Event %s at %s:: Resource Type: %s, Resource ID: %s" %
                        (event.type, event.created, event.resourcetype,
                         event.resourceid))