Exemplo n.º 1
0
 def test_block_device_mapping_destroy(self):
     fake_bdm = {'id': 'fake-bdm'}
     fake_bdm2 = {'id': 'fake-bdm-2'}
     fake_inst = {'uuid': 'fake-uuid'}
     self.mox.StubOutWithMock(db, 'block_device_mapping_destroy')
     self.mox.StubOutWithMock(
         db, 'block_device_mapping_destroy_by_instance_and_device')
     self.mox.StubOutWithMock(
         db, 'block_device_mapping_destroy_by_instance_and_volume')
     db.block_device_mapping_destroy(self.context, 'fake-bdm')
     db.block_device_mapping_destroy(self.context, 'fake-bdm-2')
     db.block_device_mapping_destroy_by_instance_and_device(self.context,
                                                            'fake-uuid',
                                                            'fake-device')
     db.block_device_mapping_destroy_by_instance_and_volume(self.context,
                                                            'fake-uuid',
                                                            'fake-volume')
     self.mox.ReplayAll()
     self.conductor.block_device_mapping_destroy(self.context,
                                                 [fake_bdm,
                                                  fake_bdm2])
     self.conductor.block_device_mapping_destroy(self.context,
                                                 instance=fake_inst,
                                                 device_name='fake-device')
     self.conductor.block_device_mapping_destroy(self.context,
                                                 instance=fake_inst,
                                                 volume_id='fake-volume')
Exemplo n.º 2
0
 def test_block_device_mapping_destroy(self):
     fake_bdm = {'id': 'fake-bdm'}
     fake_bdm2 = {'id': 'fake-bdm-2'}
     fake_inst = {'uuid': 'fake-uuid'}
     self.mox.StubOutWithMock(db, 'block_device_mapping_destroy')
     self.mox.StubOutWithMock(
         db, 'block_device_mapping_destroy_by_instance_and_device')
     self.mox.StubOutWithMock(
         db, 'block_device_mapping_destroy_by_instance_and_volume')
     db.block_device_mapping_destroy(self.context, 'fake-bdm')
     db.block_device_mapping_destroy(self.context, 'fake-bdm-2')
     db.block_device_mapping_destroy_by_instance_and_device(self.context,
                                                            'fake-uuid',
                                                            'fake-device')
     db.block_device_mapping_destroy_by_instance_and_volume(self.context,
                                                            'fake-uuid',
                                                            'fake-volume')
     self.mox.ReplayAll()
     self.conductor.block_device_mapping_destroy(self.context,
                                                 [fake_bdm,
                                                  fake_bdm2])
     self.conductor.block_device_mapping_destroy(self.context,
                                                 instance=fake_inst,
                                                 device_name='fake-device')
     self.conductor.block_device_mapping_destroy(self.context,
                                                 instance=fake_inst,
                                                 volume_id='fake-volume')
Exemplo n.º 3
0
 def _tearDownBlockDeviceMapping(self, inst1, inst2, volumes):
     for vol in volumes:
         self.volume_api.delete(self.context, vol)
     for uuid in (inst1["uuid"], inst2["uuid"]):
         for bdm in db.block_device_mapping_get_all_by_instance(self.context, uuid):
             db.block_device_mapping_destroy(self.context, bdm["id"])
     db.instance_destroy(self.context, inst2["uuid"])
     db.instance_destroy(self.context, inst1["uuid"])
Exemplo n.º 4
0
 def _tearDownBlockDeviceMapping(self, inst1, inst2, volumes):
     for vol in volumes:
         self.volume_api.delete(self.context, vol['id'])
     for uuid in (inst1['uuid'], inst2['uuid']):
         for bdm in db.block_device_mapping_get_all_by_instance(
             self.context, uuid):
             db.block_device_mapping_destroy(self.context, bdm['id'])
     db.instance_destroy(self.context, inst2['uuid'])
     db.instance_destroy(self.context, inst1['uuid'])
Exemplo n.º 5
0
 def _tearDownBlockDeviceMapping(self, instances, volumes):
     for vols in volumes:
         for vol in vols:
             self.volume_api.delete(self.context, vol['id'])
     for instance in instances:
         for bdm in db.block_device_mapping_get_all_by_instance(
                 self.context, instance['uuid']):
             db.block_device_mapping_destroy(self.context, bdm['id'])
         db.instance_destroy(self.context, instance['uuid'])
Exemplo n.º 6
0
 def _tearDownBlockDeviceMapping(self, instances, volumes):
     for vols in volumes:
         for vol in vols:
             self.volume_api.delete(self.context, vol['id'])
     for instance in instances:
         for bdm in db.block_device_mapping_get_all_by_instance(
                 self.context, instance['uuid']):
             db.block_device_mapping_destroy(self.context, bdm['id'])
         db.instance_destroy(self.context, instance['uuid'])
Exemplo n.º 7
0
 def destroy(self, context):
     if not self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='destroy',
                                           reason='already destroyed')
     db.block_device_mapping_destroy(context, self.id)
     delattr(self, base.get_attrname('id'))
     cells_api = cells_rpcapi.CellsAPI()
     cells_api.bdm_destroy_at_top(context, self.instance_uuid,
                                  device_name=self.device_name,
                                  volume_id=self.volume_id)
Exemplo n.º 8
0
 def destroy(self, context):
     if not self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='destroy',
                                           reason='already destroyed')
     db.block_device_mapping_destroy(context, self.id)
     delattr(self, base.get_attrname('id'))
     cells_api = cells_rpcapi.CellsAPI()
     cells_api.bdm_destroy_at_top(context, self.instance_uuid,
                                  device_name=self.device_name,
                                  volume_id=self.volume_id)
Exemplo n.º 9
0
    def destroy(self):
        if not self.obj_attr_is_set("id"):
            raise exception.ObjectActionError(action="destroy", reason="already destroyed")
        db.block_device_mapping_destroy(self._context, self.id)
        delattr(self, base.get_attrname("id"))

        cell_type = cells_opts.get_cell_type()
        if cell_type == "compute":
            cells_api = cells_rpcapi.CellsAPI()
            cells_api.bdm_destroy_at_top(
                self._context, self.instance_uuid, device_name=self.device_name, volume_id=self.volume_id
            )
Exemplo n.º 10
0
 def test_block_device_mapping_destroy(self):
     fake_bdm = {"id": "fake-bdm"}
     fake_inst = {"uuid": "fake-uuid"}
     self.mox.StubOutWithMock(db, "block_device_mapping_destroy")
     self.mox.StubOutWithMock(db, "block_device_mapping_destroy_by_instance_and_device")
     self.mox.StubOutWithMock(db, "block_device_mapping_destroy_by_instance_and_volume")
     db.block_device_mapping_destroy(self.context, "fake-bdm")
     db.block_device_mapping_destroy_by_instance_and_device(self.context, "fake-uuid", "fake-device")
     db.block_device_mapping_destroy_by_instance_and_volume(self.context, "fake-uuid", "fake-volume")
     self.mox.ReplayAll()
     self.conductor.block_device_mapping_destroy(self.context, [fake_bdm])
     self.conductor.block_device_mapping_destroy_by_instance_and_device(self.context, fake_inst, "fake-device")
     self.conductor.block_device_mapping_destroy_by_instance_and_volume(self.context, fake_inst, "fake-volume")
Exemplo n.º 11
0
    def test_update_block_device_mapping(self):
        instance_id = self._create_instance()
        mappings = [{
            'virtual': 'ami',
            'device': 'sda1'
        }, {
            'virtual': 'root',
            'device': '/dev/sda1'
        }, {
            'virtual': 'swap',
            'device': 'sdb1'
        }, {
            'virtual': 'swap',
            'device': 'sdb2'
        }, {
            'virtual': 'swap',
            'device': 'sdb3'
        }, {
            'virtual': 'swap',
            'device': 'sdb4'
        }, {
            'virtual': 'ephemeral0',
            'device': 'sdc1'
        }, {
            'virtual': 'ephemeral1',
            'device': 'sdc2'
        }, {
            'virtual': 'ephemeral2',
            'device': 'sdc3'
        }]
        block_device_mapping = [
            # root
            {
                'device_name': '/dev/sda1',
                'snapshot_id': 0x12345678,
                'delete_on_termination': False
            },

            # overwrite swap
            {
                'device_name': '/dev/sdb2',
                'snapshot_id': 0x23456789,
                'delete_on_termination': False
            },
            {
                'device_name': '/dev/sdb3',
                'snapshot_id': 0x3456789A
            },
            {
                'device_name': '/dev/sdb4',
                'no_device': True
            },

            # overwrite ephemeral
            {
                'device_name': '/dev/sdc2',
                'snapshot_id': 0x456789AB,
                'delete_on_termination': False
            },
            {
                'device_name': '/dev/sdc3',
                'snapshot_id': 0x56789ABC
            },
            {
                'device_name': '/dev/sdc4',
                'no_device': True
            },

            # volume
            {
                'device_name': '/dev/sdd1',
                'snapshot_id': 0x87654321,
                'delete_on_termination': False
            },
            {
                'device_name': '/dev/sdd2',
                'snapshot_id': 0x98765432
            },
            {
                'device_name': '/dev/sdd3',
                'snapshot_id': 0xA9875463
            },
            {
                'device_name': '/dev/sdd4',
                'no_device': True
            }
        ]

        self.compute_api._update_image_block_device_mapping(
            self.context, instance_id, mappings)

        bdms = [
            self._parse_db_block_device_mapping(bdm_ref)
            for bdm_ref in db.block_device_mapping_get_all_by_instance(
                self.context, instance_id)
        ]
        expected_result = [{
            'virtual_name': 'swap',
            'device_name': '/dev/sdb1'
        }, {
            'virtual_name': 'swap',
            'device_name': '/dev/sdb2'
        }, {
            'virtual_name': 'swap',
            'device_name': '/dev/sdb3'
        }, {
            'virtual_name': 'swap',
            'device_name': '/dev/sdb4'
        }, {
            'virtual_name': 'ephemeral0',
            'device_name': '/dev/sdc1'
        }, {
            'virtual_name': 'ephemeral1',
            'device_name': '/dev/sdc2'
        }, {
            'virtual_name': 'ephemeral2',
            'device_name': '/dev/sdc3'
        }]
        bdms.sort()
        expected_result.sort()
        self.assertDictListMatch(bdms, expected_result)

        self.compute_api._update_block_device_mapping(self.context,
                                                      instance_id,
                                                      block_device_mapping)
        bdms = [
            self._parse_db_block_device_mapping(bdm_ref)
            for bdm_ref in db.block_device_mapping_get_all_by_instance(
                self.context, instance_id)
        ]
        expected_result = [{
            'snapshot_id': 0x12345678,
            'device_name': '/dev/sda1'
        }, {
            'virtual_name': 'swap',
            'device_name': '/dev/sdb1'
        }, {
            'snapshot_id': 0x23456789,
            'device_name': '/dev/sdb2'
        }, {
            'snapshot_id': 0x3456789A,
            'device_name': '/dev/sdb3'
        }, {
            'no_device': True,
            'device_name': '/dev/sdb4'
        }, {
            'virtual_name': 'ephemeral0',
            'device_name': '/dev/sdc1'
        }, {
            'snapshot_id': 0x456789AB,
            'device_name': '/dev/sdc2'
        }, {
            'snapshot_id': 0x56789ABC,
            'device_name': '/dev/sdc3'
        }, {
            'no_device': True,
            'device_name': '/dev/sdc4'
        }, {
            'snapshot_id': 0x87654321,
            'device_name': '/dev/sdd1'
        }, {
            'snapshot_id': 0x98765432,
            'device_name': '/dev/sdd2'
        }, {
            'snapshot_id': 0xA9875463,
            'device_name': '/dev/sdd3'
        }, {
            'no_device': True,
            'device_name': '/dev/sdd4'
        }]
        bdms.sort()
        expected_result.sort()
        self.assertDictListMatch(bdms, expected_result)

        for bdm in db.block_device_mapping_get_all_by_instance(
                self.context, instance_id):
            db.block_device_mapping_destroy(self.context, bdm['id'])
        self.compute.terminate_instance(self.context, instance_id)
Exemplo n.º 12
0
    def test_update_block_device_mapping(self):
        instance_id = self._create_instance()
        mappings = [
                {'virtual': 'ami', 'device': 'sda1'},
                {'virtual': 'root', 'device': '/dev/sda1'},

                {'virtual': 'swap', 'device': 'sdb1'},
                {'virtual': 'swap', 'device': 'sdb2'},
                {'virtual': 'swap', 'device': 'sdb3'},
                {'virtual': 'swap', 'device': 'sdb4'},

                {'virtual': 'ephemeral0', 'device': 'sdc1'},
                {'virtual': 'ephemeral1', 'device': 'sdc2'},
                {'virtual': 'ephemeral2', 'device': 'sdc3'}]
        block_device_mapping = [
                # root
                {'device_name': '/dev/sda1',
                 'snapshot_id': 0x12345678,
                 'delete_on_termination': False},


                # overwrite swap
                {'device_name': '/dev/sdb2',
                 'snapshot_id': 0x23456789,
                 'delete_on_termination': False},
                {'device_name': '/dev/sdb3',
                 'snapshot_id': 0x3456789A},
                {'device_name': '/dev/sdb4',
                 'no_device': True},

                # overwrite ephemeral
                {'device_name': '/dev/sdc2',
                 'snapshot_id': 0x456789AB,
                 'delete_on_termination': False},
                {'device_name': '/dev/sdc3',
                 'snapshot_id': 0x56789ABC},
                {'device_name': '/dev/sdc4',
                 'no_device': True},

                # volume
                {'device_name': '/dev/sdd1',
                 'snapshot_id': 0x87654321,
                 'delete_on_termination': False},
                {'device_name': '/dev/sdd2',
                 'snapshot_id': 0x98765432},
                {'device_name': '/dev/sdd3',
                 'snapshot_id': 0xA9875463},
                {'device_name': '/dev/sdd4',
                 'no_device': True}]

        self.compute_api._update_image_block_device_mapping(
            self.context, instance_id, mappings)

        bdms = [self._parse_db_block_device_mapping(bdm_ref)
                for bdm_ref in db.block_device_mapping_get_all_by_instance(
                    self.context, instance_id)]
        expected_result = [
            {'virtual_name': 'swap', 'device_name': '/dev/sdb1'},
            {'virtual_name': 'swap', 'device_name': '/dev/sdb2'},
            {'virtual_name': 'swap', 'device_name': '/dev/sdb3'},
            {'virtual_name': 'swap', 'device_name': '/dev/sdb4'},
            {'virtual_name': 'ephemeral0', 'device_name': '/dev/sdc1'},
            {'virtual_name': 'ephemeral1', 'device_name': '/dev/sdc2'},
            {'virtual_name': 'ephemeral2', 'device_name': '/dev/sdc3'}]
        bdms.sort()
        expected_result.sort()
        self.assertDictListMatch(bdms, expected_result)

        self.compute_api._update_block_device_mapping(
            self.context, instance_id, block_device_mapping)
        bdms = [self._parse_db_block_device_mapping(bdm_ref)
                for bdm_ref in db.block_device_mapping_get_all_by_instance(
                    self.context, instance_id)]
        expected_result = [
            {'snapshot_id': 0x12345678, 'device_name': '/dev/sda1'},

            {'virtual_name': 'swap', 'device_name': '/dev/sdb1'},
            {'snapshot_id': 0x23456789, 'device_name': '/dev/sdb2'},
            {'snapshot_id': 0x3456789A, 'device_name': '/dev/sdb3'},
            {'no_device': True, 'device_name': '/dev/sdb4'},

            {'virtual_name': 'ephemeral0', 'device_name': '/dev/sdc1'},
            {'snapshot_id': 0x456789AB, 'device_name': '/dev/sdc2'},
            {'snapshot_id': 0x56789ABC, 'device_name': '/dev/sdc3'},
            {'no_device': True, 'device_name': '/dev/sdc4'},

            {'snapshot_id': 0x87654321, 'device_name': '/dev/sdd1'},
            {'snapshot_id': 0x98765432, 'device_name': '/dev/sdd2'},
            {'snapshot_id': 0xA9875463, 'device_name': '/dev/sdd3'},
            {'no_device': True, 'device_name': '/dev/sdd4'}]
        bdms.sort()
        expected_result.sort()
        self.assertDictListMatch(bdms, expected_result)

        for bdm in db.block_device_mapping_get_all_by_instance(
            self.context, instance_id):
            db.block_device_mapping_destroy(self.context, bdm['id'])
        self.compute.terminate_instance(self.context, instance_id)