def test_vol_glance_metadata_copy_to_snapshot(self):
        ctxt = context.get_admin_context()
        db.volume_create(ctxt, {"id": 1})
        db.snapshot_create(ctxt, {"id": 100, "volume_id": 1})
        db.volume_glance_metadata_create(ctxt, 1, "key1", "value1")
        db.volume_glance_metadata_copy_to_snapshot(ctxt, 100, 1)

        expected_meta = {"snapshot_id": "100", "key": "key1", "value": "value1"}

        for meta in db.volume_snapshot_glance_metadata_get(ctxt, 100):
            for (key, value) in expected_meta.items():
                self.assertEqual(meta[key], value)
Example #2
0
    def test_vol_glance_metadata_copy_to_snapshot(self):
        ctxt = context.get_admin_context()
        db.volume_create(ctxt, {'id': 1})
        db.snapshot_create(ctxt, {'id': 100, 'volume_id': 1})
        db.volume_glance_metadata_create(ctxt, 1, 'key1', 'value1')
        db.volume_glance_metadata_copy_to_snapshot(ctxt, 100, 1)

        expected_meta = {'snapshot_id': '100',
                         'key': 'key1',
                         'value': 'value1'}

        for meta in db.volume_snapshot_glance_metadata_get(ctxt, 100):
            for (key, value) in expected_meta.items():
                self.assertEqual(value, meta[key])
    def test_vol_glance_metadata_copy_to_snapshot(self):
        ctxt = context.get_admin_context()
        db.volume_create(ctxt, {"id": fake.VOLUME_ID})
        snap = objects.Snapshot(ctxt, volume_id=fake.VOLUME_ID)
        snap.create()
        db.volume_glance_metadata_create(ctxt, fake.VOLUME_ID, "key1", "value1")
        db.volume_glance_metadata_copy_to_snapshot(ctxt, snap.id, fake.VOLUME_ID)

        expected_meta = {"snapshot_id": snap.id, "key": "key1", "value": "value1"}

        for meta in db.volume_snapshot_glance_metadata_get(ctxt, snap.id):
            for (key, value) in expected_meta.items():
                self.assertEqual(value, meta[key])
        snap.destroy()
Example #4
0
    def test_vol_glance_metadata_copy_to_snapshot(self):
        ctxt = context.get_admin_context()
        db.volume_create(ctxt, {'id': 1})
        snap = objects.Snapshot(ctxt, volume_id=1)
        snap.create()
        db.volume_glance_metadata_create(ctxt, 1, 'key1', 'value1')
        db.volume_glance_metadata_copy_to_snapshot(ctxt, snap.id, 1)

        expected_meta = {'snapshot_id': snap.id,
                         'key': 'key1',
                         'value': 'value1'}

        for meta in db.volume_snapshot_glance_metadata_get(ctxt, snap.id):
            for (key, value) in expected_meta.items():
                self.assertEqual(value, meta[key])
        snap.destroy()
Example #5
0
    def test_create_snapshot_from_bootable_volume(self, mock_qemu_info):
        """Test create snapshot from bootable volume."""
        # create bootable volume from image
        volume = self._create_volume_from_image()
        volume_id = volume['id']
        self.assertEqual('available', volume['status'])
        self.assertTrue(volume['bootable'])

        image_info = imageutils.QemuImgInfo()
        image_info.virtual_size = '1073741824'
        mock_qemu_info.return_value = image_info

        # get volume's volume_glance_metadata
        ctxt = context.get_admin_context()
        vol_glance_meta = db.volume_glance_metadata_get(ctxt, volume_id)
        self.assertTrue(bool(vol_glance_meta))

        # create snapshot from bootable volume
        snap = create_snapshot(volume_id)
        self.volume.create_snapshot(ctxt, snap)

        # get snapshot's volume_glance_metadata
        snap_glance_meta = db.volume_snapshot_glance_metadata_get(
            ctxt, snap.id)
        self.assertTrue(bool(snap_glance_meta))

        # ensure that volume's glance metadata is copied
        # to snapshot's glance metadata
        self.assertEqual(len(vol_glance_meta), len(snap_glance_meta))
        vol_glance_dict = {x.key: x.value for x in vol_glance_meta}
        snap_glance_dict = {x.key: x.value for x in snap_glance_meta}
        self.assertDictEqual(vol_glance_dict, snap_glance_dict)

        # ensure that snapshot's status is changed to 'available'
        self.assertEqual(fields.SnapshotStatus.AVAILABLE, snap.status)

        # cleanup resource
        snap.destroy()
        db.volume_destroy(ctxt, volume_id)
Example #6
0
    def test_create_snapshot_from_bootable_volume(self, mock_qemu_info):
        """Test create snapshot from bootable volume."""
        # create bootable volume from image
        volume = self._create_volume_from_image()
        volume_id = volume['id']
        self.assertEqual('available', volume['status'])
        self.assertTrue(volume['bootable'])

        image_info = imageutils.QemuImgInfo()
        image_info.virtual_size = '1073741824'
        mock_qemu_info.return_value = image_info

        # get volume's volume_glance_metadata
        ctxt = context.get_admin_context()
        vol_glance_meta = db.volume_glance_metadata_get(ctxt, volume_id)
        self.assertTrue(bool(vol_glance_meta))

        # create snapshot from bootable volume
        snap = create_snapshot(volume_id)
        self.volume.create_snapshot(ctxt, snap)

        # get snapshot's volume_glance_metadata
        snap_glance_meta = db.volume_snapshot_glance_metadata_get(
            ctxt, snap.id)
        self.assertTrue(bool(snap_glance_meta))

        # ensure that volume's glance metadata is copied
        # to snapshot's glance metadata
        self.assertEqual(len(vol_glance_meta), len(snap_glance_meta))
        vol_glance_dict = {x.key: x.value for x in vol_glance_meta}
        snap_glance_dict = {x.key: x.value for x in snap_glance_meta}
        self.assertDictEqual(vol_glance_dict, snap_glance_dict)

        # ensure that snapshot's status is changed to 'available'
        self.assertEqual(fields.SnapshotStatus.AVAILABLE, snap.status)

        # cleanup resource
        snap.destroy()
        db.volume_destroy(ctxt, volume_id)