use glanceclient version '2'. fix keystone error message.

current devstack deploys glance version '2' only.
use it.

messages in keystone's exceptions was changed.
fix unit tests that checks it.

Change-Id: I7ed1f0ff518efa374a5e3b693c5785958c77340d
This commit is contained in:
Andrey Pavlov 2017-03-28 07:22:49 +03:00 committed by tikitavi
parent 824db94f5e
commit 6d30c69895
13 changed files with 224 additions and 234 deletions

View File

@ -126,7 +126,7 @@ auth="--os-project-name $project_name --os-username $user_name --os-password pas
volume_status() { cinder $auth show $1|awk '/ status / {print $4}'; } volume_status() { cinder $auth show $1|awk '/ status / {print $4}'; }
instance_status() { nova $auth show $1|awk '/ status / {print $4}'; } instance_status() { nova $auth show $1|awk '/ status / {print $4}'; }
openstack_image_id=$(openstack $auth image list --long | grep "cirros" | grep " ami " | head -1 | awk '{print $2}') openstack_image_id=$(openstack $auth image list --long | grep "cirros" | grep " bare " | head -1 | awk '{print $2}')
if [[ -n "$openstack_image_id" ]]; then if [[ -n "$openstack_image_id" ]]; then
volume_id=$(cinder $auth create --image-id $openstack_image_id 1 | awk '/ id / {print $4}') volume_id=$(cinder $auth create --image-id $openstack_image_id 1 | awk '/ id / {print $4}')
[[ -n "$volume_id" ]] || { echo "can't create volume for EBS image creation"; exit 1; } [[ -n "$volume_id" ]] || { echo "can't create volume for EBS image creation"; exit 1; }

View File

@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import copy
import datetime import datetime
import json import json
import re import re
@ -373,13 +372,14 @@ def get_os_image(context, ec2_image_id):
def deserialize_os_image_properties(os_image): def deserialize_os_image_properties(os_image):
def prepare_property(property_name): def prepare_property(property_name):
if property_name in properties: if property_name in os_image_dict:
properties[property_name] = json.loads(properties[property_name]) os_image_dict[property_name] = json.loads(
os_image_dict[property_name])
properties = copy.copy(os_image.properties) os_image_dict = dict(os_image)
prepare_property('mappings') prepare_property('mappings')
prepare_property('block_device_mapping') prepare_property('block_device_mapping')
return properties return os_image_dict
def create_virtual_bdm(device_name, virtual_name): def create_virtual_bdm(device_name, virtual_name):

View File

@ -213,18 +213,17 @@ def register_image(context, name=None, image_location=None,
raise exception.MissingParameter(msg) raise exception.MissingParameter(msg)
# TODO(ft): check parameters # TODO(ft): check parameters
properties = {} metadata = {}
metadata = {'properties': properties}
if name: if name:
# TODO(ft): check the name is unique (at least for EBS image case) # TODO(ft): check the name is unique (at least for EBS image case)
metadata['name'] = name metadata['name'] = name
if image_location: if image_location:
properties['image_location'] = image_location metadata['image_location'] = image_location
if 'name' not in metadata: if 'name' not in metadata:
# NOTE(ft): it's needed for backward compatibility # NOTE(ft): it's needed for backward compatibility
metadata['name'] = image_location metadata['name'] = image_location
if root_device_name: if root_device_name:
properties['root_device_name'] = root_device_name metadata['root_device_name'] = root_device_name
cinder = clients.cinder(context) cinder = clients.cinder(context)
if block_device_mapping: if block_device_mapping:
mappings = instance_api._parse_block_device_mapping( mappings = instance_api._parse_block_device_mapping(
@ -246,27 +245,28 @@ def register_image(context, name=None, image_location=None,
bdm['volume_size'] = volume.size bdm['volume_size'] = volume.size
except cinder_exception.NotFound: except cinder_exception.NotFound:
pass pass
properties['bdm_v2'] = True metadata['bdm_v2'] = 'True'
properties['block_device_mapping'] = json.dumps(mappings) metadata['block_device_mapping'] = json.dumps(mappings)
if architecture is not None: if architecture is not None:
properties['architecture'] = architecture metadata['architecture'] = architecture
if kernel_id: if kernel_id:
properties['kernel_id'] = ec2utils.get_os_image(context, metadata['kernel_id'] = ec2utils.get_os_image(context,
kernel_id).id kernel_id).id
if ramdisk_id: if ramdisk_id:
properties['ramdisk_id'] = ec2utils.get_os_image(context, metadata['ramdisk_id'] = ec2utils.get_os_image(context,
ramdisk_id).id ramdisk_id).id
with common.OnCrashCleaner() as cleaner: with common.OnCrashCleaner() as cleaner:
if 'image_location' in properties: glance = clients.glance(context)
if 'image_location' in metadata:
os_image = _s3_create(context, metadata) os_image = _s3_create(context, metadata)
else: else:
metadata.update({'size': 0, metadata.update({'visibility': 'private',
'is_public': False}) 'container_format': 'bare',
# TODO(ft): set default values of image properties 'disk_format': 'raw'})
glance = clients.glance(context)
os_image = glance.images.create(**metadata) os_image = glance.images.create(**metadata)
cleaner.addCleanup(os_image.delete) glance.images.upload(os_image.id, '', image_size=0)
cleaner.addCleanup(glance.images.delete, os_image.id)
kind = _get_os_image_kind(os_image) kind = _get_os_image_kind(os_image)
image = db_api.add_item(context, kind, {'os_id': os_image.id, image = db_api.add_item(context, kind, {'os_id': os_image.id,
'is_public': False, 'is_public': False,
@ -366,9 +366,9 @@ class ImageDescriber(common.TaggableItemsDescriber):
def get_os_items(self): def get_os_items(self):
os_images = list(clients.glance(self.context).images.list()) os_images = list(clients.glance(self.context).images.list())
self.ec2_created_os_images = { self.ec2_created_os_images = {
os_image.properties['ec2_id']: os_image os_image.ec2_id: os_image
for os_image in os_images for os_image in os_images
if (os_image.properties.get('ec2_id') and if (hasattr(os_image, 'ec2_id') and
self.context.project_id == os_image.owner)} self.context.project_id == os_image.owner)}
return os_images return os_images
@ -376,12 +376,12 @@ class ImageDescriber(common.TaggableItemsDescriber):
if not image: if not image:
kind = _get_os_image_kind(os_image) kind = _get_os_image_kind(os_image)
if self.context.project_id == os_image.owner: if self.context.project_id == os_image.owner:
if os_image.properties.get('ec2_id') in self.pending_images: if getattr(os_image, 'ec2_id', None) in self.pending_images:
# NOTE(ft): the image is being creating, Glance had created # NOTE(ft): the image is being creating, Glance had created
# image, but creating thread doesn't yet update db item # image, but creating thread doesn't yet update db item
image = self.pending_images[os_image.properties['ec2_id']] image = self.pending_images[os_image.ec2_id]
image['os_id'] = os_image.id image['os_id'] = os_image.id
image['is_public'] = os_image.is_public image['is_public'] = os_image.visibility == 'public'
db_api.update_item(self.context, image) db_api.update_item(self.context, image)
else: else:
image = ec2utils.get_db_item_by_os_id( image = ec2utils.get_db_item_by_os_id(
@ -394,8 +394,8 @@ class ImageDescriber(common.TaggableItemsDescriber):
image = {'id': image_id, image = {'id': image_id,
'os_id': os_image.id} 'os_id': os_image.id}
elif (self.context.project_id == os_image.owner and elif (self.context.project_id == os_image.owner and
image.get('is_public') != os_image.is_public): image.get('is_public') != os_image.visibility == 'public'):
image['is_public'] = os_image.is_public image['is_public'] = os_image.visibility == 'public'
if image['id'] in self.local_images_os_ids: if image['id'] in self.local_images_os_ids:
db_api.update_item(self.context, image) db_api.update_item(self.context, image)
else: else:
@ -430,7 +430,7 @@ class ImageDescriber(common.TaggableItemsDescriber):
os_image = self.ec2_created_os_images.get(item['id']) os_image = self.ec2_created_os_images.get(item['id'])
if os_image: if os_image:
item['os_id'] = os_image.id item['os_id'] = os_image.id
item['is_public'] = os_image.is_public item['is_public'] = os_image.visibility == 'public'
db_api.update_item(self.context, item) db_api.update_item(self.context, item)
image = self.format(item, os_image) image = self.format(item, os_image)
else: else:
@ -468,18 +468,18 @@ def describe_image_attribute(context, image_id, attribute):
def _launch_permission_attribute(os_image, image, result): def _launch_permission_attribute(os_image, image, result):
result['launchPermission'] = [] result['launchPermission'] = []
if os_image.is_public: if os_image.visibility == 'public':
result['launchPermission'].append({'group': 'all'}) result['launchPermission'].append({'group': 'all'})
def _kernel_attribute(os_image, image, result): def _kernel_attribute(os_image, image, result):
kernel_id = os_image.properties.get('kernel_id') kernel_id = getattr(os_image, 'kernel_id', None)
if kernel_id: if kernel_id:
result['kernel'] = { result['kernel'] = {
'value': ec2utils.os_id_to_ec2_id(context, 'aki', kernel_id) 'value': ec2utils.os_id_to_ec2_id(context, 'aki', kernel_id)
} }
def _ramdisk_attribute(os_image, image, result): def _ramdisk_attribute(os_image, image, result):
ramdisk_id = os_image.properties.get('ramdisk_id') ramdisk_id = getattr(os_image, 'ramdisk_id', None)
if ramdisk_id: if ramdisk_id:
result['ramdisk'] = { result['ramdisk'] = {
'value': ec2utils.os_id_to_ec2_id(context, 'ari', ramdisk_id) 'value': ec2utils.os_id_to_ec2_id(context, 'ari', ramdisk_id)
@ -589,7 +589,9 @@ def modify_image_attribute(context, image_id, attribute=None,
reason=msg) reason=msg)
_check_owner(context, os_image) _check_owner(context, os_image)
os_image.update(is_public=(operation_type == 'add')) glance = clients.glance(context)
visibility = 'public' if operation_type == 'add' else 'private'
glance.images.update(os_image.id, visibility=visibility)
return True return True
if 'description' in attributes: if 'description' in attributes:
@ -610,8 +612,8 @@ def reset_image_attribute(context, image_id, attribute):
os_image = ec2utils.get_os_image(context, image_id) os_image = ec2utils.get_os_image(context, image_id)
_check_owner(context, os_image) _check_owner(context, os_image)
glance = clients.glance(context)
os_image.update(is_public=False) glance.images.update(os_image.id, visibility='private')
return True return True
@ -627,8 +629,8 @@ def _format_image(context, image, os_image, images_dict, ids_dict,
'imageOwnerId': os_image.owner, 'imageOwnerId': os_image.owner,
'imageType': IMAGE_TYPES[ 'imageType': IMAGE_TYPES[
ec2utils.get_ec2_id_kind(image['id'])], ec2utils.get_ec2_id_kind(image['id'])],
'isPublic': os_image.is_public, 'isPublic': os_image.visibility == 'public',
'architecture': os_image.properties.get('architecture'), 'architecture': getattr(os_image, 'architecture', None),
'creationDate': os_image.created_at 'creationDate': os_image.created_at
} }
if 'description' in image: if 'description' in image:
@ -638,23 +640,23 @@ def _format_image(context, image, os_image, images_dict, ids_dict,
else: else:
state = GLANCE_STATUS_TO_EC2.get(os_image.status, 'error') state = GLANCE_STATUS_TO_EC2.get(os_image.status, 'error')
if state in ('available', 'pending'): if state in ('available', 'pending'):
state = _s3_image_state_map.get(os_image.properties.get('image_state'), state = _s3_image_state_map.get(getattr(os_image, 'image_state', None),
state) state)
ec2_image['imageState'] = state ec2_image['imageState'] = state
kernel_id = os_image.properties.get('kernel_id') kernel_id = getattr(os_image, 'kernel_id', None)
if kernel_id: if kernel_id:
ec2_image['kernelId'] = ec2utils.os_id_to_ec2_id( ec2_image['kernelId'] = ec2utils.os_id_to_ec2_id(
context, 'aki', kernel_id, context, 'aki', kernel_id,
items_by_os_id=images_dict, ids_by_os_id=ids_dict) items_by_os_id=images_dict, ids_by_os_id=ids_dict)
ramdisk_id = os_image.properties.get('ramdisk_id') ramdisk_id = getattr(os_image, 'ramdisk_id', None)
if ramdisk_id: if ramdisk_id:
ec2_image['ramdiskId'] = ec2utils.os_id_to_ec2_id( ec2_image['ramdiskId'] = ec2utils.os_id_to_ec2_id(
context, 'ari', ramdisk_id, context, 'ari', ramdisk_id,
items_by_os_id=images_dict, ids_by_os_id=ids_dict) items_by_os_id=images_dict, ids_by_os_id=ids_dict)
name = os_image.name name = os_image.name
img_loc = os_image.properties.get('image_location') img_loc = getattr(os_image, 'image_location', None)
if img_loc: if img_loc:
ec2_image['imageLocation'] = img_loc ec2_image['imageLocation'] = img_loc
else: else:
@ -783,7 +785,7 @@ def _get_os_image_kind(os_image):
def _auto_create_image_extension(context, image, os_image): def _auto_create_image_extension(context, image, os_image):
image['is_public'] = os_image.is_public image['is_public'] = os_image.visibility == 'public'
ec2utils.register_auto_create_db_item_extension( ec2utils.register_auto_create_db_item_extension(
@ -810,7 +812,7 @@ _s3_image_state_map = {'downloading': 'pending',
def _s3_create(context, metadata): def _s3_create(context, metadata):
"""Gets a manifest from s3 and makes an image.""" """Gets a manifest from s3 and makes an image."""
image_location = metadata['properties']['image_location'].lstrip('/') image_location = metadata['image_location'].lstrip('/')
bucket_name = image_location.split('/')[0] bucket_name = image_location.split('/')[0]
manifest_path = image_location[len(bucket_name) + 1:] manifest_path = image_location[len(bucket_name) + 1:]
bucket = _s3_conn(context).get_bucket(bucket_name) bucket = _s3_conn(context).get_bucket(bucket_name)
@ -819,12 +821,9 @@ def _s3_create(context, metadata):
(image_metadata, image_parts, (image_metadata, image_parts,
encrypted_key, encrypted_iv) = _s3_parse_manifest(context, manifest) encrypted_key, encrypted_iv) = _s3_parse_manifest(context, manifest)
properties = metadata['properties']
properties.update(image_metadata['properties'])
properties['image_state'] = 'pending'
metadata.update(image_metadata) metadata.update(image_metadata)
metadata.update({'properties': properties, metadata.update({'image_state': 'pending',
'is_public': False}) 'visibility': 'private'})
# TODO(bcwaldon): right now, this removes user-defined ids # TODO(bcwaldon): right now, this removes user-defined ids
# We need to re-enable this. # We need to re-enable this.
@ -834,7 +833,7 @@ def _s3_create(context, metadata):
image = glance.images.create(**metadata) image = glance.images.create(**metadata)
def _update_image_state(image_state): def _update_image_state(image_state):
image.update(properties={'image_state': image_state}) glance.images.update(image.id, image_state=image_state)
def delayed_create(): def delayed_create():
"""This handles the fetching and decrypting of the part files.""" """This handles the fetching and decrypting of the part files."""
@ -887,7 +886,7 @@ def _s3_create(context, metadata):
_update_image_state('uploading') _update_image_state('uploading')
try: try:
with open(unz_filename) as image_file: with open(unz_filename) as image_file:
image.update(data=image_file) glance.images.upload(image.id, image_file)
except Exception: except Exception:
LOG.exception(_LE('Failed to upload %(image_location)s ' LOG.exception(_LE('Failed to upload %(image_location)s '
'to %(image_path)s'), log_vars) 'to %(image_path)s'), log_vars)
@ -916,7 +915,7 @@ def _s3_parse_manifest(context, manifest):
except Exception: except Exception:
arch = 'x86_64' arch = 'x86_64'
properties = {'architecture': arch} metadata = {'architecture': arch}
mappings = [] mappings = []
try: try:
@ -930,7 +929,7 @@ def _s3_parse_manifest(context, manifest):
mappings = [] mappings = []
if mappings: if mappings:
properties['mappings'] = mappings metadata['mappings'] = mappings
def set_dependent_image_id(image_key): def set_dependent_image_id(image_key):
try: try:
@ -942,7 +941,7 @@ def _s3_parse_manifest(context, manifest):
if image_id == 'true': if image_id == 'true':
return True return True
os_image = ec2utils.get_os_image(context, image_id) os_image = ec2utils.get_os_image(context, image_id)
properties[image_key] = os_image.id metadata[image_key] = os_image.id
image_format = 'ami' image_format = 'ami'
if set_dependent_image_id('kernel_id'): if set_dependent_image_id('kernel_id'):
@ -950,9 +949,8 @@ def _s3_parse_manifest(context, manifest):
if set_dependent_image_id('ramdisk_id'): if set_dependent_image_id('ramdisk_id'):
image_format = 'ari' image_format = 'ari'
metadata = {'disk_format': image_format, metadata.update({'disk_format': image_format,
'container_format': image_format, 'container_format': image_format})
'properties': properties}
image_parts = [ image_parts = [
fn_element.text fn_element.text
for fn_element in manifest.find('image').getiterator('filename')] for fn_element in manifest.find('image').getiterator('filename')]

View File

@ -1518,7 +1518,7 @@ def _cloud_get_image_state(image):
state = image.status state = image.status
if state == 'active': if state == 'active':
state = 'available' state = 'available'
return image.properties.get('image_state', state) return getattr(image, 'image_state', state)
def _cloud_format_kernel_id(context, os_instance, image_ids=None): def _cloud_format_kernel_id(context, os_instance, image_ids=None):

View File

@ -117,7 +117,7 @@ def neutron(context):
def glance(context): def glance(context):
return glanceclient.Client('1', service_type='image', return glanceclient.Client(version='2', service_type='image',
session=context.session) session=context.session)

View File

@ -218,11 +218,11 @@ class ImageTest(base.EC2TestCase):
data = self.client.describe_image_attribute( data = self.client.describe_image_attribute(
ImageId=image_id, Attribute='kernel') ImageId=image_id, Attribute='kernel')
self.assertIn('KernelId', data) self.assertNotIn('KernelId', data)
data = self.client.describe_image_attribute( data = self.client.describe_image_attribute(
ImageId=image_id, Attribute='ramdisk') ImageId=image_id, Attribute='ramdisk')
self.assertIn('RamdiskId', data) self.assertNotIn('RamdiskId', data)
# description # description
data = self.client.describe_image_attribute( data = self.client.describe_image_attribute(

View File

@ -111,8 +111,9 @@ class MockOSMixin(object):
def mock_glance(self): def mock_glance(self):
glance_patcher = mock.patch('glanceclient.client.Client') glance_patcher = mock.patch('glanceclient.client.Client')
glance = mock.create_autospec(glanceclient.Client(endpoint='v1')) with mock.patch('glanceclient.v2.schemas.Controller'):
glance_patcher.start().return_value = glance glance = mock.create_autospec(glanceclient.Client(endpoint='v2'))
glance_patcher.start().return_value = glance
self.addCleanup(glance_patcher.stop) self.addCleanup(glance_patcher.stop)
return glance return glance

View File

@ -1597,31 +1597,33 @@ class OSImage(object):
def __init__(self, image_dict, from_get=False): def __init__(self, image_dict, from_get=False):
def set_attr(attr): if from_get:
if not from_get or image_dict.get(attr) is not None: attrs = [k for k in image_dict.keys()
setattr(self, attr, image_dict.get(attr)) if image_dict[k] is not None]
else:
self.id = image_dict['id'] attrs = list(image_dict)
set_attr('owner') attrs.extend(
set_attr('created_at') ['owner', 'created_at', 'visibility', 'status',
set_attr('is_public') 'container_format', 'name'])
set_attr('status') self._image_dict = {'id': image_dict['id']}
set_attr('container_format') self._image_dict.update({k: image_dict.get(k)
set_attr('name') for k in attrs})
self.properties = copy.deepcopy(image_dict.get('properties', {}))
for complex_attr in ('mappings', 'block_device_mapping'): for complex_attr in ('mappings', 'block_device_mapping'):
if complex_attr in self.properties: if complex_attr in self._image_dict:
self.properties[complex_attr] = ( self._image_dict[complex_attr] = json.dumps(
json.dumps(self.properties[complex_attr])) self._image_dict[complex_attr])
for k in self._image_dict:
setattr(self, k, self._image_dict[k])
def __eq__(self, other): def __eq__(self, other):
return type(self) == type(other) and self.__dict__ == other.__dict__ return type(self) == type(other) and self.__dict__ == other.__dict__
def update(self, **kwargs): def __iter__(self):
pass for key in self._image_dict.items():
yield key
def delete(self): def __getitem__(self, key):
pass return self._image_dict.get(key)
TIME_CREATE_IMAGE = timeutils.isotime(None, True) TIME_CREATE_IMAGE = timeutils.isotime(None, True)
@ -1709,63 +1711,59 @@ OS_IMAGE_1 = {
'id': ID_OS_IMAGE_1, 'id': ID_OS_IMAGE_1,
'owner': ID_OS_PROJECT, 'owner': ID_OS_PROJECT,
'created_at': TIME_CREATE_IMAGE, 'created_at': TIME_CREATE_IMAGE,
'is_public': False, 'visibility': 'private',
'status': 'active', 'status': 'active',
'container_format': 'ami', 'container_format': 'ami',
'name': 'fake_name', 'name': 'fake_name',
'properties': { 'kernel_id': ID_OS_IMAGE_AKI_1,
'kernel_id': ID_OS_IMAGE_AKI_1, 'ramdisk_id': ID_OS_IMAGE_ARI_1,
'ramdisk_id': ID_OS_IMAGE_ARI_1, 'type': 'machine',
'type': 'machine', 'image_state': 'available',
'image_state': 'available', 'image_location': LOCATION_IMAGE_1,
'image_location': LOCATION_IMAGE_1, 'mappings': [
'mappings': [ {'device': '/dev/sda1', 'virtual': 'root'},
{'device': '/dev/sda1', 'virtual': 'root'}, {'device': 'sdb0', 'virtual': 'ephemeral0'},
{'device': 'sdb0', 'virtual': 'ephemeral0'}, {'device': 'sdb1', 'virtual': 'ephemeral1'},
{'device': 'sdb1', 'virtual': 'ephemeral1'}, {'device': 'sdb2', 'virtual': 'ephemeral2'},
{'device': 'sdb2', 'virtual': 'ephemeral2'}, {'device': 'sdb3', 'virtual': 'ephemeral3'},
{'device': 'sdb3', 'virtual': 'ephemeral3'}, {'device': 'sdb4', 'virtual': 'ephemeral4'},
{'device': 'sdb4', 'virtual': 'ephemeral4'}, {'device': 'sdc0', 'virtual': 'swap'},
{'device': 'sdc0', 'virtual': 'swap'}, {'device': 'sdc1', 'virtual': 'swap'},
{'device': 'sdc1', 'virtual': 'swap'}, {'device': 'sdc2', 'virtual': 'swap'},
{'device': 'sdc2', 'virtual': 'swap'}, {'device': 'sdc3', 'virtual': 'swap'},
{'device': 'sdc3', 'virtual': 'swap'}, {'device': 'sdc4', 'virtual': 'swap'}],
{'device': 'sdc4', 'virtual': 'swap'}], 'block_device_mapping': [
'block_device_mapping': [ {'device_name': '/dev/sdb1',
{'device_name': '/dev/sdb1', 'snapshot_id': ID_OS_SNAPSHOT_1,
'snapshot_id': ID_OS_SNAPSHOT_1, 'volume_size': 22},
'volume_size': 22}, {'device_name': '/dev/sdb2',
{'device_name': '/dev/sdb2', 'volume_id': ID_OS_VOLUME_1},
'volume_id': ID_OS_VOLUME_1}, {'device_name': '/dev/sdb3', 'virtual_name': 'ephemeral5'},
{'device_name': '/dev/sdb3', 'virtual_name': 'ephemeral5'}, {'device_name': '/dev/sdb4', 'no_device': True},
{'device_name': '/dev/sdb4', 'no_device': True}, {'device_name': '/dev/sdc1',
{'device_name': '/dev/sdc1', 'snapshot_id': ID_OS_SNAPSHOT_2},
'snapshot_id': ID_OS_SNAPSHOT_2}, {'device_name': '/dev/sdc2',
{'device_name': '/dev/sdc2', 'volume_id': ID_OS_VOLUME_2},
'volume_id': ID_OS_VOLUME_2}, {'device_name': '/dev/sdc3', 'virtual_name': 'ephemeral6'},
{'device_name': '/dev/sdc3', 'virtual_name': 'ephemeral6'}, {'device_name': '/dev/sdc4', 'no_device': True}]
{'device_name': '/dev/sdc4', 'no_device': True}],
}
} }
OS_IMAGE_2 = { OS_IMAGE_2 = {
'id': ID_OS_IMAGE_2, 'id': ID_OS_IMAGE_2,
'owner': ID_OS_PROJECT, 'owner': ID_OS_PROJECT,
'created_at': TIME_CREATE_IMAGE, 'created_at': TIME_CREATE_IMAGE,
'is_public': True, 'visibility': 'public',
'status': 'active', 'status': 'active',
'container_format': None, 'container_format': None,
'name': None, 'name': None,
'properties': { 'type': 'machine',
'type': 'machine', 'root_device_name': '/dev/sdb1',
'root_device_name': '/dev/sdb1', 'architecture': 'x86_64',
'architecture': 'x86_64', 'mappings': [{'device': '/dev/sda1',
'mappings': [{'device': '/dev/sda1', 'virtual': 'root'}],
'virtual': 'root'}], 'block_device_mapping': [
'block_device_mapping': [ {'device_name': '/dev/sdb1',
{'device_name': '/dev/sdb1', 'snapshot_id': ID_OS_SNAPSHOT_1,
'snapshot_id': ID_OS_SNAPSHOT_1, 'delete_on_termination': True}],
'delete_on_termination': True}],
}
} }
OS_IMAGE_AKI_1 = { OS_IMAGE_AKI_1 = {
'id': ID_OS_IMAGE_AKI_1, 'id': ID_OS_IMAGE_AKI_1,

View File

@ -99,6 +99,6 @@ class ApiInitTestCase(base.BaseTestCase):
do_check(neutron_exception.BadRequest(message='fake_msg'), do_check(neutron_exception.BadRequest(message='fake_msg'),
400, 'BadRequest', 'fake_msg') 400, 'BadRequest', 'fake_msg')
do_check(keystone_exception.BadRequest(message='fake_msg'), do_check(keystone_exception.BadRequest(message='fake_msg'),
400, 'BadRequest', 'fake_msg') 400, 'BadRequest', 'fake_msg (HTTP 400)')
do_check(boto_exception.S3ResponseError(400, '', 'fake_msg'), do_check(boto_exception.S3ResponseError(400, '', 'fake_msg'),
400, 'S3ResponseError', 'fake_msg') 400, 'S3ResponseError', 'fake_msg')

View File

@ -107,7 +107,7 @@ class ClientsTestCase(base.BaseTestCase):
context = mock.NonCallableMock(session=mock.sentinel.session) context = mock.NonCallableMock(session=mock.sentinel.session)
res = clients.glance(context) res = clients.glance(context)
self.assertEqual(glance.return_value, res) self.assertEqual(glance.return_value, res)
glance.assert_called_with('1', service_type='image', glance.assert_called_with(version='2', service_type='image',
session=mock.sentinel.session) session=mock.sentinel.session)
@mock.patch('cinderclient.client.Client') @mock.patch('cinderclient.client.Client')

View File

@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import copy
import json import json
import os import os
import tempfile import tempfile
@ -179,7 +178,7 @@ class ImageTestCase(base.ApiTestCase):
s3_create.assert_called_once_with( s3_create.assert_called_once_with(
mock.ANY, mock.ANY,
{'name': fakes.LOCATION_IMAGE_1, {'name': fakes.LOCATION_IMAGE_1,
'properties': {'image_location': fakes.LOCATION_IMAGE_1}}) 'image_location': fakes.LOCATION_IMAGE_1})
s3_create.reset_mock() s3_create.reset_mock()
resp = self.execute( resp = self.execute(
@ -192,12 +191,14 @@ class ImageTestCase(base.ApiTestCase):
s3_create.assert_called_once_with( s3_create.assert_called_once_with(
mock.ANY, mock.ANY,
{'name': 'an image name', {'name': 'an image name',
'properties': {'image_location': fakes.LOCATION_IMAGE_1}}) 'image_location': fakes.LOCATION_IMAGE_1})
@mock.patch('ec2api.api.ec2utils.get_os_image') @mock.patch('ec2api.api.ec2utils.get_os_image')
def test_register_image_by_bdm(self, get_os_image): def test_register_image_by_bdm(self, get_os_image):
self.glance.images.create.return_value = ( self.glance.images.create.return_value = (
fakes.OSImage(fakes.OS_IMAGE_2)) fakes.OSImage(fakes.OS_IMAGE_2))
self.glance.images.upload.return_value = (
fakes.OSImage(fakes.OS_IMAGE_2))
self.cinder.volume_snapshots.get.side_effect = ( self.cinder.volume_snapshots.get.side_effect = (
tools.get_by_1st_arg_getter( tools.get_by_1st_arg_getter(
{fakes.ID_OS_SNAPSHOT_1: ( {fakes.ID_OS_SNAPSHOT_1: (
@ -235,21 +236,19 @@ class ImageTestCase(base.ApiTestCase):
'description': None}) 'description': None})
self.assertEqual(1, self.glance.images.create.call_count) self.assertEqual(1, self.glance.images.create.call_count)
self.assertEqual((), self.glance.images.create.call_args[0]) self.assertEqual((), self.glance.images.create.call_args[0])
self.assertIn('properties', self.glance.images.create.call_args[1])
self.assertIsInstance( self.assertIsInstance(
self.glance.images.create.call_args[1]['properties'], self.glance.images.create.call_args[1], dict)
dict) bdm = self.glance.images.create.call_args[1].pop(
bdm = self.glance.images.create.call_args[1]['properties'].pop(
'block_device_mapping', 'null') 'block_device_mapping', 'null')
self.assertEqual( self.assertEqual(
{'is_public': False, {'visibility': 'private',
'size': 0,
'name': 'fake_name', 'name': 'fake_name',
'properties': { 'kernel_id': fakes.ID_OS_IMAGE_AKI_1,
'root_device_name': fakes.ROOT_DEVICE_NAME_IMAGE_2, 'ramdisk_id': fakes.ID_OS_IMAGE_ARI_1,
'kernel_id': fakes.ID_OS_IMAGE_AKI_1, 'root_device_name': fakes.ROOT_DEVICE_NAME_IMAGE_2,
'ramdisk_id': fakes.ID_OS_IMAGE_ARI_1, 'container_format': 'bare',
'bdm_v2': True}}, 'disk_format': 'raw',
'bdm_v2': 'True'},
self.glance.images.create.call_args[1]) self.glance.images.create.call_args[1])
self.assertEqual([{'boot_index': 0, self.assertEqual([{'boot_index': 0,
'delete_on_termination': True, 'delete_on_termination': True,
@ -438,8 +437,7 @@ class ImageTestCase(base.ApiTestCase):
{'ImageId': image_id, {'ImageId': image_id,
'Attribute': 'kernel'}) 'Attribute': 'kernel'})
@mock.patch.object(fakes.OSImage, 'update', autospec=True) def test_modify_image_attributes(self):
def test_modify_image_attributes(self, osimage_update):
self._setup_model() self._setup_model()
resp = self.execute('ModifyImageAttribute', resp = self.execute('ModifyImageAttribute',
@ -448,10 +446,8 @@ class ImageTestCase(base.ApiTestCase):
'operationType': 'add', 'operationType': 'add',
'userGroup.1': 'all'}) 'userGroup.1': 'all'})
self.assertThat(resp, matchers.DictMatches({'return': True})) self.assertThat(resp, matchers.DictMatches({'return': True}))
osimage_update.assert_called_once_with( self.glance.images.update.assert_called_once_with(
mock.ANY, is_public=True) fakes.ID_OS_IMAGE_1, visibility='public')
self.assertEqual(fakes.ID_OS_IMAGE_1,
osimage_update.call_args[0][0].id)
def test_modify_image_attributes_invalid_parameters(self): def test_modify_image_attributes_invalid_parameters(self):
image_id = fakes.random_ec2_id('ami') image_id = fakes.random_ec2_id('ami')
@ -487,10 +483,16 @@ class ImagePrivateTestCase(base.BaseTestCase):
image_ids = {fakes.ID_OS_IMAGE_1: fakes.ID_EC2_IMAGE_1, image_ids = {fakes.ID_OS_IMAGE_1: fakes.ID_EC2_IMAGE_1,
fakes.ID_OS_IMAGE_AKI_1: fakes.ID_EC2_IMAGE_AKI_1, fakes.ID_OS_IMAGE_AKI_1: fakes.ID_EC2_IMAGE_AKI_1,
fakes.ID_OS_IMAGE_ARI_1: fakes.ID_EC2_IMAGE_ARI_1} fakes.ID_OS_IMAGE_ARI_1: fakes.ID_EC2_IMAGE_ARI_1}
os_image = copy.deepcopy(fakes.OS_IMAGE_1) os_image = {'id': fakes.ID_OS_IMAGE_1,
'owner': fakes.ID_OS_PROJECT,
'created_at': fakes.TIME_CREATE_IMAGE,
'visibility': 'private',
'status': 'active',
'container_format': 'ami',
'name': 'fake_name'}
# check name and location attributes for an unnamed image # check name and location attributes for an unnamed image
os_image['properties'] = {'image_location': 'location'} os_image['image_location'] = 'location'
os_image['name'] = None os_image['name'] = None
image = image_api._format_image( image = image_api._format_image(
@ -501,7 +503,7 @@ class ImagePrivateTestCase(base.BaseTestCase):
self.assertEqual('location', image['name']) self.assertEqual('location', image['name'])
# check name and location attributes for complete image # check name and location attributes for complete image
os_image['properties'] = {} os_image['image_location'] = None
os_image['name'] = 'fake_name' os_image['name'] = 'fake_name'
image = image_api._format_image( image = image_api._format_image(
@ -512,14 +514,13 @@ class ImagePrivateTestCase(base.BaseTestCase):
self.assertEqual('fake_name', image['name']) self.assertEqual('fake_name', image['name'])
# check ebs image type for bdm_v2 mapping type # check ebs image type for bdm_v2 mapping type
os_image['properties'] = { os_image['bdm_v2'] = True
'bdm_v2': True, os_image['root_device_name'] = '/dev/vda'
'root_device_name': '/dev/vda', os_image['block_device_mapping'] = [
'block_device_mapping': [ {'boot_index': 0,
{'boot_index': 0, 'snapshot_id': fakes.ID_OS_SNAPSHOT_2,
'snapshot_id': fakes.ID_OS_SNAPSHOT_2, 'source_type': 'snapshot',
'source_type': 'snapshot', 'destination_type': 'volume'}]
'destination_type': 'volume'}]}
image = image_api._format_image( image = image_api._format_image(
'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image),
@ -529,7 +530,9 @@ class ImagePrivateTestCase(base.BaseTestCase):
self.assertEqual('ebs', image['rootDeviceType']) self.assertEqual('ebs', image['rootDeviceType'])
# check instance-store image attributes with no any device mappings # check instance-store image attributes with no any device mappings
os_image['properties'] = {'root_device_name': '/dev/vda'} os_image['bdm_v2'] = False
os_image['root_device_name'] = '/dev/vda'
os_image['block_device_mapping'] = []
image = image_api._format_image( image = image_api._format_image(
'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image),
None, None) None, None)
@ -559,7 +562,7 @@ class ImagePrivateTestCase(base.BaseTestCase):
os_image.status = 'queued' os_image.status = 'queued'
def check_state_translation(state, expected): def check_state_translation(state, expected):
os_image.properties['image_state'] = state os_image.image_state = state
image = image_api._format_image( image = image_api._format_image(
'fake_context', fakes.DB_IMAGE_1, os_image, None, None) 'fake_context', fakes.DB_IMAGE_1, os_image, None, None)
self.assertEqual(expected, image['imageState'], self.assertEqual(expected, image['imageState'],
@ -741,8 +744,8 @@ class ImagePrivateTestCase(base.BaseTestCase):
os_image = {'id': os_image_id, os_image = {'id': os_image_id,
'owner': fakes.ID_OS_PROJECT, 'owner': fakes.ID_OS_PROJECT,
'status': 'active', 'status': 'active',
'is_public': False, 'visibility': 'private',
'properties': {'ec2_id': image_id}} 'ec2_id': image_id}
glance.images.list.return_value = [fakes.OSImage(os_image)] glance.images.list.return_value = [fakes.OSImage(os_image)]
expected['imagesSet'] = [{ expected['imagesSet'] = [{
'architecture': None, 'architecture': None,
@ -788,14 +791,14 @@ class S3TestCase(base.BaseTestCase):
expected_metadata = { expected_metadata = {
'disk_format': 'ami', 'disk_format': 'ami',
'container_format': 'ami', 'container_format': 'ami',
'properties': {'architecture': 'x86_64', 'architecture': 'x86_64',
'kernel_id': fakes.ID_OS_IMAGE_AKI_1, 'kernel_id': fakes.ID_OS_IMAGE_AKI_1,
'ramdisk_id': fakes.ID_OS_IMAGE_ARI_1, 'ramdisk_id': fakes.ID_OS_IMAGE_ARI_1,
'mappings': [ 'mappings': [
{"device": "sda1", "virtual": "ami"}, {"device": "sda1", "virtual": "ami"},
{"device": "/dev/sda1", "virtual": "root"}, {"device": "/dev/sda1", "virtual": "root"},
{"device": "sda2", "virtual": "ephemeral0"}, {"device": "sda2", "virtual": "ephemeral0"},
{"device": "sda3", "virtual": "swap"}]}} {"device": "sda3", "virtual": "swap"}]}
self.assertThat(metadata, self.assertThat(metadata,
matchers.DictMatches(expected_metadata, matchers.DictMatches(expected_metadata,
orderless_lists=True)) orderless_lists=True))
@ -810,8 +813,7 @@ class S3TestCase(base.BaseTestCase):
mock.ANY, 'ari', item_ids=(fakes.ID_EC2_IMAGE_ARI_1,), mock.ANY, 'ari', item_ids=(fakes.ID_EC2_IMAGE_ARI_1,),
item_os_ids=None) item_os_ids=None)
@mock.patch.object(fakes.OSImage, 'update', autospec=True) def test_s3_create_image_locations(self):
def test_s3_create_image_locations(self, osimage_update):
self.configure(image_decryption_dir=None) self.configure(image_decryption_dir=None)
glance = self.mock_glance() glance = self.mock_glance()
_handle, tempf = tempfile.mkstemp() _handle, tempf = tempfile.mkstemp()
@ -829,24 +831,23 @@ class S3TestCase(base.BaseTestCase):
get_contents_as_string.return_value) = FILE_MANIFEST_XML get_contents_as_string.return_value) = FILE_MANIFEST_XML
s3_download_file.return_value = tempf s3_download_file.return_value = tempf
s3_untarzip_image.return_value = tempf s3_untarzip_image.return_value = tempf
os_image_id = fakes.random_os_id()
(glance.images.create.return_value) = ( (glance.images.create.return_value) = (
fakes.OSImage({'id': fakes.random_os_id(), fakes.OSImage({'id': os_image_id,
'status': 'queued'})) 'status': 'queued'}))
data = [ data = [
({'properties': { ({'image_location': 'testbucket_1/test.img.manifest.xml'},
'image_location': 'testbucket_1/test.img.manifest.xml'}},
'testbucket_1', 'test.img.manifest.xml'), 'testbucket_1', 'test.img.manifest.xml'),
({'properties': { ({'image_location': '/testbucket_2/test.img.manifest.xml'},
'image_location': '/testbucket_2/test.img.manifest.xml'}},
'testbucket_2', 'test.img.manifest.xml')] 'testbucket_2', 'test.img.manifest.xml')]
for mdata, bucket, manifest in data: for mdata, bucket, manifest in data:
image = image_api._s3_create(fake_context, mdata) image = image_api._s3_create(fake_context, mdata)
eventlet.sleep() eventlet.sleep()
osimage_update.assert_called_with( self.glance.images.update.assert_called_with(
image, properties={'image_state': 'available'}) os_image_id, image_state='available')
osimage_update.assert_any_call( self.glance.images.upload.assert_any_call(
image, data=mock.ANY) os_image_id, mock.ANY)
s3_conn.return_value.get_bucket.assert_called_with(bucket) s3_conn.return_value.get_bucket.assert_called_with(bucket)
(s3_conn.return_value.get_bucket.return_value. (s3_conn.return_value.get_bucket.return_value.
get_key.assert_called_with(manifest)) get_key.assert_called_with(manifest))
@ -865,17 +866,16 @@ class S3TestCase(base.BaseTestCase):
@mock.patch('ec2api.api.image.eventlet.spawn_n') @mock.patch('ec2api.api.image.eventlet.spawn_n')
def test_s3_create_bdm(self, spawn_n): def test_s3_create_bdm(self, spawn_n):
glance = self.mock_glance() glance = self.mock_glance()
metadata = {'properties': { metadata = {'image_location': 'fake_bucket/fake_manifest',
'image_location': 'fake_bucket/fake_manifest', 'root_device_name': '/dev/sda1',
'root_device_name': '/dev/sda1', 'block_device_mapping': [
'block_device_mapping': [ {'device_name': '/dev/sda1',
{'device_name': '/dev/sda1', 'snapshot_id': fakes.ID_OS_SNAPSHOT_1,
'snapshot_id': fakes.ID_OS_SNAPSHOT_1, 'delete_on_termination': True},
'delete_on_termination': True}, {'device_name': '/dev/sda2',
{'device_name': '/dev/sda2', 'virtual_name': 'ephemeral0'},
'virtual_name': 'ephemeral0'}, {'device_name': '/dev/sdb0',
{'device_name': '/dev/sdb0', 'no_device': True}]}
'no_device': True}]}}
fake_context = base.create_context() fake_context = base.create_context()
with mock.patch('ec2api.api.image._s3_conn') as s3_conn: with mock.patch('ec2api.api.image._s3_conn') as s3_conn:
@ -887,19 +887,17 @@ class S3TestCase(base.BaseTestCase):
image_api._s3_create(fake_context, metadata) image_api._s3_create(fake_context, metadata)
glance.images.create.assert_called_once_with( glance.images.create.assert_called_once_with(
disk_format='ami', container_format='ami', is_public=False, disk_format='ami', container_format='ami',
properties={'architecture': 'x86_64', visibility='private', architecture='x86_64',
'image_state': 'pending', image_state='pending', root_device_name='/dev/sda1',
'root_device_name': '/dev/sda1', block_device_mapping=[{'device_name': '/dev/sda1',
'block_device_mapping': [ 'snapshot_id': fakes.ID_OS_SNAPSHOT_1,
{'device_name': '/dev/sda1', 'delete_on_termination': True},
'snapshot_id': fakes.ID_OS_SNAPSHOT_1, {'device_name': '/dev/sda2',
'delete_on_termination': True}, 'virtual_name': 'ephemeral0'},
{'device_name': '/dev/sda2', {'device_name': '/dev/sdb0',
'virtual_name': 'ephemeral0'}, 'no_device': True}],
{'device_name': '/dev/sdb0', image_location='fake_bucket/fake_manifest')
'no_device': True}],
'image_location': 'fake_bucket/fake_manifest'})
def test_s3_malicious_tarballs(self): def test_s3_malicious_tarballs(self):
self.assertRaises( self.assertRaises(

View File

@ -1487,8 +1487,7 @@ class InstancePrivateTestCase(base.BaseTestCase):
# NOTE(ft): check cases of not available image # NOTE(ft): check cases of not available image
os_image = fakes.OSImage({ os_image = fakes.OSImage({
'id': fakes.random_os_id(), 'id': fakes.random_os_id(),
'status': None, 'status': None})
'properties': {}})
get_os_image.return_value = os_image get_os_image.return_value = os_image
self.assertRaises( self.assertRaises(
@ -1497,7 +1496,7 @@ class InstancePrivateTestCase(base.BaseTestCase):
fake_context, fakes.random_ec2_id('ami'), None, None) fake_context, fakes.random_ec2_id('ami'), None, None)
os_image.status = 'active' os_image.status = 'active'
os_image.properties['image_state'] = 'decrypting' os_image.image_state = 'decrypting'
self.assertRaises( self.assertRaises(
exception.InvalidAMIIDUnavailable, exception.InvalidAMIIDUnavailable,
@ -1622,12 +1621,12 @@ class InstancePrivateTestCase(base.BaseTestCase):
fake_image_template = { fake_image_template = {
'id': fakes.random_os_id(), 'id': fakes.random_os_id(),
'properties': {'root_device_name': '/dev/vda', 'root_device_name': '/dev/vda',
'bdm_v2': True, 'bdm_v2': True,
'block_device_mapping': []}} 'block_device_mapping': []}
# check merging with image bdms # check merging with image bdms
fake_image_template['properties']['block_device_mapping'] = [ fake_image_template['block_device_mapping'] = [
{'boot_index': 0, {'boot_index': 0,
'device_name': '/dev/vda', 'device_name': '/dev/vda',
'source_type': 'snapshot', 'source_type': 'snapshot',
@ -1676,7 +1675,7 @@ class InstancePrivateTestCase(base.BaseTestCase):
self.assertEqual(expected, result) self.assertEqual(expected, result)
# check result order for adjusting some bdm of all # check result order for adjusting some bdm of all
fake_image_template['properties']['block_device_mapping'] = [ fake_image_template['block_device_mapping'] = [
{'device_name': '/dev/vdc', {'device_name': '/dev/vdc',
'source_type': 'blank', 'source_type': 'blank',
'volume_size': 10}, 'volume_size': 10},
@ -1722,7 +1721,7 @@ class InstancePrivateTestCase(base.BaseTestCase):
self.assertEqual(expected, result) self.assertEqual(expected, result)
# check conflict of short and full device names # check conflict of short and full device names
fake_image_template['properties']['block_device_mapping'] = [ fake_image_template['block_device_mapping'] = [
{'device_name': '/dev/vdc', {'device_name': '/dev/vdc',
'source_type': 'blank', 'source_type': 'blank',
'volume_size': 10}, 'volume_size': 10},
@ -1737,7 +1736,7 @@ class InstancePrivateTestCase(base.BaseTestCase):
fakes.OSImage(fake_image_template)) fakes.OSImage(fake_image_template))
# opposit combination of the same case # opposit combination of the same case
fake_image_template['properties']['block_device_mapping'] = [ fake_image_template['block_device_mapping'] = [
{'device_name': 'vdc', {'device_name': 'vdc',
'source_type': 'blank', 'source_type': 'blank',
'volume_size': 10}, 'volume_size': 10},
@ -1752,7 +1751,7 @@ class InstancePrivateTestCase(base.BaseTestCase):
fakes.OSImage(fake_image_template)) fakes.OSImage(fake_image_template))
# check fault on root device snapshot changing # check fault on root device snapshot changing
fake_image_template['properties']['block_device_mapping'] = [ fake_image_template['block_device_mapping'] = [
{'boot_index': 0, {'boot_index': 0,
'source_type': 'snapshot', 'source_type': 'snapshot',
'snapshot_id': fakes.ID_EC2_SNAPSHOT_1}, 'snapshot_id': fakes.ID_EC2_SNAPSHOT_1},
@ -1767,11 +1766,11 @@ class InstancePrivateTestCase(base.BaseTestCase):
fakes.OSImage(fake_image_template)) fakes.OSImage(fake_image_template))
# same case for legacy bdm # same case for legacy bdm
fake_image_template['properties']['block_device_mapping'] = [ fake_image_template['block_device_mapping'] = [
{'device_name': '/dev/vda', {'device_name': '/dev/vda',
'snapshot_id': fakes.ID_EC2_SNAPSHOT_1}, 'snapshot_id': fakes.ID_EC2_SNAPSHOT_1},
] ]
fake_image_template['properties']['bdm_v2'] = False fake_image_template['bdm_v2'] = False
bdms = [ bdms = [
{'device_name': '/dev/vda', {'device_name': '/dev/vda',
'ebs': {'snapshot_id': fakes.ID_EC2_SNAPSHOT_2}}, 'ebs': {'snapshot_id': fakes.ID_EC2_SNAPSHOT_2}},
@ -1782,11 +1781,11 @@ class InstancePrivateTestCase(base.BaseTestCase):
fakes.OSImage(fake_image_template)) fakes.OSImage(fake_image_template))
# same case for legacy bdm with short names # same case for legacy bdm with short names
fake_image_template['properties']['block_device_mapping'] = [ fake_image_template['block_device_mapping'] = [
{'device_name': 'vda', {'device_name': 'vda',
'snapshot_id': fakes.ID_EC2_SNAPSHOT_1}, 'snapshot_id': fakes.ID_EC2_SNAPSHOT_1},
] ]
fake_image_template['properties']['bdm_v2'] = False fake_image_template['bdm_v2'] = False
bdms = [ bdms = [
{'device_name': 'vda', {'device_name': 'vda',
'ebs': {'snapshot_id': fakes.ID_EC2_SNAPSHOT_2}}, 'ebs': {'snapshot_id': fakes.ID_EC2_SNAPSHOT_2}},
@ -1796,10 +1795,10 @@ class InstancePrivateTestCase(base.BaseTestCase):
fake_context, bdms, fake_context, bdms,
fakes.OSImage(fake_image_template)) fakes.OSImage(fake_image_template))
fake_image_template['properties']['bdm_v2'] = True fake_image_template['bdm_v2'] = True
# check fault on reduce volume size # check fault on reduce volume size
fake_image_template['properties']['block_device_mapping'] = [ fake_image_template['block_device_mapping'] = [
{'device_name': 'vdc', {'device_name': 'vdc',
'source_type': 'blank', 'source_type': 'blank',
'volume_size': 15}, 'volume_size': 15},
@ -1814,7 +1813,7 @@ class InstancePrivateTestCase(base.BaseTestCase):
fakes.OSImage(fake_image_template)) fakes.OSImage(fake_image_template))
# check fault on set snapshot id if bdm doesn't have one # check fault on set snapshot id if bdm doesn't have one
fake_image_template['properties']['block_device_mapping'] = [ fake_image_template['block_device_mapping'] = [
{'device_name': 'vdc', {'device_name': 'vdc',
'source_type': 'blank', 'source_type': 'blank',
'volume_size': 10}, 'volume_size': 10},

View File

@ -76,9 +76,7 @@ class DBItemsAutoCreationTestCase(base.DbTestCase):
'owner': image_project_id, 'owner': image_project_id,
'is_public': True, 'is_public': True,
'container_format': 'ami', 'container_format': 'ami',
'properties': { 'kernel_id': os_aki_image_id,
'kernel_id': os_aki_image_id,
},
} }
os_aki_image = { os_aki_image = {
'id': os_aki_image_id, 'id': os_aki_image_id,
@ -173,16 +171,14 @@ class DBItemsAutoCreationTestCase(base.DbTestCase):
'owner': image_project_id, 'owner': image_project_id,
'is_public': True, 'is_public': True,
'container_format': 'ami', 'container_format': 'ami',
'properties': { 'bdm_v2': True,
'bdm_v2': True, 'block_device_mapping': [{'device_name': '/dev/vds',
'block_device_mapping': [{'device_name': '/dev/vds',
'source_type': 'snapshot', 'source_type': 'snapshot',
'destination_type': 'volume', 'destination_type': 'volume',
'snapshot_id': os_snapshot_id}], 'snapshot_id': os_snapshot_id}],
},
} }
if os_bdm_image_id: if os_bdm_image_id:
os_image['properties']['block_device_mapping'].append({ os_image['block_device_mapping'].append({
'device_name': '/dev/vdi', 'device_name': '/dev/vdi',
'source_type': 'image', 'source_type': 'image',
'destination_type': 'volume', 'destination_type': 'volume',
@ -263,7 +259,7 @@ class DBItemsAutoCreationTestCase(base.DbTestCase):
os_image = { os_image = {
'id': os_image_id, 'id': os_image_id,
'owner': image_project_id, 'owner': image_project_id,
'is_public': True, 'visibility': 'public',
} }
self.nova_admin.servers.list.return_value = [ self.nova_admin.servers.list.return_value = [
fakes.OSInstance_full(os_instance)] fakes.OSInstance_full(os_instance)]