def _verify_no_basic_volume_details(self):
        sql_query = "Select id From volume_details Where name like 'basic_'"

        # make sure you can connect to MySQL: https://teamtreehouse.com/community/cant-connect-remotely-to-mysql-server-with-mysql-workbench
        sql_result = self.dbConnection.execute(sql_query)

        sf_util.check_list(sql_result, 0, self, "The cloud.volume_details table should not have any name fields that start with 'basic_'.")
    def _get_only_volume(self, virtual_machine_id):
        list_volumes_response = list_volumes(
            self.apiClient, virtualmachineid=virtual_machine_id, listall=True)

        sf_util.check_list(
            list_volumes_response, 1, self, TestOnlineStorageMigration.
            _should_only_be_one_volume_in_list_err_msg)

        return list_volumes_response[0]
    def _verify_no_basic_volume_details(self):
        sql_query = "Select id From volume_details Where name like 'basic_'"

        # make sure you can connect to MySQL: https://teamtreehouse.com/community/cant-connect-remotely-to-mysql-server-with-mysql-workbench
        sql_result = self.dbConnection.execute(sql_query)

        sf_util.check_list(
            sql_result, 0, self,
            "The cloud.volume_details table should not have any name fields that start with 'basic_'."
        )
    def _verify_different_volume_access_groups(self, src_sf_volume, dest_sf_volume):
        src_vags = src_sf_volume.volume_access_groups

        sf_util.check_list(src_vags, 1, self, "'src_vags' should be a list with only one element in it.")

        dest_vags = dest_sf_volume.volume_access_groups

        sf_util.check_list(dest_vags, 1, self, "'dest_vags' should be a list with only one element in it.")

        self.assertNotEqual(src_vags[0], dest_vags[0], "The source and destination volumes should not be in the same volume access group.")
예제 #5
0
    def _check_and_get_cs_volume(self, volume_id, volume_name):
        list_volumes_response = list_volumes(self.apiClient, id=volume_id)

        sf_util.check_list(list_volumes_response, 1, self, TestVolumes._should_only_be_one_volume_in_list_err_msg)

        cs_volume = list_volumes_response[0]

        self._check_volume(cs_volume, volume_name)

        return cs_volume
예제 #6
0
    def _verify_vm_snapshot(self, list_vm_snapshots, vm_snapshot):
        sf_util.check_list(
            list_vm_snapshots, 1, self,
            TestVMSnapshots._should_only_be_one_vm_snapshot_err_msg)

        vm_snapshot_from_list = list_vm_snapshots[0]

        self.assertEqual(vm_snapshot.id, vm_snapshot_from_list.id,
                         "There is a problem with the VM snapshot ID.")

        self.assertEqual(
            vm_snapshot.virtualmachineid, self.virtual_machine.id,
            "The ID of the snapshot's virtual machine does not match the expected virtual machine."
        )

        self.assertEqual(vm_snapshot.state, "Ready",
                         "The snapshot is not in the 'Ready' state.")
    def _verify_different_volume_access_groups(self, src_sf_volume,
                                               dest_sf_volume):
        src_vags = src_sf_volume.volume_access_groups

        sf_util.check_list(
            src_vags, 1, self,
            "'src_vags' should be a list with only one element in it.")

        dest_vags = dest_sf_volume.volume_access_groups

        sf_util.check_list(
            dest_vags, 1, self,
            "'dest_vags' should be a list with only one element in it.")

        self.assertNotEqual(
            src_vags[0], dest_vags[0],
            "The source and destination volumes should not be in the same volume access group."
        )
예제 #8
0
    def _verify_vm_snapshot(self, list_vm_snapshots, vm_snapshot):
        sf_util.check_list(list_vm_snapshots, 1, self, TestVMSnapshots._should_only_be_one_vm_snapshot_err_msg)

        vm_snapshot_from_list = list_vm_snapshots[0]

        self.assertEqual(
            vm_snapshot.id,
            vm_snapshot_from_list.id,
            "There is a problem with the VM snapshot ID."
        )

        self.assertEqual(
            vm_snapshot.virtualmachineid,
            self.virtual_machine.id,
            "The ID of the snapshot's virtual machine does not match the expected virtual machine."
        )

        self.assertEqual(
            vm_snapshot.state,
            "Ready",
            "The snapshot is not in the 'Ready' state."
        )
예제 #9
0
    def test_01_upload_and_download_snapshot(self):
        list_volumes_response = list_volumes(
            self.apiClient,
            virtualmachineid=self.virtual_machine.id,
            listall=True
        )

        sf_util.check_list(list_volumes_response, 1, self, "There should only be one volume in this list.")

        vm_root_volume = list_volumes_response[0]

        ### Perform tests related to uploading a QCOW2 file to secondary storage and then moving it to managed storage

        volume_name = "Volume-A"
        services = {"format": TestData.file_type, "diskname": volume_name}

        uploaded_volume = Volume.upload(self.apiClient, services, self.zone.id,
                                        account=self.account.name, domainid=self.account.domainid,
                                        url=TestData.volume_url, diskofferingid=self.disk_offering.id)

        self._wait_for_volume_state(uploaded_volume.id, "Uploaded")

        uploaded_volume_id = sf_util.get_cs_volume_db_id(self.dbConnection, uploaded_volume)

        result = self._get_volume_store_ref_row(uploaded_volume_id)

        self.assertEqual(
            len(result),
            1,
            TestUploadDownload.assertText
        )

        install_path = self._get_install_path(result[0][TestData.install_path_index])

        self._verify_uploaded_volume_present(install_path)

        uploaded_volume = self.virtual_machine.attach_volume(
            self.apiClient,
            uploaded_volume
        )

        uploaded_volume = sf_util.check_and_get_cs_volume(self, uploaded_volume.id, volume_name, self)

        sf_account_id = sf_util.get_sf_account_id(self.cs_api, self.account.id, self.primary_storage.id, self, "The SolidFire account ID should be a non-zero integer.")

        sf_volumes = sf_util.get_active_sf_volumes(self.sfe, sf_account_id)

        self.assertNotEqual(
            len(sf_volumes),
            0,
            "The length of the response for the SolidFire-volume query should not be zero."
        )

        sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, uploaded_volume.name, self)

        sf_volume_size = sf_util.get_volume_size_with_hsr(self.cs_api, uploaded_volume, self)

        sf_util.check_size_and_iops(sf_volume, uploaded_volume, sf_volume_size, self)

        sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id, self.primary_storage.id, self)

        sf_util.check_vag(sf_volume, sf_vag_id, self)

        result = self._get_volume_store_ref_row(uploaded_volume_id)

        self.assertEqual(
            len(result),
            0,
            TestUploadDownload.assertText2
        )

        self._verify_uploaded_volume_not_present(install_path)

        ### Perform tests related to extracting the contents of a volume on managed storage to a QCOW2 file
        ### and downloading the file

        try:
            # for data disk
            Volume.extract(self.apiClient, uploaded_volume.id, self.zone.id, TestData.download_mode)

            raise Exception("The volume extraction (for the data disk) did not fail (as expected).")
        except Exception as e:
            if TestUploadDownload.errorText in str(e):
                pass
            else:
                raise

        vm_root_volume_id = sf_util.get_cs_volume_db_id(self.dbConnection, vm_root_volume)

        try:
            # for root disk
            Volume.extract(self.apiClient, vm_root_volume.id, self.zone.id, TestData.download_mode)

            raise Exception("The volume extraction (for the root disk) did not fail (as expected).")
        except Exception as e:
            if TestUploadDownload.errorText in str(e):
                pass
            else:
                raise

        self.virtual_machine.stop(self.apiClient)

        self._extract_volume_and_verify(uploaded_volume_id, "Unable to locate the extracted file for the data disk (attached)")

        result = self._get_volume_store_ref_row(vm_root_volume_id)

        self.assertEqual(
            len(result),
            0,
            TestUploadDownload.assertText2
        )

        self._extract_volume_and_verify(vm_root_volume_id, "Unable to locate the extracted file for the root disk")

        uploaded_volume = self.virtual_machine.detach_volume(
            self.apiClient,
            uploaded_volume
        )

        self._extract_volume_and_verify(uploaded_volume_id, "Unable to locate the extracted file for the data disk (detached)")

        uploaded_volume = Volume(uploaded_volume.__dict__)

        uploaded_volume.delete(self.apiClient)
예제 #10
0
    def test_02_take_VM_snapshot_with_data_disk(self):
        self.virtual_machine.start(self.apiClient)

        data_volume = Volume.create(self.apiClient,
                                    self.testdata[TestData.volume_1],
                                    account=self.account.name,
                                    domainid=self.domain.id,
                                    zoneid=self.zone.id,
                                    diskofferingid=self.disk_offering.id)

        self.cleanup = [data_volume]

        self.virtual_machine.attach_volume(self.apiClient, data_volume)

        root_volumes = list_volumes(self.apiClient,
                                    type="ROOT",
                                    listAll="true")

        sf_util.check_list(
            root_volumes, 1, self,
            TestVMSnapshots._should_only_be_one_root_volume_err_msg)

        root_volume = root_volumes[0]

        root_volume_id = {'volumeid': root_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(root_volume_id)
        sf_iscsi_root_volume_name = sf_iscsi_name_result['apivolumeiscsiname'][
            'volumeiScsiName']

        sf_util.check_iscsi_name(sf_iscsi_root_volume_name, self)

        root_volume_path_1 = self._get_path(root_volume_id)

        data_volumes = list_volumes(self.apiClient,
                                    type="DATADISK",
                                    listAll="true")

        sf_util.check_list(data_volumes, 1, self,
                           "There should only be one data volume.")

        data_volume = data_volumes[0]

        data_volume_id = {'volumeid': data_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(data_volume_id)
        sf_iscsi_data_volume_name = sf_iscsi_name_result['apivolumeiscsiname'][
            'volumeiScsiName']

        sf_util.check_iscsi_name(sf_iscsi_data_volume_name, self)

        data_volume_path_1 = self._get_path(data_volume_id)

        #######################################
        #######################################
        # STEP 1: Take snapshot of running VM #
        #######################################
        #######################################
        vm_snapshot = VmSnapshot.create(self.apiClient,
                                        vmid=self.virtual_machine.id,
                                        snapshotmemory="false",
                                        name="Test Snapshot",
                                        description="Test Snapshot Desc")

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._verify_vm_snapshot(list_vm_snapshots, vm_snapshot)

        root_volume_path_2 = self._get_path(root_volume_id)

        self.assertEqual(root_volume_path_1, root_volume_path_2,
                         TestVMSnapshots._path_should_not_have_changed_err_msg)

        data_volume_path_2 = self._get_path(data_volume_id)

        self.assertEqual(data_volume_path_1, data_volume_path_2,
                         TestVMSnapshots._path_should_not_have_changed_err_msg)

        root_volume_xen_sr = self.xen_session.xenapi.SR.get_by_name_label(
            sf_iscsi_root_volume_name)[0]

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(
            root_volume_xen_sr)

        sf_util.check_list(root_volume_xen_vdis, 3, self,
                           TestVMSnapshots._should_be_three_vdis_err_msg)

        root_volume_vdis_after_create = self._get_vdis(root_volume_xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(
            root_volume_vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(vdiSnapshotOf["uuid"],
                         root_volume_vdis_after_create.active_vdi["uuid"],
                         TestVMSnapshots._snapshot_parent_not_correct_err_msg)

        data_volume_xen_sr = self.xen_session.xenapi.SR.get_by_name_label(
            sf_iscsi_data_volume_name)[0]

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(
            data_volume_xen_sr)

        sf_util.check_list(data_volume_xen_vdis, 3, self,
                           TestVMSnapshots._should_be_three_vdis_err_msg)

        data_volume_vdis_after_create = self._get_vdis(data_volume_xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(
            data_volume_vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(vdiSnapshotOf["uuid"],
                         data_volume_vdis_after_create.active_vdi["uuid"],
                         TestVMSnapshots._snapshot_parent_not_correct_err_msg)

        #######################################
        #######################################
        ###  STEP 2: Revert VM to Snapshot  ###
        #######################################
        #######################################
        self.virtual_machine.stop(self.apiClient)

        VmSnapshot.revertToSnapshot(self.apiClient,
                                    vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        sf_util.check_list(
            list_vm_snapshots, 1, self,
            TestVMSnapshots._should_only_be_one_vm_snapshot_err_msg)

        root_volume_path_3 = self._get_path(root_volume_id)

        self.assertNotEqual(root_volume_path_1, root_volume_path_3,
                            TestVMSnapshots._path_should_have_changed_err_msg)

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(
            root_volume_xen_sr)

        sf_util.check_list(root_volume_xen_vdis, 3, self,
                           TestVMSnapshots._should_be_three_vdis_err_msg)

        root_volume_vdis_after_revert = self._get_vdis(root_volume_xen_vdis)

        self.assertNotEqual(
            root_volume_vdis_after_create.active_vdi["uuid"],
            root_volume_vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg)

        self.assertEqual(
            root_volume_vdis_after_create.snapshot_vdi["uuid"],
            root_volume_vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg)

        self.assertEqual(root_volume_vdis_after_create.base_vdi["uuid"],
                         root_volume_vdis_after_revert.base_vdi["uuid"],
                         TestVMSnapshots._base_vdis_should_be_the_same_err_msg)

        data_volume_path_3 = self._get_path(data_volume_id)

        self.assertNotEqual(data_volume_path_1, data_volume_path_3,
                            TestVMSnapshots._path_should_have_changed_err_msg)

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(
            data_volume_xen_sr)

        sf_util.check_list(data_volume_xen_vdis, 3, self,
                           TestVMSnapshots._should_be_three_vdis_err_msg)

        data_volume_vdis_after_revert = self._get_vdis(data_volume_xen_vdis)

        self.assertNotEqual(
            data_volume_vdis_after_create.active_vdi["uuid"],
            data_volume_vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg)

        self.assertEqual(
            data_volume_vdis_after_create.snapshot_vdi["uuid"],
            data_volume_vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg)

        self.assertEqual(data_volume_vdis_after_create.base_vdi["uuid"],
                         data_volume_vdis_after_revert.base_vdi["uuid"],
                         TestVMSnapshots._base_vdis_should_be_the_same_err_msg)

        #######################################
        #######################################
        ##### STEP 3: Delete VM snapshot  #####
        #######################################
        #######################################
        VmSnapshot.deleteVMSnapshot(self.apiClient,
                                    vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self.assertEqual(list_vm_snapshots, None,
                         TestVMSnapshots._should_be_no_vm_snapshots_err_msg)

        root_volume_path_4 = self._get_path(root_volume_id)

        self.assertEqual(root_volume_path_3, root_volume_path_4,
                         TestVMSnapshots._path_should_not_have_changed_err_msg)

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(
            root_volume_xen_sr)

        sf_util.check_list(root_volume_xen_vdis, 1, self,
                           TestVMSnapshots._should_only_be_one_vdi_err_msg)

        root_volume_vdis_after_delete = self._get_vdis(root_volume_xen_vdis,
                                                       True)

        self.assertEqual(
            root_volume_vdis_after_revert.active_vdi["uuid"],
            root_volume_vdis_after_delete.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_be_the_same_err_msg)

        data_volume_path_4 = self._get_path(data_volume_id)

        self.assertEqual(data_volume_path_3, data_volume_path_4,
                         TestVMSnapshots._path_should_not_have_changed_err_msg)

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(
            data_volume_xen_sr)

        sf_util.check_list(data_volume_xen_vdis, 1, self,
                           TestVMSnapshots._should_only_be_one_vdi_err_msg)

        data_volume_vdis_after_delete = self._get_vdis(data_volume_xen_vdis,
                                                       True)

        self.assertEqual(
            data_volume_vdis_after_revert.active_vdi["uuid"],
            data_volume_vdis_after_delete.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_be_the_same_err_msg)

        #######################################
        #######################################
        #####      STEP 4: Start VM       #####
        #######################################
        #######################################
        self.virtual_machine.detach_volume(self.apiClient, data_volume)

        self.virtual_machine.start(self.apiClient)
예제 #11
0
    def test_01_take_VM_snapshot(self):
        self.virtual_machine.start(self.apiClient)

        root_volumes = list_volumes(self.apiClient,
                                    type="ROOT",
                                    listAll="true")

        sf_util.check_list(
            root_volumes, 1, self,
            TestVMSnapshots._should_only_be_one_root_volume_err_msg)

        root_volume = root_volumes[0]

        volume_id = {'volumeid': root_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(volume_id)
        sf_iscsi_name = sf_iscsi_name_result['apivolumeiscsiname'][
            'volumeiScsiName']

        sf_util.check_iscsi_name(sf_iscsi_name, self)

        root_volume_path_1 = self._get_path(volume_id)

        #######################################
        #######################################
        # STEP 1: Take snapshot of running VM #
        #######################################
        #######################################
        vm_snapshot = VmSnapshot.create(self.apiClient,
                                        vmid=self.virtual_machine.id,
                                        snapshotmemory="false",
                                        name="Test Snapshot",
                                        description="Test Snapshot Desc")

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._verify_vm_snapshot(list_vm_snapshots, vm_snapshot)

        root_volume_path_2 = self._get_path(volume_id)

        self.assertEqual(root_volume_path_1, root_volume_path_2,
                         TestVMSnapshots._path_should_not_have_changed_err_msg)

        xen_sr = self.xen_session.xenapi.SR.get_by_name_label(sf_iscsi_name)[0]

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        sf_util.check_list(xen_vdis, 3, self,
                           TestVMSnapshots._should_be_three_vdis_err_msg)

        vdis_after_create = self._get_vdis(xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(
            vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(vdiSnapshotOf["uuid"],
                         vdis_after_create.active_vdi["uuid"],
                         TestVMSnapshots._snapshot_parent_not_correct_err_msg)

        #######################################
        #######################################
        ###  STEP 2: Revert VM to Snapshot  ###
        #######################################
        #######################################
        self.virtual_machine.stop(self.apiClient)

        VmSnapshot.revertToSnapshot(self.apiClient,
                                    vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        sf_util.check_list(
            list_vm_snapshots, 1, self,
            TestVMSnapshots._should_only_be_one_vm_snapshot_err_msg)

        root_volume_path_3 = self._get_path(volume_id)

        self.assertNotEqual(root_volume_path_1, root_volume_path_3,
                            TestVMSnapshots._path_should_have_changed_err_msg)

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        sf_util.check_list(xen_vdis, 3, self,
                           TestVMSnapshots._should_be_three_vdis_err_msg)

        vdis_after_revert = self._get_vdis(xen_vdis)

        self.assertNotEqual(
            vdis_after_create.active_vdi["uuid"],
            vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg)

        self.assertEqual(
            vdis_after_create.snapshot_vdi["uuid"],
            vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg)

        self.assertEqual(vdis_after_create.base_vdi["uuid"],
                         vdis_after_revert.base_vdi["uuid"],
                         TestVMSnapshots._base_vdis_should_be_the_same_err_msg)

        #######################################
        #######################################
        ##### STEP 3: Delete VM snapshot  #####
        #######################################
        #######################################
        VmSnapshot.deleteVMSnapshot(self.apiClient,
                                    vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self.assertEqual(list_vm_snapshots, None,
                         TestVMSnapshots._should_be_no_vm_snapshots_err_msg)

        root_volume_path_4 = self._get_path(volume_id)

        self.assertEqual(root_volume_path_3, root_volume_path_4,
                         TestVMSnapshots._path_should_not_have_changed_err_msg)

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        sf_util.check_list(xen_vdis, 1, self,
                           TestVMSnapshots._should_only_be_one_vdi_err_msg)

        vdis_after_delete = self._get_vdis(xen_vdis, True)

        self.assertEqual(
            vdis_after_revert.active_vdi["uuid"],
            vdis_after_delete.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_be_the_same_err_msg)

        #######################################
        #######################################
        #####      STEP 4: Start VM       #####
        #######################################
        #######################################
        self.virtual_machine.start(self.apiClient)
    def test_managed_clustered_filesystems_limit(self):
        args = {
            "id": self.testdata[TestData.clusterId2],
            TestData.allocationstate: "Disabled"
        }

        Cluster.update(self.apiClient, **args)

        virtual_machine_names = {"name": "TestVM1", "displayname": "Test VM 1"}

        virtual_machine_1 = self._create_vm(virtual_machine_names)

        list_volumes_response = list_volumes(
            self.apiClient,
            virtualmachineid=virtual_machine_1.id,
            listall=True)

        sf_util.check_list(
            list_volumes_response, 1, self, TestManagedClusteredFilesystems.
            _should_only_be_one_volume_in_list_err_msg)

        vm_1_root_volume = list_volumes_response[0]

        virtual_machine_names = {"name": "TestVM2", "displayname": "Test VM 2"}

        virtual_machine_2 = self._create_vm(virtual_machine_names)

        virtual_machine_names = {"name": "TestVM3", "displayname": "Test VM 3"}

        class VMStartedException(Exception):
            def __init__(self, *args, **kwargs):
                Exception.__init__(self, *args, **kwargs)

        try:
            # The VM should fail to be created as there should be an insufficient number of clustered filesystems
            # remaining in the compute cluster.
            self._create_vm(virtual_machine_names)

            raise VMStartedException("The VM should have failed to start.")
        except VMStartedException:
            raise
        except Exception:
            pass

        vol_snap = Snapshot.create(self.apiClient,
                                   volume_id=vm_1_root_volume.id)

        services = {
            "diskname": "Vol-1",
            "zoneid": self.testdata[TestData.zoneId],
            "ispublic": True
        }

        volume_created_from_snapshot_1 = Volume.create_from_snapshot(
            self.apiClient,
            vol_snap.id,
            services,
            account=self.account.name,
            domainid=self.domain.id)

        class VolumeAttachedException(Exception):
            def __init__(self, *args, **kwargs):
                Exception.__init__(self, *args, **kwargs)

        try:
            # The volume should fail to be attached as there should be an insufficient number of clustered filesystems
            # remaining in the compute cluster.
            virtual_machine_2.attach_volume(self.apiClient,
                                            volume_created_from_snapshot_1)

            raise VolumeAttachedException(
                TestManagedClusteredFilesystems.
                _volume_should_have_failed_to_attach_to_vm)
        except VolumeAttachedException:
            raise
        except Exception:
            pass

        args = {
            "id": self.testdata[TestData.clusterId2],
            TestData.allocationstate: "Enabled"
        }

        Cluster.update(self.apiClient, **args)

        try:
            # The volume should fail to be attached as there should be an insufficient number of clustered filesystems
            # remaining in the compute cluster.
            virtual_machine_2.attach_volume(self.apiClient,
                                            volume_created_from_snapshot_1)

            raise VolumeAttachedException(
                TestManagedClusteredFilesystems.
                _volume_should_have_failed_to_attach_to_vm)
        except VolumeAttachedException:
            raise
        except Exception:
            pass

        virtual_machine_names = {"name": "TestVMA", "displayname": "Test VM A"}

        virtual_machine_a = self._create_vm(virtual_machine_names)

        host_for_vm_1 = list_hosts(self.apiClient,
                                   id=virtual_machine_1.hostid)[0]
        host_for_vm_a = list_hosts(self.apiClient,
                                   id=virtual_machine_a.hostid)[0]

        self.assertTrue(host_for_vm_1.clusterid != host_for_vm_a.clusterid,
                        "VMs 1 and VM a should be in different clusters.")

        virtual_machine_1.delete(self.apiClient, True)

        volume_created_from_snapshot_1 = virtual_machine_2.attach_volume(
            self.apiClient, volume_created_from_snapshot_1)

        virtual_machine_2.detach_volume(self.apiClient,
                                        volume_created_from_snapshot_1)

        volume_created_from_snapshot_1 = virtual_machine_2.attach_volume(
            self.apiClient, volume_created_from_snapshot_1)

        services = {
            "diskname": "Vol-2",
            "zoneid": self.testdata[TestData.zoneId],
            "ispublic": True
        }

        volume_created_from_snapshot_2 = Volume.create_from_snapshot(
            self.apiClient,
            vol_snap.id,
            services,
            account=self.account.name,
            domainid=self.domain.id)

        try:
            # The volume should fail to be attached as there should be an insufficient number of clustered filesystems
            # remaining in the compute cluster.
            virtual_machine_2.attach_volume(self.apiClient,
                                            volume_created_from_snapshot_2)

            raise VolumeAttachedException(
                TestManagedClusteredFilesystems.
                _volume_should_have_failed_to_attach_to_vm)
        except VolumeAttachedException:
            raise
        except Exception:
            pass

        virtual_machine_a.attach_volume(self.apiClient,
                                        volume_created_from_snapshot_2)
예제 #13
0
    def _verify_no_active_solidfire_volumes(self):
        sf_active_volumes = sf_util.get_active_sf_volumes(self.sfe)

        sf_util.check_list(sf_active_volumes, 0, self, "There should be no active SolidFire volumes in the cluster.")
예제 #14
0
    def test_01_take_VM_snapshot(self):
        self.virtual_machine.start(self.apiClient)

        root_volumes = list_volumes(self.apiClient, type="ROOT", listAll="true")

        sf_util.check_list(root_volumes, 1, self, TestVMSnapshots._should_only_be_one_root_volume_err_msg)

        root_volume = root_volumes[0]

        volume_id = {'volumeid': root_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(volume_id)
        sf_iscsi_name = sf_iscsi_name_result['apivolumeiscsiname']['volumeiScsiName']

        sf_util.check_iscsi_name(sf_iscsi_name, self)

        root_volume_path_1 = self._get_path(volume_id)

        #######################################
        #######################################
        # STEP 1: Take snapshot of running VM #
        #######################################
        #######################################
        vm_snapshot = VmSnapshot.create(
            self.apiClient,
            vmid=self.virtual_machine.id,
            snapshotmemory="false",
            name="Test Snapshot",
            description="Test Snapshot Desc"
        )

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._verify_vm_snapshot(list_vm_snapshots, vm_snapshot)

        root_volume_path_2 = self._get_path(volume_id)

        self.assertEqual(
            root_volume_path_1,
            root_volume_path_2,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        xen_sr = self.xen_session.xenapi.SR.get_by_name_label(sf_iscsi_name)[0]

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        sf_util.check_list(xen_vdis, 3, self, TestVMSnapshots._should_be_three_vdis_err_msg)

        vdis_after_create = self._get_vdis(xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(
            vdiSnapshotOf["uuid"],
            vdis_after_create.active_vdi["uuid"],
            TestVMSnapshots._snapshot_parent_not_correct_err_msg
        )

        #######################################
        #######################################
        ###  STEP 2: Revert VM to Snapshot  ###
        #######################################
        #######################################
        self.virtual_machine.stop(self.apiClient)

        VmSnapshot.revertToSnapshot(self.apiClient, vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        sf_util.check_list(list_vm_snapshots, 1, self, TestVMSnapshots._should_only_be_one_vm_snapshot_err_msg)

        root_volume_path_3 = self._get_path(volume_id)

        self.assertNotEqual(
            root_volume_path_1,
            root_volume_path_3,
            TestVMSnapshots._path_should_have_changed_err_msg
        )

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        sf_util.check_list(xen_vdis, 3, self, TestVMSnapshots._should_be_three_vdis_err_msg)

        vdis_after_revert = self._get_vdis(xen_vdis)

        self.assertNotEqual(
            vdis_after_create.active_vdi["uuid"],
            vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg
        )

        self.assertEqual(
            vdis_after_create.snapshot_vdi["uuid"],
            vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg
        )

        self.assertEqual(
            vdis_after_create.base_vdi["uuid"],
            vdis_after_revert.base_vdi["uuid"],
            TestVMSnapshots._base_vdis_should_be_the_same_err_msg
        )

        #######################################
        #######################################
        ##### STEP 3: Delete VM snapshot  #####
        #######################################
        #######################################
        VmSnapshot.deleteVMSnapshot(self.apiClient, vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self.assertEqual(
            list_vm_snapshots,
            None,
            TestVMSnapshots._should_be_no_vm_snapshots_err_msg
        )

        root_volume_path_4 = self._get_path(volume_id)

        self.assertEqual(
            root_volume_path_3,
            root_volume_path_4,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        sf_util.check_list(xen_vdis, 1, self, TestVMSnapshots._should_only_be_one_vdi_err_msg)

        vdis_after_delete = self._get_vdis(xen_vdis, True)

        self.assertEqual(
            vdis_after_revert.active_vdi["uuid"],
            vdis_after_delete.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_be_the_same_err_msg
        )

        #######################################
        #######################################
        #####      STEP 4: Start VM       #####
        #######################################
        #######################################
        self.virtual_machine.start(self.apiClient)
예제 #15
0
    def _get_vm(self, vm_id):
        list_vms_response = list_virtual_machines(self.apiClient, id=vm_id)

        sf_util.check_list(list_vms_response, 1, self, TestVolumes._should_only_be_one_vm_in_list_err_msg)

        return list_vms_response[0]
    def test_01_upload_and_download_snapshot(self):
        list_volumes_response = list_volumes(
            self.apiClient,
            virtualmachineid=self.virtual_machine.id,
            listall=True)

        sf_util.check_list(list_volumes_response, 1, self,
                           "There should only be one volume in this list.")

        vm_root_volume = list_volumes_response[0]

        ### Perform tests related to uploading a QCOW2 file to secondary storage and then moving it to managed storage

        volume_name = "Volume-A"
        services = {"format": TestData.file_type, "diskname": volume_name}

        uploaded_volume = Volume.upload(self.apiClient,
                                        services,
                                        self.zone.id,
                                        account=self.account.name,
                                        domainid=self.account.domainid,
                                        url=TestData.volume_url,
                                        diskofferingid=self.disk_offering.id)

        self._wait_for_volume_state(uploaded_volume.id, "Uploaded")

        uploaded_volume_id = sf_util.get_cs_volume_db_id(
            self.dbConnection, uploaded_volume)

        result = self._get_volume_store_ref_row(uploaded_volume_id)

        self.assertEqual(len(result), 1, TestUploadDownload.assertText)

        install_path = self._get_install_path(
            result[0][TestData.install_path_index])

        self._verify_uploaded_volume_present(install_path)

        uploaded_volume = self.virtual_machine.attach_volume(
            self.apiClient, uploaded_volume)

        uploaded_volume = sf_util.check_and_get_cs_volume(
            self, uploaded_volume.id, volume_name, self)

        sf_account_id = sf_util.get_sf_account_id(
            self.cs_api, self.account.id, self.primary_storage.id, self,
            "The SolidFire account ID should be a non-zero integer.")

        sf_volumes = sf_util.get_active_sf_volumes(self.sfe, sf_account_id)

        self.assertNotEqual(
            len(sf_volumes), 0,
            "The length of the response for the SolidFire-volume query should not be zero."
        )

        sf_volume = sf_util.check_and_get_sf_volume(sf_volumes,
                                                    uploaded_volume.name, self)

        sf_volume_size = sf_util.get_volume_size_with_hsr(
            self.cs_api, uploaded_volume, self)

        sf_util.check_size_and_iops(sf_volume, uploaded_volume, sf_volume_size,
                                    self)

        sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id,
                                       self.primary_storage.id, self)

        sf_util.check_vag(sf_volume, sf_vag_id, self)

        result = self._get_volume_store_ref_row(uploaded_volume_id)

        self.assertEqual(len(result), 0, TestUploadDownload.assertText2)

        self._verify_uploaded_volume_not_present(install_path)

        ### Perform tests related to extracting the contents of a volume on managed storage to a QCOW2 file
        ### and downloading the file

        try:
            # for data disk
            Volume.extract(self.apiClient, uploaded_volume.id, self.zone.id,
                           TestData.download_mode)

            raise Exception(
                "The volume extraction (for the data disk) did not fail (as expected)."
            )
        except Exception as e:
            if TestUploadDownload.errorText in str(e):
                pass
            else:
                raise

        vm_root_volume_id = sf_util.get_cs_volume_db_id(
            self.dbConnection, vm_root_volume)

        try:
            # for root disk
            Volume.extract(self.apiClient, vm_root_volume.id, self.zone.id,
                           TestData.download_mode)

            raise Exception(
                "The volume extraction (for the root disk) did not fail (as expected)."
            )
        except Exception as e:
            if TestUploadDownload.errorText in str(e):
                pass
            else:
                raise

        self.virtual_machine.stop(self.apiClient)

        self._extract_volume_and_verify(
            uploaded_volume_id,
            "Unable to locate the extracted file for the data disk (attached)")

        result = self._get_volume_store_ref_row(vm_root_volume_id)

        self.assertEqual(len(result), 0, TestUploadDownload.assertText2)

        self._extract_volume_and_verify(
            vm_root_volume_id,
            "Unable to locate the extracted file for the root disk")

        uploaded_volume = self.virtual_machine.detach_volume(
            self.apiClient, uploaded_volume)

        self._extract_volume_and_verify(
            uploaded_volume_id,
            "Unable to locate the extracted file for the data disk (detached)")

        uploaded_volume = Volume(uploaded_volume.__dict__)

        uploaded_volume.delete(self.apiClient)
예제 #17
0
    def test_02_take_VM_snapshot_with_data_disk(self):
        self.virtual_machine.start(self.apiClient)

        data_volume = Volume.create(
            self.apiClient,
            self.testdata[TestData.volume_1],
            account=self.account.name,
            domainid=self.domain.id,
            zoneid=self.zone.id,
            diskofferingid=self.disk_offering.id
        )

        self.cleanup = [data_volume]

        self.virtual_machine.attach_volume(self.apiClient, data_volume)

        root_volumes = list_volumes(self.apiClient, type="ROOT", listAll="true")

        sf_util.check_list(root_volumes, 1, self, TestVMSnapshots._should_only_be_one_root_volume_err_msg)

        root_volume = root_volumes[0]

        root_volume_id = {'volumeid': root_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(root_volume_id)
        sf_iscsi_root_volume_name = sf_iscsi_name_result['apivolumeiscsiname']['volumeiScsiName']

        sf_util.check_iscsi_name(sf_iscsi_root_volume_name, self)

        root_volume_path_1 = self._get_path(root_volume_id)

        data_volumes = list_volumes(self.apiClient, type="DATADISK", listAll="true")

        sf_util.check_list(data_volumes, 1, self, "There should only be one data volume.")

        data_volume = data_volumes[0]

        data_volume_id = {'volumeid': data_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(data_volume_id)
        sf_iscsi_data_volume_name = sf_iscsi_name_result['apivolumeiscsiname']['volumeiScsiName']

        sf_util.check_iscsi_name(sf_iscsi_data_volume_name, self)

        data_volume_path_1 = self._get_path(data_volume_id)

        #######################################
        #######################################
        # STEP 1: Take snapshot of running VM #
        #######################################
        #######################################
        vm_snapshot = VmSnapshot.create(
            self.apiClient,
            vmid=self.virtual_machine.id,
            snapshotmemory="false",
            name="Test Snapshot",
            description="Test Snapshot Desc"
        )

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._verify_vm_snapshot(list_vm_snapshots, vm_snapshot)

        root_volume_path_2 = self._get_path(root_volume_id)

        self.assertEqual(
            root_volume_path_1,
            root_volume_path_2,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        data_volume_path_2 = self._get_path(data_volume_id)

        self.assertEqual(
            data_volume_path_1,
            data_volume_path_2,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        root_volume_xen_sr = self.xen_session.xenapi.SR.get_by_name_label(sf_iscsi_root_volume_name)[0]

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(root_volume_xen_sr)

        sf_util.check_list(root_volume_xen_vdis, 3, self, TestVMSnapshots._should_be_three_vdis_err_msg)

        root_volume_vdis_after_create = self._get_vdis(root_volume_xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(root_volume_vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(
            vdiSnapshotOf["uuid"],
            root_volume_vdis_after_create.active_vdi["uuid"],
            TestVMSnapshots._snapshot_parent_not_correct_err_msg
        )

        data_volume_xen_sr = self.xen_session.xenapi.SR.get_by_name_label(sf_iscsi_data_volume_name)[0]

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(data_volume_xen_sr)

        sf_util.check_list(data_volume_xen_vdis, 3, self, TestVMSnapshots._should_be_three_vdis_err_msg)

        data_volume_vdis_after_create = self._get_vdis(data_volume_xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(data_volume_vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(
            vdiSnapshotOf["uuid"],
            data_volume_vdis_after_create.active_vdi["uuid"],
            TestVMSnapshots._snapshot_parent_not_correct_err_msg
        )

        #######################################
        #######################################
        ###  STEP 2: Revert VM to Snapshot  ###
        #######################################
        #######################################
        self.virtual_machine.stop(self.apiClient)

        VmSnapshot.revertToSnapshot(self.apiClient, vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        sf_util.check_list(list_vm_snapshots, 1, self, TestVMSnapshots._should_only_be_one_vm_snapshot_err_msg)

        root_volume_path_3 = self._get_path(root_volume_id)

        self.assertNotEqual(
            root_volume_path_1,
            root_volume_path_3,
            TestVMSnapshots._path_should_have_changed_err_msg
        )

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(root_volume_xen_sr)

        sf_util.check_list(root_volume_xen_vdis, 3, self, TestVMSnapshots._should_be_three_vdis_err_msg)

        root_volume_vdis_after_revert = self._get_vdis(root_volume_xen_vdis)

        self.assertNotEqual(
            root_volume_vdis_after_create.active_vdi["uuid"],
            root_volume_vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg
        )

        self.assertEqual(
            root_volume_vdis_after_create.snapshot_vdi["uuid"],
            root_volume_vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg
        )

        self.assertEqual(
            root_volume_vdis_after_create.base_vdi["uuid"],
            root_volume_vdis_after_revert.base_vdi["uuid"],
            TestVMSnapshots._base_vdis_should_be_the_same_err_msg
        )

        data_volume_path_3 = self._get_path(data_volume_id)

        self.assertNotEqual(
            data_volume_path_1,
            data_volume_path_3,
            TestVMSnapshots._path_should_have_changed_err_msg
        )

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(data_volume_xen_sr)

        sf_util.check_list(data_volume_xen_vdis, 3, self, TestVMSnapshots._should_be_three_vdis_err_msg)

        data_volume_vdis_after_revert = self._get_vdis(data_volume_xen_vdis)

        self.assertNotEqual(
            data_volume_vdis_after_create.active_vdi["uuid"],
            data_volume_vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg
        )

        self.assertEqual(
            data_volume_vdis_after_create.snapshot_vdi["uuid"],
            data_volume_vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg
        )

        self.assertEqual(
            data_volume_vdis_after_create.base_vdi["uuid"],
            data_volume_vdis_after_revert.base_vdi["uuid"],
            TestVMSnapshots._base_vdis_should_be_the_same_err_msg
        )

        #######################################
        #######################################
        ##### STEP 3: Delete VM snapshot  #####
        #######################################
        #######################################
        VmSnapshot.deleteVMSnapshot(self.apiClient, vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self.assertEqual(
            list_vm_snapshots,
            None,
            TestVMSnapshots._should_be_no_vm_snapshots_err_msg
        )

        root_volume_path_4 = self._get_path(root_volume_id)

        self.assertEqual(
            root_volume_path_3,
            root_volume_path_4,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(root_volume_xen_sr)

        sf_util.check_list(root_volume_xen_vdis, 1, self, TestVMSnapshots._should_only_be_one_vdi_err_msg)

        root_volume_vdis_after_delete = self._get_vdis(root_volume_xen_vdis, True)

        self.assertEqual(
            root_volume_vdis_after_revert.active_vdi["uuid"],
            root_volume_vdis_after_delete.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_be_the_same_err_msg
        )

        data_volume_path_4 = self._get_path(data_volume_id)

        self.assertEqual(
            data_volume_path_3,
            data_volume_path_4,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(data_volume_xen_sr)

        sf_util.check_list(data_volume_xen_vdis, 1, self, TestVMSnapshots._should_only_be_one_vdi_err_msg)

        data_volume_vdis_after_delete = self._get_vdis(data_volume_xen_vdis, True)

        self.assertEqual(
            data_volume_vdis_after_revert.active_vdi["uuid"],
            data_volume_vdis_after_delete.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_be_the_same_err_msg
        )

        #######################################
        #######################################
        #####      STEP 4: Start VM       #####
        #######################################
        #######################################
        self.virtual_machine.detach_volume(self.apiClient, data_volume)

        self.virtual_machine.start(self.apiClient)