def test_03_update_security_group_with_existing_name(self):
        # Validate the following
        #
        # 1. Create a security groups with name "test"
        # 2. Create another security group
        # 3. Try to update the second security group to update its name to "test"
        # 4. Update security group should fail

        # Create security group
        security_group = SecurityGroup.create(
            self.apiclient,
            self.testdata["security_group"],
            account=self.account.name,
            domainid=self.account.domainid
        )
        self.debug("Created security group with ID: %s" % security_group.id)
        security_group_name = security_group.name

        # Make sure its created
        security_group_list = SecurityGroup.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            keyword=security_group_name
        )
        self.assertNotEqual(
            len(security_group_list),
            0,
            "Creating security group failed"
        )

        # Create another security group
        second_security_group = SecurityGroup.create(
            self.apiclient,
            self.testdata["security_group"],
            account=self.account.name,
            domainid=self.account.domainid
        )
        self.debug("Created security group with ID: %s" % second_security_group.id)

        # Make sure its created
        security_group_list = SecurityGroup.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            keyword=second_security_group.name
        )
        self.assertNotEqual(
            len(security_group_list),
            0,
            "Creating security group failed"
        )

        # Update the security group
        with self.assertRaises(Exception):
            cmd = updateSecurityGroup.updateSecurityGroupCmd()
            cmd.id = second_security_group.id
            cmd.name = security_group_name
            self.apiclient.updateSecurityGroup(cmd)
    def test_01_create_security_group(self):
        # Validate the following:
        #
        # 1. Create a new security group
        # 2. Update the security group with new name
        # 3. List the security group with new name as the keyword
        # 4. Make sure that the response is not empty

        security_group = SecurityGroup.create(
            self.apiclient,
            self.testdata["security_group"],
            account=self.account.name,
            domainid=self.account.domainid
        )
        self.debug("Created security group with ID: %s" % security_group.id)

        initial_secgroup_name = security_group.name
        new_secgroup_name = "testing-update-security-group"

        cmd = updateSecurityGroup.updateSecurityGroupCmd()
        cmd.id = security_group.id
        cmd.name = new_secgroup_name
        self.apiclient.updateSecurityGroup(cmd)

        new_security_group = SecurityGroup.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            keyword=new_secgroup_name
        )
        self.assertNotEqual(
            len(new_security_group),
            0,
            "Update security group failed"
        )
Example #3
0
    def test_02_duplicate_security_group_name(self):
        # Validate the following
        #
        # 1. Create a security groups with name "test"
        # 2. Try to create another security group with name "test"
        # 3. Creation of second security group should fail

        security_group_name = "test"
        security_group = SecurityGroup.create(self.apiclient,
                                              {"name": security_group_name},
                                              account=self.account.name,
                                              domainid=self.account.domainid)
        self.debug("Created security group with name: %s" %
                   security_group.name)

        security_group_list = SecurityGroup.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            keyword=security_group.name)
        self.assertNotEqual(len(security_group_list), 0,
                            "Creating security group failed")

        # Need to use createSecurituGroupCmd since SecurityGroup.create
        # adds random string to security group name
        with self.assertRaises(Exception):
            cmd = createSecurityGroup.createSecurityGroupCmd()
            cmd.name = security_group.name
            cmd.account = self.account.name
            cmd.domainid = self.account.domainid
            self.apiclient.createSecurityGroup(cmd)
 def verify_security_group_rules(self, securitygroupid, numIngress, numEgress):
     security_groups = SecurityGroup.list(
         self.apiclient,
         account=self.account.name,
         domainid=self.account.domainid,
         id=securitygroupid
     )
     ingressrule = security_groups[0].ingressrule
     if len(ingressrule) != numIngress:
         raise Exception("Failed to verify ingress rule for security group %s" % security_groups[0].name)
     egressrule = security_groups[0].egressrule
     if len(egressrule) != numEgress:
         raise Exception("Failed to verify egress rule for security group %s" % security_groups[0].name)
    def test_08_security_group(self):
        """Test security groups in project
        """
        # Validate the following:
        # 1. Create a project
        # 2. Assign some security groups to that project
        # 3. Verify the security groups can only be assigned to VM belonging
        #    to that project.

        security_group = SecurityGroup.create(
            self.apiclient, self.services["security_group"], projectid=self.project.id
        )
        self.debug("Created security group with ID: %s" % security_group.id)
        # Default Security group should not have any ingress rule
        sercurity_groups = SecurityGroup.list(self.apiclient, projectid=self.project.id)
        self.assertEqual(isinstance(sercurity_groups, list), True, "Check for list security groups response")

        self.assertNotEqual(len(sercurity_groups), 0, "Check List Security groups response")
        # Authorize Security group to SSH to VM
        ingress_rule = security_group.authorize(
            self.apiclient, self.services["security_group"], projectid=self.project.id
        )
        self.assertEqual(isinstance(ingress_rule, dict), True, "Check ingress rule created properly")

        self.debug("Authorizing ingress rule for sec group ID: %s for ssh access" % security_group.id)
        self.virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["server"],
            serviceofferingid=self.service_offering.id,
            securitygroupids=[security_group.id],
            projectid=self.project.id,
        )
        self.debug("Deployed VM (ID: %s) in project: %s" % (self.virtual_machine.id, self.project.id))
        self.assertEqual(self.virtual_machine.state, "Running", "VM state should be running after deployment")
        # Deploy another VM with same security group outside the project
        self.debug("Deploying VM with security group: %s outside project:%s" % (security_group.id, self.project.id))
        with self.assertRaises(Exception):
            VirtualMachine.create(
                self.apiclient,
                self.services["server"],
                serviceofferingid=self.service_offering.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                securitygroupids=[security_group.id],
            )
        return
    def test_01_create_list_delete_security_group(self):
        """
        Test Security Group Creation,List,Deletion on a Basic
        """
        if self.zone.networktype!="Basic":
            self.skipTest("Security Group creation is applicable only with Basic zone setup. skipping")

        sg=SecurityGroup.create(self.user_api_client,
                                self.services("security_group")
                                )

        listsg=SecurityGroup.list(self.user_api_client,id=sg.id)

        if sg.name!=listsg[0].name:
            self.fail("Security Group is not created with specified details")

        sg.delete(self.user_api_client)

        return
    def test_01_create_list_delete_security_group(self):
        """
        Test Security Group Creation,List,Deletion on a Basic
        """
        if self.zone.networktype!="Basic":
            self.skipTest("Security Group creation is applicable only with Basic zone setup. skipping")

        sg=SecurityGroup.create(self.user_api_client,
                                self.services("security_group")
                                )

        listsg=SecurityGroup.list(self.user_api_client,id=sg.id)

        if sg.name!=listsg[0].name:
            self.fail("Security Group is not created with specified details")

        sg.delete(self.user_api_client)

        return
    def setUpCloudStack(cls):
        testClient = super(TestStoragePool, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        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 = None
        cls._cleanup = []

        zones = list_zones(cls.apiclient)

        for z in zones:
            if z.internaldns1 == cls.getClsConfig().mgtSvr[0].mgtSvrIp:
                cls.zone = z

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

        cls.account = cls.helper.create_account(cls.apiclient,
                                                cls.services["account"],
                                                accounttype=1,
                                                domainid=cls.domain.id,
                                                roleid=1)
        cls._cleanup.append(cls.account)

        securitygroup = SecurityGroup.list(cls.apiclient,
                                           account=cls.account.name,
                                           domainid=cls.account.domainid)[0]
        cls.helper.set_securityGroups(cls.apiclient,
                                      account=cls.account.name,
                                      domainid=cls.account.domainid,
                                      id=securitygroup.id)

        storpool_primary_storage = cls.testdata[TestData.primaryStorage]

        storpool_service_offerings = cls.testdata[TestData.serviceOffering]

        cls.template_name = storpool_primary_storage.get("name")

        storage_pool = list_storage_pools(cls.apiclient,
                                          name=cls.template_name)

        service_offerings = list_service_offering(cls.apiclient,
                                                  name=cls.template_name)

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

        disk_offering_20 = list_disk_offering(cls.apiclient, name="Medium")

        disk_offering_100 = list_disk_offering(cls.apiclient, name="Large")

        cls.disk_offerings = disk_offerings[0]
        cls.disk_offering_20 = disk_offering_20[0]
        cls.disk_offering_100 = disk_offering_100[0]
        cls.debug(pprint.pformat(storage_pool))
        if storage_pool is None:
            storage_pool = StoragePool.create(cls.apiclient,
                                              storpool_primary_storage)
        else:
            storage_pool = storage_pool[0]
        cls.storage_pool = storage_pool
        cls.debug(pprint.pformat(storage_pool))
        if service_offerings is None:
            service_offerings = ServiceOffering.create(
                cls.apiclient, storpool_service_offerings)
        else:
            service_offerings = service_offerings[0]
        #The version of CentOS has to be supported
        template = get_template(cls.apiclient, cls.zone.id, account="system")

        cls.debug(pprint.pformat(template))
        cls.debug(pprint.pformat(cls.hypervisor))

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

        cls.service_offering = service_offerings
        cls.debug(pprint.pformat(cls.service_offering))

        cls.local_cluster = cls.helper.get_local_cluster(cls.apiclient,
                                                         zoneid=cls.zone.id)
        cls.host = cls.helper.list_hosts_by_cluster_id(cls.apiclient,
                                                       cls.local_cluster.id)

        cls.remote_cluster = cls.helper.get_remote_cluster(cls.apiclient,
                                                           zoneid=cls.zone.id)
        cls.host_remote = cls.helper.list_hosts_by_cluster_id(
            cls.apiclient, cls.remote_cluster.id)

        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
        cls.services["diskofferingid"] = cls.disk_offerings.id

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

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

        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=cls.zone.id,
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            hostid=cls.host[0].id,
            rootdisksize=10)
        cls.virtual_machine2 = VirtualMachine.create(
            cls.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=cls.zone.id,
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            hostid=cls.host[0].id,
            rootdisksize=10)
        cls.virtual_machine3 = VirtualMachine.create(
            cls.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=cls.zone.id,
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            hostid=cls.host[0].id,
            rootdisksize=10)
        cls.template = template
        cls.random_data_0 = random_gen(size=100)
        cls.test_dir = "/tmp"
        cls.random_data = "random.data"

        return
    def test_03_securitygroups_authorize_revoke_egress(self):
        """
        @Desc: Test to Authorize and Revoke Egress for Security Group
        @steps:
        Step1: Listing all the Security Groups for a user
        Step2: Verifying that list size is 1
        Step3: Creating a Security Groups
        Step4: Listing all the Security Groups again for a user
        Step5: Verifying that list size is 2
        Step6: Authorizing Egress for the security group created in step3
        Step7: Listing the security groups by passing id of security group created in step3
        Step8: Verifying that list size is 1
        Step9: Verifying that Egress is authorized to the security group
        Step10: Verifying the details of the Egress rule are as expected
        Step11: Revoking Egress for the security group created in step3
        Step12: Listing the security groups by passing id of security group created in step3
        Step13: Verifying that list size is 1
        Step14: Verifying that Egress is revoked from the security group
        """
        # Listing all the Security Groups for a User
        list_securitygroups_before = SecurityGroup.list(
            self.userapiclient, listall=self.services["listall"])
        # Verifying that default security group is created
        status = validateList(list_securitygroups_before)
        self.assertEqual(PASS, status[0],
                         "Default Security Groups creation failed")
        # Verifying the size of the list is 1
        self.assertEqual(1, len(list_securitygroups_before),
                         "Count of Security Groups list is not matching")
        # Creating a security group
        securitygroup_created = SecurityGroup.create(
            self.userapiclient,
            self.services["security_group"],
            account=self.account.name,
            domainid=self.domain.id,
            description=self.services["security_group"]["name"])
        self.assertIsNotNone(securitygroup_created,
                             "Security Group creation failed")
        self.cleanup.append(securitygroup_created)

        # Listing all the security groups for user again
        list_securitygroups_after = SecurityGroup.list(
            self.userapiclient, listall=self.services["listall"])
        status = validateList(list_securitygroups_after)
        self.assertEqual(PASS, status[0], "Security Groups creation failed")
        # Verifying that list size is 2
        self.assertEqual(2, len(list_securitygroups_after),
                         "Failed to create Security Group")
        # Authorizing Egress for the security group created in step3
        securitygroup_created.authorizeEgress(
            self.userapiclient,
            self.services["ingress_rule"],
            self.account.name,
            self.domain.id,
        )
        # Listing the security group by Id
        list_securitygroups_byid = SecurityGroup.list(
            self.userapiclient,
            listall=self.services["listall"],
            id=securitygroup_created.id,
            domainid=self.domain.id)
        # Verifying that security group is listed
        status = validateList(list_securitygroups_byid)
        self.assertEqual(PASS, status[0],
                         "Listing of Security Groups by id failed")
        # Verifying size of the list is 1
        self.assertEqual(
            1, len(list_securitygroups_byid),
            "Count of the listing security group by id is not matching")
        securitygroup_egress = list_securitygroups_byid[0].egressrule
        # Validating the Ingress rule
        status = validateList(securitygroup_egress)
        self.assertEqual(PASS, status[0],
                         "Security Groups Egress rule authorization failed")
        self.assertEqual(1, len(securitygroup_egress),
                         "Security Group Egress rules count is not matching")
        # Verifying the details of the Egress rule are as expected
        #Creating expected and actual values dictionaries
        expected_dict = {
            "cidr": self.services["ingress_rule"]["cidrlist"],
            "protocol": self.services["ingress_rule"]["protocol"],
            "startport": self.services["ingress_rule"]["startport"],
            "endport": self.services["ingress_rule"]["endport"],
        }
        actual_dict = {
            "cidr": str(securitygroup_egress[0].cidr),
            "protocol": str(securitygroup_egress[0].protocol.upper()),
            "startport": str(securitygroup_egress[0].startport),
            "endport": str(securitygroup_egress[0].endport),
        }
        ingress_status = self.__verify_values(expected_dict, actual_dict)
        self.assertEqual(
            True, ingress_status,
            "Listed Security group Egress rule details are not as expected")
        # Revoking the Egress rule from Security Group
        securitygroup_created.revokeEgress(self.userapiclient,
                                           securitygroup_egress[0].ruleid)
        # Listing the security group by Id
        list_securitygroups_byid = SecurityGroup.list(
            self.userapiclient,
            listall=self.services["listall"],
            id=securitygroup_created.id,
            domainid=self.domain.id)
        # Verifying that security group is listed
        status = validateList(list_securitygroups_byid)
        self.assertEqual(PASS, status[0],
                         "Listing of Security Groups by id failed")
        # Verifying size of the list is 1
        self.assertEqual(
            1, len(list_securitygroups_byid),
            "Count of the listing security group by id is not matching")
        securitygroup_egress = list_securitygroups_byid[0].egressrule
        # Verifying that Ingress rule is empty(revoked)
        status = validateList(securitygroup_egress)
        self.assertEqual(EMPTY_LIST, status[2],
                         "Security Groups Egress rule is not revoked")
        return
    def test_01_list_securitygroups_pagination(self):
        """
        @Desc: Test to List Security Groups pagination
        @steps:
        Step1: Listing all the Security Groups for a user
        Step2: Verifying that list size is 1
        Step3: Creating (page size) number of Security Groups
        Step4: Listing all the Security Groups again for a user
        Step5: Verifying that list size is (page size + 1)
        Step6: Listing all the Security Groups in page1
        Step7: Verifying that list size is (page size)
        Step8: Listing all the Security Groups in page2
        Step9: Verifying that list size is 1
        Step10: Deleting the Security Group present in page 2
        Step11: Listing all the Security Groups in page2
        Step12: Verifying that no security groups are listed
        """
        # Listing all the Security Groups for a User
        list_securitygroups_before = SecurityGroup.list(
            self.userapiclient, listall=self.services["listall"])
        # Verifying that default security group is created
        status = validateList(list_securitygroups_before)
        self.assertEqual(PASS, status[0],
                         "Default Security Groups creation failed")
        # Verifying the size of the list is 1
        self.assertEqual(1, len(list_securitygroups_before),
                         "Count of Security Groups list is not matching")
        # Creating pagesize number of security groups
        for i in range(0, (self.services["pagesize"])):
            securitygroup_created = SecurityGroup.create(
                self.userapiclient,
                self.services["security_group"],
                account=self.account.name,
                domainid=self.domain.id,
                description=self.services["security_group"]["name"])
            self.assertIsNotNone(securitygroup_created,
                                 "Security Group creation failed")
            if (i < self.services["pagesize"]):
                self.cleanup.append(securitygroup_created)

        # Listing all the security groups for user again
        list_securitygroups_after = SecurityGroup.list(
            self.userapiclient, listall=self.services["listall"])
        status = validateList(list_securitygroups_after)
        self.assertEqual(PASS, status[0], "Security Groups creation failed")
        # Verifying that list size is pagesize + 1
        self.assertEqual(
            self.services["pagesize"] + 1, len(list_securitygroups_after),
            "Failed to create pagesize + 1 number of Security Groups")
        # Listing all the security groups in page 1
        list_securitygroups_page1 = SecurityGroup.list(
            self.userapiclient,
            listall=self.services["listall"],
            page=1,
            pagesize=self.services["pagesize"])
        status = validateList(list_securitygroups_page1)
        self.assertEqual(PASS, status[0],
                         "Failed to list security groups in page 1")
        # Verifying the list size to be equal to pagesize
        self.assertEqual(self.services["pagesize"],
                         len(list_securitygroups_page1),
                         "Size of security groups in page 1 is not matching")
        # Listing all the security groups in page 2
        list_securitygroups_page2 = SecurityGroup.list(
            self.userapiclient,
            listall=self.services["listall"],
            page=2,
            pagesize=self.services["pagesize"])
        status = validateList(list_securitygroups_page2)
        self.assertEqual(PASS, status[0],
                         "Failed to list security groups in page 2")
        # Verifying the list size to be equal to pagesize
        self.assertEqual(1, len(list_securitygroups_page2),
                         "Size of security groups in page 2 is not matching")
        # Deleting the security group present in page 2
        SecurityGroup.delete(securitygroup_created, self.userapiclient)
        self.cleanup.remove(securitygroup_created)
        # Listing all the security groups in page 2 again
        list_securitygroups_page2 = SecurityGroup.list(
            self.userapiclient,
            listall=self.services["listall"],
            page=2,
            pagesize=self.services["pagesize"])
        # Verifying that there are no security groups listed
        self.assertIsNone(list_securitygroups_page2,
                          "Security Groups not deleted from page 2")
        return
    def setUpCloudStack(cls):
        cls.spapi = spapi.Api.fromConfig(multiCluster=True)
        testClient = super(TestMigrateVMWithVolumes, 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 = None

        zones = list_zones(cls.apiclient)

        for z in zones:
            if z.internaldns1 == cls.getClsConfig().mgtSvr[0].mgtSvrIp:
                cls.zone = z

        td = TestData()
        cls.testdata = td.testdata
        cls.helper = StorPoolHelper()
        storpool_primary_storage = cls.testdata[TestData.primaryStorage]
        cls.template_name = storpool_primary_storage.get("name")
        storpool_service_offerings = cls.testdata[TestData.serviceOffering]

        nfs_service_offerings = cls.testdata[TestData.serviceOfferingsPrimary]
        ceph_service_offerings = cls.testdata[TestData.serviceOfferingsCeph]

        nfs_disk_offerings = cls.testdata[TestData.nfsDiskOffering]
        ceph_disk_offerings = cls.testdata[TestData.cephDiskOffering]

        storage_pool = list_storage_pools(cls.apiclient,
                                          name=cls.template_name)

        nfs_storage_pool = list_storage_pools(cls.apiclient, name='primary')

        ceph_primary_storage = cls.testdata[TestData.primaryStorage4]

        cls.ceph_storage_pool = list_storage_pools(
            cls.apiclient, name=ceph_primary_storage.get("name"))[0]

        service_offerings = list_service_offering(cls.apiclient,
                                                  name=cls.template_name)
        nfs_service_offering = list_service_offering(cls.apiclient, name='nfs')

        ceph_service_offering = list_service_offering(
            cls.apiclient, name=ceph_primary_storage.get("name"))

        if storage_pool is None:
            storage_pool = StoragePool.create(cls.apiclient,
                                              storpool_primary_storage)
        else:
            storage_pool = storage_pool[0]
        cls.storage_pool = storage_pool
        cls.debug(pprint.pformat(storage_pool))
        if service_offerings is None:
            service_offerings = ServiceOffering.create(
                cls.apiclient, storpool_service_offerings)
        else:
            service_offerings = service_offerings[0]
        if nfs_service_offering is None:
            nfs_service_offering = ServiceOffering.create(
                cls.apiclient, nfs_service_offerings)
        else:
            nfs_service_offering = nfs_service_offering[0]

        if ceph_service_offering is None:
            ceph_service_offering = ServiceOffering.create(
                cls.apiclient, ceph_service_offerings)
        else:
            ceph_service_offering = ceph_service_offering[0]

        nfs_disk_offering = list_disk_offering(cls.apiclient, name="nfs")
        if nfs_disk_offering is None:
            nfs_disk_offering = DiskOffering.create(cls.apiclient,
                                                    nfs_disk_offerings)
        else:
            cls.nfs_disk_offering = nfs_disk_offering[0]

        ceph_disk_offering = list_disk_offering(cls.apiclient, name="ceph")
        if ceph_disk_offering is None:
            cls.ceph_disk_offering = DiskOffering.create(
                cls.apiclient, ceph_disk_offerings)
        else:
            cls.ceph_disk_offering = ceph_disk_offering[0]

        template = get_template(cls.apiclient, cls.zone.id, account="system")

        cls.nfs_storage_pool = nfs_storage_pool[0]
        if cls.nfs_storage_pool.state == "Maintenance":
            cls.nfs_storage_pool = StoragePool.cancelMaintenance(
                cls.apiclient, cls.nfs_storage_pool.id)

        if cls.ceph_storage_pool.state == "Maintenance":
            cls.ceph_storage_pool = StoragePool.cancelMaintenance(
                cls.apiclient, cls.ceph_storage_pool.id)

        cls.account = cls.helper.create_account(cls.apiclient,
                                                cls.services["account"],
                                                accounttype=1,
                                                domainid=cls.domain.id,
                                                roleid=1)
        cls._cleanup.append(cls.account)

        securitygroup = SecurityGroup.list(cls.apiclient,
                                           account=cls.account.name,
                                           domainid=cls.account.domainid)[0]
        cls.helper.set_securityGroups(cls.apiclient,
                                      account=cls.account.name,
                                      domainid=cls.account.domainid,
                                      id=securitygroup.id)

        cls.vm = VirtualMachine.create(
            cls.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=cls.zone.id,
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=nfs_service_offering.id,
            diskofferingid=cls.nfs_disk_offering.id,
            hypervisor=cls.hypervisor,
            rootdisksize=10)

        cls.vm2 = VirtualMachine.create(
            cls.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=cls.zone.id,
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=ceph_service_offering.id,
            diskofferingid=cls.ceph_disk_offering.id,
            hypervisor=cls.hypervisor,
            rootdisksize=10)

        cls.debug(pprint.pformat(template))
        cls.debug(pprint.pformat(cls.hypervisor))

        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["small"]["zoneid"] = cls.zone.id
        cls.services["templates"]["ostypeid"] = template.ostypeid
        cls.services["zoneid"] = cls.zone.id

        cls.service_offering = service_offerings
        cls.nfs_service_offering = nfs_service_offering
        cls.debug(pprint.pformat(cls.service_offering))

        cls.template = template
        cls.random_data_0 = random_gen(size=100)
        cls.test_dir = "/tmp"
        cls.random_data = "random.data"
        return
Example #12
0
    def setUpCloudStack(cls):
        testClient = super(TestVmSnapshot, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls._cleanup = []
        cls.unsupportedHypervisor = False

        # Setup test data
        td = TestData()
        cls.testdata = td.testdata
        cls.helper = StorPoolHelper()


        cls.services = testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = None
        zones = list_zones(cls.apiclient)

        for z in zones:
            if z.name == cls.getClsConfig().mgtSvr[0].zone:
                cls.zone = z

        assert cls.zone is not None

        cls.cluster = list_clusters(cls.apiclient)[0]
        cls.hypervisor = get_hypervisor_type(cls.apiclient)

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


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

        cls.template = template

        cls.account = cls.helper.create_account(
                            cls.apiclient,
                            cls.services["account"],
                            accounttype = 1,
                            domainid=cls.domain.id,
                            roleid = 1
                            )
        cls._cleanup.append(cls.account)

        securitygroup = SecurityGroup.list(cls.apiclient, account = cls.account.name, domainid= cls.account.domainid)[0]
        cls.helper.set_securityGroups(cls.apiclient, account = cls.account.name, domainid= cls.account.domainid, id = securitygroup.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="ssd"
            )

        assert disk_offering is not None


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

        cls.disk_offering = disk_offering[0]

        # Create 1 data volume_1
        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,
            size=10
        )

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

        cls.random_data_0 = random_gen(size=100)
        cls.test_dir = "/tmp"
        cls.random_data = "random.data"
        return
Example #13
0
    def setUpCloudStack(cls):
        cls._cleanup = []

        cls.spapi = spapi.Api.fromConfig(multiCluster=True)
        testClient = super(TestResizeVolumes, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        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 = None

        zones = list_zones(cls.apiclient)

        for z in zones:
            if z.internaldns1 == cls.getClsConfig().mgtSvr[0].mgtSvrIp:
                cls.zone = z

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

        storpool_primary_storage = cls.testdata[TestData.primaryStorage]

        cls.template_name = storpool_primary_storage.get("name")

        storpool_service_offerings = cls.testdata[TestData.serviceOfferingsIops]

        storpool_disk_offerings = {
            "name": "iops",
            "displaytext": "Testing IOPS on StorPool",
            "customizediops": True,
            "storagetype": "shared",
            "tags" : cls.template_name,
            }

        storage_pool = list_storage_pools(
            cls.apiclient,
            name = cls.template_name
            )

        service_offerings = list_service_offering(
            cls.apiclient,
            name='iops'
            )

        disk_offerings = list_disk_offering(
            cls.apiclient,
            name="iops"
            )

        if disk_offerings is None:
            disk_offerings = DiskOffering.create(cls.apiclient, storpool_disk_offerings, custom = True)
        else:
            disk_offerings = disk_offerings[0]
        cls.disk_offerings = disk_offerings
        if storage_pool is None:
            storage_pool = StoragePool.create(cls.apiclient, storpool_primary_storage)
        else:
            storage_pool = storage_pool[0]
        cls.storage_pool = storage_pool
        cls.debug(pprint.pformat(storage_pool))
        if service_offerings is None:
            service_offerings = ServiceOffering.create(cls.apiclient, storpool_service_offerings)
        else:
            service_offerings = service_offerings[0]

        template = get_template(
             cls.apiclient,
            cls.zone.id,
            account = "system"
        )

        cls.debug(pprint.pformat(template))
        cls.debug(pprint.pformat(cls.hypervisor))

        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["small"]["zoneid"] = cls.zone.id
        cls.services["templates"]["ostypeid"] = template.ostypeid
        cls.services["zoneid"] = cls.zone.id

        cls.account = cls.helper.create_account(
                            cls.apiclient,
                            cls.services["account"],
                            accounttype = 1,
                            domainid=cls.domain.id,
                            )
        cls._cleanup.append(cls.account)

        securitygroup = SecurityGroup.list(cls.apiclient, account = cls.account.name, domainid= cls.account.domainid)[0]
        cls.helper.set_securityGroups(cls.apiclient, account = cls.account.name, domainid= cls.account.domainid, id = securitygroup.id)

        cls.service_offering = service_offerings
        cls.debug(pprint.pformat(cls.service_offering))

        cls.local_cluster = cls.helper.get_local_cluster(cls.apiclient, zoneid = cls.zone.id)
        cls.host = cls.helper.list_hosts_by_cluster_id(cls.apiclient, cls.local_cluster.id)

        assert len(cls.host) > 1, "Hosts list is less than 1"
        cls.host_on_local_1 = cls.host[0]
        cls.host_on_local_2 = cls.host[1]

        cls.remote_cluster = cls.helper.get_remote_cluster(cls.apiclient, zoneid = cls.zone.id)
        cls.host_remote = cls.helper.list_hosts_by_cluster_id(cls.apiclient, cls.remote_cluster.id)
        assert len(cls.host_remote) > 1, "Hosts list is less than 1"

        cls.host_on_remote1 = cls.host_remote[0]
        cls.host_on_remote2 = cls.host_remote[1]

        cls.volume_1 = cls.helper.create_custom_disk(
            cls.apiclient,
            {"diskname":"StorPoolDisk" },
            zoneid=cls.zone.id,
            size = 5,
            miniops = 2000,
            maxiops = 5000,
            account=cls.account.name,
            domainid=cls.account.domainid,
            diskofferingid=cls.disk_offerings.id,
        )
        cls.volume_2 = cls.helper.create_custom_disk(
            cls.apiclient,
            {"diskname":"StorPoolDisk" },
            zoneid=cls.zone.id,
            size = 5,
            miniops = 2000,
            maxiops = 5000,
            account=cls.account.name,
            domainid=cls.account.domainid,
            diskofferingid=cls.disk_offerings.id,
        )
        cls.volume = cls.helper.create_custom_disk(
            cls.apiclient,
            {"diskname":"StorPoolDisk" },
            zoneid=cls.zone.id,
            size = 5,
            miniops = 2000,
            maxiops = 5000,
            account=cls.account.name,
            domainid=cls.account.domainid,
            diskofferingid=cls.disk_offerings.id,
        )
        cls.virtual_machine = cls.helper.create_vm_custom(
            cls.apiclient,
            {"name":"StorPool-%s" % uuid.uuid4() },
            zoneid=cls.zone.id,
            templateid=template.id,
            account=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            minIops = 1000,
            maxIops = 5000,
            rootdisksize = 10
        )
        cls.virtual_machine2= cls.helper.create_vm_custom(
            cls.apiclient,
            {"name":"StorPool-%s" % uuid.uuid4() },
            zoneid=cls.zone.id,
            templateid=template.id,
            account=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            minIops = 1000,
            maxIops = 5000,
            rootdisksize = 10
        )

        cls.virtual_machine_live_migration_1 = cls.helper.create_vm_custom(
            cls.apiclient,
            {"name":"StorPool-%s" % uuid.uuid4() },
            zoneid=cls.zone.id,
            templateid=template.id,
            account=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            minIops = 1000,
            maxIops = 5000,
            hostid = cls.host_on_local_1.id,
            rootdisksize = 10
        )
        cls.virtual_machine_live_migration_2= cls.helper.create_vm_custom(
            cls.apiclient,
            {"name":"StorPool-%s" % uuid.uuid4() },
            zoneid=cls.zone.id,
            templateid=template.id,
            account=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            minIops = 1000,
            maxIops = 5000,
            hostid = cls.host_on_remote1.id,
            rootdisksize = 10
        )

        cls.template = template
        cls.random_data_0 = random_gen(size=100)
        cls.test_dir = "/tmp"
        cls.random_data = "random.data"
        return
    def test_01_list_securitygroups_pagination(self):
        """
        @Desc: Test to List Security Groups pagination
        @steps:
        Step1: Listing all the Security Groups for a user
        Step2: Verifying that list size is 1
        Step3: Creating (page size) number of Security Groups
        Step4: Listing all the Security Groups again for a user
        Step5: Verifying that list size is (page size + 1)
        Step6: Listing all the Security Groups in page1
        Step7: Verifying that list size is (page size)
        Step8: Listing all the Security Groups in page2
        Step9: Verifying that list size is 1
        Step10: Deleting the Security Group present in page 2
        Step11: Listing all the Security Groups in page2
        Step12: Verifying that no security groups are listed
        """
        # Listing all the Security Groups for a User
        list_securitygroups_before = SecurityGroup.list(self.userapiclient, listall=self.services["listall"])
        # Verifying that default security group is created
        status = validateList(list_securitygroups_before)
        self.assertEquals(PASS, status[0], "Default Security Groups creation failed")
        # Verifying the size of the list is 1
        self.assertEquals(1, len(list_securitygroups_before), "Count of Security Groups list is not matching")
        # Creating pagesize number of security groups
        for i in range(0, (self.services["pagesize"])):
            securitygroup_created = SecurityGroup.create(
                self.userapiclient,
                self.services["security_group"],
                account=self.account.name,
                domainid=self.domain.id,
                description=self.services["security_group"]["name"],
            )
            self.assertIsNotNone(securitygroup_created, "Security Group creation failed")
            if i < self.services["pagesize"]:
                self.cleanup.append(securitygroup_created)

        # Listing all the security groups for user again
        list_securitygroups_after = SecurityGroup.list(self.userapiclient, listall=self.services["listall"])
        status = validateList(list_securitygroups_after)
        self.assertEquals(PASS, status[0], "Security Groups creation failed")
        # Verifying that list size is pagesize + 1
        self.assertEquals(
            self.services["pagesize"] + 1,
            len(list_securitygroups_after),
            "Failed to create pagesize + 1 number of Security Groups",
        )
        # Listing all the security groups in page 1
        list_securitygroups_page1 = SecurityGroup.list(
            self.userapiclient, listall=self.services["listall"], page=1, pagesize=self.services["pagesize"]
        )
        status = validateList(list_securitygroups_page1)
        self.assertEquals(PASS, status[0], "Failed to list security groups in page 1")
        # Verifying the list size to be equal to pagesize
        self.assertEquals(
            self.services["pagesize"],
            len(list_securitygroups_page1),
            "Size of security groups in page 1 is not matching",
        )
        # Listing all the security groups in page 2
        list_securitygroups_page2 = SecurityGroup.list(
            self.userapiclient, listall=self.services["listall"], page=2, pagesize=self.services["pagesize"]
        )
        status = validateList(list_securitygroups_page2)
        self.assertEquals(PASS, status[0], "Failed to list security groups in page 2")
        # Verifying the list size to be equal to pagesize
        self.assertEquals(1, len(list_securitygroups_page2), "Size of security groups in page 2 is not matching")
        # Deleting the security group present in page 2
        SecurityGroup.delete(securitygroup_created, self.userapiclient)
        self.cleanup.remove(securitygroup_created)
        # Listing all the security groups in page 2 again
        list_securitygroups_page2 = SecurityGroup.list(
            self.userapiclient, listall=self.services["listall"], page=2, pagesize=self.services["pagesize"]
        )
        # Verifying that there are no security groups listed
        self.assertIsNone(list_securitygroups_page2, "Security Groups not deleted from page 2")
        return
    def test_03_securitygroups_authorize_revoke_egress(self):
        """
        @Desc: Test to Authorize and Revoke Egress for Security Group
        @steps:
        Step1: Listing all the Security Groups for a user
        Step2: Verifying that list size is 1
        Step3: Creating a Security Groups
        Step4: Listing all the Security Groups again for a user
        Step5: Verifying that list size is 2
        Step6: Authorizing Egress for the security group created in step3
        Step7: Listing the security groups by passing id of security group created in step3
        Step8: Verifying that list size is 1
        Step9: Verifying that Egress is authorized to the security group
        Step10: Verifying the details of the Egress rule are as expected
        Step11: Revoking Egress for the security group created in step3
        Step12: Listing the security groups by passing id of security group created in step3
        Step13: Verifying that list size is 1
        Step14: Verifying that Egress is revoked from the security group
        """
        # Listing all the Security Groups for a User
        list_securitygroups_before = SecurityGroup.list(self.userapiclient, listall=self.services["listall"])
        # Verifying that default security group is created
        status = validateList(list_securitygroups_before)
        self.assertEquals(PASS, status[0], "Default Security Groups creation failed")
        # Verifying the size of the list is 1
        self.assertEquals(1, len(list_securitygroups_before), "Count of Security Groups list is not matching")
        # Creating a security group
        securitygroup_created = SecurityGroup.create(
            self.userapiclient,
            self.services["security_group"],
            account=self.account.name,
            domainid=self.domain.id,
            description=self.services["security_group"]["name"],
        )
        self.assertIsNotNone(securitygroup_created, "Security Group creation failed")
        self.cleanup.append(securitygroup_created)

        # Listing all the security groups for user again
        list_securitygroups_after = SecurityGroup.list(self.userapiclient, listall=self.services["listall"])
        status = validateList(list_securitygroups_after)
        self.assertEquals(PASS, status[0], "Security Groups creation failed")
        # Verifying that list size is 2
        self.assertEquals(2, len(list_securitygroups_after), "Failed to create Security Group")
        # Authorizing Egress for the security group created in step3
        securitygroup_created.authorizeEgress(
            self.userapiclient, self.services["ingress_rule"], self.account.name, self.domain.id
        )
        # Listing the security group by Id
        list_securitygroups_byid = SecurityGroup.list(
            self.userapiclient, listall=self.services["listall"], id=securitygroup_created.id, domainid=self.domain.id
        )
        # Verifying that security group is listed
        status = validateList(list_securitygroups_byid)
        self.assertEquals(PASS, status[0], "Listing of Security Groups by id failed")
        # Verifying size of the list is 1
        self.assertEquals(1, len(list_securitygroups_byid), "Count of the listing security group by id is not matching")
        securitygroup_egress = list_securitygroups_byid[0].egressrule
        # Validating the Ingress rule
        status = validateList(securitygroup_egress)
        self.assertEquals(PASS, status[0], "Security Groups Egress rule authorization failed")
        self.assertEquals(1, len(securitygroup_egress), "Security Group Egress rules count is not matching")
        # Verifying the details of the Egress rule are as expected
        # Creating expected and actual values dictionaries
        expected_dict = {
            "cidr": self.services["ingress_rule"]["cidrlist"],
            "protocol": self.services["ingress_rule"]["protocol"],
            "startport": self.services["ingress_rule"]["startport"],
            "endport": self.services["ingress_rule"]["endport"],
        }
        actual_dict = {
            "cidr": str(securitygroup_egress[0].cidr),
            "protocol": str(securitygroup_egress[0].protocol.upper()),
            "startport": str(securitygroup_egress[0].startport),
            "endport": str(securitygroup_egress[0].endport),
        }
        ingress_status = self.__verify_values(expected_dict, actual_dict)
        self.assertEqual(True, ingress_status, "Listed Security group Egress rule details are not as expected")
        # Revoking the Egress rule from Security Group
        securitygroup_created.revokeEgress(self.userapiclient, securitygroup_egress[0].ruleid)
        # Listing the security group by Id
        list_securitygroups_byid = SecurityGroup.list(
            self.userapiclient, listall=self.services["listall"], id=securitygroup_created.id, domainid=self.domain.id
        )
        # Verifying that security group is listed
        status = validateList(list_securitygroups_byid)
        self.assertEquals(PASS, status[0], "Listing of Security Groups by id failed")
        # Verifying size of the list is 1
        self.assertEquals(1, len(list_securitygroups_byid), "Count of the listing security group by id is not matching")
        securitygroup_egress = list_securitygroups_byid[0].egressrule
        # Verifying that Ingress rule is empty(revoked)
        status = validateList(securitygroup_egress)
        self.assertEquals(EMPTY_LIST, status[2], "Security Groups Egress rule is not revoked")
        return
Example #16
0
    def setUpCloudStack(cls):
        cls._cleanup = []
        cls.spapi = spapi.Api.fromConfig(multiCluster=True)

        testClient = super(TestStoragePool, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        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 = None

        zones = list_zones(cls.apiclient)

        for z in zones:
            if z.internaldns1 == cls.getClsConfig().mgtSvr[0].mgtSvrIp:
                cls.zone = z

        cls.debug("##################### zone %s" % cls.zone)
        td = TestData()
        cls.testdata = td.testdata
        cls.helper = StorPoolHelper()

        storpool_primary_storage = {
            "name": "ssd",
            TestData.scope: "ZONE",
            "url": "ssd",
            TestData.provider: "StorPool",
            "path": "/dev/storpool",
            TestData.capacityBytes: 2251799813685248,
            TestData.hypervisor: "KVM"
        }

        storpool_without_qos = {
            "name": "ssd",
            "displaytext": "ssd",
            "cpunumber": 1,
            "cpuspeed": 500,
            "memory": 512,
            "storagetype": "shared",
            "customizediops": False,
            "hypervisorsnapshotreserve": 200,
            "tags": "ssd"
        }

        storpool_qos_template = {
            "name": "qos",
            "displaytext": "qos",
            "cpunumber": 1,
            "cpuspeed": 500,
            "memory": 512,
            "storagetype": "shared",
            "customizediops": False,
            "hypervisorsnapshotreserve": 200,
            "tags": "ssd"
        }

        disk_offering_ssd = {
            "name": "ssd",
            "displaytext": "SP_DO_1 (5GB Min IOPS = 300; Max IOPS = 500)",
            "disksize": 10,
            "customizediops": False,
            "hypervisorsnapshotreserve": 200,
            TestData.tags: "ssd",
            "storagetype": "shared"
        }

        disk_offering_qos = {
            "name": "qos",
            "displaytext": "SP_DO_1 (5GB Min IOPS = 300; Max IOPS = 500)",
            "disksize": 10,
            "customizediops": False,
            "hypervisorsnapshotreserve": 200,
            TestData.tags: "ssd",
            "storagetype": "shared"
        }

        cls.template_name = storpool_primary_storage.get("name")

        cls.template_name_2 = "qos"

        storage_pool = list_storage_pools(cls.apiclient, name="ssd")
        cls.primary_storage = storage_pool[0]

        if storage_pool is None:
            storage_pool = StoragePool.create(cls.apiclient,
                                              storpool_primary_storage)
        else:
            storage_pool = storage_pool[0]
        cls.storage_pool = storage_pool
        cls.debug(pprint.pformat(storage_pool))

        service_offerings_ssd = list_service_offering(cls.apiclient,
                                                      name=cls.template_name)

        service_offerings_qos = list_service_offering(cls.apiclient,
                                                      name=cls.template_name_2)

        if service_offerings_ssd is None:
            service_offerings_ssd = ServiceOffering.create(
                cls.apiclient, storpool_without_qos)
        else:
            service_offerings_ssd = service_offerings_ssd[0]

        if service_offerings_qos is None:
            service_offerings_qos = ServiceOffering.create(
                cls.apiclient, storpool_qos_template)
            ResourceDetails.create(cls.apiclient,
                                   resourceid=service_offerings_qos.id,
                                   resourcetype="ServiceOffering",
                                   details={"SP_TEMPLATE": "qos"},
                                   fordisplay=True)

        else:
            service_offerings_qos = service_offerings_qos[0]

        cls.service_offering_ssd = service_offerings_ssd
        cls.service_offering_qos = service_offerings_qos

        cls.disk_offering_ssd = list_disk_offering(cls.apiclient,
                                                   name=cls.template_name)
        cls.disk_offering_qos = list_disk_offering(cls.apiclient,
                                                   name=cls.template_name_2)

        if cls.disk_offering_ssd is None:
            cls.disk_offering_ssd = DiskOffering.create(
                cls.apiclient, disk_offering_ssd)
        else:
            cls.disk_offering_ssd = cls.disk_offering_ssd[0]

        if cls.disk_offering_qos is None:
            cls.disk_offering_qos = DiskOffering.create(
                cls.apiclient, disk_offering_qos)
            ResourceDetails.create(cls.apiclient,
                                   resourceid=cls.disk_offering_qos.id,
                                   resourcetype="DiskOffering",
                                   details={"SP_TEMPLATE": "qos"},
                                   fordisplay=True)
        else:
            cls.disk_offering_qos = cls.disk_offering_qos[0]

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

        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["small"]["zoneid"] = cls.zone.id
        cls.services["templates"]["ostypeid"] = template.ostypeid
        cls.services["zoneid"] = cls.zone.id
        cls.services["diskofferingid"] = cls.disk_offering_ssd.id

        cls.account = cls.helper.create_account(cls.apiclient,
                                                cls.services["account"],
                                                accounttype=1,
                                                domainid=cls.domain.id,
                                                roleid=1)
        cls._cleanup.append(cls.account)

        securitygroup = SecurityGroup.list(cls.apiclient,
                                           account=cls.account.name,
                                           domainid=cls.account.domainid)[0]
        cls.helper.set_securityGroups(cls.apiclient,
                                      account=cls.account.name,
                                      domainid=cls.account.domainid,
                                      id=securitygroup.id)

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

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

        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=cls.zone.id,
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering_ssd.id,
            hypervisor=cls.hypervisor,
            rootdisksize=10)
        cls.virtual_machine.attach_volume(cls.apiclient, cls.volume_1)

        cls.virtual_machine.attach_volume(cls.apiclient, cls.volume_2)

        cls.template = template
        cls.hostid = cls.virtual_machine.hostid

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