Merge "Use oslo.config-1.1.0b1"
diff --git a/tempest/clients.py b/tempest/clients.py
index 16f73d3..b3b5906 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -53,6 +53,7 @@
from tempest.services.identity.xml.identity_client import IdentityClientXML
from tempest.services.identity.xml.identity_client import TokenClientXML
from tempest.services.image.v1.json.image_client import ImageClientJSON
+from tempest.services.image.v2.json.image_client import ImageClientV2JSON
from tempest.services.network.json.network_client import NetworkClient
from tempest.services.object_storage.account_client import AccountClient
from tempest.services.object_storage.account_client import \
@@ -225,6 +226,7 @@
self.hosts_client = HostsClientJSON(*client_args)
self.account_client = AccountClient(*client_args)
self.image_client = ImageClientJSON(*client_args)
+ self.image_client_v2 = ImageClientV2JSON(*client_args)
self.container_client = ContainerClient(*client_args)
self.object_client = ObjectClient(*client_args)
self.ec2api_client = botoclients.APIClientEC2(*client_args)
diff --git a/tempest/common/ssh.py b/tempest/common/ssh.py
index 151060f..be6fe27 100644
--- a/tempest/common/ssh.py
+++ b/tempest/common/ssh.py
@@ -106,6 +106,7 @@
ssh = self._get_ssh_connection()
transport = ssh.get_transport()
channel = transport.open_session()
+ channel.fileno() # Register event pipe
channel.exec_command(cmd)
channel.shutdown_write()
out_data = []
diff --git a/tempest/services/image/v2/__init__.py b/tempest/services/image/v2/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/services/image/v2/__init__.py
diff --git a/tempest/services/image/v2/json/__init__.py b/tempest/services/image/v2/json/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/services/image/v2/json/__init__.py
diff --git a/tempest/services/image/v2/json/image_client.py b/tempest/services/image/v2/json/image_client.py
new file mode 100644
index 0000000..bcae79b
--- /dev/null
+++ b/tempest/services/image/v2/json/image_client.py
@@ -0,0 +1,123 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+#
+# Copyright 2013 IBM
+# 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.
+
+import json
+import urllib
+
+import jsonschema
+
+from tempest.common import glance_http
+from tempest.common import rest_client
+from tempest import exceptions
+
+
+class ImageClientV2JSON(rest_client.RestClient):
+
+ def __init__(self, config, username, password, auth_url, tenant_name=None):
+ super(ImageClientV2JSON, self).__init__(config, username, password,
+ auth_url, tenant_name)
+ self.service = self.config.images.catalog_type
+ self.http = self._get_http()
+
+ def _get_http(self):
+ token, endpoint = self.keystone_auth(self.user, self.password,
+ self.auth_url, self.service,
+ self.tenant_name)
+ dscv = self.config.identity.disable_ssl_certificate_validation
+ return glance_http.HTTPClient(endpoint=endpoint, token=token,
+ insecure=dscv)
+
+ def get_images_schema(self):
+ url = 'v2/schemas/images'
+ resp, body = self.get(url)
+ body = json.loads(body)
+ return resp, body
+
+ def get_image_schema(self):
+ url = 'v2/schemas/image'
+ resp, body = self.get(url)
+ body = json.loads(body)
+ return resp, body
+
+ def _validate_schema(self, body, type='image'):
+ if type == 'image':
+ resp, schema = self.get_image_schema()
+ elif type == 'images':
+ resp, schema = self.get_images_schema()
+ else:
+ raise ValueError("%s is not a valid schema type" % type)
+
+ jsonschema.validate(body, schema)
+
+ def create_image(self, name, container_format, disk_format, is_public=True,
+ properties=None):
+ params = {
+ "name": name,
+ "container_format": container_format,
+ "disk_format": disk_format,
+ }
+ if is_public:
+ params["visibility"] = "public"
+ else:
+ params["visibility"] = "private"
+
+ data = json.dumps(params)
+ self._validate_schema(data)
+
+ resp, body = self.post('v2/images', data, self.headers)
+ body = json.loads(body)
+ return resp, body
+
+ def delete_image(self, image_id):
+ url = 'v2/images/%s' % image_id
+ self.delete(url)
+
+ def image_list(self, params=None):
+ url = 'v2/images'
+
+ if params:
+ url += '?%s' % urllib.urlencode(params)
+
+ resp, body = self.get(url)
+ body = json.loads(body)
+ self._validate_schema(body, type='images')
+ return resp, body['images']
+
+ def get_image_metadata(self, image_id):
+ url = 'v2/images/%s' % image_id
+ resp, body = self.get(url)
+ body = json.loads(body)
+ return resp, body
+
+ def is_resource_deleted(self, id):
+ try:
+ self.get_image_metadata(id)
+ except exceptions.NotFound:
+ return True
+ return False
+
+ def store_image(self, image_id, data):
+ url = 'v2/images/%s/file' % image_id
+ headers = {'Content-Type': 'application/octet-stream'}
+ resp, body = self.http.raw_request('PUT', url, headers=headers,
+ body=data)
+ return resp, body
+
+ def get_image_file(self, image_id):
+ url = 'v2/images/%s/file' % image_id
+ resp, body = self.get(url)
+ return resp, body
diff --git a/tempest/tests/boto/test_ec2_instance_run.py b/tempest/tests/boto/test_ec2_instance_run.py
index 4ad37b6..3293dea 100644
--- a/tempest/tests/boto/test_ec2_instance_run.py
+++ b/tempest/tests/boto/test_ec2_instance_run.py
@@ -142,7 +142,6 @@
#NOTE(afazekas): doctored test case,
# with normal validation it would fail
@attr("slow", type='smoke')
- @testtools.skip("Skipped until the Bug #1117555 is resolved")
def test_integration_1(self):
# EC2 1. integration test (not strict)
image_ami = self.ec2_client.get_image(self.images["ami"]["image_id"])
diff --git a/tempest/tests/compute/test_live_block_migration.py b/tempest/tests/compute/test_live_block_migration.py
index f2ec753..abaaf85 100644
--- a/tempest/tests/compute/test_live_block_migration.py
+++ b/tempest/tests/compute/test_live_block_migration.py
@@ -108,7 +108,6 @@
self.servers_client.wait_for_server_status(server_id, 'ACTIVE')
self.assertEquals(target_host, self._get_host_for_server(server_id))
- @testtools.skip('Until bug 1051881 is dealt with.')
@testtools.skipIf(not live_migration_available,
'Block Live migration not available')
def test_invalid_host_for_migration(self):
diff --git a/tempest/tests/image/v2/__init__.py b/tempest/tests/image/v2/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/tests/image/v2/__init__.py
diff --git a/tempest/tests/image/v2/test_images.py b/tempest/tests/image/v2/test_images.py
new file mode 100644
index 0000000..9abf28d
--- /dev/null
+++ b/tempest/tests/image/v2/test_images.py
@@ -0,0 +1,126 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 OpenStack, LLC
+# All Rights Reserved.
+# Copyright 2013 IBM Corp
+#
+# 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.
+
+import cStringIO as StringIO
+import random
+
+from tempest import clients
+from tempest import exceptions
+import tempest.test
+from tempest.test import attr
+
+
+class CreateRegisterImagesTest(tempest.test.BaseTestCase):
+
+ """
+ Here we test the registration and creation of images
+ """
+
+ @classmethod
+ def setUpClass(cls):
+ cls.os = clients.Manager()
+ cls.client = cls.os.image_client_v2
+ cls.created_images = []
+
+ @classmethod
+ def tearDownClass(cls):
+ for image_id in cls.created_images:
+ cls.client.delete(image_id)
+
+ @attr(type='negative')
+ def test_register_with_invalid_container_format(self):
+ # Negative tests for invalid data supplied to POST /images
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ 'test', 'wrong', 'vhd')
+
+ @attr(type='negative')
+ def test_register_with_invalid_disk_format(self):
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ 'test', 'bare', 'wrong')
+
+ @attr(type='image')
+ def test_register_then_upload(self):
+ # Register, then upload an image
+ resp, body = self.client.create_image('New Name', 'bare', 'raw',
+ is_public=True)
+ self.assertTrue('id' in body)
+ image_id = body.get('id')
+ self.created_images.append(image_id)
+ self.assertTrue('name' in body)
+ self.assertEqual('New Name', body.get('name'))
+ self.assertTrue('visibility' in body)
+ self.assertTrue(body.get('visibility') == 'public')
+ self.assertTrue('status' in body)
+ self.assertEqual('queued', body.get('status'))
+
+ # Now try uploading an image file
+ image_file = StringIO.StringIO(('*' * 1024))
+ resp, body = self.client.store_image(image_id, image_file)
+ self.assertEqual(resp.status, 204)
+ resp, body = self.client.get_image_metadata(image_id)
+ self.assertTrue('size' in body)
+ self.assertEqual(1024, body.get('size'))
+
+
+class ListImagesTest(tempest.test.BaseTestCase):
+
+ """
+ Here we test the listing of image information
+ """
+
+ @classmethod
+ def setUpClass(cls):
+ cls.os = clients.Manager()
+ cls.client = cls.os.image_client_v2
+ cls.created_images = []
+
+ # We add a few images here to test the listing functionality of
+ # the images API
+ for x in xrange(0, 10):
+ cls.created_images.append(cls._create_standard_image(x))
+
+ @classmethod
+ def tearDownClass(cls):
+ for image_id in cls.created_images:
+ cls.client.delete_image(image_id)
+ cls.client.wait_for_resource_deletion(image_id)
+
+ @classmethod
+ def _create_standard_image(cls, number):
+ """
+ Create a new standard image and return the ID of the newly-registered
+ image. Note that the size of the new image is a random number between
+ 1024 and 4096
+ """
+ image_file = StringIO.StringIO('*' * random.randint(1024, 4096))
+ name = 'New Standard Image %s' % number
+ resp, body = cls.client.create_image(name, 'bare', 'raw',
+ is_public=True)
+ image_id = body['id']
+ resp, body = cls.client.store_image(image_id, data=image_file)
+
+ return image_id
+
+ @attr(type='image')
+ def test_index_no_params(self):
+ # Simple test to see all fixture images returned
+ resp, images_list = self.client.image_list()
+ self.assertEqual(resp['status'], '200')
+ image_list = map(lambda x: x['id'], images_list)
+ for image in self.created_images:
+ self.assertTrue(image in image_list)