Beispiel #1
0
    def test_rm_vdisks(self, mock_update):
        mock_update.return_value = self.vg_resp
        vg_wrap = stor.VG.wrap(self.vg_resp)
        # Remove a valid VDisk
        valid_vd = vg_wrap.virtual_disks[0]
        # Removal should hit.
        vg_wrap = ts.rm_vg_storage(vg_wrap, vdisks=[valid_vd])
        # Update happens, by default
        self.assertEqual(1, mock_update.call_count)
        self.assertEqual(1, len(vg_wrap.virtual_disks))
        self.assertNotEqual(valid_vd.udid, vg_wrap.virtual_disks[0].udid)

        # Bogus removal doesn't affect vg_wrap, and doesn't update.
        mock_update.reset_mock()
        invalid_vd = mock.Mock()
        invalid_vd.name = 'vdisk_name'
        invalid_vd.udid = 'vdisk_udid'
        vg_wrap = ts.rm_vg_storage(vg_wrap, vdisks=[invalid_vd])
        # Update doesn't happen, because no changes
        self.assertEqual(0, mock_update.call_count)
        self.assertEqual(1, len(vg_wrap.virtual_disks))

        # Valid (but sparse) removal; invalid is ignored.
        mock_update.reset_mock()
        valid_vd = mock.Mock()
        valid_vd.name = 'vdisk_name'
        valid_vd.udid = '0300f8d6de00004b000000014a54555cd9.3'
        vg_wrap = ts.rm_vg_storage(vg_wrap, vdisks=[valid_vd, invalid_vd])
        self.assertEqual(1, mock_update.call_count)
        self.assertEqual(0, len(vg_wrap.virtual_disks))
Beispiel #2
0
    def test_rm_vopts(self, mock_update):
        mock_update.return_value = self.vg_resp
        vg_wrap = stor.VG.wrap(self.vg_resp)
        repo = vg_wrap.vmedia_repos[0]
        # Remove a valid VOptMedia
        valid_vopt = repo.optical_media[0]
        # Removal should hit.
        vg_wrap = ts.rm_vg_storage(vg_wrap, vopts=[valid_vopt])
        # Update happens, by default
        self.assertEqual(1, mock_update.call_count)
        repo = vg_wrap.vmedia_repos[0]
        self.assertEqual(2, len(repo.optical_media))
        self.assertNotEqual(valid_vopt.udid, repo.optical_media[0].udid)
        self.assertNotEqual(valid_vopt.udid, repo.optical_media[1].udid)

        # Bogus removal doesn't affect vg_wrap, and doesn't update.
        mock_update.reset_mock()
        invalid_vopt = stor.VOptMedia.bld(self.adpt, 'bogus')
        mock_update.reset_mock()
        vg_wrap = ts.rm_vg_storage(vg_wrap, vopts=[invalid_vopt])
        self.assertEqual(0, mock_update.call_count)
        self.assertEqual(2, len(vg_wrap.vmedia_repos[0].optical_media))

        # Valid multiple removal
        mock_update.reset_mock()
        vg_wrap = ts.rm_vg_storage(vg_wrap, vopts=repo.optical_media[:])
        self.assertEqual(1, mock_update.call_count)
        self.assertEqual(0, len(vg_wrap.vmedia_repos[0].optical_media))
Beispiel #3
0
    def _age_and_verify_cached_images(self, context, all_instances, base_dir):
        """Finds and removes unused images from the cache.

        :param context: nova context
        :param all_instances: List of all instances on the node
        :param base_dir: Volume group of cached images
        """
        # Use the 'used_images' key from nova imagecache to get a dict that
        # uses image_ids as keys.
        cache = self._scan_base_image(base_dir)
        running_inst = self._list_running_instances(context, all_instances)
        adjusted_ids = []
        for img_id in running_inst.get('used_images'):
            if img_id:
                adjusted_ids.append(
                    driver.DiskAdapter.get_name_by_uuid(driver.DiskType.IMAGE,
                                                        img_id,
                                                        short=True))
        # Compare base images with running instances remove unused
        unused = [image for image in cache if image.name not in adjusted_ids]
        # Remove unused
        if unused:
            for image in unused:
                LOG.info("Removing unused cache image: '%s'", image.name)
            tsk_stg.rm_vg_storage(base_dir, vdisks=unused)
Beispiel #4
0
 def rm_vopt():
     LOG.info("Removing virtual optical storage.", instance=instance)
     vg_wrap = pvm_stg.VG.get(self.adapter,
                              uuid=self.vg_uuid,
                              parent_type=pvm_vios.VIOS,
                              parent_uuid=self.vios_uuid)
     tsk_stg.rm_vg_storage(vg_wrap, vopts=media_elems)
Beispiel #5
0
 def rm_vopt():
     LOG.info("Removing virtual optical storage.",
              instance=instance)
     vg_wrap = pvm_stg.VG.get(self.adapter, uuid=self.vg_uuid,
                              parent_type=pvm_vios.VIOS,
                              parent_uuid=self.vios_uuid)
     tsk_stg.rm_vg_storage(vg_wrap, vopts=media_elems)
Beispiel #6
0
    def test_rm_vopts(self, mock_update):
        mock_update.return_value = self.vg_resp
        vg_wrap = stor.VG.wrap(self.vg_resp)
        repo = vg_wrap.vmedia_repos[0]
        # Remove a valid VOptMedia
        valid_vopt = repo.optical_media[0]
        # Removal should hit.
        vg_wrap = ts.rm_vg_storage(vg_wrap, vopts=[valid_vopt])
        # Update happens, by default
        self.assertEqual(1, mock_update.call_count)
        repo = vg_wrap.vmedia_repos[0]
        self.assertEqual(2, len(repo.optical_media))
        self.assertNotEqual(valid_vopt.udid, repo.optical_media[0].udid)
        self.assertNotEqual(valid_vopt.udid, repo.optical_media[1].udid)

        # Bogus removal doesn't affect vg_wrap, and doesn't update.
        mock_update.reset_mock()
        invalid_vopt = stor.VOptMedia.bld(self.adpt, 'bogus')
        mock_update.reset_mock()
        vg_wrap = ts.rm_vg_storage(vg_wrap, vopts=[invalid_vopt])
        self.assertEqual(0, mock_update.call_count)
        self.assertEqual(2, len(vg_wrap.vmedia_repos[0].optical_media))

        # Valid multiple removal
        mock_update.reset_mock()
        vg_wrap = ts.rm_vg_storage(vg_wrap, vopts=repo.optical_media[:])
        self.assertEqual(1, mock_update.call_count)
        self.assertEqual(0, len(vg_wrap.vmedia_repos[0].optical_media))
Beispiel #7
0
    def test_rm_vdisks(self, mock_update):
        mock_update.return_value = self.vg_resp
        vg_wrap = stor.VG.wrap(self.vg_resp)
        # Remove a valid VDisk
        valid_vd = vg_wrap.virtual_disks[0]
        # Removal should hit.
        vg_wrap = ts.rm_vg_storage(vg_wrap, vdisks=[valid_vd])
        # Update happens, by default
        self.assertEqual(1, mock_update.call_count)
        self.assertEqual(1, len(vg_wrap.virtual_disks))
        self.assertNotEqual(valid_vd.udid, vg_wrap.virtual_disks[0].udid)

        # Bogus removal doesn't affect vg_wrap, and doesn't update.
        mock_update.reset_mock()
        invalid_vd = mock.Mock()
        invalid_vd.name = 'vdisk_name'
        invalid_vd.udid = 'vdisk_udid'
        vg_wrap = ts.rm_vg_storage(vg_wrap, vdisks=[invalid_vd])
        # Update doesn't happen, because no changes
        self.assertEqual(0, mock_update.call_count)
        self.assertEqual(1, len(vg_wrap.virtual_disks))

        # Valid (but sparse) removal; invalid is ignored.
        mock_update.reset_mock()
        valid_vd = mock.Mock()
        valid_vd.name = 'vdisk_name'
        valid_vd.udid = '0300f8d6de00004b000000014a54555cd9.3'
        vg_wrap = ts.rm_vg_storage(vg_wrap, vdisks=[valid_vd, invalid_vd])
        self.assertEqual(1, mock_update.call_count)
        self.assertEqual(0, len(vg_wrap.virtual_disks))
Beispiel #8
0
 def rm_vopt():
     LOG.info(_LI("Removing virtual optical for VM with UUID %s."),
              lpar_uuid)
     vg_rsp = self.adapter.read(pvm_vios.VIOS.schema_type,
                                root_id=self.vios_uuid,
                                child_type=pvm_stg.VG.schema_type,
                                child_id=self.vg_uuid)
     tsk_stg.rm_vg_storage(pvm_stg.VG.wrap(vg_rsp), vopts=media_elems)
Beispiel #9
0
 def rm_vopt():
     LOG.info(_LI("Removing virtual optical for VM with UUID %s."),
              lpar_uuid)
     vg_rsp = self.adapter.read(pvm_vios.VIOS.schema_type,
                                root_id=self.vios_uuid,
                                child_type=pvm_stg.VG.schema_type,
                                child_id=self.vg_uuid)
     tsk_stg.rm_vg_storage(pvm_stg.VG.wrap(vg_rsp), vopts=media_elems)
Beispiel #10
0
 def rm_vopt():
     LOG.info(_LI("Removing virtual optical for VM with UUID %s."),
              lpar_uuid)
     vg_wrap = pvm_stg.VG.get(self.adapter,
                              uuid=self.vg_uuid,
                              parent_type=pvm_vios.VIOS,
                              parent_uuid=self.vios_uuid)
     tsk_stg.rm_vg_storage(vg_wrap, vopts=media_elems)
Beispiel #11
0
    def delete_disks(self, storage_elems):
        """Removes the specified disks.

        :param storage_elems: A list of the storage elements that are to be
                              deleted.  Derived from the return value from
                              disconnect_disk.
        """
        # All of local disk is done against the volume group.  So reload
        # that (to get new etag) and then update against it.
        tsk_stg.rm_vg_storage(self._get_vg_wrap(), vdisks=storage_elems)
Beispiel #12
0
    def delete_disks(self, storage_elems):
        """Removes the specified disks.

        :param storage_elems: A list of the storage elements that are to be
                              deleted. Derived from the return value from
                              detach_disk.
        """
        # All of localdisk is done against the volume group. So reload
        # that (to get new etag) and then update against it.
        tsk_stg.rm_vg_storage(self._get_vg_wrap(), vdisks=storage_elems)
Beispiel #13
0
    def delete_disks(self, context, instance, storage_elems):
        """Removes the specified disks.

        :param context: nova context for operation
        :param instance: instance to delete the disk for.
        :param storage_elems: A list of the storage elements that are to be
                              deleted.  Derived from the return value from
                              disconnect_image_disk.
        """
        # All of local disk is done against the volume group.  So reload
        # that (to get new etag) and then update against it.
        tsk_stg.rm_vg_storage(self._get_vg_wrap(), vdisks=storage_elems)