'Contrived test to ensure finish_resize doesn\'t raise anything.'

def test_finish_resize_with_volumes(self):

    instance = self._create_fake_instance_obj()
    volume = {'instance_uuid': None, 'device_name': None, 'id': 'fake', 'size': 200, 'attach_status': 'detached'}
    bdm = objects.BlockDeviceMapping(**{'context': self.context, 'source_type': 'volume', 'destination_type': 'volume', 'volume_id': uuids.volume_id, 'instance_uuid': instance['uuid'], 'device_name': '/dev/vdc'})
    bdm.create()
    def fake_volume_get(self, context, volume_id):
        return volume
    self.stub_out('nova.volume.cinder.API.get', fake_volume_get)
    def fake_volume_check_availability_zone(self, context, volume_id, instance):
        pass
    self.stub_out('nova.volume.cinder.API.check_availability_zone', fake_volume_check_availability_zone)
    def fake_get_volume_encryption_metadata(self, context, volume_id):
        return {}
    self.stub_out('nova.volume.cinder.API.get_volume_encryption_metadata', fake_get_volume_encryption_metadata)
    orig_connection_data = {'target_discovered': True, 'target_iqn': ('iqn.2010-10.org.openstack:%s.1' % uuids.volume_id), 'target_portal': '127.0.0.0.1:3260', 'volume_id': uuids.volume_id}
    connection_info = {'driver_volume_type': 'iscsi', 'data': orig_connection_data}
    def fake_init_conn(self, context, volume_id, session):
        return connection_info
    self.stub_out('nova.volume.cinder.API.initialize_connection', fake_init_conn)
    def fake_attach(self, context, volume_id, instance_uuid, device_name, mode='rw'):
        volume['instance_uuid'] = instance_uuid
        volume['device_name'] = device_name
    self.stub_out('nova.volume.cinder.API.attach', fake_attach)
    def fake_get_volume_connector(*args, **kwargs):
        return {}
    self.stub_out('nova.virt.fake.FakeDriver.get_volume_connector', fake_get_volume_connector)
    def fake_attach_volume(*args, **kwargs):
        pass
    self.stub_out('nova.virt.fake.FakeDriver.attach_volume', fake_attach_volume)
    self.compute.attach_volume(self.context, instance, bdm)
    self.assertEqual(volume['device_name'], '/dev/vdc')
    disk_info = db.block_device_mapping_get_all_by_instance(self.context, instance.uuid)
    self.assertEqual(len(disk_info), 1)
    for bdm in disk_info:
        self.assertEqual(bdm['device_name'], volume['device_name'])
        self.assertEqual(bdm['connection_info'], jsonutils.dumps(connection_info))
    instance_type = flavors.get_default_flavor()
    instance.task_state = task_states.RESIZE_PREP
    instance.save()
    self.compute.prep_resize(self.context, instance=instance, instance_type=instance_type, image={}, reservations=[], request_spec={}, filter_properties={}, node=None, clean_shutdown=True)
    def fake_terminate_connection(self, context, volume, connector):
        connection_info['data'] = None
    self.stub_out('nova.volume.cinder.API.terminate_connection', fake_terminate_connection)
    self._stub_out_resize_network_methods()
    migration = objects.Migration.get_by_instance_and_status(self.context.elevated(), instance.uuid, 'pre-migrating')
    self.compute.resize_instance(self.context, instance=instance, migration=migration, image={}, reservations=[], instance_type=jsonutils.to_primitive(instance_type), clean_shutdown=True)
    disk_info = db.block_device_mapping_get_all_by_instance(self.context, instance.uuid)
    self.assertEqual(len(disk_info), 1)
    for bdm in disk_info:
        self.assertEqual(bdm['device_name'], volume['device_name'])
        cached_connection_info = jsonutils.loads(bdm['connection_info'])
        self.assertEqual(cached_connection_info['data'], orig_connection_data)
    self.assertIsNone(connection_info['data'])
    def fake(*args, **kwargs):
        pass
    self.stub_out('nova.virt.fake.FakeDriver.finish_migration', fake)
    instance.task_state = task_states.RESIZE_MIGRATED
    instance.save()
    reservations = list('fake_res')
    new_connection_data = dict(orig_connection_data)
    new_iqn = (('iqn.2010-10.org.openstack:%s.2' % uuids.volume_id),)
    new_connection_data['target_iqn'] = new_iqn
    def fake_init_conn_with_data(self, context, volume, session):
        connection_info['data'] = new_connection_data
        return connection_info
    self.stub_out('nova.volume.cinder.API.initialize_connection', fake_init_conn_with_data)
    self.compute.finish_resize(self.context, migration=migration, disk_info={}, image={}, instance=instance, reservations=reservations)
    disk_info = db.block_device_mapping_get_all_by_instance(self.context, instance['uuid'])
    self.assertEqual(len(disk_info), 1)
    for bdm in disk_info:
        self.assertEqual(bdm['connection_info'], jsonutils.dumps(connection_info))
    def fake_detach(self, context, volume_uuid):
        volume['device_path'] = None
        volume['instance_uuid'] = None
    self.stub_out('nova.volume.cinder.API.detach', fake_detach)
    self.compute.terminate_instance(self.context, instance, [], [])
