Ejemplo n.º 1
0
    def test_volume_accessibility(self):
        with fake_block_env() as env:
            sd_id = env.sd_manifest.sdUUID
            img_id = make_uuid()
            vol_id = make_uuid()
            make_block_volume(env.lvm, env.sd_manifest, 1 * MB, img_id, vol_id)

            self.assertTrue(os.path.isfile(env.lvm.lvPath(sd_id, vol_id)))

            domain_path = os.path.join(env.sd_manifest.domaindir,
                                       sd.DOMAIN_IMAGES,
                                       img_id,
                                       vol_id)
            repo_path = os.path.join(env.sd_manifest.getRepoPath(),
                                     sd_id,
                                     sd.DOMAIN_IMAGES,
                                     img_id,
                                     vol_id)
            self.assertNotEqual(repo_path, domain_path)
            # The links to the dev are created only when producing the volume
            self.assertFalse(os.path.isfile(domain_path))
            self.assertFalse(os.path.isfile(repo_path))

            env.sd_manifest.produceVolume(img_id, vol_id)
            self.assertTrue(os.path.samefile(repo_path, domain_path))
Ejemplo n.º 2
0
 def test_getvsize_inactive_lv(self):
     # Tests the path when the device file is not present
     with fake_block_env() as env:
         lv_name = str(uuid.uuid4())
         env.lvm.createLV(env.sd_manifest.sdUUID, lv_name, VOLSIZE / MB)
         self.assertEqual(VOLSIZE,
                          env.sd_manifest.getVSize('<imgUUID>', lv_name))
Ejemplo n.º 3
0
 def test_unaligned_size_raises(self):
     with fake_block_env() as env:
         artifacts = env.sd_manifest.get_volume_artifacts(
             self.img_id, self.vol_id)
         size, vol_format, disk_type, desc = BASE_PARAMS[sc.RAW_FORMAT]
         size = MB + 1
         self.assertRaises(se.InvalidParameterException, artifacts.create,
                           size, vol_format, disk_type, desc)
Ejemplo n.º 4
0
 def test_volume_type(self, vol_type):
     with fake_block_env() as env:
         img_id = make_uuid()
         vol_id = make_uuid()
         make_block_volume(env.lvm, env.sd_manifest, 0,
                           img_id, vol_id, vol_type=vol_type)
         vol = env.sd_manifest.produceVolume(img_id, vol_id)
         self.assertEqual(vol.getVolType(), sc.type2name(vol_type))
Ejemplo n.º 5
0
    def test_domain_metadata_io(self):
        with fake_block_env() as env:
            desc = 'foo'
            set_domain_metaparams(env.sd_manifest, {sd.DMDK_DESCRIPTION: desc})

            # Test that metadata is persisted to our temporary storage area
            sd_id = env.sd_manifest.sdUUID
            manifest = blockSD.BlockStorageDomainManifest(sd_id)
            self.assertEqual(desc, manifest.getMetaParam(sd.DMDK_DESCRIPTION))
 def test_unaligned_initial_size_raises(self):
     with fake_block_env() as env:
         artifacts = env.sd_manifest.get_volume_artifacts(
             self.img_id, self.vol_id)
         size, vol_format, disk_type, desc = BASE_PARAMS[sc.COW_FORMAT]
         initial_size = size - 1
         self.assertRaises(se.InvalidParameterException,
                           artifacts.create, size, vol_format, disk_type,
                           desc, initial_size=initial_size)
Ejemplo n.º 7
0
    def test_domain_metadata_io(self):
        with fake_block_env() as env:
            desc = 'foo'
            set_domain_metaparams(env.sd_manifest, {sd.DMDK_DESCRIPTION: desc})

            # Test that metadata is persisted to our temporary storage area
            sd_id = env.sd_manifest.sdUUID
            manifest = blockSD.BlockStorageDomainManifest(sd_id)
            self.assertEqual(desc, manifest.getMetaParam(sd.DMDK_DESCRIPTION))
Ejemplo n.º 8
0
 def test_metaslot_selection(self, used_slots, free_slot):
     with fake_block_env() as env:
         for offset in used_slots:
             lv = make_uuid()
             sduuid = env.sd_manifest.sdUUID
             env.lvm.createLV(sduuid, lv, VOLSIZE / MB)
             tag = sc.TAG_PREFIX_MD + str(offset)
             env.lvm.addtag(sduuid, lv, tag)
         with env.sd_manifest.acquireVolumeMetadataSlot(None, 1) as mdSlot:
             self.assertEqual(mdSlot, free_slot)
Ejemplo n.º 9
0
 def test_metaslot_selection(self, used_slots, free_slot):
     with fake_block_env() as env:
         for offset in used_slots:
             lv = make_uuid()
             sduuid = env.sd_manifest.sdUUID
             env.lvm.createLV(sduuid, lv, VOLSIZE / MB)
             tag = sc.TAG_PREFIX_MD + str(offset)
             env.lvm.addtag(sduuid, lv, tag)
         with env.sd_manifest.acquireVolumeMetadataSlot(None, 1) as mdSlot:
             self.assertEqual(mdSlot, free_slot)
Ejemplo n.º 10
0
 def test_metaslot_selection(self):
     with fake_block_env() as env:
         lvs = ('0b6287f0-3679-4c4d-8be5-9bbfe3ec9c1f',
                'ea13af29-b64a-4d1a-b35f-3e6ab15c3b04')
         for lv, offset in zip(lvs, [4, 7]):
             sduuid = env.sd_manifest.sdUUID
             env.lvm.createLV(sduuid, lv, VOLSIZE / MB)
             tag = sc.TAG_PREFIX_MD + str(offset)
             env.lvm.addtag(sduuid, lv, tag)
         with env.sd_manifest.acquireVolumeMetadataSlot(None, 1) as mdSlot:
             self.assertEqual(mdSlot, 5)
 def test_getallimages(self):
     # The current behavior of getAllImages for block domains does not
     # report images that contain only artifacts.  This differs from the
     # file implementation.
     with fake_block_env() as env:
         self.assertEqual(set(), env.sd_manifest.getAllImages())
         artifacts = env.sd_manifest.get_volume_artifacts(
             self.img_id, self.vol_id)
         artifacts.create(*BASE_PARAMS[sc.RAW_FORMAT])
         self.assertEqual(set(), env.sd_manifest.getAllImages())
         artifacts.commit()
         self.assertEqual({self.img_id}, env.sd_manifest.getAllImages())
Ejemplo n.º 12
0
 def test_volume_type(self, vol_type):
     with fake_block_env() as env:
         img_id = make_uuid()
         vol_id = make_uuid()
         make_block_volume(env.lvm,
                           env.sd_manifest,
                           0,
                           img_id,
                           vol_id,
                           vol_type=vol_type)
         vol = env.sd_manifest.produceVolume(img_id, vol_id)
         self.assertEqual(vol.getVolType(), sc.type2name(vol_type))
Ejemplo n.º 13
0
 def test_getallimages(self):
     # The current behavior of getAllImages for block domains does not
     # report images that contain only artifacts.  This differs from the
     # file implementation.
     with fake_block_env() as env:
         self.assertEqual(set(), env.sd_manifest.getAllImages())
         artifacts = env.sd_manifest.get_volume_artifacts(
             self.img_id, self.vol_id)
         artifacts.create(*BASE_PARAMS[sc.RAW_FORMAT])
         self.assertEqual(set(), env.sd_manifest.getAllImages())
         artifacts.commit()
         self.assertEqual({self.img_id}, env.sd_manifest.getAllImages())
Ejemplo n.º 14
0
 def test_size_rounded_up(self):
     # If the underlying device is larger the size will be updated
     with fake_block_env() as env:
         sd_id = env.sd_manifest.sdUUID
         vg = env.lvm.getVG(sd_id)
         expected_size = int(vg.extent_size)
         requested_size = expected_size - MB
         artifacts = env.sd_manifest.get_volume_artifacts(
             self.img_id, self.vol_id)
         artifacts.create(requested_size, sc.RAW_FORMAT,
                          image.SYSTEM_DISK_TYPE, 'raw_volume')
         artifacts.commit()
         vol = env.sd_manifest.produceVolume(self.img_id, self.vol_id)
         self.assertEqual(expected_size / sc.BLOCK_SIZE, vol.getSize())
         self.assertEqual(expected_size,
                          int(env.lvm.getLV(sd_id, self.vol_id).size))
 def test_size_rounded_up(self):
     # If the underlying device is larger the size will be updated
     with fake_block_env() as env:
         sd_id = env.sd_manifest.sdUUID
         vg = env.lvm.getVG(sd_id)
         expected_size = int(vg.extent_size)
         requested_size = expected_size - MB
         artifacts = env.sd_manifest.get_volume_artifacts(
             self.img_id, self.vol_id)
         artifacts.create(requested_size, sc.RAW_FORMAT,
                          image.SYSTEM_DISK_TYPE, 'raw_volume')
         artifacts.commit()
         vol = env.sd_manifest.produceVolume(self.img_id, self.vol_id)
         self.assertEqual(expected_size / sc.BLOCK_SIZE, vol.getSize())
         self.assertEqual(expected_size,
                          int(env.lvm.getLV(sd_id, self.vol_id).size))
Ejemplo n.º 16
0
    def test_volume_size_alignment(self, size_param):
        with fake_block_env() as env:
            sd_id = env.sd_manifest.sdUUID
            img_id = make_uuid()
            vol_id = make_uuid()
            make_block_volume(env.lvm, env.sd_manifest, size_param,
                              img_id, vol_id)
            vol = env.sd_manifest.produceVolume(img_id, vol_id)

            extent_size = sc.VG_EXTENT_SIZE_MB * MB
            expected_size = utils.round(size_param, extent_size)
            self.assertEqual(expected_size / sc.BLOCK_SIZE, vol.getSize())
            self.assertEqual(expected_size,
                             int(env.lvm.getLV(sd_id, vol_id).size))
            lv_file_size = os.stat(env.lvm.lvPath(sd_id, vol_id)).st_size
            self.assertEqual(expected_size, lv_file_size)
Ejemplo n.º 17
0
    def test_volume_size_alignment(self, size_param):
        with fake_block_env() as env:
            sd_id = env.sd_manifest.sdUUID
            img_id = make_uuid()
            vol_id = make_uuid()
            make_block_volume(env.lvm, env.sd_manifest, size_param, img_id,
                              vol_id)
            vol = env.sd_manifest.produceVolume(img_id, vol_id)

            extent_size = sc.VG_EXTENT_SIZE_MB * MB
            expected_size = utils.round(size_param, extent_size)
            self.assertEqual(expected_size / sc.BLOCK_SIZE, vol.getSize())
            self.assertEqual(expected_size,
                             int(env.lvm.getLV(sd_id, vol_id).size))
            lv_file_size = os.stat(env.lvm.lvPath(sd_id, vol_id)).st_size
            self.assertEqual(expected_size, lv_file_size)
Ejemplo n.º 18
0
    def test_overwrite_blocksize(self):
        metadata = {sd.DMDK_VERSION: 3,
                    blockSD.DMDK_LOGBLKSIZE: 2048,
                    blockSD.DMDK_PHYBLKSIZE: 1024}
        with fake_block_env() as env:
            # Replacing the metadata will not overwrite these values since they
            # are set only in the manifest constructor.
            env.sd_manifest.replaceMetadata(metadata)
            self.assertEquals(512, env.sd_manifest.logBlkSize)
            self.assertEquals(512, env.sd_manifest.phyBlkSize)

            # If we supply values in the metadata used to construct the
            # manifest then those values will apply.
            new_manifest = blockSD.BlockStorageDomainManifest(
                env.sd_manifest.sdUUID, metadata)
            self.assertEquals(2048, new_manifest.logBlkSize)
            self.assertEquals(1024, new_manifest.phyBlkSize)
Ejemplo n.º 19
0
    def test_domain_structure(self):
        with fake_block_env() as env:
            vg_name = env.sd_manifest.sdUUID
            md_path = env.lvm.lvPath(vg_name, sd.METADATA)
            self.assertTrue(os.path.exists(md_path))

            for lv in blockSD.SPECIAL_LVS:
                self.assertEqual(lv, env.lvm.getLV(vg_name, lv).name)

            images_dir = os.path.join(env.sd_manifest.domaindir,
                                      sd.DOMAIN_IMAGES)
            self.assertTrue(os.path.exists(images_dir))

            # Check the storage repository
            repo_path = env.sd_manifest.getRepoPath()
            domain_link = os.path.join(repo_path, env.sd_manifest.sdUUID)
            self.assertTrue(os.path.islink(domain_link))
            self.assertEqual(env.sd_manifest.domaindir,
                             os.readlink(domain_link))
Ejemplo n.º 20
0
    def test_volume_metadata_io(self):
        with fake_block_env() as env:
            sd_id = env.sd_manifest.sdUUID
            img_id = make_uuid()
            vol_id = make_uuid()
            size_mb = sc.VG_EXTENT_SIZE_MB
            size = size_mb * MB
            size_blk = size_mb * MB / sc.BLOCK_SIZE
            make_block_volume(env.lvm, env.sd_manifest, size, img_id, vol_id)

            self.assertEqual(vol_id, env.lvm.getLV(sd_id, vol_id).name)
            vol = env.sd_manifest.produceVolume(img_id, vol_id)
            self.assertEqual(size_blk, vol.getSize())
            desc = 'foo'
            vol.setDescription(desc)

            # Test that metadata is persisted to our temporary storage area
            vol = env.sd_manifest.produceVolume(img_id, vol_id)
            self.assertEqual(desc, vol.getDescription())
Ejemplo n.º 21
0
    def test_domain_structure(self):
        with fake_block_env() as env:
            vg_name = env.sd_manifest.sdUUID
            md_path = env.lvm.lvPath(vg_name, sd.METADATA)
            self.assertTrue(os.path.exists(md_path))

            for lv in blockSD.SPECIAL_LVS:
                self.assertEqual(lv, env.lvm.getLV(vg_name, lv).name)

            images_dir = os.path.join(env.sd_manifest.domaindir,
                                      sd.DOMAIN_IMAGES)
            self.assertTrue(os.path.exists(images_dir))

            # Check the storage repository
            repo_path = env.sd_manifest.getRepoPath()
            domain_link = os.path.join(repo_path, env.sd_manifest.sdUUID)
            self.assertTrue(os.path.islink(domain_link))
            self.assertEqual(env.sd_manifest.domaindir,
                             os.readlink(domain_link))
Ejemplo n.º 22
0
    def test_volume_metadata_io(self):
        with fake_block_env() as env:
            sd_id = env.sd_manifest.sdUUID
            img_id = str(uuid.uuid4())
            vol_id = str(uuid.uuid4())
            size_mb = 1 * MB
            size_blk = size_mb * MB / sc.BLOCK_SIZE
            make_block_volume(env.lvm, env.sd_manifest, size_mb,
                              img_id, vol_id)

            self.assertEqual(vol_id, env.lvm.getLV(sd_id, vol_id).name)
            vol = env.sd_manifest.produceVolume(img_id, vol_id)
            self.assertEqual(size_blk, vol.getSize())
            desc = 'foo'
            vol.setDescription(desc)

            # Test that metadata is persisted to our temporary storage area
            vol = env.sd_manifest.produceVolume(img_id, vol_id)
            self.assertEqual(desc, vol.getDescription())
Ejemplo n.º 23
0
    def test_volume_accessibility(self):
        with fake_block_env() as env:
            sd_id = env.sd_manifest.sdUUID
            img_id = make_uuid()
            vol_id = make_uuid()
            make_block_volume(env.lvm, env.sd_manifest, 1 * MB, img_id, vol_id)

            self.assertTrue(os.path.isfile(env.lvm.lvPath(sd_id, vol_id)))

            domain_path = os.path.join(env.sd_manifest.domaindir,
                                       sd.DOMAIN_IMAGES, img_id, vol_id)
            repo_path = os.path.join(env.sd_manifest.getRepoPath(), sd_id,
                                     sd.DOMAIN_IMAGES, img_id, vol_id)
            self.assertNotEqual(repo_path, domain_path)
            # The links to the dev are created only when producing the volume
            self.assertFalse(os.path.isfile(domain_path))
            self.assertFalse(os.path.isfile(repo_path))

            env.sd_manifest.produceVolume(img_id, vol_id)
            self.assertTrue(os.path.samefile(repo_path, domain_path))
Ejemplo n.º 24
0
 def test_get_monitoring_path(self):
     with fake_block_env() as env:
         md_lv_path = env.lvm.lvPath(env.sd_manifest.sdUUID, sd.METADATA)
         self.assertEqual(md_lv_path, env.sd_manifest.getMonitoringPath())
Ejemplo n.º 25
0
 def test_metaslot_lock(self):
     with fake_block_env() as env:
         with env.sd_manifest.acquireVolumeMetadataSlot(None, 1):
             acquired = env.sd_manifest._lvTagMetaSlotLock.acquire(False)
             self.assertFalse(acquired)
Ejemplo n.º 26
0
 def fake_env(self):
     return fake_block_env()
Ejemplo n.º 27
0
 def test_getblocksize_defaults(self):
     with fake_block_env() as env:
         self.assertEquals(512, env.sd_manifest.logBlkSize)
         self.assertEquals(512, env.sd_manifest.phyBlkSize)
Ejemplo n.º 28
0
 def test_getmetaparam(self):
     with fake_block_env() as env:
         self.assertEquals(env.sd_manifest.sdUUID,
                           env.sd_manifest.getMetaParam(sd.DMDK_SDUUID))
Ejemplo n.º 29
0
 def test_getreaddelay(self):
     with fake_block_env() as env:
         vg_name = env.sd_manifest.sdUUID
         make_file(env.lvm.lvPath(vg_name, 'metadata'))
         self.assertIsInstance(env.sd_manifest.getReadDelay(), float)
Ejemplo n.º 30
0
 def test_repopath_location(self):
     with fake_block_env() as env:
         self.assertTrue(env.sd_manifest.getRepoPath().startswith(TEMPDIR))
Ejemplo n.º 31
0
 def test_repopath_location(self):
     with fake_block_env() as env:
         self.assertTrue(env.sd_manifest.getRepoPath().startswith(TEMPDIR))
 def fake_env(self):
     return fake_block_env()