Blackify openstack.image
Black used with the '-l 79 -S' flags. A future change will ignore this commit in git-blame history by adding a 'git-blame-ignore-revs' file. Change-Id: Ibd4a585a225f60b26ed394da118c52a29091710d Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
9325626769
commit
bcf99f3433
@ -20,11 +20,11 @@ def _verify_checksum(md5, checksum):
|
||||
digest = md5.hexdigest()
|
||||
if digest != checksum:
|
||||
raise exceptions.InvalidResponse(
|
||||
"checksum mismatch: %s != %s" % (checksum, digest))
|
||||
"checksum mismatch: %s != %s" % (checksum, digest)
|
||||
)
|
||||
|
||||
|
||||
class DownloadMixin:
|
||||
|
||||
def download(self, session, stream=False, output=None, chunk_size=1024):
|
||||
"""Download the data contained in an image"""
|
||||
# TODO(briancurtin): This method should probably offload the get
|
||||
@ -53,8 +53,7 @@ class DownloadMixin:
|
||||
md5.update(chunk)
|
||||
else:
|
||||
with open(output, 'wb') as fd:
|
||||
for chunk in resp.iter_content(
|
||||
chunk_size=chunk_size):
|
||||
for chunk in resp.iter_content(chunk_size=chunk_size):
|
||||
fd.write(chunk)
|
||||
md5.update(chunk)
|
||||
_verify_checksum(md5, checksum)
|
||||
@ -62,7 +61,8 @@ class DownloadMixin:
|
||||
return resp
|
||||
except Exception as e:
|
||||
raise exceptions.SDKException(
|
||||
"Unable to download image: %s" % e)
|
||||
"Unable to download image: %s" % e
|
||||
)
|
||||
# if we are returning the repsonse object, ensure that it
|
||||
# has the content-md5 header so that the caller doesn't
|
||||
# need to jump through the same hoops through which we
|
||||
@ -72,10 +72,12 @@ class DownloadMixin:
|
||||
return resp
|
||||
|
||||
if checksum is not None:
|
||||
_verify_checksum(utils.md5(resp.content, usedforsecurity=False),
|
||||
checksum)
|
||||
_verify_checksum(
|
||||
utils.md5(resp.content, usedforsecurity=False), checksum
|
||||
)
|
||||
else:
|
||||
session.log.warning(
|
||||
"Unable to verify the integrity of image %s", (self.id))
|
||||
"Unable to verify the integrity of image %s", (self.id)
|
||||
)
|
||||
|
||||
return resp
|
||||
|
@ -37,7 +37,7 @@ class ImageSigner:
|
||||
padding_types = {
|
||||
'RSA-PSS': padding.PSS(
|
||||
mgf=padding.MGF1(HASH_METHODS[hash_method]),
|
||||
salt_length=padding.PSS.MAX_LENGTH
|
||||
salt_length=padding.PSS.MAX_LENGTH,
|
||||
)
|
||||
}
|
||||
# informational attributes
|
||||
|
@ -32,8 +32,12 @@ class Image(resource.Resource, _download.DownloadMixin):
|
||||
_store_unknown_attrs_as_properties = True
|
||||
|
||||
_query_mapping = resource.QueryParameters(
|
||||
'name', 'container_format', 'disk_format',
|
||||
'status', 'size_min', 'size_max'
|
||||
'name',
|
||||
'container_format',
|
||||
'disk_format',
|
||||
'status',
|
||||
'size_min',
|
||||
'size_max',
|
||||
)
|
||||
|
||||
#: Hash of the image data used. The Image service uses this value
|
||||
@ -114,7 +118,8 @@ class Image(resource.Resource, _download.DownloadMixin):
|
||||
match = cls.existing(
|
||||
id=name_or_id,
|
||||
connection=session._get_connection(),
|
||||
**params)
|
||||
**params,
|
||||
)
|
||||
return match.fetch(session, **params)
|
||||
except exceptions.NotFoundException:
|
||||
pass
|
||||
@ -130,4 +135,5 @@ class Image(resource.Resource, _download.DownloadMixin):
|
||||
if ignore_missing:
|
||||
return None
|
||||
raise exceptions.ResourceNotFound(
|
||||
"No %s found for %s" % (cls.__name__, name_or_id))
|
||||
"No %s found for %s" % (cls.__name__, name_or_id)
|
||||
)
|
||||
|
@ -97,7 +97,7 @@ class Proxy(proxy.Proxy):
|
||||
return cache.queue(self, image_id)
|
||||
|
||||
def clear_cache(self, target):
|
||||
""" Clear all images from cache, queue or both
|
||||
"""Clear all images from cache, queue or both
|
||||
|
||||
:param target: Specify which target you want to clear
|
||||
One of: ``both``(default), ``cache``, ``queue``.
|
||||
|
@ -32,8 +32,11 @@ class Cache(resource.Resource):
|
||||
|
||||
_max_microversion = '2.14'
|
||||
|
||||
cached_images = resource.Body('cached_images', type=list,
|
||||
list_type=CachedImage)
|
||||
cached_images = resource.Body(
|
||||
'cached_images',
|
||||
type=list,
|
||||
list_type=CachedImage,
|
||||
)
|
||||
queued_images = resource.Body('queued_images', type=list)
|
||||
|
||||
def queue(self, session, image, *, microversion=None):
|
||||
|
@ -150,7 +150,9 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin):
|
||||
#: Optional property allows created servers to have a different bandwidth
|
||||
#: cap than that defined in the network they are attached to.
|
||||
instance_type_rxtx_factor = resource.Body(
|
||||
"instance_type_rxtx_factor", type=float)
|
||||
"instance_type_rxtx_factor",
|
||||
type=float,
|
||||
)
|
||||
# For snapshot images, this is the UUID of the server used to
|
||||
#: create this image.
|
||||
instance_uuid = resource.Body('instance_uuid')
|
||||
@ -221,7 +223,9 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin):
|
||||
#: number of guest vCPUs. This makes the network performance scale
|
||||
#: across a number of vCPUs.
|
||||
is_hw_vif_multiqueue_enabled = resource.Body(
|
||||
'hw_vif_multiqueue_enabled', type=bool)
|
||||
'hw_vif_multiqueue_enabled',
|
||||
type=bool,
|
||||
)
|
||||
#: If true, enables the BIOS bootmenu.
|
||||
is_hw_boot_menu_enabled = resource.Body('hw_boot_menu', type=bool)
|
||||
#: The virtual SCSI or IDE controller used by the hypervisor.
|
||||
@ -247,7 +251,7 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin):
|
||||
def _action(self, session, action):
|
||||
"""Call an action on an image ID."""
|
||||
url = utils.urljoin(self.base_path, self.id, 'actions', action)
|
||||
return session.post(url,)
|
||||
return session.post(url)
|
||||
|
||||
def deactivate(self, session):
|
||||
"""Deactivate an image
|
||||
@ -275,9 +279,11 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin):
|
||||
if data:
|
||||
self.data = data
|
||||
url = utils.urljoin(self.base_path, self.id, 'file')
|
||||
return session.put(url, data=self.data,
|
||||
headers={"Content-Type": "application/octet-stream",
|
||||
"Accept": ""})
|
||||
return session.put(
|
||||
url,
|
||||
data=self.data,
|
||||
headers={"Content-Type": "application/octet-stream", "Accept": ""},
|
||||
)
|
||||
|
||||
def stage(self, session, *, data=None):
|
||||
"""Stage binary image data into an existing image
|
||||
@ -292,9 +298,10 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin):
|
||||
|
||||
url = utils.urljoin(self.base_path, self.id, 'stage')
|
||||
response = session.put(
|
||||
url, data=self.data,
|
||||
headers={"Content-Type": "application/octet-stream",
|
||||
"Accept": ""})
|
||||
url,
|
||||
data=self.data,
|
||||
headers={"Content-Type": "application/octet-stream", "Accept": ""},
|
||||
)
|
||||
self._translate_response(response, has_body=False)
|
||||
return self
|
||||
|
||||
@ -339,8 +346,9 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin):
|
||||
|
||||
if remote_region and remote_image_id:
|
||||
if remote_service_interface:
|
||||
data['method']['glance_service_interface'] = \
|
||||
remote_service_interface
|
||||
data['method'][
|
||||
'glance_service_interface'
|
||||
] = remote_service_interface
|
||||
data['method']['glance_region'] = remote_region
|
||||
data['method']['glance_image_id'] = remote_image_id
|
||||
|
||||
@ -367,16 +375,24 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin):
|
||||
|
||||
return super()._consume_header_attrs(attrs)
|
||||
|
||||
def _prepare_request(self, requires_id=None, prepend_key=False,
|
||||
patch=False, base_path=None, **kwargs):
|
||||
request = super(Image, self)._prepare_request(requires_id=requires_id,
|
||||
prepend_key=prepend_key,
|
||||
patch=patch,
|
||||
base_path=base_path)
|
||||
def _prepare_request(
|
||||
self,
|
||||
requires_id=None,
|
||||
prepend_key=False,
|
||||
patch=False,
|
||||
base_path=None,
|
||||
**kwargs,
|
||||
):
|
||||
request = super(Image, self)._prepare_request(
|
||||
requires_id=requires_id,
|
||||
prepend_key=prepend_key,
|
||||
patch=patch,
|
||||
base_path=base_path,
|
||||
)
|
||||
if patch:
|
||||
headers = {
|
||||
'Content-Type': 'application/openstack-images-v2.1-json-patch',
|
||||
'Accept': ''
|
||||
'Accept': '',
|
||||
}
|
||||
request.headers.update(headers)
|
||||
|
||||
@ -385,8 +401,7 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin):
|
||||
@classmethod
|
||||
def find(cls, session, name_or_id, ignore_missing=True, **params):
|
||||
# Do a regular search first (ignoring missing)
|
||||
result = super(Image, cls).find(session, name_or_id, True,
|
||||
**params)
|
||||
result = super(Image, cls).find(session, name_or_id, True, **params)
|
||||
|
||||
if result:
|
||||
return result
|
||||
@ -402,4 +417,5 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin):
|
||||
if ignore_missing:
|
||||
return None
|
||||
raise exceptions.ResourceNotFound(
|
||||
"No %s found for %s" % (cls.__name__, name_or_id))
|
||||
"No %s found for %s" % (cls.__name__, name_or_id)
|
||||
)
|
||||
|
@ -19,7 +19,6 @@ TEST_IMAGE_NAME = 'Test Image'
|
||||
|
||||
|
||||
class TestImage(base.BaseImageTest):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
|
@ -45,7 +45,8 @@ class TestMetadefNamespace(base.BaseImageTest):
|
||||
self.metadef_namespace.namespace
|
||||
)
|
||||
self.assertEqual(
|
||||
self.metadef_namespace.namespace, metadef_namespace.namespace,
|
||||
self.metadef_namespace.namespace,
|
||||
metadef_namespace.namespace,
|
||||
)
|
||||
|
||||
# (no find_metadef_namespace method)
|
||||
|
@ -16,7 +16,6 @@ from openstack.tests.functional.image.v2 import base
|
||||
|
||||
|
||||
class TestMetadefResourceType(base.BaseImageTest):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@ -33,14 +32,14 @@ class TestMetadefResourceType(base.BaseImageTest):
|
||||
|
||||
resource_type_name = 'test-resource-type'
|
||||
resource_type = {'name': resource_type_name}
|
||||
self.metadef_resource_type = \
|
||||
self.metadef_resource_type = (
|
||||
self.conn.image.create_metadef_resource_type_association(
|
||||
metadef_namespace=namespace,
|
||||
**resource_type
|
||||
metadef_namespace=namespace, **resource_type
|
||||
)
|
||||
)
|
||||
self.assertIsInstance(
|
||||
self.metadef_resource_type,
|
||||
_metadef_resource_type.MetadefResourceTypeAssociation
|
||||
_metadef_resource_type.MetadefResourceTypeAssociation,
|
||||
)
|
||||
self.assertEqual(resource_type_name, self.metadef_resource_type.name)
|
||||
|
||||
@ -54,12 +53,14 @@ class TestMetadefResourceType(base.BaseImageTest):
|
||||
|
||||
def test_metadef_resource_types(self):
|
||||
# list resource type associations
|
||||
associations = list(self.conn.image.metadef_resource_type_associations(
|
||||
metadef_namespace=self.metadef_namespace))
|
||||
associations = list(
|
||||
self.conn.image.metadef_resource_type_associations(
|
||||
metadef_namespace=self.metadef_namespace
|
||||
)
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
self.metadef_resource_type.name,
|
||||
{a.name for a in associations}
|
||||
self.metadef_resource_type.name, {a.name for a in associations}
|
||||
)
|
||||
|
||||
# (no find_metadef_resource_type_association method)
|
||||
@ -68,12 +69,11 @@ class TestMetadefResourceType(base.BaseImageTest):
|
||||
resource_types = list(self.conn.image.metadef_resource_types())
|
||||
|
||||
self.assertIn(
|
||||
self.metadef_resource_type.name,
|
||||
{t.name for t in resource_types}
|
||||
self.metadef_resource_type.name, {t.name for t in resource_types}
|
||||
)
|
||||
|
||||
# delete
|
||||
self.conn.image.delete_metadef_resource_type_association(
|
||||
self.metadef_resource_type,
|
||||
metadef_namespace=self.metadef_namespace
|
||||
metadef_namespace=self.metadef_namespace,
|
||||
)
|
||||
|
@ -15,7 +15,6 @@ from openstack.tests.functional.image.v2 import base
|
||||
|
||||
|
||||
class TestMetadefSchema(base.BaseImageTest):
|
||||
|
||||
def test_get_metadef_namespace_schema(self):
|
||||
metadef_schema = self.conn.image.get_metadef_namespace_schema()
|
||||
self.assertIsNotNone(metadef_schema)
|
||||
|
@ -15,7 +15,6 @@ from openstack.tests.functional.image.v2 import base
|
||||
|
||||
|
||||
class TestSchema(base.BaseImageTest):
|
||||
|
||||
def test_get_images_schema(self):
|
||||
schema = self.conn.image.get_images_schema()
|
||||
self.assertIsNotNone(schema)
|
||||
|
@ -14,7 +14,6 @@ from openstack.tests.functional.image.v2 import base
|
||||
|
||||
|
||||
class TestTask(base.BaseImageTest):
|
||||
|
||||
def test_tasks(self):
|
||||
tasks = list(self.conn.image.tasks())
|
||||
# NOTE(stephenfin): Yes, this is a dumb test. Basically all that we're
|
||||
|
@ -37,7 +37,6 @@ EXAMPLE = {
|
||||
|
||||
|
||||
class TestImage(base.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
sot = image.Image()
|
||||
self.assertEqual('image', sot.resource_key)
|
||||
|
@ -19,16 +19,18 @@ from openstack.tests.unit import base
|
||||
|
||||
EXAMPLE = {
|
||||
'cached_images': [
|
||||
{'hits': 0,
|
||||
'image_id': '1a56983c-f71f-490b-a7ac-6b321a18935a',
|
||||
'last_accessed': 1671699579.444378,
|
||||
'last_modified': 1671699579.444378,
|
||||
'size': 0},
|
||||
{
|
||||
'hits': 0,
|
||||
'image_id': '1a56983c-f71f-490b-a7ac-6b321a18935a',
|
||||
'last_accessed': 1671699579.444378,
|
||||
'last_modified': 1671699579.444378,
|
||||
'size': 0,
|
||||
},
|
||||
],
|
||||
'queued_images': [
|
||||
'3a4560a1-e585-443e-9b39-553b46ec92d1',
|
||||
'6f99bf80-2ee6-47cf-acfe-1f1fabb7e810'
|
||||
]
|
||||
'6f99bf80-2ee6-47cf-acfe-1f1fabb7e810',
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@ -57,8 +59,9 @@ class TestCache(base.TestCase):
|
||||
|
||||
sot.queue(sess, image='image_id')
|
||||
|
||||
sess.put.assert_called_with('cache/image_id',
|
||||
microversion=sess.default_microversion)
|
||||
sess.put.assert_called_with(
|
||||
'cache/image_id', microversion=sess.default_microversion
|
||||
)
|
||||
|
||||
@mock.patch.object(exceptions, 'raise_from_response', mock.Mock())
|
||||
def test_clear(self):
|
||||
|
@ -35,7 +35,10 @@ EXAMPLE = {
|
||||
'min_disk': 5,
|
||||
'name': '6',
|
||||
'owner': '7',
|
||||
'properties': {'a': 'z', 'b': 'y', },
|
||||
'properties': {
|
||||
'a': 'z',
|
||||
'b': 'y',
|
||||
},
|
||||
'protected': False,
|
||||
'status': '8',
|
||||
'tags': ['g', 'h', 'i'],
|
||||
@ -114,7 +117,6 @@ class FakeResponse:
|
||||
|
||||
|
||||
class TestImage(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestImage, self).setUp()
|
||||
self.resp = mock.Mock()
|
||||
@ -159,7 +161,7 @@ class TestImage(base.TestCase):
|
||||
'status': 'status',
|
||||
'tag': 'tag',
|
||||
'updated_at': 'updated_at',
|
||||
'visibility': 'visibility'
|
||||
'visibility': 'visibility',
|
||||
},
|
||||
sot._query_mapping._mapping,
|
||||
)
|
||||
@ -194,8 +196,9 @@ class TestImage(base.TestCase):
|
||||
self.assertEqual(EXAMPLE['metadata'], sot.metadata)
|
||||
self.assertEqual(EXAMPLE['architecture'], sot.architecture)
|
||||
self.assertEqual(EXAMPLE['hypervisor_type'], sot.hypervisor_type)
|
||||
self.assertEqual(EXAMPLE['instance_type_rxtx_factor'],
|
||||
sot.instance_type_rxtx_factor)
|
||||
self.assertEqual(
|
||||
EXAMPLE['instance_type_rxtx_factor'], sot.instance_type_rxtx_factor
|
||||
)
|
||||
self.assertEqual(EXAMPLE['instance_uuid'], sot.instance_uuid)
|
||||
self.assertEqual(EXAMPLE['img_config_drive'], sot.needs_config_drive)
|
||||
self.assertEqual(EXAMPLE['kernel_id'], sot.kernel_id)
|
||||
@ -211,23 +214,27 @@ class TestImage(base.TestCase):
|
||||
self.assertEqual(EXAMPLE['hw_rng_model'], sot.hw_rng_model)
|
||||
self.assertEqual(EXAMPLE['hw_machine_type'], sot.hw_machine_type)
|
||||
self.assertEqual(EXAMPLE['hw_scsi_model'], sot.hw_scsi_model)
|
||||
self.assertEqual(EXAMPLE['hw_serial_port_count'],
|
||||
sot.hw_serial_port_count)
|
||||
self.assertEqual(
|
||||
EXAMPLE['hw_serial_port_count'], sot.hw_serial_port_count
|
||||
)
|
||||
self.assertEqual(EXAMPLE['hw_video_model'], sot.hw_video_model)
|
||||
self.assertEqual(EXAMPLE['hw_video_ram'], sot.hw_video_ram)
|
||||
self.assertEqual(EXAMPLE['hw_watchdog_action'], sot.hw_watchdog_action)
|
||||
self.assertEqual(EXAMPLE['os_command_line'], sot.os_command_line)
|
||||
self.assertEqual(EXAMPLE['hw_vif_model'], sot.hw_vif_model)
|
||||
self.assertEqual(EXAMPLE['hw_vif_multiqueue_enabled'],
|
||||
sot.is_hw_vif_multiqueue_enabled)
|
||||
self.assertEqual(
|
||||
EXAMPLE['hw_vif_multiqueue_enabled'],
|
||||
sot.is_hw_vif_multiqueue_enabled,
|
||||
)
|
||||
self.assertEqual(EXAMPLE['hw_boot_menu'], sot.is_hw_boot_menu_enabled)
|
||||
self.assertEqual(EXAMPLE['vmware_adaptertype'], sot.vmware_adaptertype)
|
||||
self.assertEqual(EXAMPLE['vmware_ostype'], sot.vmware_ostype)
|
||||
self.assertEqual(EXAMPLE['auto_disk_config'], sot.has_auto_disk_config)
|
||||
self.assertEqual(EXAMPLE['os_type'], sot.os_type)
|
||||
self.assertEqual(EXAMPLE['os_admin_user'], sot.os_admin_user)
|
||||
self.assertEqual(EXAMPLE['hw_qemu_guest_agent'],
|
||||
sot.hw_qemu_guest_agent)
|
||||
self.assertEqual(
|
||||
EXAMPLE['hw_qemu_guest_agent'], sot.hw_qemu_guest_agent
|
||||
)
|
||||
self.assertEqual(EXAMPLE['os_require_quiesce'], sot.os_require_quiesce)
|
||||
|
||||
def test_deactivate(self):
|
||||
@ -267,9 +274,7 @@ class TestImage(base.TestCase):
|
||||
json = {"method": {"name": "web-download", "uri": "such-a-good-uri"}}
|
||||
sot.import_image(self.sess, "web-download", uri="such-a-good-uri")
|
||||
self.sess.post.assert_called_with(
|
||||
'images/IDENTIFIER/import',
|
||||
headers={},
|
||||
json=json
|
||||
'images/IDENTIFIER/import', headers={}, json=json
|
||||
)
|
||||
|
||||
def test_import_image_with_uri_not_web_download(self):
|
||||
@ -279,7 +284,7 @@ class TestImage(base.TestCase):
|
||||
self.sess.post.assert_called_with(
|
||||
'images/IDENTIFIER/import',
|
||||
headers={},
|
||||
json={"method": {"name": "glance-direct"}}
|
||||
json={"method": {"name": "glance-direct"}},
|
||||
)
|
||||
|
||||
def test_import_image_with_store(self):
|
||||
@ -302,7 +307,7 @@ class TestImage(base.TestCase):
|
||||
self.sess.post.assert_called_with(
|
||||
'images/IDENTIFIER/import',
|
||||
headers={'X-Image-Meta-Store': 'ceph_1'},
|
||||
json=json
|
||||
json=json,
|
||||
)
|
||||
|
||||
def test_import_image_with_stores(self):
|
||||
@ -353,21 +358,21 @@ class TestImage(base.TestCase):
|
||||
sot = image.Image(**EXAMPLE)
|
||||
|
||||
self.assertIsNotNone(sot.upload(self.sess))
|
||||
self.sess.put.assert_called_with('images/IDENTIFIER/file',
|
||||
data=sot.data,
|
||||
headers={"Content-Type":
|
||||
"application/octet-stream",
|
||||
"Accept": ""})
|
||||
self.sess.put.assert_called_with(
|
||||
'images/IDENTIFIER/file',
|
||||
data=sot.data,
|
||||
headers={"Content-Type": "application/octet-stream", "Accept": ""},
|
||||
)
|
||||
|
||||
def test_stage(self):
|
||||
sot = image.Image(**EXAMPLE)
|
||||
|
||||
self.assertIsNotNone(sot.stage(self.sess))
|
||||
self.sess.put.assert_called_with('images/IDENTIFIER/stage',
|
||||
data=sot.data,
|
||||
headers={"Content-Type":
|
||||
"application/octet-stream",
|
||||
"Accept": ""})
|
||||
self.sess.put.assert_called_with(
|
||||
'images/IDENTIFIER/stage',
|
||||
data=sot.data,
|
||||
headers={"Content-Type": "application/octet-stream", "Accept": ""},
|
||||
)
|
||||
|
||||
def test_stage_error(self):
|
||||
sot = image.Image(**EXAMPLE)
|
||||
@ -380,13 +385,17 @@ class TestImage(base.TestCase):
|
||||
|
||||
resp = FakeResponse(
|
||||
b"abc",
|
||||
headers={"Content-MD5": "900150983cd24fb0d6963f7d28e17f72",
|
||||
"Content-Type": "application/octet-stream"})
|
||||
headers={
|
||||
"Content-MD5": "900150983cd24fb0d6963f7d28e17f72",
|
||||
"Content-Type": "application/octet-stream",
|
||||
},
|
||||
)
|
||||
self.sess.get.return_value = resp
|
||||
|
||||
rv = sot.download(self.sess)
|
||||
self.sess.get.assert_called_with('images/IDENTIFIER/file',
|
||||
stream=False)
|
||||
self.sess.get.assert_called_with(
|
||||
'images/IDENTIFIER/file', stream=False
|
||||
)
|
||||
|
||||
self.assertEqual(rv, resp)
|
||||
|
||||
@ -395,8 +404,11 @@ class TestImage(base.TestCase):
|
||||
|
||||
resp = FakeResponse(
|
||||
b"abc",
|
||||
headers={"Content-MD5": "the wrong checksum",
|
||||
"Content-Type": "application/octet-stream"})
|
||||
headers={
|
||||
"Content-MD5": "the wrong checksum",
|
||||
"Content-Type": "application/octet-stream",
|
||||
},
|
||||
)
|
||||
self.sess.get.return_value = resp
|
||||
|
||||
self.assertRaises(exceptions.InvalidResponse, sot.download, self.sess)
|
||||
@ -405,19 +417,25 @@ class TestImage(base.TestCase):
|
||||
sot = image.Image(**EXAMPLE)
|
||||
|
||||
resp1 = FakeResponse(
|
||||
b"abc", headers={"Content-Type": "application/octet-stream"})
|
||||
b"abc", headers={"Content-Type": "application/octet-stream"}
|
||||
)
|
||||
|
||||
resp2 = FakeResponse(
|
||||
{"checksum": "900150983cd24fb0d6963f7d28e17f72"})
|
||||
resp2 = FakeResponse({"checksum": "900150983cd24fb0d6963f7d28e17f72"})
|
||||
|
||||
self.sess.get.side_effect = [resp1, resp2]
|
||||
|
||||
rv = sot.download(self.sess)
|
||||
self.sess.get.assert_has_calls(
|
||||
[mock.call('images/IDENTIFIER/file',
|
||||
stream=False),
|
||||
mock.call('images/IDENTIFIER', microversion=None, params={},
|
||||
skip_cache=False)])
|
||||
[
|
||||
mock.call('images/IDENTIFIER/file', stream=False),
|
||||
mock.call(
|
||||
'images/IDENTIFIER',
|
||||
microversion=None,
|
||||
params={},
|
||||
skip_cache=False,
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEqual(rv, resp1)
|
||||
|
||||
@ -425,7 +443,8 @@ class TestImage(base.TestCase):
|
||||
sot = image.Image(**EXAMPLE)
|
||||
|
||||
resp1 = FakeResponse(
|
||||
b"abc", headers={"Content-Type": "application/octet-stream"})
|
||||
b"abc", headers={"Content-Type": "application/octet-stream"}
|
||||
)
|
||||
|
||||
resp2 = FakeResponse({"checksum": None})
|
||||
|
||||
@ -434,20 +453,26 @@ class TestImage(base.TestCase):
|
||||
with self.assertLogs(logger='openstack', level="WARNING") as log:
|
||||
rv = sot.download(self.sess)
|
||||
|
||||
self.assertEqual(len(log.records), 1,
|
||||
"Too many warnings were logged")
|
||||
self.assertEqual(
|
||||
len(log.records), 1, "Too many warnings were logged"
|
||||
)
|
||||
self.assertEqual(
|
||||
"Unable to verify the integrity of image %s",
|
||||
log.records[0].msg)
|
||||
self.assertEqual(
|
||||
(sot.id,),
|
||||
log.records[0].args)
|
||||
log.records[0].msg,
|
||||
)
|
||||
self.assertEqual((sot.id,), log.records[0].args)
|
||||
|
||||
self.sess.get.assert_has_calls(
|
||||
[mock.call('images/IDENTIFIER/file',
|
||||
stream=False),
|
||||
mock.call('images/IDENTIFIER', microversion=None, params={},
|
||||
skip_cache=False)])
|
||||
[
|
||||
mock.call('images/IDENTIFIER/file', stream=False),
|
||||
mock.call(
|
||||
'images/IDENTIFIER',
|
||||
microversion=None,
|
||||
params={},
|
||||
skip_cache=False,
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEqual(rv, resp1)
|
||||
|
||||
@ -456,8 +481,11 @@ class TestImage(base.TestCase):
|
||||
|
||||
resp = FakeResponse(
|
||||
b"abc",
|
||||
headers={"Content-MD5": "900150983cd24fb0d6963f7d28e17f72",
|
||||
"Content-Type": "application/octet-stream"})
|
||||
headers={
|
||||
"Content-MD5": "900150983cd24fb0d6963f7d28e17f72",
|
||||
"Content-Type": "application/octet-stream",
|
||||
},
|
||||
)
|
||||
self.sess.get.return_value = resp
|
||||
|
||||
rv = sot.download(self.sess, stream=True)
|
||||
@ -472,8 +500,9 @@ class TestImage(base.TestCase):
|
||||
response.status_code = 200
|
||||
response.iter_content.return_value = [b'01', b'02']
|
||||
response.headers = {
|
||||
'Content-MD5':
|
||||
calculate_md5_checksum(response.iter_content.return_value)
|
||||
'Content-MD5': calculate_md5_checksum(
|
||||
response.iter_content.return_value
|
||||
)
|
||||
}
|
||||
self.sess.get = mock.Mock(return_value=response)
|
||||
sot.download(self.sess, output=output_file)
|
||||
@ -486,8 +515,9 @@ class TestImage(base.TestCase):
|
||||
response.status_code = 200
|
||||
response.iter_content.return_value = [b'01', b'02']
|
||||
response.headers = {
|
||||
'Content-MD5':
|
||||
calculate_md5_checksum(response.iter_content.return_value)
|
||||
'Content-MD5': calculate_md5_checksum(
|
||||
response.iter_content.return_value
|
||||
)
|
||||
}
|
||||
self.sess.get = mock.Mock(return_value=response)
|
||||
|
||||
@ -513,9 +543,10 @@ class TestImage(base.TestCase):
|
||||
resp.status_code = 200
|
||||
self.sess.patch.return_value = resp
|
||||
|
||||
value = [{"value": "fake_name", "op": "replace", "path": "/name"},
|
||||
{"value": "fake_value", "op": "add",
|
||||
"path": "/instance_uuid"}]
|
||||
value = [
|
||||
{"value": "fake_name", "op": "replace", "path": "/name"},
|
||||
{"value": "fake_value", "op": "add", "path": "/instance_uuid"},
|
||||
]
|
||||
|
||||
sot.name = 'fake_name'
|
||||
sot.instance_uuid = 'fake_value'
|
||||
@ -527,7 +558,8 @@ class TestImage(base.TestCase):
|
||||
self.assertEqual(url, call_args[0])
|
||||
self.assertEqual(
|
||||
sorted(value, key=operator.itemgetter('value')),
|
||||
sorted(call_kwargs['json'], key=operator.itemgetter('value')))
|
||||
sorted(call_kwargs['json'], key=operator.itemgetter('value')),
|
||||
)
|
||||
|
||||
def test_image_find(self):
|
||||
sot = image.Image()
|
||||
@ -539,20 +571,33 @@ class TestImage(base.TestCase):
|
||||
# Then list with no results
|
||||
FakeResponse({'images': []}),
|
||||
# And finally new list of hidden images with one searched
|
||||
FakeResponse({'images': [EXAMPLE]})
|
||||
|
||||
FakeResponse({'images': [EXAMPLE]}),
|
||||
]
|
||||
|
||||
result = sot.find(self.sess, EXAMPLE['name'])
|
||||
|
||||
self.sess.get.assert_has_calls([
|
||||
mock.call('images/' + EXAMPLE['name'], microversion=None,
|
||||
params={}, skip_cache=False),
|
||||
mock.call('/images', headers={'Accept': 'application/json'},
|
||||
microversion=None, params={'name': EXAMPLE['name']}),
|
||||
mock.call('/images', headers={'Accept': 'application/json'},
|
||||
microversion=None, params={'os_hidden': True})
|
||||
])
|
||||
self.sess.get.assert_has_calls(
|
||||
[
|
||||
mock.call(
|
||||
'images/' + EXAMPLE['name'],
|
||||
microversion=None,
|
||||
params={},
|
||||
skip_cache=False,
|
||||
),
|
||||
mock.call(
|
||||
'/images',
|
||||
headers={'Accept': 'application/json'},
|
||||
microversion=None,
|
||||
params={'name': EXAMPLE['name']},
|
||||
),
|
||||
mock.call(
|
||||
'/images',
|
||||
headers={'Accept': 'application/json'},
|
||||
microversion=None,
|
||||
params={'os_hidden': True},
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
self.assertIsInstance(result, image.Image)
|
||||
self.assertEqual(IDENTIFIER, result.id)
|
||||
|
@ -67,7 +67,7 @@ class TestMetadefNamespace(base.TestCase):
|
||||
'resource_types': 'resource_types',
|
||||
'sort_dir': 'sort_dir',
|
||||
'sort_key': 'sort_key',
|
||||
'visibility': 'visibility'
|
||||
'visibility': 'visibility',
|
||||
},
|
||||
sot._query_mapping._mapping,
|
||||
)
|
||||
|
@ -14,10 +14,7 @@ from openstack.image.v2 import metadef_resource_type
|
||||
from openstack.tests.unit import base
|
||||
|
||||
|
||||
EXAMPLE = {
|
||||
"name": "OS::Nova::Aggregate",
|
||||
"created_at": "2022-07-09T04:10:37Z"
|
||||
}
|
||||
EXAMPLE = {"name": "OS::Nova::Aggregate", "created_at": "2022-07-09T04:10:37Z"}
|
||||
|
||||
|
||||
class TestMetadefResourceType(base.TestCase):
|
||||
|
@ -18,7 +18,7 @@ EXAMPLE = {
|
||||
"name": "OS::Cinder::Volume",
|
||||
"prefix": "CIM_PASD_",
|
||||
"properties_target": "image",
|
||||
"created_at": "2022-07-09T04:10:38Z"
|
||||
"created_at": "2022-07-09T04:10:38Z",
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,8 @@ class TestMetadefResourceTypeAssociation(base.TestCase):
|
||||
self.assertEqual('resource_type_associations', sot.resources_key)
|
||||
self.assertEqual(
|
||||
'/metadefs/namespaces/%(namespace_name)s/resource_types',
|
||||
sot.base_path)
|
||||
sot.base_path,
|
||||
)
|
||||
self.assertTrue(sot.allow_create)
|
||||
self.assertFalse(sot.allow_fetch)
|
||||
self.assertFalse(sot.allow_commit)
|
||||
|
@ -21,101 +21,67 @@ EXAMPLE = {
|
||||
'namespace': {
|
||||
'type': 'string',
|
||||
'description': 'The unique namespace text.',
|
||||
'maxLength': 80
|
||||
'maxLength': 80,
|
||||
},
|
||||
'visibility': {
|
||||
'type': 'string',
|
||||
'description': 'Scope of namespace accessibility.',
|
||||
'enum': [
|
||||
'public',
|
||||
'private'
|
||||
]
|
||||
'enum': ['public', 'private'],
|
||||
},
|
||||
'created_at': {
|
||||
'type': 'string',
|
||||
'readOnly': True,
|
||||
'description': 'Date and time of namespace creation',
|
||||
'format': 'date-time'
|
||||
'format': 'date-time',
|
||||
},
|
||||
'resource_type_associations': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'name': {
|
||||
'type': 'string'
|
||||
},
|
||||
'prefix': {
|
||||
'type': 'string'
|
||||
},
|
||||
'properties_target': {
|
||||
'type': 'string'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'properties': {
|
||||
'$ref': '#/definitions/property'
|
||||
'name': {'type': 'string'},
|
||||
'prefix': {'type': 'string'},
|
||||
'properties_target': {'type': 'string'},
|
||||
},
|
||||
},
|
||||
},
|
||||
'properties': {'$ref': '#/definitions/property'},
|
||||
'objects': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'name': {
|
||||
'type': 'string'
|
||||
},
|
||||
'description': {
|
||||
'type': 'string'
|
||||
},
|
||||
'required': {
|
||||
'$ref': '#/definitions/stringArray'
|
||||
},
|
||||
'properties': {
|
||||
'$ref': '#/definitions/property'
|
||||
}
|
||||
}
|
||||
}
|
||||
'name': {'type': 'string'},
|
||||
'description': {'type': 'string'},
|
||||
'required': {'$ref': '#/definitions/stringArray'},
|
||||
'properties': {'$ref': '#/definitions/property'},
|
||||
},
|
||||
},
|
||||
},
|
||||
'tags': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'name': {
|
||||
'type': 'string'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'properties': {'name': {'type': 'string'}},
|
||||
},
|
||||
},
|
||||
},
|
||||
'additionalProperties': False,
|
||||
'definitions': {
|
||||
'positiveInteger': {
|
||||
'type': 'integer',
|
||||
'minimum': 0
|
||||
},
|
||||
'positiveInteger': {'type': 'integer', 'minimum': 0},
|
||||
'positiveIntegerDefault0': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#/definitions/positiveInteger'
|
||||
},
|
||||
{
|
||||
'default': 0
|
||||
}
|
||||
{'$ref': '#/definitions/positiveInteger'},
|
||||
{'default': 0},
|
||||
]
|
||||
},
|
||||
'stringArray': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'string'
|
||||
},
|
||||
'uniqueItems': True
|
||||
}
|
||||
'items': {'type': 'string'},
|
||||
'uniqueItems': True,
|
||||
},
|
||||
},
|
||||
'required': [
|
||||
'namespace'
|
||||
]
|
||||
'required': ['namespace'],
|
||||
}
|
||||
|
||||
|
||||
@ -135,7 +101,8 @@ class TestMetadefSchema(base.TestCase):
|
||||
sot = metadef_schema.MetadefSchema(**EXAMPLE)
|
||||
self.assertEqual(EXAMPLE['name'], sot.name)
|
||||
self.assertEqual(EXAMPLE['properties'], sot.properties)
|
||||
self.assertEqual(EXAMPLE['additionalProperties'],
|
||||
sot.additional_properties)
|
||||
self.assertEqual(
|
||||
EXAMPLE['additionalProperties'], sot.additional_properties
|
||||
)
|
||||
self.assertEqual(EXAMPLE['definitions'], sot.definitions)
|
||||
self.assertEqual(EXAMPLE['required'], sot.required)
|
||||
|
@ -571,7 +571,7 @@ class TestMetadefResourceType(TestImageProxy):
|
||||
def test_metadef_resource_types(self):
|
||||
self.verify_list(
|
||||
self.proxy.metadef_resource_types,
|
||||
_metadef_resource_type.MetadefResourceType
|
||||
_metadef_resource_type.MetadefResourceType,
|
||||
)
|
||||
|
||||
|
||||
@ -581,7 +581,7 @@ class TestMetadefResourceTypeAssociation(TestImageProxy):
|
||||
self.proxy.create_metadef_resource_type_association,
|
||||
_metadef_resource_type.MetadefResourceTypeAssociation,
|
||||
method_kwargs={'metadef_namespace': 'namespace_name'},
|
||||
expected_kwargs={'namespace_name': 'namespace_name'}
|
||||
expected_kwargs={'namespace_name': 'namespace_name'},
|
||||
)
|
||||
|
||||
def test_delete_metadef_resource_type_association(self):
|
||||
@ -590,7 +590,7 @@ class TestMetadefResourceTypeAssociation(TestImageProxy):
|
||||
_metadef_resource_type.MetadefResourceTypeAssociation,
|
||||
False,
|
||||
method_kwargs={'metadef_namespace': 'namespace_name'},
|
||||
expected_kwargs={'namespace_name': 'namespace_name'}
|
||||
expected_kwargs={'namespace_name': 'namespace_name'},
|
||||
)
|
||||
|
||||
def test_delete_metadef_resource_type_association_ignore(self):
|
||||
@ -599,7 +599,7 @@ class TestMetadefResourceTypeAssociation(TestImageProxy):
|
||||
_metadef_resource_type.MetadefResourceTypeAssociation,
|
||||
True,
|
||||
method_kwargs={'metadef_namespace': 'namespace_name'},
|
||||
expected_kwargs={'namespace_name': 'namespace_name'}
|
||||
expected_kwargs={'namespace_name': 'namespace_name'},
|
||||
)
|
||||
|
||||
def test_metadef_resource_type_associations(self):
|
||||
@ -607,7 +607,7 @@ class TestMetadefResourceTypeAssociation(TestImageProxy):
|
||||
self.proxy.metadef_resource_type_associations,
|
||||
_metadef_resource_type.MetadefResourceTypeAssociation,
|
||||
method_kwargs={'metadef_namespace': 'namespace_name'},
|
||||
expected_kwargs={'namespace_name': 'namespace_name'}
|
||||
expected_kwargs={'namespace_name': 'namespace_name'},
|
||||
)
|
||||
|
||||
|
||||
@ -892,9 +892,7 @@ class TestCache(TestImageProxy):
|
||||
"openstack.proxy.Proxy._get",
|
||||
self.proxy.get_image_cache,
|
||||
expected_args=[_cache.Cache],
|
||||
expected_kwargs={
|
||||
'requires_id': False
|
||||
},
|
||||
expected_kwargs={'requires_id': False},
|
||||
)
|
||||
|
||||
def test_cache_image_delete(self):
|
||||
@ -911,7 +909,8 @@ class TestCache(TestImageProxy):
|
||||
"openstack.image.v2.cache.Cache.queue",
|
||||
self.proxy.queue_image,
|
||||
method_args=['image-id'],
|
||||
expected_args=[self.proxy, 'image-id'])
|
||||
expected_args=[self.proxy, 'image-id'],
|
||||
)
|
||||
mock_get_resource.assert_called_once_with(_cache.Cache, None)
|
||||
|
||||
@mock.patch.object(proxy_base.Proxy, '_get_resource')
|
||||
@ -922,5 +921,6 @@ class TestCache(TestImageProxy):
|
||||
"openstack.image.v2.cache.Cache.clear",
|
||||
self.proxy.clear_cache,
|
||||
method_args=['both'],
|
||||
expected_args=[self.proxy, 'both'])
|
||||
expected_args=[self.proxy, 'both'],
|
||||
)
|
||||
mock_get_resource.assert_called_once_with(_cache.Cache, None)
|
||||
|
@ -16,39 +16,25 @@ from openstack.tests.unit import base
|
||||
|
||||
IDENTIFIER = 'IDENTIFIER'
|
||||
EXAMPLE = {
|
||||
'additionalProperties': {
|
||||
'type': 'string'
|
||||
},
|
||||
'additionalProperties': {'type': 'string'},
|
||||
'links': [
|
||||
{
|
||||
'href': '{self}',
|
||||
'rel': 'self'
|
||||
},
|
||||
{
|
||||
'href': '{file}',
|
||||
'rel': 'enclosure'
|
||||
},
|
||||
{
|
||||
'href': '{schema}',
|
||||
'rel': 'describedby'
|
||||
}
|
||||
{'href': '{self}', 'rel': 'self'},
|
||||
{'href': '{file}', 'rel': 'enclosure'},
|
||||
{'href': '{schema}', 'rel': 'describedby'},
|
||||
],
|
||||
'name': 'image',
|
||||
'properties': {
|
||||
'architecture': {
|
||||
'description': 'Operating system architecture',
|
||||
'is_base': False,
|
||||
'type': 'string'
|
||||
'type': 'string',
|
||||
},
|
||||
'visibility': {
|
||||
'description': 'Scope of image accessibility',
|
||||
'enum': [
|
||||
'public',
|
||||
'private'
|
||||
],
|
||||
'type': 'string'
|
||||
}
|
||||
}
|
||||
'enum': ['public', 'private'],
|
||||
'type': 'string',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -68,5 +54,6 @@ class TestSchema(base.TestCase):
|
||||
sot = schema.Schema(**EXAMPLE)
|
||||
self.assertEqual(EXAMPLE['properties'], sot.properties)
|
||||
self.assertEqual(EXAMPLE['name'], sot.name)
|
||||
self.assertEqual(EXAMPLE['additionalProperties'],
|
||||
sot.additional_properties)
|
||||
self.assertEqual(
|
||||
EXAMPLE['additionalProperties'], sot.additional_properties
|
||||
)
|
||||
|
@ -22,16 +22,13 @@ EXAMPLE_IMPORT = {
|
||||
'import-methods': {
|
||||
'description': 'Import methods available.',
|
||||
'type': 'array',
|
||||
'value': [
|
||||
'glance-direct',
|
||||
'web-download'
|
||||
]
|
||||
'value': ['glance-direct', 'web-download'],
|
||||
}
|
||||
}
|
||||
EXAMPLE_STORE = {
|
||||
'id': IDENTIFIER,
|
||||
'description': 'Fast access to rbd store',
|
||||
'default': True
|
||||
'default': True,
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,12 +19,9 @@ EXAMPLE = {
|
||||
'created_at': '2016-06-24T14:40:19Z',
|
||||
'id': IDENTIFIER,
|
||||
'input': {
|
||||
'image_properties': {
|
||||
'container_format': 'ovf',
|
||||
'disk_format': 'vhd'
|
||||
},
|
||||
'image_properties': {'container_format': 'ovf', 'disk_format': 'vhd'},
|
||||
'import_from': 'http://example.com',
|
||||
'import_from_format': 'qcow2'
|
||||
'import_from_format': 'qcow2',
|
||||
},
|
||||
'message': 'message',
|
||||
'owner': 'fa6c8c1600f4444281658a23ee6da8e8',
|
||||
@ -32,7 +29,7 @@ EXAMPLE = {
|
||||
'schema': '/v2/schemas/task',
|
||||
'status': 'processing',
|
||||
'type': 'import',
|
||||
'updated_at': '2016-06-24T14:40:20Z'
|
||||
'updated_at': '2016-06-24T14:40:20Z',
|
||||
}
|
||||
|
||||
|
||||
@ -48,14 +45,17 @@ class TestTask(base.TestCase):
|
||||
self.assertFalse(sot.allow_delete)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
self.assertDictEqual({'limit': 'limit',
|
||||
'marker': 'marker',
|
||||
'sort_dir': 'sort_dir',
|
||||
'sort_key': 'sort_key',
|
||||
'status': 'status',
|
||||
'type': 'type',
|
||||
},
|
||||
sot._query_mapping._mapping)
|
||||
self.assertDictEqual(
|
||||
{
|
||||
'limit': 'limit',
|
||||
'marker': 'marker',
|
||||
'sort_dir': 'sort_dir',
|
||||
'sort_key': 'sort_key',
|
||||
'status': 'status',
|
||||
'type': 'type',
|
||||
},
|
||||
sot._query_mapping._mapping,
|
||||
)
|
||||
|
||||
def test_make_it(self):
|
||||
sot = task.Task(**EXAMPLE)
|
||||
|
Loading…
x
Reference in New Issue
Block a user