Merge "Move get_image_meta_from_headers from images_client"
This commit is contained in:
commit
c57f4d2c5f
@ -16,6 +16,7 @@
|
||||
from six import moves
|
||||
|
||||
from tempest.api.image import base
|
||||
from tempest.common import image as common_image
|
||||
from tempest.common.utils import data_utils
|
||||
from tempest.common import waiters
|
||||
from tempest import config
|
||||
@ -306,7 +307,8 @@ class UpdateImageMetaTest(base.BaseV1ImageTest):
|
||||
@test.idempotent_id('01752c1c-0275-4de3-9e5b-876e44541928')
|
||||
def test_list_image_metadata(self):
|
||||
# All metadata key/value pairs for an image should be returned
|
||||
resp_metadata = self.client.check_image(self.image_id)
|
||||
resp = self.client.check_image(self.image_id)
|
||||
resp_metadata = common_image.get_image_meta_from_headers(resp)
|
||||
expected = {'key1': 'value1'}
|
||||
self.assertEqual(expected, resp_metadata['properties'])
|
||||
|
||||
@ -314,12 +316,14 @@ class UpdateImageMetaTest(base.BaseV1ImageTest):
|
||||
def test_update_image_metadata(self):
|
||||
# The metadata for the image should match the updated values
|
||||
req_metadata = {'key1': 'alt1', 'key2': 'value2'}
|
||||
metadata = self.client.check_image(self.image_id)
|
||||
resp = self.client.check_image(self.image_id)
|
||||
metadata = common_image.get_image_meta_from_headers(resp)
|
||||
self.assertEqual(metadata['properties'], {'key1': 'value1'})
|
||||
metadata['properties'].update(req_metadata)
|
||||
metadata = self.client.update_image(
|
||||
self.image_id, properties=metadata['properties'])['image']
|
||||
|
||||
resp_metadata = self.client.check_image(self.image_id)
|
||||
resp = self.client.check_image(self.image_id)
|
||||
resp_metadata = common_image.get_image_meta_from_headers(resp)
|
||||
expected = {'key1': 'alt1', 'key2': 'value2'}
|
||||
self.assertEqual(expected, resp_metadata['properties'])
|
||||
|
38
tempest/common/image.py
Normal file
38
tempest/common/image.py
Normal file
@ -0,0 +1,38 @@
|
||||
# Copyright 2016 NEC Corporation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
def get_image_meta_from_headers(resp):
|
||||
meta = {'properties': {}}
|
||||
for key in resp.response:
|
||||
value = resp.response[key]
|
||||
if key.startswith('x-image-meta-property-'):
|
||||
_key = key[22:]
|
||||
meta['properties'][_key] = value
|
||||
elif key.startswith('x-image-meta-'):
|
||||
_key = key[13:]
|
||||
meta[_key] = value
|
||||
|
||||
for key in ['is_public', 'protected', 'deleted']:
|
||||
if key in meta:
|
||||
meta[key] = meta[key].strip().lower() in ('t', 'true', 'yes', '1')
|
||||
|
||||
for key in ['size', 'min_ram', 'min_disk']:
|
||||
if key in meta:
|
||||
try:
|
||||
meta[key] = int(meta[key])
|
||||
except ValueError:
|
||||
pass
|
||||
return meta
|
@ -15,6 +15,7 @@ import time
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from tempest.common import image as common_image
|
||||
from tempest import config
|
||||
from tempest import exceptions
|
||||
from tempest.lib.common.utils import misc as misc_utils
|
||||
@ -127,7 +128,11 @@ def wait_for_image_status(client, image_id, status):
|
||||
# The 'check_image' method is used here because the show_image method
|
||||
# returns image details plus the image itself which is very expensive.
|
||||
# The 'check_image' method returns just image details.
|
||||
show_image = client.check_image
|
||||
def _show_image_v1(image_id):
|
||||
resp = client.check_image(image_id)
|
||||
return common_image.get_image_meta_from_headers(resp)
|
||||
|
||||
show_image = _show_image_v1
|
||||
else:
|
||||
show_image = client.show_image
|
||||
|
||||
|
@ -23,6 +23,7 @@ from oslo_utils import netutils
|
||||
import six
|
||||
|
||||
from tempest.common import compute
|
||||
from tempest.common import image as common_image
|
||||
from tempest.common.utils import data_utils
|
||||
from tempest.common.utils.linux import remote_client
|
||||
from tempest.common import waiters
|
||||
@ -468,7 +469,8 @@ class ScenarioTest(tempest.test.BaseTestCase):
|
||||
cleanup_args=[_image_client.delete_image, image_id])
|
||||
if CONF.image_feature_enabled.api_v1:
|
||||
# In glance v1 the additional properties are stored in the headers.
|
||||
snapshot_image = _image_client.check_image(image_id)
|
||||
resp = _image_client.check_image(image_id)
|
||||
snapshot_image = common_image.get_image_meta_from_headers(resp)
|
||||
image_props = snapshot_image.get('properties', {})
|
||||
else:
|
||||
# In glance v2 the additional properties are flattened.
|
||||
|
@ -31,28 +31,6 @@ CHUNKSIZE = 1024 * 64 # 64kB
|
||||
class ImagesClient(rest_client.RestClient):
|
||||
api_version = "v1"
|
||||
|
||||
def _image_meta_from_headers(self, headers):
|
||||
meta = {'properties': {}}
|
||||
for key, value in six.iteritems(headers):
|
||||
if key.startswith('x-image-meta-property-'):
|
||||
_key = key[22:]
|
||||
meta['properties'][_key] = value
|
||||
elif key.startswith('x-image-meta-'):
|
||||
_key = key[13:]
|
||||
meta[_key] = value
|
||||
|
||||
for key in ['is_public', 'protected', 'deleted']:
|
||||
if key in meta:
|
||||
meta[key] = meta[key].strip().lower() in ('t', 'true', 'yes',
|
||||
'1')
|
||||
for key in ['size', 'min_ram', 'min_disk']:
|
||||
if key in meta:
|
||||
try:
|
||||
meta[key] = int(meta[key])
|
||||
except ValueError:
|
||||
pass
|
||||
return meta
|
||||
|
||||
def _image_meta_to_headers(self, fields):
|
||||
headers = {}
|
||||
fields_copy = copy.deepcopy(fields)
|
||||
@ -164,9 +142,8 @@ class ImagesClient(rest_client.RestClient):
|
||||
def check_image(self, image_id):
|
||||
"""Check image metadata."""
|
||||
url = 'images/%s' % image_id
|
||||
resp, __ = self.head(url)
|
||||
resp, body = self.head(url)
|
||||
self.expected_success(200, resp.status)
|
||||
body = self._image_meta_from_headers(resp)
|
||||
return rest_client.ResponseBody(resp, body)
|
||||
|
||||
def show_image(self, image_id):
|
||||
@ -178,7 +155,8 @@ class ImagesClient(rest_client.RestClient):
|
||||
|
||||
def is_resource_deleted(self, id):
|
||||
try:
|
||||
if self.check_image(id)['status'] == 'deleted':
|
||||
resp = self.check_image(id)
|
||||
if resp.response["x-image-meta-status"] == 'deleted':
|
||||
return True
|
||||
except lib_exc.NotFound:
|
||||
return True
|
||||
|
40
tempest/tests/common/test_image.py
Normal file
40
tempest/tests/common/test_image.py
Normal file
@ -0,0 +1,40 @@
|
||||
# Copyright 2016 NEC Corporation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from tempest.common import image
|
||||
from tempest.lib.common import rest_client
|
||||
from tempest.tests import base
|
||||
|
||||
|
||||
class TestImage(base.TestCase):
|
||||
|
||||
def test_get_image_meta_from_headers(self):
|
||||
resp = {
|
||||
'x-image-meta-id': 'ea30c926-0629-4400-bb6e-f8a8da6a4e56',
|
||||
'x-image-meta-owner': '8f421f9470e645b1b10f5d2db7804924',
|
||||
'x-image-meta-status': 'queued',
|
||||
'x-image-meta-name': 'New Http Image'
|
||||
}
|
||||
respbody = rest_client.ResponseBody(resp)
|
||||
observed = image.get_image_meta_from_headers(respbody)
|
||||
|
||||
expected = {
|
||||
'properties': {},
|
||||
'id': 'ea30c926-0629-4400-bb6e-f8a8da6a4e56',
|
||||
'owner': '8f421f9470e645b1b10f5d2db7804924',
|
||||
'status': 'queued',
|
||||
'name': 'New Http Image'
|
||||
}
|
||||
self.assertEqual(expected, observed)
|
Loading…
Reference in New Issue
Block a user