Merge "Add network quota exceeding negative test"
diff --git a/HACKING.rst b/HACKING.rst
index 9f7487d..0962f80 100644
--- a/HACKING.rst
+++ b/HACKING.rst
@@ -330,24 +330,25 @@
# The created server should be in the detailed list of all servers
...
-Tempest includes a ``check_uuid.py`` tool that will test for the existence
-and uniqueness of idempotent_id metadata for every test. By default the
-tool runs against the Tempest package by calling::
+Tempest-lib includes a ``check-uuid`` tool that will test for the existence
+and uniqueness of idempotent_id metadata for every test. If you have
+tempest-lib installed you run the tool against Tempest by calling from the
+tempest repo::
- python check_uuid.py
+ check-uuid
It can be invoked against any test suite by passing a package name::
- python check_uuid.py --package <package_name>
+ check-uuid --package <package_name>
Tests without an ``idempotent_id`` can be automatically fixed by running
the command with the ``--fix`` flag, which will modify the source package
by inserting randomly generated uuids for every test that does not have
one::
- python check_uuid.py --fix
+ check-uuid --fix
-The ``check_uuid.py`` tool is used as part of the tempest gate job
+The ``check-uuid`` tool is used as part of the tempest gate job
to ensure that all tests have an ``idempotent_id`` decorator.
Branchless Tempest Considerations
diff --git a/requirements.txt b/requirements.txt
index 17d063d..d470c30 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -22,6 +22,6 @@
iso8601>=0.1.9
fixtures>=1.3.1
testscenarios>=0.4
-tempest-lib>=0.10.0
+tempest-lib>=0.11.0
PyYAML>=3.1.0
stevedore>=1.5.0 # Apache-2.0
diff --git a/run_tests.sh b/run_tests.sh
index 9a158e4..908056f 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -90,9 +90,9 @@
fi
if [ $serial -eq 1 ]; then
- ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
+ ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-trace -n -f
else
- ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
+ ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-trace -n -f
fi
}
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index a5c0600..5bc0769 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -18,6 +18,7 @@
from oslo_log import log as logging
from tempest_lib import exceptions as lib_exc
+from tempest.common import api_version_utils
from tempest.common import compute
from tempest.common.utils import data_utils
from tempest.common import waiters
@@ -29,7 +30,8 @@
LOG = logging.getLogger(__name__)
-class BaseV2ComputeTest(tempest.test.BaseTestCase):
+class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest,
+ tempest.test.BaseTestCase):
"""Base test case class for all Compute API tests."""
force_tenant_isolation = False
@@ -43,6 +45,12 @@
super(BaseV2ComputeTest, cls).skip_checks()
if not CONF.service_available.nova:
raise cls.skipException("Nova is not available")
+ cfg_min_version = CONF.compute_feature_enabled.min_microversion
+ cfg_max_version = CONF.compute_feature_enabled.max_microversion
+ api_version_utils.check_skip_with_microversion(cls.min_microversion,
+ cls.max_microversion,
+ cfg_min_version,
+ cfg_max_version)
@classmethod
def setup_credentials(cls):
diff --git a/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py b/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py
index 64aac80..0223c0d 100644
--- a/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py
+++ b/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py
@@ -60,7 +60,7 @@
# to a project should fail
self.assertRaises(lib_exc.NotFound,
self.client.create_floating_ip,
- "non_exist_pool")
+ pool="non_exist_pool")
@test.attr(type=['negative'])
@test.idempotent_id('ae1c55a8-552b-44d4-bfb6-2a115a15d0ba')
diff --git a/tempest/api/compute/servers/test_servers_negative.py b/tempest/api/compute/servers/test_servers_negative.py
index 98b292a..a5e9afd 100644
--- a/tempest/api/compute/servers/test_servers_negative.py
+++ b/tempest/api/compute/servers/test_servers_negative.py
@@ -169,8 +169,8 @@
@test.attr(type=['negative'])
@test.idempotent_id('98fa0458-1485-440f-873b-fe7f0d714930')
- def test_rebuild_reboot_deleted_server(self):
- # Rebuild and Reboot a deleted server
+ def test_rebuild_deleted_server(self):
+ # Rebuild a deleted server
server = self.create_test_server()
self.client.delete_server(server['id'])
waiters.wait_for_server_termination(self.client, server['id'])
@@ -178,6 +178,15 @@
self.assertRaises(lib_exc.NotFound,
self.client.rebuild_server,
server['id'], self.image_ref_alt)
+
+ @test.attr(type=['negative'])
+ @test.idempotent_id('581a397d-5eab-486f-9cf9-1014bbd4c984')
+ def test_reboot_deleted_server(self):
+ # Reboot a deleted server
+ server = self.create_test_server()
+ self.client.delete_server(server['id'])
+ waiters.wait_for_server_termination(self.client, server['id'])
+
self.assertRaises(lib_exc.NotFound, self.client.reboot_server,
server['id'], 'SOFT')
diff --git a/tempest/api/identity/admin/v3/test_groups.py b/tempest/api/identity/admin/v3/test_groups.py
index 82e4ec8..260ea54 100644
--- a/tempest/api/identity/admin/v3/test_groups.py
+++ b/tempest/api/identity/admin/v3/test_groups.py
@@ -42,6 +42,21 @@
self.assertEqual(new_name, new_group['name'])
self.assertEqual(new_desc, new_group['description'])
+ @test.idempotent_id('b66eb441-b08a-4a6d-81ab-fef71baeb26c')
+ def test_group_update_with_few_fields(self):
+ name = data_utils.rand_name('Group')
+ old_description = data_utils.rand_name('Description')
+ group = self.groups_client.create_group(
+ name=name, description=old_description)['group']
+ self.addCleanup(self.groups_client.delete_group, group['id'])
+
+ new_name = data_utils.rand_name('UpdateGroup')
+ updated_group = self.groups_client.update_group(
+ group['id'], name=new_name)['group']
+ self.assertEqual(new_name, updated_group['name'])
+ # Verify that 'description' is not being updated or deleted.
+ self.assertEqual(old_description, updated_group['description'])
+
@test.attr(type='smoke')
@test.idempotent_id('1598521a-2f36-4606-8df9-30772bd51339')
def test_group_users_add_list_delete(self):
diff --git a/tempest/api/identity/admin/v3/test_users_negative.py b/tempest/api/identity/admin/v3/test_users_negative.py
index ca2aaa4..d40a5b9 100644
--- a/tempest/api/identity/admin/v3/test_users_negative.py
+++ b/tempest/api/identity/admin/v3/test_users_negative.py
@@ -33,3 +33,14 @@
u_name, u_password,
email=u_email,
domain_id=data_utils.rand_uuid_hex())
+
+ @test.attr(type=['negative'])
+ @test.idempotent_id('b3c9fccc-4134-46f5-b600-1da6fb0a3b1f')
+ def test_authentication_for_disabled_user(self):
+ # Attempt to authenticate for disabled user should fail
+ self.data.setup_test_v3_user()
+ self.disable_user(self.data.test_user)
+ self.assertRaises(lib_exc.Unauthorized, self.token.auth,
+ username=self.data.test_user,
+ password=self.data.test_password,
+ user_domain_id='default')
diff --git a/tempest/api/identity/base.py b/tempest/api/identity/base.py
index c56f4fb..0364f3a 100644
--- a/tempest/api/identity/base.py
+++ b/tempest/api/identity/base.py
@@ -170,6 +170,11 @@
if len(role) > 0:
return role[0]
+ @classmethod
+ def disable_user(cls, user_name):
+ user = cls.get_user_by_name(user_name)
+ cls.client.update_user(user['id'], user_name, enabled=False)
+
def delete_domain(self, domain_id):
# NOTE(mpavlase) It is necessary to disable the domain before deleting
# otherwise it raises Forbidden exception
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index b798cb2..b4ea29b 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -105,7 +105,7 @@
# Clean up metering labels
for metering_label in cls.metering_labels:
cls._try_delete_resource(
- cls.admin_client.delete_metering_label,
+ cls.admin_metering_labels_client.delete_metering_label,
metering_label['id'])
# Clean up ports
for port in cls.ports:
@@ -272,11 +272,12 @@
cls.admin_subnets_client = cls.os_adm.subnets_client
cls.admin_ports_client = cls.os_adm.ports_client
cls.admin_floating_ips_client = cls.os_adm.floating_ips_client
+ cls.admin_metering_labels_client = cls.os_adm.metering_labels_client
@classmethod
def create_metering_label(cls, name, description):
"""Wrapper utility that returns a test metering label."""
- body = cls.admin_client.create_metering_label(
+ body = cls.admin_metering_labels_client.create_metering_label(
description=description,
name=data_utils.rand_name("metering-label"))
metering_label = body['metering_label']
diff --git a/tempest/api/network/test_metering_extensions.py b/tempest/api/network/test_metering_extensions.py
index a213f92..c4021b4 100644
--- a/tempest/api/network/test_metering_extensions.py
+++ b/tempest/api/network/test_metering_extensions.py
@@ -51,9 +51,11 @@
def _delete_metering_label(self, metering_label_id):
# Deletes a label and verifies if it is deleted or not
- self.admin_client.delete_metering_label(metering_label_id)
+ self.admin_metering_labels_client.delete_metering_label(
+ metering_label_id)
# Asserting that the label is not found in list after deletion
- labels = self.admin_client.list_metering_labels(id=metering_label_id)
+ labels = self.admin_metering_labels_client.list_metering_labels(
+ id=metering_label_id)
self.assertEqual(len(labels['metering_labels']), 0)
def _delete_metering_label_rule(self, metering_label_rule_id):
@@ -68,7 +70,7 @@
@test.idempotent_id('e2fb2f8c-45bf-429a-9f17-171c70444612')
def test_list_metering_labels(self):
# Verify label filtering
- body = self.admin_client.list_metering_labels(id=33)
+ body = self.admin_metering_labels_client.list_metering_labels(id=33)
metering_labels = body['metering_labels']
self.assertEqual(0, len(metering_labels))
@@ -77,21 +79,22 @@
# Creates a label
name = data_utils.rand_name('metering-label-')
description = "label created by tempest"
- body = self.admin_client.create_metering_label(name=name,
- description=description)
+ body = self.admin_metering_labels_client.create_metering_label(
+ name=name, description=description)
metering_label = body['metering_label']
self.addCleanup(self._delete_metering_label,
metering_label['id'])
# Assert whether created labels are found in labels list or fail
# if created labels are not found in labels list
- labels = (self.admin_client.list_metering_labels(
+ labels = (self.admin_metering_labels_client.list_metering_labels(
id=metering_label['id']))
self.assertEqual(len(labels['metering_labels']), 1)
@test.idempotent_id('30abb445-0eea-472e-bd02-8649f54a5968')
def test_show_metering_label(self):
# Verifies the details of a label
- body = self.admin_client.show_metering_label(self.metering_label['id'])
+ body = self.admin_metering_labels_client.show_metering_label(
+ self.metering_label['id'])
metering_label = body['metering_label']
self.assertEqual(self.metering_label['id'], metering_label['id'])
self.assertEqual(self.metering_label['tenant_id'],
diff --git a/tempest/api_schema/response/compute/v2_1/agents.py b/tempest/api_schema/response/compute/v2_1/agents.py
deleted file mode 100644
index da38198..0000000
--- a/tempest/api_schema/response/compute/v2_1/agents.py
+++ /dev/null
@@ -1,60 +0,0 @@
-# Copyright 2014 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.
-
-common_agent_info = {
- 'type': 'object',
- 'properties': {
- 'agent_id': {'type': ['integer', 'string']},
- 'hypervisor': {'type': 'string'},
- 'os': {'type': 'string'},
- 'architecture': {'type': 'string'},
- 'version': {'type': 'string'},
- 'url': {'type': 'string', 'format': 'uri'},
- 'md5hash': {'type': 'string'}
- },
- 'additionalProperties': False,
- 'required': ['agent_id', 'hypervisor', 'os', 'architecture',
- 'version', 'url', 'md5hash']
-}
-
-list_agents = {
- 'status_code': [200],
- 'response_body': {
- 'type': 'object',
- 'properties': {
- 'agents': {
- 'type': 'array',
- 'items': common_agent_info
- }
- },
- 'additionalProperties': False,
- 'required': ['agents']
- }
-}
-
-create_agent = {
- 'status_code': [200],
- 'response_body': {
- 'type': 'object',
- 'properties': {
- 'agent': common_agent_info
- },
- 'additionalProperties': False,
- 'required': ['agent']
- }
-}
-
-delete_agent = {
- 'status_code': [200]
-}
diff --git a/tempest/clients.py b/tempest/clients.py
index 2566d79..d16b47b 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -35,7 +35,8 @@
from tempest_lib.services.compute.hosts_client import HostsClient
from tempest_lib.services.compute.hypervisor_client import \
HypervisorClient
-from tempest_lib.services.compute.images_client import ImagesClient
+from tempest_lib.services.compute.images_client import ImagesClient \
+ as ComputeImagesClient
from tempest_lib.services.compute.instance_usage_audit_log_client import \
InstanceUsagesAuditLogClient
from tempest_lib.services.compute.limits_client import LimitsClient
@@ -102,11 +103,13 @@
RegionClient as RegionV3Client
from tempest.services.identity.v3.json.service_client import \
ServiceClient as ServiceV3Client
-from tempest.services.image.v1.json.image_client import ImageClient
-from tempest.services.image.v2.json.image_client import ImageClientV2
+from tempest.services.image.v1.json.images_client import ImagesClient
+from tempest.services.image.v2.json.images_client import ImagesClientV2
from tempest.services.messaging.json.messaging_client import \
MessagingClient
from tempest.services.network.json.floating_ips_client import FloatingIPsClient
+from tempest.services.network.json.metering_labels_client import \
+ MeteringLabelsClient
from tempest.services.network.json.network_client import NetworkClient
from tempest.services.network.json.networks_client import NetworksClient
from tempest.services.network.json.ports_client import PortsClient
@@ -230,6 +233,14 @@
build_interval=CONF.network.build_interval,
build_timeout=CONF.network.build_timeout,
**self.default_params)
+ self.metering_labels_client = MeteringLabelsClient(
+ self.auth_provider,
+ CONF.network.catalog_type,
+ CONF.network.region or CONF.identity.region,
+ endpoint_type=CONF.network.endpoint_type,
+ build_interval=CONF.network.build_interval,
+ build_timeout=CONF.network.build_timeout,
+ **self.default_params)
self.messaging_client = MessagingClient(
self.auth_provider,
CONF.messaging.catalog_type,
@@ -250,7 +261,7 @@
endpoint_type=CONF.alarming.endpoint_type,
**self.default_params_with_timeout_values)
if CONF.service_available.glance:
- self.image_client = ImageClient(
+ self.image_client = ImagesClient(
self.auth_provider,
CONF.image.catalog_type,
CONF.image.region or CONF.identity.region,
@@ -258,7 +269,7 @@
build_interval=CONF.image.build_interval,
build_timeout=CONF.image.build_timeout,
**self.default_params)
- self.image_client_v2 = ImageClientV2(
+ self.image_client_v2 = ImagesClientV2(
self.auth_provider,
CONF.image.catalog_type,
CONF.image.region or CONF.identity.region,
@@ -319,7 +330,7 @@
self.server_groups_client = ServerGroupsClient(
self.auth_provider, **params)
self.limits_client = LimitsClient(self.auth_provider, **params)
- self.images_client = ImagesClient(self.auth_provider, **params)
+ self.images_client = ComputeImagesClient(self.auth_provider, **params)
self.keypairs_client = KeyPairsClient(self.auth_provider, **params)
self.quotas_client = QuotasClient(self.auth_provider, **params)
self.quota_classes_client = QuotaClassesClient(self.auth_provider,
diff --git a/tempest/cmd/cleanup_service.py b/tempest/cmd/cleanup_service.py
index ba6bf6c..f2dd7af 100644
--- a/tempest/cmd/cleanup_service.py
+++ b/tempest/cmd/cleanup_service.py
@@ -387,6 +387,7 @@
self.subnets_client = manager.subnets_client
self.ports_client = manager.ports_client
self.floating_ips_client = manager.floating_ips_client
+ self.metering_labels_client = manager.metering_labels_client
def _filter_by_conf_networks(self, item_list):
if not item_list or not all(('network_id' in i for i in item_list)):
@@ -600,7 +601,7 @@
class NetworkMeteringLabelService(NetworkService):
def list(self):
- client = self.client
+ client = self.metering_labels_client
labels = client.list_metering_labels()
labels = labels['metering_labels']
labels = self._filter_by_tenant_id(labels)
@@ -608,7 +609,7 @@
return labels
def delete(self):
- client = self.client
+ client = self.metering_labels_client
labels = self.list()
for label in labels:
try:
diff --git a/tempest/cmd/javelin.py b/tempest/cmd/javelin.py
index b126ef6..c5e4a7e 100755
--- a/tempest/cmd/javelin.py
+++ b/tempest/cmd/javelin.py
@@ -128,7 +128,7 @@
from tempest.services.compute.json import security_group_rules_client
from tempest.services.compute.json import servers_client
from tempest.services.identity.v2.json import identity_client
-from tempest.services.image.v2.json import image_client
+from tempest.services.image.v2.json import images_client
from tempest.services.network.json import network_client
from tempest.services.network.json import subnets_client
from tempest.services.object_storage import container_client
@@ -213,7 +213,7 @@
**object_storage_params)
self.containers = container_client.ContainerClient(
_auth, **object_storage_params)
- self.images = image_client.ImageClientV2(
+ self.images = images_client.ImagesClientV2(
_auth,
CONF.image.catalog_type,
CONF.image.region or CONF.identity.region,
diff --git a/tempest/common/api_version_request.py b/tempest/common/api_version_request.py
new file mode 100644
index 0000000..72a11ea
--- /dev/null
+++ b/tempest/common/api_version_request.py
@@ -0,0 +1,152 @@
+# Copyright 2014 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 re
+
+from tempest import exceptions
+
+
+# Define the minimum and maximum version of the API across all of the
+# REST API. The format of the version is:
+# X.Y where:
+#
+# - X will only be changed if a significant backwards incompatible API
+# change is made which affects the API as whole. That is, something
+# that is only very very rarely incremented.
+#
+# - Y when you make any change to the API. Note that this includes
+# semantic changes which may not affect the input or output formats or
+# even originate in the API code layer. We are not distinguishing
+# between backwards compatible and backwards incompatible changes in
+# the versioning system. It must be made clear in the documentation as
+# to what is a backwards compatible change and what is a backwards
+# incompatible one.
+
+class APIVersionRequest(object):
+ """This class represents an API Version Request.
+
+ This class provides convenience methods for manipulation
+ and comparison of version numbers that we need to do to
+ implement microversions.
+ """
+
+ # NOTE: This 'latest' version is a magic number, we assume any
+ # projects(Nova, etc.) never achieve this number.
+ latest_ver_major = 99999
+ latest_ver_minor = 99999
+
+ def __init__(self, version_string=None):
+ """Create an API version request object.
+
+ :param version_string: String representation of APIVersionRequest.
+ Correct format is 'X.Y', where 'X' and 'Y' are int values.
+ None value should be used to create Null APIVersionRequest,
+ which is equal to 0.0
+ """
+ self.ver_major = 0
+ self.ver_minor = 0
+
+ if version_string is not None:
+ match = re.match(r"^([1-9]\d*)\.([1-9]\d*|0)$",
+ version_string)
+ if match:
+ self.ver_major = int(match.group(1))
+ self.ver_minor = int(match.group(2))
+ elif version_string == 'latest':
+ self.ver_major = self.latest_ver_major
+ self.ver_minor = self.latest_ver_minor
+ else:
+ raise exceptions.InvalidAPIVersionString(
+ version=version_string)
+
+ def __str__(self):
+ """Debug/Logging representation of object."""
+ return ("API Version Request: %s" % self.get_string())
+
+ def is_null(self):
+ return self.ver_major == 0 and self.ver_minor == 0
+
+ def _format_type_error(self, other):
+ return TypeError("'%(other)s' should be an instance of '%(cls)s'" %
+ {"other": other, "cls": self.__class__})
+
+ def __lt__(self, other):
+ if not isinstance(other, APIVersionRequest):
+ raise self._format_type_error(other)
+
+ return ((self.ver_major, self.ver_minor) <
+ (other.ver_major, other.ver_minor))
+
+ def __eq__(self, other):
+ if not isinstance(other, APIVersionRequest):
+ raise self._format_type_error(other)
+
+ return ((self.ver_major, self.ver_minor) ==
+ (other.ver_major, other.ver_minor))
+
+ def __gt__(self, other):
+ if not isinstance(other, APIVersionRequest):
+ raise self._format_type_error(other)
+
+ return ((self.ver_major, self.ver_minor) >
+ (other.ver_major, other.ver_minor))
+
+ def __le__(self, other):
+ return self < other or self == other
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __ge__(self, other):
+ return self > other or self == other
+
+ def matches(self, min_version, max_version):
+ """Matches the version object.
+
+ Returns whether the version object represents a version
+ greater than or equal to the minimum version and less than
+ or equal to the maximum version.
+
+ @param min_version: Minimum acceptable version.
+ @param max_version: Maximum acceptable version.
+ @returns: boolean
+
+ If min_version is null then there is no minimum limit.
+ If max_version is null then there is no maximum limit.
+ If self is null then raise ValueError
+ """
+
+ if self.is_null():
+ raise ValueError
+ if max_version.is_null() and min_version.is_null():
+ return True
+ elif max_version.is_null():
+ return min_version <= self
+ elif min_version.is_null():
+ return self <= max_version
+ else:
+ return min_version <= self <= max_version
+
+ def get_string(self):
+ """Version string representation.
+
+ Converts object to string representation which if used to create
+ an APIVersionRequest object results in the same version request.
+ """
+ if self.is_null():
+ return None
+ if (self.ver_major == self.latest_ver_major and
+ self.ver_minor == self.latest_ver_minor):
+ return 'latest'
+ return "%s.%s" % (self.ver_major, self.ver_minor)
diff --git a/tempest/common/api_version_utils.py b/tempest/common/api_version_utils.py
new file mode 100644
index 0000000..c499f23
--- /dev/null
+++ b/tempest/common/api_version_utils.py
@@ -0,0 +1,64 @@
+# Copyright 2015 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.
+
+import testtools
+
+from tempest.common import api_version_request
+from tempest import exceptions
+
+
+class BaseMicroversionTest(object):
+ """Mixin class for API microversion test class."""
+
+ # NOTE: Basically, each microversion is small API change and we
+ # can use the same tests for most microversions in most cases.
+ # So it is nice to define the test class as possible to run
+ # for all microversions. We need to define microversion range
+ # (min_microversion, max_microversion) on each test class if necessary.
+ min_microversion = None
+ max_microversion = 'latest'
+
+
+def check_skip_with_microversion(test_min_version, test_max_version,
+ cfg_min_version, cfg_max_version):
+ min_version = api_version_request.APIVersionRequest(test_min_version)
+ max_version = api_version_request.APIVersionRequest(test_max_version)
+ config_min_version = api_version_request.APIVersionRequest(cfg_min_version)
+ config_max_version = api_version_request.APIVersionRequest(cfg_max_version)
+ if ((min_version > max_version) or
+ (config_min_version > config_max_version)):
+ msg = ("Min version is greater than Max version. Test Class versions "
+ "[%s - %s]. configration versions [%s - %s]."
+ % (min_version.get_string(),
+ max_version.get_string(),
+ config_min_version.get_string(),
+ config_max_version.get_string()))
+ raise exceptions.InvalidConfiguration(msg)
+
+ # NOTE: Select tests which are in range of configuration like
+ # config min config max
+ # ----------------+--------------------------+----------------
+ # ...don't-select|
+ # ...select... ...select... ...select...
+ # |don't-select...
+ # ......................select............................
+ if (max_version < config_min_version or
+ config_max_version < min_version):
+ msg = ("The microversion range[%s - %s] of this test is out of the "
+ "configration range[%s - %s]."
+ % (min_version.get_string(),
+ max_version.get_string(),
+ config_min_version.get_string(),
+ config_max_version.get_string()))
+ raise testtools.TestCase.skipException(msg)
diff --git a/tempest/common/glance_http.py b/tempest/common/glance_http.py
index e5431a0..800e977 100644
--- a/tempest/common/glance_http.py
+++ b/tempest/common/glance_http.py
@@ -24,12 +24,10 @@
import OpenSSL
from oslo_log import log as logging
-from oslo_serialization import jsonutils as json
import six
from six import moves
from six.moves import http_client as httplib
from six.moves.urllib import parse as urlparse
-from tempest_lib import exceptions as lib_exc
from tempest import exceptions as exc
@@ -51,19 +49,20 @@
self.endpoint_port = endpoint_parts.port
self.endpoint_path = endpoint_parts.path
- self.connection_class = self.get_connection_class(self.endpoint_scheme)
- self.connection_kwargs = self.get_connection_kwargs(
+ self.connection_class = self._get_connection_class(
+ self.endpoint_scheme)
+ self.connection_kwargs = self._get_connection_kwargs(
self.endpoint_scheme, **kwargs)
@staticmethod
- def get_connection_class(scheme):
+ def _get_connection_class(scheme):
if scheme == 'https':
return VerifiedHTTPSConnection
else:
return httplib.HTTPConnection
@staticmethod
- def get_connection_kwargs(scheme, **kwargs):
+ def _get_connection_kwargs(scheme, **kwargs):
_kwargs = {'timeout': float(kwargs.get('timeout', 600))}
if scheme == 'https':
@@ -75,7 +74,7 @@
return _kwargs
- def get_connection(self):
+ def _get_connection(self):
_class = self.connection_class
try:
return _class(self.endpoint_hostname, self.endpoint_port,
@@ -95,7 +94,7 @@
self._log_request(method, url, kwargs['headers'])
- conn = self.get_connection()
+ conn = self._get_connection()
try:
url_parts = urlparse.urlparse(url)
@@ -159,30 +158,6 @@
self.LOG.debug("Large body (%d) md5 summary: %s", length,
hashlib.md5(str_body).hexdigest())
- def json_request(self, method, url, **kwargs):
- kwargs.setdefault('headers', {})
- kwargs['headers'].setdefault('Content-Type', 'application/json')
- if kwargs['headers']['Content-Type'] != 'application/json':
- msg = "Only application/json content-type is supported."
- raise lib_exc.InvalidContentType(msg)
-
- if 'body' in kwargs:
- kwargs['body'] = json.dumps(kwargs['body'])
-
- resp, body_iter = self._http_request(url, method, **kwargs)
-
- if 'application/json' in resp.getheader('content-type', ''):
- body = ''.join([chunk for chunk in body_iter])
- try:
- body = json.loads(body)
- except ValueError:
- LOG.error('Could not decode response body as JSON')
- else:
- msg = "Only json/application content-type is supported."
- raise lib_exc.InvalidContentType(msg)
-
- return resp, body
-
def raw_request(self, method, url, **kwargs):
kwargs.setdefault('headers', {})
kwargs['headers'].setdefault('Content-Type',
diff --git a/tempest/config.py b/tempest/config.py
index 8c3656f..26dda2d 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -341,6 +341,22 @@
title="Enabled Compute Service Features")
ComputeFeaturesGroup = [
+ cfg.StrOpt('min_microversion',
+ default=None,
+ help="Lower version of the test target microversion range. "
+ "The format is 'X.Y', where 'X' and 'Y' are int values. "
+ "Tempest selects tests based on the range between "
+ "min_microversion and max_microversion. "
+ "If both values are None, Tempest avoids tests which "
+ "require a microversion."),
+ cfg.StrOpt('max_microversion',
+ default=None,
+ help="Upper version of the test target microversion range. "
+ "The format is 'X.Y', where 'X' and 'Y' are int values. "
+ "Tempest selects tests based on the range between "
+ "min_microversion and max_microversion. "
+ "If both values are None, Tempest avoids tests which "
+ "require a microversion."),
cfg.BoolOpt('disk_config',
default=True,
help="If false, skip disk config tests"),
diff --git a/tempest/exceptions.py b/tempest/exceptions.py
index 031df7f..8537898 100644
--- a/tempest/exceptions.py
+++ b/tempest/exceptions.py
@@ -176,6 +176,11 @@
message = "Invalid structure of table with details"
+class InvalidAPIVersionString(TempestException):
+ msg_fmt = ("API Version String %(version)s is of invalid format. Must "
+ "be of format MajorNum.MinorNum.")
+
+
class CommandFailed(Exception):
def __init__(self, returncode, cmd, output, stderr):
super(CommandFailed, self).__init__()
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index d787c3f..24877f4 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -23,7 +23,7 @@
from tempest_lib.common.utils import misc as misc_utils
from tempest_lib import exceptions as lib_exc
-from tempest.common import fixed_network
+from tempest.common import compute
from tempest.common.utils import data_utils
from tempest.common.utils.linux import remote_client
from tempest.common import waiters
@@ -158,52 +158,100 @@
return body['keypair']
def create_server(self, name=None, image=None, flavor=None,
- wait_on_boot=True, wait_on_delete=True,
- create_kwargs=None):
- """Creates VM instance.
+ validatable=False, wait_until=None,
+ wait_on_delete=True, clients=None, **kwargs):
+ """Wrapper utility that returns a test server.
- @param image: image from which to create the instance
- @param wait_on_boot: wait for status ACTIVE before continue
- @param wait_on_delete: force synchronous delete on cleanup
- @param create_kwargs: additional details for instance creation
- @return: server dict
+ This wrapper utility calls the common create test server and
+ returns a test server. The purpose of this wrapper is to minimize
+ the impact on the code of the tests already using this
+ function.
"""
- if name is None:
- name = data_utils.rand_name(self.__class__.__name__)
- if image is None:
- image = CONF.compute.image_ref
- if flavor is None:
- flavor = CONF.compute.flavor_ref
- if create_kwargs is None:
- create_kwargs = {}
- network = self.get_tenant_network()
- create_kwargs = fixed_network.set_networks_kwarg(network,
- create_kwargs)
- LOG.debug("Creating a server (name: %s, image: %s, flavor: %s)",
- name, image, flavor)
- server = self.servers_client.create_server(name=name, imageRef=image,
- flavorRef=flavor,
- **create_kwargs)['server']
+ # NOTE(jlanoux): As a first step, ssh checks in the scenario
+ # tests need to be run regardless of the run_validation and
+ # validatable parameters and thus until the ssh validation job
+ # becomes voting in CI. The test resources management and IP
+ # association are taken care of in the scenario tests.
+ # Therefore, the validatable parameter is set to false in all
+ # those tests. In this way create_server just return a standard
+ # server and the scenario tests always perform ssh checks.
+
+ # Needed for the cross_tenant_traffic test:
+ if clients is None:
+ clients = self.manager
+
+ vnic_type = CONF.network.port_vnic_type
+
+ # If vnic_type is configured create port for
+ # every network
+ if vnic_type:
+ ports = []
+ networks = []
+ create_port_body = {'binding:vnic_type': vnic_type,
+ 'namestart': 'port-smoke'}
+ if kwargs:
+ # Convert security group names to security group ids
+ # to pass to create_port
+ if 'security_groups' in kwargs:
+ security_groups =\
+ clients.network_client.list_security_groups(
+ ).get('security_groups')
+ sec_dict = dict([(s['name'], s['id'])
+ for s in security_groups])
+
+ sec_groups_names = [s['name'] for s in kwargs.pop(
+ 'security_groups')]
+ security_groups_ids = [sec_dict[s]
+ for s in sec_groups_names]
+
+ if security_groups_ids:
+ create_port_body[
+ 'security_groups'] = security_groups_ids
+ networks = kwargs.pop('networks')
+
+ # If there are no networks passed to us we look up
+ # for the tenant's private networks and create a port
+ # if there is only one private network. The same behaviour
+ # as we would expect when passing the call to the clients
+ # with no networks
+ if not networks:
+ networks = clients.networks_client.list_networks(
+ filters={'router:external': False})
+ self.assertEqual(1, len(networks),
+ "There is more than one"
+ " network for the tenant")
+ for net in networks:
+ net_id = net['uuid']
+ port = self._create_port(network_id=net_id,
+ client=clients.ports_client,
+ **create_port_body)
+ ports.append({'port': port.id})
+ if ports:
+ kwargs['networks'] = ports
+ self.ports = ports
+
+ tenant_network = self.get_tenant_network()
+
+ body, servers = compute.create_test_server(
+ clients,
+ tenant_network=tenant_network,
+ wait_until=wait_until,
+ **kwargs)
+
+ # TODO(jlanoux) Move wait_on_delete in compute.py
if wait_on_delete:
self.addCleanup(waiters.wait_for_server_termination,
- self.servers_client,
- server['id'])
+ clients.servers_client,
+ body['id'])
+
self.addCleanup_with_wait(
waiter_callable=waiters.wait_for_server_termination,
- thing_id=server['id'], thing_id_param='server_id',
+ thing_id=body['id'], thing_id_param='server_id',
cleanup_callable=self.delete_wrapper,
- cleanup_args=[self.servers_client.delete_server, server['id']],
- waiter_client=self.servers_client)
- if wait_on_boot:
- waiters.wait_for_server_status(self.servers_client,
- server_id=server['id'],
- status='ACTIVE')
- # The instance retrieved on creation is missing network
- # details, necessitating retrieval after it becomes active to
- # ensure correct details.
- server = self.servers_client.show_server(server['id'])['server']
- self.assertEqual(server['name'], name)
+ cleanup_args=[clients.servers_client.delete_server, body['id']],
+ waiter_client=clients.servers_client)
+ server = clients.servers_client.show_server(body['id'])['server']
return server
def create_volume(self, size=None, name=None, snapshot_id=None,
@@ -321,7 +369,7 @@
username = CONF.scenario.ssh_user
# Set this with 'keypair' or others to log in with keypair or
# username/password.
- if CONF.compute.ssh_auth_method == 'keypair':
+ if CONF.validation.auth_method == 'keypair':
password = None
if private_key is None:
private_key = self.keypair['private_key']
@@ -491,7 +539,7 @@
def ping_ip_address(self, ip_address, should_succeed=True,
ping_timeout=None):
- timeout = ping_timeout or CONF.compute.ping_timeout
+ timeout = ping_timeout or CONF.validation.ping_timeout
cmd = ['ping', '-c1', '-w1', ip_address]
def ping():
@@ -568,7 +616,7 @@
"""Create a floating IP and associates to a server on Nova"""
floating_ip = (self.compute_floating_ips_client.
- create_floating_ip(pool_name)['floating_ip'])
+ create_floating_ip(pool=pool_name)['floating_ip'])
self.addCleanup(self.delete_wrapper,
self.compute_floating_ips_client.delete_floating_ip,
floating_ip['id'])
@@ -886,7 +934,7 @@
return should_succeed
return tempest.test.call_until_true(ping_remote,
- CONF.compute.ping_timeout,
+ CONF.validation.ping_timeout,
1)
def _create_security_group(self, client=None, tenant_id=None,
@@ -1137,71 +1185,6 @@
subnet.add_to_router(router.id)
return network, subnet, router
- def create_server(self, name=None, image=None, flavor=None,
- wait_on_boot=True, wait_on_delete=True,
- network_client=None, networks_client=None,
- ports_client=None, create_kwargs=None):
- if network_client is None:
- network_client = self.network_client
- if networks_client is None:
- networks_client = self.networks_client
- if ports_client is None:
- ports_client = self.ports_client
-
- vnic_type = CONF.network.port_vnic_type
-
- # If vnic_type is configured create port for
- # every network
- if vnic_type:
- ports = []
- networks = []
- create_port_body = {'binding:vnic_type': vnic_type,
- 'namestart': 'port-smoke'}
- if create_kwargs:
- # Convert security group names to security group ids
- # to pass to create_port
- if create_kwargs.get('security_groups'):
- security_groups = network_client.list_security_groups(
- ).get('security_groups')
- sec_dict = dict([(s['name'], s['id'])
- for s in security_groups])
-
- sec_groups_names = [s['name'] for s in create_kwargs.get(
- 'security_groups')]
- security_groups_ids = [sec_dict[s]
- for s in sec_groups_names]
-
- if security_groups_ids:
- create_port_body[
- 'security_groups'] = security_groups_ids
- networks = create_kwargs.get('networks')
-
- # If there are no networks passed to us we look up
- # for the tenant's private networks and create a port
- # if there is only one private network. The same behaviour
- # as we would expect when passing the call to the clients
- # with no networks
- if not networks:
- networks = networks_client.list_networks(filters={
- 'router:external': False})
- self.assertEqual(1, len(networks),
- "There is more than one"
- " network for the tenant")
- for net in networks:
- net_id = net['uuid']
- port = self._create_port(network_id=net_id,
- client=ports_client,
- **create_port_body)
- ports.append({'port': port.id})
- if ports:
- create_kwargs['networks'] = ports
- self.ports = ports
-
- return super(NetworkScenarioTest, self).create_server(
- name=name, image=image, flavor=flavor,
- wait_on_boot=wait_on_boot, wait_on_delete=wait_on_delete,
- create_kwargs=create_kwargs)
-
# power/provision states as of icehouse
class BaremetalPowerStates(object):
@@ -1324,11 +1307,8 @@
dest.validate_authentication()
def boot_instance(self):
- create_kwargs = {
- 'key_name': self.keypair['name']
- }
self.instance = self.create_server(
- wait_on_boot=False, create_kwargs=create_kwargs)
+ key_name=self.keypair['name'])
self.wait_node(self.instance['id'])
self.node = self.get_node(instance_id=self.instance['id'])
diff --git a/tempest/scenario/test_baremetal_basic_ops.py b/tempest/scenario/test_baremetal_basic_ops.py
index e629f0a..9415629 100644
--- a/tempest/scenario/test_baremetal_basic_ops.py
+++ b/tempest/scenario/test_baremetal_basic_ops.py
@@ -113,7 +113,7 @@
self.boot_instance()
self.validate_ports()
self.verify_connectivity()
- if CONF.compute.ssh_connect_method == 'floating':
+ if CONF.validation.connect_method == 'floating':
floating_ip = self.create_floating_ip(self.instance)['ip']
self.verify_connectivity(ip=floating_ip)
diff --git a/tempest/scenario/test_encrypted_cinder_volumes.py b/tempest/scenario/test_encrypted_cinder_volumes.py
index 082a8bf..dcd77ad 100644
--- a/tempest/scenario/test_encrypted_cinder_volumes.py
+++ b/tempest/scenario/test_encrypted_cinder_volumes.py
@@ -45,8 +45,9 @@
image = self.glance_image_create()
keypair = self.create_keypair()
- return self.create_server(image=image,
- create_kwargs={'key_name': keypair['name']})
+ return self.create_server(image_id=image,
+ key_name=keypair['name'],
+ wait_until='ACTIVE')
def create_encrypted_volume(self, encryption_provider, volume_type):
volume_type = self.create_volume_type(name=volume_type)
diff --git a/tempest/scenario/test_minimum_basic.py b/tempest/scenario/test_minimum_basic.py
index 92e3592..25e3e6f 100644
--- a/tempest/scenario/test_minimum_basic.py
+++ b/tempest/scenario/test_minimum_basic.py
@@ -117,9 +117,9 @@
image = self.glance_image_create()
keypair = self.create_keypair()
- create_kwargs = {'key_name': keypair['name']}
- server = self.create_server(image=image,
- create_kwargs=create_kwargs)
+ server = self.create_server(image_id=image,
+ key_name=keypair['name'],
+ wait_until='ACTIVE')
servers = self.nova_list()
self.assertIn(server['id'], [x['id'] for x in servers])
diff --git a/tempest/scenario/test_network_advanced_server_ops.py b/tempest/scenario/test_network_advanced_server_ops.py
index 3689508..a45a730 100644
--- a/tempest/scenario/test_network_advanced_server_ops.py
+++ b/tempest/scenario/test_network_advanced_server_ops.py
@@ -57,16 +57,13 @@
security_group = self._create_security_group()
network, subnet, router = self.create_networks()
public_network_id = CONF.network.public_network_id
- create_kwargs = {
- 'networks': [
- {'uuid': network.id},
- ],
- 'key_name': keypair['name'],
- 'security_groups': [{'name': security_group['name']}],
- }
server_name = data_utils.rand_name('server-smoke')
- server = self.create_server(name=server_name,
- create_kwargs=create_kwargs)
+ server = self.create_server(
+ name=server_name,
+ networks=[{'uuid': network.id}],
+ key_name=keypair['name'],
+ security_groups=[{'name': security_group['name']}],
+ wait_until='ACTIVE')
floating_ip = self.create_floating_ip(server, public_network_id)
# Verify that we can indeed connect to the server before we mess with
# it's state
diff --git a/tempest/scenario/test_network_basic_ops.py b/tempest/scenario/test_network_basic_ops.py
index 28f1cd3..41d13fe 100644
--- a/tempest/scenario/test_network_basic_ops.py
+++ b/tempest/scenario/test_network_basic_ops.py
@@ -155,16 +155,16 @@
keypair = self.create_keypair()
self.keypairs[keypair['name']] = keypair
security_groups = [{'name': self.security_group['name']}]
- create_kwargs = {
- 'networks': [
- {'uuid': network.id},
- ],
- 'key_name': keypair['name'],
- 'security_groups': security_groups,
- }
+ network = {'uuid': network.id}
if port_id is not None:
- create_kwargs['networks'][0]['port'] = port_id
- server = self.create_server(name=name, create_kwargs=create_kwargs)
+ network['port'] = port_id
+
+ server = self.create_server(
+ name=name,
+ networks=[network],
+ key_name=keypair['name'],
+ security_groups=security_groups,
+ wait_until='ACTIVE')
self.servers.append(server)
return server
diff --git a/tempest/scenario/test_network_v6.py b/tempest/scenario/test_network_v6.py
index a18dd2e..d6ad46a 100644
--- a/tempest/scenario/test_network_v6.py
+++ b/tempest/scenario/test_network_v6.py
@@ -65,9 +65,6 @@
super(TestGettingAddress, self).setUp()
self.keypair = self.create_keypair()
self.sec_grp = self._create_security_group(tenant_id=self.tenant_id)
- self.srv_kwargs = {
- 'key_name': self.keypair['name'],
- 'security_groups': [{'name': self.sec_grp['name']}]}
def prepare_network(self, address6_mode, n_subnets6=1, dualnet=False):
"""Prepare network
@@ -119,11 +116,13 @@
def prepare_server(self, networks=None):
username = CONF.compute.image_ssh_user
- create_kwargs = self.srv_kwargs
networks = networks or [self.network]
- create_kwargs['networks'] = [{'uuid': n.id} for n in networks]
- srv = self.create_server(create_kwargs=create_kwargs)
+ srv = self.create_server(
+ key_name=self.keypair['name'],
+ security_groups=[{'name': self.sec_grp['name']}],
+ networks=[{'uuid': n.id} for n in networks],
+ wait_until='ACTIVE')
fip = self.create_floating_ip(thing=srv)
ips = self.define_server_ips(srv=srv)
ssh = self.get_remote_client(
@@ -181,10 +180,10 @@
guest_has_address, sshv4_2, ips_from_api_2['6'][i])
self.assertTrue(test.call_until_true(srv1_v6_addr_assigned,
- CONF.compute.ping_timeout, 1))
+ CONF.validation.ping_timeout, 1))
self.assertTrue(test.call_until_true(srv2_v6_addr_assigned,
- CONF.compute.ping_timeout, 1))
+ CONF.validation.ping_timeout, 1))
self._check_connectivity(sshv4_1, ips_from_api_2['4'])
self._check_connectivity(sshv4_2, ips_from_api_1['4'])
diff --git a/tempest/scenario/test_security_groups_basic_ops.py b/tempest/scenario/test_security_groups_basic_ops.py
index 6a23c4b..e266dc2 100644
--- a/tempest/scenario/test_security_groups_basic_ops.py
+++ b/tempest/scenario/test_security_groups_basic_ops.py
@@ -234,23 +234,16 @@
def _create_server(self, name, tenant, security_groups=None):
"""creates a server and assigns to security group"""
- self._set_compute_context(tenant)
if security_groups is None:
security_groups = [tenant.security_groups['default']]
security_groups_names = [{'name': s['name']} for s in security_groups]
- create_kwargs = {
- 'networks': [
- {'uuid': tenant.network.id},
- ],
- 'key_name': tenant.keypair['name'],
- 'security_groups': security_groups_names
- }
server = self.create_server(
name=name,
- network_client=tenant.manager.network_client,
- networks_client=tenant.manager.networks_client,
- ports_client=tenant.manager.ports_client,
- create_kwargs=create_kwargs)
+ networks=[{'uuid': tenant.network.id}],
+ key_name=tenant.keypair['name'],
+ security_groups=security_groups_names,
+ wait_until='ACTIVE',
+ clients=tenant.manager)
self.assertEqual(
sorted([s['name'] for s in security_groups]),
sorted([s['name'] for s in server['security_groups']]))
@@ -293,10 +286,6 @@
subnets_client=tenant.manager.subnets_client)
tenant.set_network(network, subnet, router)
- def _set_compute_context(self, tenant):
- self.servers_client = tenant.manager.servers_client
- return self.servers_client
-
def _deploy_tenant(self, tenant_or_id):
"""creates:
@@ -310,7 +299,6 @@
tenant = self.tenants[tenant_or_id]
else:
tenant = tenant_or_id
- self._set_compute_context(tenant)
self._create_tenant_keypairs(tenant)
self._create_tenant_network(tenant)
self._create_tenant_security_groups(tenant)
diff --git a/tempest/scenario/test_server_advanced_ops.py b/tempest/scenario/test_server_advanced_ops.py
index 9387dc7..4b932ce 100644
--- a/tempest/scenario/test_server_advanced_ops.py
+++ b/tempest/scenario/test_server_advanced_ops.py
@@ -53,7 +53,7 @@
@test.services('compute')
def test_resize_server_confirm(self):
# We create an instance for use in this test
- instance = self.create_server()
+ instance = self.create_server(wait_until='ACTIVE')
instance_id = instance['id']
resize_flavor = CONF.compute.flavor_ref_alt
LOG.debug("Resizing instance %s from flavor %s to flavor %s",
@@ -74,7 +74,7 @@
@test.services('compute')
def test_server_sequence_suspend_resume(self):
# We create an instance for use in this test
- instance = self.create_server()
+ instance = self.create_server(wait_until='ACTIVE')
instance_id = instance['id']
LOG.debug("Suspending instance %s. Current status: %s",
instance_id, instance['status'])
diff --git a/tempest/scenario/test_server_basic_ops.py b/tempest/scenario/test_server_basic_ops.py
index 8a19254..239e120 100644
--- a/tempest/scenario/test_server_basic_ops.py
+++ b/tempest/scenario/test_server_basic_ops.py
@@ -72,20 +72,6 @@
def add_keypair(self):
self.keypair = self.create_keypair()
- def boot_instance(self):
- # Create server with image and flavor from input scenario
- security_groups = [{'name': self.security_group['name']}]
- self.md = {'meta1': 'data1', 'meta2': 'data2', 'metaN': 'dataN'}
- create_kwargs = {
- 'key_name': self.keypair['name'],
- 'security_groups': security_groups,
- 'config_drive': CONF.compute_feature_enabled.config_drive,
- 'metadata': self.md
- }
- self.instance = self.create_server(image=self.image_ref,
- flavor=self.flavor_ref,
- create_kwargs=create_kwargs)
-
def verify_ssh(self):
if self.run_ssh:
# Obtain a floating IP
@@ -139,7 +125,16 @@
def test_server_basicops(self):
self.add_keypair()
self.security_group = self._create_security_group()
- self.boot_instance()
+ security_groups = [{'name': self.security_group['name']}]
+ self.md = {'meta1': 'data1', 'meta2': 'data2', 'metaN': 'dataN'}
+ self.instance = self.create_server(
+ image_id=self.image_ref,
+ flavor=self.flavor_ref,
+ key_name=self.keypair['name'],
+ security_groups=security_groups,
+ config_drive=CONF.compute_feature_enabled.config_drive,
+ metadata=self.md,
+ wait_until='ACTIVE')
self.verify_ssh()
self.verify_metadata()
self.verify_metadata_on_config_drive()
diff --git a/tempest/scenario/test_server_multinode.py b/tempest/scenario/test_server_multinode.py
index 403804d..7e0e41c 100644
--- a/tempest/scenario/test_server_multinode.py
+++ b/tempest/scenario/test_server_multinode.py
@@ -60,15 +60,11 @@
servers = []
for host in hosts[:CONF.compute.min_compute_nodes]:
- create_kwargs = {
- 'availability_zone': '%(zone)s:%(host_name)s' % host
- }
-
# by getting to active state here, this means this has
# landed on the host in question.
- inst = self.create_server(image=CONF.compute.image_ref,
- flavor=CONF.compute.flavor_ref,
- create_kwargs=create_kwargs)
+ inst = self.create_server(
+ availability_zone='%(zone)s:%(host_name)s' % host,
+ wait_until='ACTIVE')
server = self.servers_client.show_server(inst['id'])['server']
servers.append(server)
diff --git a/tempest/scenario/test_shelve_instance.py b/tempest/scenario/test_shelve_instance.py
index 5778107..378ae9d 100644
--- a/tempest/scenario/test_shelve_instance.py
+++ b/tempest/scenario/test_shelve_instance.py
@@ -59,10 +59,6 @@
security_group = self._create_security_group()
security_groups = [{'name': security_group['name']}]
- create_kwargs = {
- 'key_name': keypair['name'],
- 'security_groups': security_groups
- }
if boot_from_volume:
volume = self.create_volume(size=CONF.volume.volume_size,
@@ -72,11 +68,17 @@
'volume_id': volume['id'],
'delete_on_termination': '0'}]
- create_kwargs['block_device_mapping'] = bd_map
- server = self.create_server(create_kwargs=create_kwargs)
+ server = self.create_server(
+ key_name=keypair['name'],
+ security_groups=security_groups,
+ block_device_mapping=bd_map,
+ wait_until='ACTIVE')
else:
- server = self.create_server(image=CONF.compute.image_ref,
- create_kwargs=create_kwargs)
+ server = self.create_server(
+ image_id=CONF.compute.image_ref,
+ key_name=keypair['name'],
+ security_groups=security_groups,
+ wait_until='ACTIVE')
instance_ip = self.get_server_or_ip(server)
timestamp = self.create_timestamp(instance_ip,
diff --git a/tempest/scenario/test_snapshot_pattern.py b/tempest/scenario/test_snapshot_pattern.py
index cd59334..f3b6558 100644
--- a/tempest/scenario/test_snapshot_pattern.py
+++ b/tempest/scenario/test_snapshot_pattern.py
@@ -36,14 +36,6 @@
"""
- def _boot_image(self, image_id, keypair, security_group):
- security_groups = [{'name': security_group['name']}]
- create_kwargs = {
- 'key_name': keypair['name'],
- 'security_groups': security_groups
- }
- return self.create_server(image=image_id, create_kwargs=create_kwargs)
-
@test.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4')
@testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
'Snapshotting is not available.')
@@ -54,8 +46,12 @@
security_group = self._create_security_group()
# boot an instance and create a timestamp file in it
- server = self._boot_image(CONF.compute.image_ref, keypair,
- security_group)
+ server = self.create_server(
+ image_id=CONF.compute.image_ref,
+ key_name=keypair['name'],
+ security_groups=[{'name': security_group['name']}],
+ wait_until='ACTIVE')
+
instance_ip = self.get_server_or_ip(server)
timestamp = self.create_timestamp(instance_ip,
private_key=keypair['private_key'])
@@ -64,8 +60,11 @@
snapshot_image = self.create_server_snapshot(server=server)
# boot a second instance from the snapshot
- server_from_snapshot = self._boot_image(snapshot_image['id'],
- keypair, security_group)
+ server_from_snapshot = self.create_server(
+ image_id=snapshot_image['id'],
+ key_name=keypair['name'],
+ security_groups=[{'name': security_group['name']}],
+ wait_until='ACTIVE')
# check the existence of the timestamp file in the second instance
server_from_snapshot_ip = self.get_server_or_ip(server_from_snapshot)
diff --git a/tempest/scenario/test_stamp_pattern.py b/tempest/scenario/test_stamp_pattern.py
index 05ae33e..faae800 100644
--- a/tempest/scenario/test_stamp_pattern.py
+++ b/tempest/scenario/test_stamp_pattern.py
@@ -64,14 +64,6 @@
self.snapshots_client.wait_for_snapshot_status(volume_snapshot['id'],
status)
- def _boot_image(self, image_id, keypair, security_group):
- security_groups = [{'name': security_group['name']}]
- create_kwargs = {
- 'key_name': keypair['name'],
- 'security_groups': security_groups
- }
- return self.create_server(image=image_id, create_kwargs=create_kwargs)
-
def _create_volume_snapshot(self, volume):
snapshot_name = data_utils.rand_name('scenario-snapshot')
snapshot = self.snapshots_client.create_snapshot(
@@ -135,8 +127,11 @@
# boot an instance and create a timestamp file in it
volume = self._create_volume()
- server = self._boot_image(CONF.compute.image_ref, keypair,
- security_group)
+ server = self.create_server(
+ image_id=CONF.compute.image_ref,
+ key_name=keypair['name'],
+ security_groups=security_group,
+ wait_until='ACTIVE')
# create and add floating IP to server1
ip_for_server = self.get_server_or_ip(server)
@@ -160,8 +155,10 @@
snapshot_id=volume_snapshot['id'])
# boot second instance from the snapshot(instance2)
- server_from_snapshot = self._boot_image(snapshot_image['id'],
- keypair, security_group)
+ server_from_snapshot = self.create_server(
+ image_id=snapshot_image['id'],
+ key_name=keypair['name'],
+ security_groups=security_group)
# create and add floating IP to server_from_snapshot
ip_for_snapshot = self.get_server_or_ip(server_from_snapshot)
diff --git a/tempest/scenario/test_volume_boot_pattern.py b/tempest/scenario/test_volume_boot_pattern.py
index 96e79e6..81ecda0 100644
--- a/tempest/scenario/test_volume_boot_pattern.py
+++ b/tempest/scenario/test_volume_boot_pattern.py
@@ -69,7 +69,10 @@
{'name': security_group['name']}]
create_kwargs.update(self._get_bdm(
vol_id, delete_on_termination=delete_on_termination))
- return self.create_server(image='', create_kwargs=create_kwargs)
+ return self.create_server(
+ image='',
+ wait_until='ACTIVE',
+ **create_kwargs)
def _create_snapshot_from_volume(self, vol_id):
snap_name = data_utils.rand_name('snapshot')
@@ -158,7 +161,8 @@
self._delete_server(instance)
# boot instance from EBS image
- instance = self.create_server(image=image['id'])
+ instance = self.create_server(
+ image_id=image['id'])
# just ensure that instance booted
# delete instance
diff --git a/tempest/services/compute/json/floating_ips_client.py b/tempest/services/compute/json/floating_ips_client.py
index 69d06a3..b3e2f2f 100644
--- a/tempest/services/compute/json/floating_ips_client.py
+++ b/tempest/services/compute/json/floating_ips_client.py
@@ -42,11 +42,14 @@
self.validate_response(schema.create_get_floating_ip, resp, body)
return service_client.ResponseBody(resp, body)
- def create_floating_ip(self, pool_name=None):
- """Allocate a floating IP to the project."""
+ def create_floating_ip(self, **kwargs):
+ """Allocate a floating IP to the project.
+
+ Available params: see http://developer.openstack.org/
+ api-ref-compute-v2.1.html#createFloatingIP
+ """
url = 'os-floating-ips'
- post_body = {'pool': pool_name}
- post_body = json.dumps(post_body)
+ post_body = json.dumps(kwargs)
resp, body = self.post(url, post_body)
body = json.loads(body)
self.validate_response(schema.create_get_floating_ip, resp, body)
diff --git a/tempest/services/image/v1/json/image_client.py b/tempest/services/image/v1/json/images_client.py
similarity index 96%
rename from tempest/services/image/v1/json/image_client.py
rename to tempest/services/image/v1/json/images_client.py
index d97da36..3406db8 100644
--- a/tempest/services/image/v1/json/image_client.py
+++ b/tempest/services/image/v1/json/images_client.py
@@ -32,13 +32,13 @@
LOG = logging.getLogger(__name__)
-class ImageClient(service_client.ServiceClient):
+class ImagesClient(service_client.ServiceClient):
def __init__(self, auth_provider, catalog_type, region, endpoint_type=None,
build_interval=None, build_timeout=None,
disable_ssl_certificate_validation=None,
ca_certs=None, trace_requests=None):
- super(ImageClient, self).__init__(
+ super(ImagesClient, self).__init__(
auth_provider,
catalog_type,
region,
@@ -265,11 +265,14 @@
body = json.loads(body)
return service_client.ResponseBody(resp, body)
- def add_member(self, member_id, image_id, can_share=False):
+ def add_member(self, member_id, image_id, **kwargs):
+ """Add a member to an image.
+
+ Available params: see http://developer.openstack.org/
+ api-ref-image-v1.html#addMember-v1
+ """
url = 'v1/images/%s/members/%s' % (image_id, member_id)
- body = None
- if can_share:
- body = json.dumps({'member': {'can_share': True}})
+ body = json.dumps({'member': kwargs})
resp, __ = self.put(url, body)
self.expected_success(204, resp.status)
return service_client.ResponseBody(resp)
diff --git a/tempest/services/image/v2/json/image_client.py b/tempest/services/image/v2/json/images_client.py
similarity index 97%
rename from tempest/services/image/v2/json/image_client.py
rename to tempest/services/image/v2/json/images_client.py
index a7e0f04..33bfcb8 100644
--- a/tempest/services/image/v2/json/image_client.py
+++ b/tempest/services/image/v2/json/images_client.py
@@ -22,13 +22,13 @@
from tempest.common import service_client
-class ImageClientV2(service_client.ServiceClient):
+class ImagesClientV2(service_client.ServiceClient):
def __init__(self, auth_provider, catalog_type, region, endpoint_type=None,
build_interval=None, build_timeout=None,
disable_ssl_certificate_validation=None, ca_certs=None,
trace_requests=None):
- super(ImageClientV2, self).__init__(
+ super(ImagesClientV2, self).__init__(
auth_provider,
catalog_type,
region,
@@ -187,6 +187,11 @@
return service_client.ResponseBody(resp, body)
def update_image_member(self, image_id, member_id, **kwargs):
+ """Update an image member.
+
+ Available params: see http://developer.openstack.org/
+ api-ref-image-v2.html#updateImageMember-v2
+ """
url = 'v2/images/%s/members/%s' % (image_id, member_id)
data = json.dumps(kwargs)
resp, body = self.put(url, data)
diff --git a/tempest/services/network/json/metering_labels_client.py b/tempest/services/network/json/metering_labels_client.py
new file mode 100644
index 0000000..2e5cdae
--- /dev/null
+++ b/tempest/services/network/json/metering_labels_client.py
@@ -0,0 +1,33 @@
+# 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.services.network.json import base
+
+
+class MeteringLabelsClient(base.BaseNetworkClient):
+
+ def create_metering_label(self, **kwargs):
+ uri = '/metering/metering-labels'
+ post_data = {'metering_label': kwargs}
+ return self.create_resource(uri, post_data)
+
+ def show_metering_label(self, metering_label_id, **fields):
+ uri = '/metering/metering-labels/%s' % metering_label_id
+ return self.show_resource(uri, **fields)
+
+ def delete_metering_label(self, metering_label_id):
+ uri = '/metering/metering-labels/%s' % metering_label_id
+ return self.delete_resource(uri)
+
+ def list_metering_labels(self, **filters):
+ uri = '/metering/metering-labels'
+ return self.list_resources(uri, **filters)
diff --git a/tempest/services/network/json/network_client.py b/tempest/services/network/json/network_client.py
index 5a4229c..b525143 100644
--- a/tempest/services/network/json/network_client.py
+++ b/tempest/services/network/json/network_client.py
@@ -35,23 +35,6 @@
quotas
"""
- def create_metering_label(self, **kwargs):
- uri = '/metering/metering-labels'
- post_data = {'metering_label': kwargs}
- return self.create_resource(uri, post_data)
-
- def show_metering_label(self, metering_label_id, **fields):
- uri = '/metering/metering-labels/%s' % metering_label_id
- return self.show_resource(uri, **fields)
-
- def delete_metering_label(self, metering_label_id):
- uri = '/metering/metering-labels/%s' % metering_label_id
- return self.delete_resource(uri)
-
- def list_metering_labels(self, **filters):
- uri = '/metering/metering-labels'
- return self.list_resources(uri, **filters)
-
def create_metering_label_rule(self, **kwargs):
uri = '/metering/metering-label-rules'
post_data = {'metering_label_rule': kwargs}
diff --git a/tempest/services/volume/base/admin/base_volume_quotas_client.py b/tempest/services/volume/base/admin/base_volume_quotas_client.py
index d7909ff..ad8ba03 100644
--- a/tempest/services/volume/base/admin/base_volume_quotas_client.py
+++ b/tempest/services/volume/base/admin/base_volume_quotas_client.py
@@ -50,21 +50,14 @@
body = self.show_quota_set(tenant_id, params={'usage': True})
return body
- def update_quota_set(self, tenant_id, gigabytes=None, volumes=None,
- snapshots=None):
- post_body = {}
+ def update_quota_set(self, tenant_id, **kwargs):
+ """Updates quota set
- if gigabytes is not None:
- post_body['gigabytes'] = gigabytes
-
- if volumes is not None:
- post_body['volumes'] = volumes
-
- if snapshots is not None:
- post_body['snapshots'] = snapshots
-
- post_body = jsonutils.dumps({'quota_set': post_body})
- resp, body = self.put('os-quota-sets/%s' % tenant_id, post_body)
+ Available params: see http://developer.openstack.org/
+ api-ref-blockstorage-v2.html#updateQuotas-v2
+ """
+ put_body = jsonutils.dumps({'quota_set': kwargs})
+ resp, body = self.put('os-quota-sets/%s' % tenant_id, put_body)
self.expected_success(200, resp.status)
body = jsonutils.loads(body)
return service_client.ResponseBody(resp, body)
diff --git a/tempest/test.py b/tempest/test.py
index 435d10a..30eb93d 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -27,6 +27,7 @@
from oslo_serialization import jsonutils as json
from oslo_utils import importutils
import six
+from tempest_lib import decorators
import testscenarios
import testtools
@@ -43,6 +44,8 @@
CONF = config.CONF
+idempotent_id = decorators.idempotent_id
+
def attr(**kwargs):
"""A decorator which applies the testtools attr decorator
@@ -62,23 +65,6 @@
return decorator
-def idempotent_id(id):
- """Stub for metadata decorator"""
- if not isinstance(id, six.string_types):
- raise TypeError('Test idempotent_id must be string not %s'
- '' % type(id).__name__)
- uuid.UUID(id)
-
- def decorator(f):
- f = testtools.testcase.attr('id-%s' % id)(f)
- if f.__doc__:
- f.__doc__ = 'Test idempotent id: %s\n%s' % (id, f.__doc__)
- else:
- f.__doc__ = 'Test idempotent id: %s' % id
- return f
- return decorator
-
-
def get_service_list():
service_list = {
'compute': CONF.service_available.nova,
diff --git a/tempest/tests/common/test_api_version_request.py b/tempest/tests/common/test_api_version_request.py
new file mode 100644
index 0000000..38fbfc1
--- /dev/null
+++ b/tempest/tests/common/test_api_version_request.py
@@ -0,0 +1,146 @@
+# Copyright 2014 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.
+
+from tempest.common import api_version_request
+from tempest import exceptions
+from tempest.tests import base
+
+
+class APIVersionRequestTests(base.TestCase):
+ def test_valid_version_strings(self):
+ def _test_string(version, exp_major, exp_minor):
+ v = api_version_request.APIVersionRequest(version)
+ self.assertEqual(v.ver_major, exp_major)
+ self.assertEqual(v.ver_minor, exp_minor)
+
+ _test_string("1.1", 1, 1)
+ _test_string("2.10", 2, 10)
+ _test_string("5.234", 5, 234)
+ _test_string("12.5", 12, 5)
+ _test_string("2.0", 2, 0)
+ _test_string("2.200", 2, 200)
+
+ def test_null_version(self):
+ v = api_version_request.APIVersionRequest()
+ self.assertTrue(v.is_null())
+
+ def test_invalid_version_strings(self):
+ self.assertRaises(exceptions.InvalidAPIVersionString,
+ api_version_request.APIVersionRequest, "2")
+
+ self.assertRaises(exceptions.InvalidAPIVersionString,
+ api_version_request.APIVersionRequest, "200")
+
+ self.assertRaises(exceptions.InvalidAPIVersionString,
+ api_version_request.APIVersionRequest, "2.1.4")
+
+ self.assertRaises(exceptions.InvalidAPIVersionString,
+ api_version_request.APIVersionRequest, "200.23.66.3")
+
+ self.assertRaises(exceptions.InvalidAPIVersionString,
+ api_version_request.APIVersionRequest, "5 .3")
+
+ self.assertRaises(exceptions.InvalidAPIVersionString,
+ api_version_request.APIVersionRequest, "5. 3")
+
+ self.assertRaises(exceptions.InvalidAPIVersionString,
+ api_version_request.APIVersionRequest, "5.03")
+
+ self.assertRaises(exceptions.InvalidAPIVersionString,
+ api_version_request.APIVersionRequest, "02.1")
+
+ self.assertRaises(exceptions.InvalidAPIVersionString,
+ api_version_request.APIVersionRequest, "2.001")
+
+ self.assertRaises(exceptions.InvalidAPIVersionString,
+ api_version_request.APIVersionRequest, "")
+
+ self.assertRaises(exceptions.InvalidAPIVersionString,
+ api_version_request.APIVersionRequest, " 2.1")
+
+ self.assertRaises(exceptions.InvalidAPIVersionString,
+ api_version_request.APIVersionRequest, "2.1 ")
+
+ def test_version_comparisons(self):
+ vers2_0 = api_version_request.APIVersionRequest("2.0")
+ vers2_5 = api_version_request.APIVersionRequest("2.5")
+ vers5_23 = api_version_request.APIVersionRequest("5.23")
+ v_null = api_version_request.APIVersionRequest()
+ v_latest = api_version_request.APIVersionRequest('latest')
+
+ self.assertTrue(v_null < vers2_5)
+ self.assertTrue(vers2_0 < vers2_5)
+ self.assertTrue(vers2_0 <= vers2_5)
+ self.assertTrue(vers2_0 <= vers2_0)
+ self.assertTrue(vers2_5 > v_null)
+ self.assertTrue(vers5_23 > vers2_5)
+ self.assertTrue(vers2_0 >= vers2_0)
+ self.assertTrue(vers5_23 >= vers2_5)
+ self.assertTrue(vers2_0 != vers2_5)
+ self.assertTrue(vers2_0 == vers2_0)
+ self.assertTrue(vers2_0 != v_null)
+ self.assertTrue(v_null == v_null)
+ self.assertTrue(vers2_0 <= v_latest)
+ self.assertTrue(vers2_0 != v_latest)
+ self.assertTrue(v_latest == v_latest)
+ self.assertRaises(TypeError, vers2_0.__lt__, "2.1")
+
+ def test_version_matches(self):
+ vers2_0 = api_version_request.APIVersionRequest("2.0")
+ vers2_5 = api_version_request.APIVersionRequest("2.5")
+ vers2_45 = api_version_request.APIVersionRequest("2.45")
+ vers3_3 = api_version_request.APIVersionRequest("3.3")
+ vers3_23 = api_version_request.APIVersionRequest("3.23")
+ vers4_0 = api_version_request.APIVersionRequest("4.0")
+ v_null = api_version_request.APIVersionRequest()
+ v_latest = api_version_request.APIVersionRequest('latest')
+
+ def _check_version_matches(version, version1, version2, check=True):
+ if check:
+ msg = "Version %s does not matches with [%s - %s] range"
+ self.assertTrue(version.matches(version1, version2),
+ msg % (version.get_string(),
+ version1.get_string(),
+ version2.get_string()))
+ else:
+ msg = "Version %s matches with [%s - %s] range"
+ self.assertFalse(version.matches(version1, version2),
+ msg % (version.get_string(),
+ version1.get_string(),
+ version2.get_string()))
+
+ _check_version_matches(vers2_5, vers2_0, vers2_45)
+ _check_version_matches(vers2_5, vers2_0, v_null)
+ _check_version_matches(vers2_0, vers2_0, vers2_5)
+ _check_version_matches(vers3_3, vers2_5, vers3_3)
+ _check_version_matches(vers3_3, v_null, vers3_3)
+ _check_version_matches(vers3_3, v_null, vers4_0)
+ _check_version_matches(vers2_0, vers2_5, vers2_45, False)
+ _check_version_matches(vers3_23, vers2_5, vers3_3, False)
+ _check_version_matches(vers2_5, vers2_45, vers2_0, False)
+ _check_version_matches(vers2_5, vers2_0, v_latest)
+ _check_version_matches(v_latest, v_latest, v_latest)
+ _check_version_matches(vers2_5, v_latest, v_latest, False)
+ _check_version_matches(v_latest, vers2_0, vers4_0, False)
+
+ self.assertRaises(ValueError, v_null.matches, vers2_0, vers2_45)
+
+ def test_get_string(self):
+ vers_string = ["3.23", "latest"]
+ for ver in vers_string:
+ ver_obj = api_version_request.APIVersionRequest(ver)
+ self.assertEqual(ver, ver_obj.get_string())
+
+ self.assertIsNotNone(
+ api_version_request.APIVersionRequest().get_string)
diff --git a/tempest/tests/common/test_api_version_utils.py b/tempest/tests/common/test_api_version_utils.py
new file mode 100644
index 0000000..33024b6
--- /dev/null
+++ b/tempest/tests/common/test_api_version_utils.py
@@ -0,0 +1,194 @@
+# Copyright 2015 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 oslo_config import cfg
+import testtools
+
+from tempest.api.compute import base as compute_base
+from tempest.common import api_version_utils
+from tempest import config
+from tempest import exceptions
+from tempest.tests import base
+from tempest.tests import fake_config
+
+
+class VersionTestNoneTolatest(compute_base.BaseV2ComputeTest):
+ min_microversion = None
+ max_microversion = 'latest'
+
+
+class VersionTestNoneTo2_2(compute_base.BaseV2ComputeTest):
+ min_microversion = None
+ max_microversion = '2.2'
+
+
+class VersionTest2_3ToLatest(compute_base.BaseV2ComputeTest):
+ min_microversion = '2.3'
+ max_microversion = 'latest'
+
+
+class VersionTest2_5To2_10(compute_base.BaseV2ComputeTest):
+ min_microversion = '2.5'
+ max_microversion = '2.10'
+
+
+class VersionTest2_10To2_10(compute_base.BaseV2ComputeTest):
+ min_microversion = '2.10'
+ max_microversion = '2.10'
+
+
+class InvalidVersionTest(compute_base.BaseV2ComputeTest):
+ min_microversion = '2.11'
+ max_microversion = '2.1'
+
+
+class TestMicroversionsTestsClass(base.TestCase):
+
+ def setUp(self):
+ super(TestMicroversionsTestsClass, self).setUp()
+ self.useFixture(fake_config.ConfigFixture())
+ self.stubs.Set(config, 'TempestConfigPrivate',
+ fake_config.FakePrivate)
+
+ def _test_version(self, cfg_min, cfg_max,
+ expected_pass_tests,
+ expected_skip_tests):
+ cfg.CONF.set_default('min_microversion',
+ cfg_min, group='compute-feature-enabled')
+ cfg.CONF.set_default('max_microversion',
+ cfg_max, group='compute-feature-enabled')
+ try:
+ for test_class in expected_pass_tests:
+ test_class.skip_checks()
+ for test_class in expected_skip_tests:
+ self.assertRaises(testtools.TestCase.skipException,
+ test_class.skip_checks)
+ except testtools.TestCase.skipException as e:
+ raise testtools.TestCase.failureException(e.message)
+
+ def test_config_version_none_none(self):
+ expected_pass_tests = [VersionTestNoneTolatest, VersionTestNoneTo2_2]
+ expected_skip_tests = [VersionTest2_3ToLatest, VersionTest2_5To2_10,
+ VersionTest2_10To2_10]
+ self._test_version(None, None,
+ expected_pass_tests,
+ expected_skip_tests)
+
+ def test_config_version_none_23(self):
+ expected_pass_tests = [VersionTestNoneTolatest, VersionTestNoneTo2_2,
+ VersionTest2_3ToLatest]
+ expected_skip_tests = [VersionTest2_5To2_10, VersionTest2_10To2_10]
+ self._test_version(None, '2.3',
+ expected_pass_tests,
+ expected_skip_tests)
+
+ def test_config_version_22_latest(self):
+ expected_pass_tests = [VersionTestNoneTolatest, VersionTestNoneTo2_2,
+ VersionTest2_3ToLatest, VersionTest2_5To2_10,
+ VersionTest2_10To2_10]
+ expected_skip_tests = []
+ self._test_version('2.2', 'latest',
+ expected_pass_tests,
+ expected_skip_tests)
+
+ def test_config_version_22_23(self):
+ expected_pass_tests = [VersionTestNoneTolatest, VersionTestNoneTo2_2,
+ VersionTest2_3ToLatest]
+ expected_skip_tests = [VersionTest2_5To2_10, VersionTest2_10To2_10]
+ self._test_version('2.2', '2.3',
+ expected_pass_tests,
+ expected_skip_tests)
+
+ def test_config_version_210_210(self):
+ expected_pass_tests = [VersionTestNoneTolatest,
+ VersionTest2_3ToLatest,
+ VersionTest2_5To2_10,
+ VersionTest2_10To2_10]
+ expected_skip_tests = [VersionTestNoneTo2_2]
+ self._test_version('2.10', '2.10',
+ expected_pass_tests,
+ expected_skip_tests)
+
+ def test_config_version_none_latest(self):
+ expected_pass_tests = [VersionTestNoneTolatest, VersionTestNoneTo2_2,
+ VersionTest2_3ToLatest, VersionTest2_5To2_10,
+ VersionTest2_10To2_10]
+ expected_skip_tests = []
+ self._test_version(None, 'latest',
+ expected_pass_tests,
+ expected_skip_tests)
+
+ def test_config_version_latest_latest(self):
+ expected_pass_tests = [VersionTestNoneTolatest, VersionTest2_3ToLatest]
+ expected_skip_tests = [VersionTestNoneTo2_2, VersionTest2_5To2_10,
+ VersionTest2_10To2_10]
+ self._test_version('latest', 'latest',
+ expected_pass_tests,
+ expected_skip_tests)
+
+ def test_config_invalid_version(self):
+ cfg.CONF.set_default('min_microversion',
+ '2.5', group='compute-feature-enabled')
+ cfg.CONF.set_default('max_microversion',
+ '2.1', group='compute-feature-enabled')
+ self.assertRaises(exceptions.InvalidConfiguration,
+ VersionTestNoneTolatest.skip_checks)
+
+ def test_config_version_invalid_test_version(self):
+ cfg.CONF.set_default('min_microversion',
+ None, group='compute-feature-enabled')
+ cfg.CONF.set_default('max_microversion',
+ '2.13', group='compute-feature-enabled')
+ self.assertRaises(exceptions.InvalidConfiguration,
+ InvalidVersionTest.skip_checks)
+
+
+class TestVersionSkipLogic(base.TestCase):
+
+ def _test_version(self, test_min_version, test_max_version,
+ cfg_min_version, cfg_max_version, expected_skip=False):
+ try:
+ api_version_utils.check_skip_with_microversion(test_min_version,
+ test_max_version,
+ cfg_min_version,
+ cfg_max_version)
+ except testtools.TestCase.skipException as e:
+ if not expected_skip:
+ raise testtools.TestCase.failureException(e.message)
+
+ def test_version_min_in_range(self):
+ self._test_version('2.2', '2.10', '2.1', '2.7')
+
+ def test_version_max_in_range(self):
+ self._test_version('2.1', '2.3', '2.2', '2.7')
+
+ def test_version_cfg_in_range(self):
+ self._test_version('2.2', '2.9', '2.3', '2.7')
+
+ def test_version_equal(self):
+ self._test_version('2.2', '2.2', '2.2', '2.2')
+
+ def test_version_below_cfg_min(self):
+ self._test_version('2.2', '2.4', '2.5', '2.7', expected_skip=True)
+
+ def test_version_above_cfg_max(self):
+ self._test_version('2.8', '2.9', '2.3', '2.7', expected_skip=True)
+
+ def test_version_min_greater_than_max(self):
+ self.assertRaises(exceptions.InvalidConfiguration,
+ self._test_version, '2.8', '2.7', '2.3', '2.7')
+
+ def test_cfg_version_min_greater_than_max(self):
+ self.assertRaises(exceptions.InvalidConfiguration,
+ self._test_version, '2.2', '2.7', '2.9', '2.7')
diff --git a/tempest/tests/common/test_service_clients.py b/tempest/tests/common/test_service_clients.py
index 272eba4..8de014f 100644
--- a/tempest/tests/common/test_service_clients.py
+++ b/tempest/tests/common/test_service_clients.py
@@ -36,8 +36,8 @@
from tempest.services.identity.v3.json import policy_client
from tempest.services.identity.v3.json import region_client
from tempest.services.identity.v3.json import service_client
-from tempest.services.image.v1.json import image_client
-from tempest.services.image.v2.json import image_client as image_v2_client
+from tempest.services.image.v1.json import images_client
+from tempest.services.image.v2.json import images_client as images_v2_client
from tempest.services.messaging.json import messaging_client
from tempest.services.network.json import network_client
from tempest.services.object_storage import account_client
@@ -130,8 +130,8 @@
policy_client.PolicyClient,
region_client.RegionClient,
service_client.ServiceClient,
- image_client.ImageClient,
- image_v2_client.ImageClientV2
+ images_client.ImagesClient,
+ images_v2_client.ImagesClientV2
]
for client in test_clients:
diff --git a/tempest/tests/services/compute/test_servers_client.py b/tempest/tests/services/compute/test_servers_client.py
index e347cf1..95b81c1 100644
--- a/tempest/tests/services/compute/test_servers_client.py
+++ b/tempest/tests/services/compute/test_servers_client.py
@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import copy
from tempest.services.compute.json import servers_client
from tempest.tests import fake_auth_provider
from tempest.tests.services.compute import base
@@ -34,6 +35,24 @@
"name": u"new\u1234-server-test"}]
}
+ FAKE_SERVER_DIAGNOSTICS = {
+ "cpu0_time": 17300000000,
+ "memory": 524288,
+ "vda_errors": -1,
+ "vda_read": 262144,
+ "vda_read_req": 112,
+ "vda_write": 5778432,
+ "vda_write_req": 488,
+ "vnet1_rx": 2070139,
+ "vnet1_rx_drop": 0,
+ "vnet1_rx_errors": 0,
+ "vnet1_rx_packets": 26701,
+ "vnet1_tx": 140208,
+ "vnet1_tx_drop": 0,
+ "vnet1_tx_errors": 0,
+ "vnet1_tx_packets": 662
+ }
+
FAKE_SERVER_GET = {'server': {
"accessIPv4": "",
"accessIPv6": "",
@@ -116,6 +135,48 @@
]}
}
+ FAKE_COMMON_VOLUME = {
+ "id": "a6b0875b-6b5d-4a5a-81eb-0c3aa62e5fdb",
+ "device": "fake-device",
+ "volumeId": "a6b0875b-46ca-475e-917e-0c3aa62e5fdb",
+ "serverId": "616fb98f-46ca-475e-917e-2563e5a8cd19"
+ }
+
+ FAKE_VIRTUAL_INTERFACES = {
+ "id": "a6b0875b-46ca-475e-917e-0c3aa62e5fdb",
+ "mac_address": "00:25:90:5b:f8:c3",
+ "OS-EXT-VIF-NET:net_id": "fake-os-net-id"
+ }
+
+ FAKE_INSTANCE_ACTIONS = {
+ "action": "fake-action",
+ "request_id": "16fb98f-46ca-475e-917e-2563e5a8cd19",
+ "user_id": "16fb98f-46ca-475e-917e-2563e5a8cd12",
+ "project_id": "16fb98f-46ca-475e-917e-2563e5a8cd34",
+ "start_time": "09MAR2015 11:15",
+ "message": "fake-msg",
+ "instance_uuid": "16fb98f-46ca-475e-917e-2563e5a8cd12"
+ }
+
+ FAKE_VNC_CONSOLE = {
+ "type": "fake-type",
+ "url": "http://os.co/v2/616fb98f-46ca-475e-917e-2563e5a8cd19"
+ }
+
+ FAKE_INSTANCE_ACTION_EVENTS = {
+ "event": "fake-event",
+ "start_time": "09MAR2015 11:15",
+ "finish_time": "09MAR2015 11:15",
+ "result": "fake-result",
+ "traceback": "fake-trace-back"
+ }
+
+ FAKE_INSTANCE_WITH_EVENTS = copy.deepcopy(FAKE_INSTANCE_ACTIONS)
+ FAKE_INSTANCE_WITH_EVENTS['events'] = [FAKE_INSTANCE_ACTION_EVENTS]
+
+ FAKE_REBUILD_SERVER = copy.deepcopy(FAKE_SERVER_GET)
+ FAKE_REBUILD_SERVER['server']['adminPass'] = 'fake-admin-pass'
+
server_id = FAKE_SERVER_GET['server']['id']
network_id = 'a6b0875b-6b5d-4a5a-81eb-0c3aa62e5fdb'
@@ -206,7 +267,733 @@
self.client.list_addresses_by_network,
'tempest.common.service_client.ServiceClient.get',
self.FAKE_ADDRESS['addresses'],
- bytes_body,
server_id=self.server_id,
network_id=self.network_id
)
+
+ def test_action_with_str_body(self):
+ self._test_action()
+
+ def test_action_with_bytes_body(self):
+ self._test_action(True)
+
+ def _test_action(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.action,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ server_id=self.server_id,
+ action_name='fake-action-name',
+ schema={'status_code': 200}
+ )
+
+ def test_create_backup_with_str_body(self):
+ self._test_create_backup()
+
+ def test_create_backup_with_bytes_body(self):
+ self._test_create_backup(True)
+
+ def _test_create_backup(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.create_backup,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id,
+ backup_type='fake-backup',
+ rotation='fake-rotation',
+ name='fake-name'
+ )
+
+ def test_change_password_with_str_body(self):
+ self._test_change_password()
+
+ def test_change_password_with_bytes_body(self):
+ self._test_change_password(True)
+
+ def _test_change_password(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.change_password,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id,
+ adminPass='fake-admin-pass'
+ )
+
+ def test_show_password_with_str_body(self):
+ self._test_show_password()
+
+ def test_show_password_with_bytes_body(self):
+ self._test_show_password(True)
+
+ def _test_show_password(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.show_password,
+ 'tempest.common.service_client.ServiceClient.get',
+ {'password': 'fake-password'},
+ server_id=self.server_id
+ )
+
+ def test_delete_password_with_str_body(self):
+ self._test_delete_password()
+
+ def test_delete_password_with_bytes_body(self):
+ self._test_delete_password(True)
+
+ def _test_delete_password(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.delete_password,
+ 'tempest.common.service_client.ServiceClient.delete',
+ {},
+ status=204,
+ server_id=self.server_id
+ )
+
+ def test_reboot_server_with_str_body(self):
+ self._test_reboot_server()
+
+ def test_reboot_server_with_bytes_body(self):
+ self._test_reboot_server(True)
+
+ def _test_reboot_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.reboot_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id,
+ reboot_type='fake-reboot-type'
+ )
+
+ def test_rebuild_server_with_str_body(self):
+ self._test_rebuild_server()
+
+ def test_rebuild_server_with_bytes_body(self):
+ self._test_rebuild_server(True)
+
+ def _test_rebuild_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.rebuild_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ self.FAKE_REBUILD_SERVER,
+ status=202,
+ server_id=self.server_id,
+ image_ref='fake-image-ref'
+ )
+
+ def test_resize_server_with_str_body(self):
+ self._test_resize_server()
+
+ def test_resize_server_with_bytes_body(self):
+ self._test_resize_server(True)
+
+ def _test_resize_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.resize_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id,
+ flavor_ref='fake-flavor-ref'
+ )
+
+ def test_confirm_resize_server_with_str_body(self):
+ self._test_confirm_resize_server()
+
+ def test_confirm_resize_server_with_bytes_body(self):
+ self._test_confirm_resize_server(True)
+
+ def _test_confirm_resize_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.confirm_resize_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=204,
+ server_id=self.server_id
+ )
+
+ def test_revert_resize_server_with_str_body(self):
+ self._test_revert_resize()
+
+ def test_revert_resize_server_with_bytes_body(self):
+ self._test_revert_resize(True)
+
+ def _test_revert_resize(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.revert_resize_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_list_server_metadata_with_str_body(self):
+ self._test_list_server_metadata()
+
+ def test_list_server_metadata_with_bytes_body(self):
+ self._test_list_server_metadata()
+
+ def _test_list_server_metadata(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.list_server_metadata,
+ 'tempest.common.service_client.ServiceClient.get',
+ {'metadata': {'fake-key': 'fake-meta-data'}},
+ server_id=self.server_id
+ )
+
+ def test_set_server_metadata_with_str_body(self):
+ self._test_set_server_metadata()
+
+ def test_set_server_metadata_with_bytes_body(self):
+ self._test_set_server_metadata(True)
+
+ def _test_set_server_metadata(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.set_server_metadata,
+ 'tempest.common.service_client.ServiceClient.put',
+ {'metadata': {'fake-key': 'fake-meta-data'}},
+ server_id=self.server_id,
+ meta='fake-meta'
+ )
+
+ def test_update_server_metadata_with_str_body(self):
+ self._test_update_server_metadata()
+
+ def test_update_server_metadata_with_bytes_body(self):
+ self._test_update_server_metadata(True)
+
+ def _test_update_server_metadata(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.update_server_metadata,
+ 'tempest.common.service_client.ServiceClient.post',
+ {'metadata': {'fake-key': 'fake-meta-data'}},
+ server_id=self.server_id,
+ meta='fake-meta'
+ )
+
+ def test_show_server_metadata_item_with_str_body(self):
+ self._test_show_server_metadata()
+
+ def test_show_server_metadata_item_with_bytes_body(self):
+ self._test_show_server_metadata(True)
+
+ def _test_show_server_metadata(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.show_server_metadata_item,
+ 'tempest.common.service_client.ServiceClient.get',
+ {'meta': {'fake-key': 'fake-meta-data'}},
+ server_id=self.server_id,
+ key='fake-key'
+ )
+
+ def test_set_server_metadata_item_with_str_body(self):
+ self._test_set_server_metadata_item()
+
+ def test_set_server_metadata_item_with_bytes_body(self):
+ self._test_set_server_metadata_item(True)
+
+ def _test_set_server_metadata_item(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.set_server_metadata_item,
+ 'tempest.common.service_client.ServiceClient.put',
+ {'meta': {'fake-key': 'fake-meta-data'}},
+ server_id=self.server_id,
+ key='fake-key',
+ meta='fake-meta'
+ )
+
+ def test_delete_server_metadata_item_with_str_body(self):
+ self._test_delete_server_metadata()
+
+ def test_delete_server_metadata_item_with_bytes_body(self):
+ self._test_delete_server_metadata(True)
+
+ def _test_delete_server_metadata(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.delete_server_metadata_item,
+ 'tempest.common.service_client.ServiceClient.delete',
+ {},
+ status=204,
+ server_id=self.server_id,
+ key='fake-key'
+ )
+
+ def test_stop_server_with_str_body(self):
+ self._test_stop_server()
+
+ def test_stop_server_with_bytes_body(self):
+ self._test_stop_server(True)
+
+ def _test_stop_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.stop_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_start_server_with_str_body(self):
+ self._test_start_server()
+
+ def test_start_server_with_bytes_body(self):
+ self._test_start_server(True)
+
+ def _test_start_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.start_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_attach_volume_with_str_body(self):
+ self._test_attach_volume_server()
+
+ def test_attach_volume_with_bytes_body(self):
+ self._test_attach_volume_server(True)
+
+ def _test_attach_volume_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.attach_volume,
+ 'tempest.common.service_client.ServiceClient.post',
+ {'volumeAttachment': self.FAKE_COMMON_VOLUME},
+ server_id=self.server_id
+ )
+
+ def test_detach_volume_with_str_body(self):
+ self._test_detach_volume_server()
+
+ def test_detach_volume_with_bytes_body(self):
+ self._test_detach_volume_server(True)
+
+ def _test_detach_volume_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.detach_volume,
+ 'tempest.common.service_client.ServiceClient.delete',
+ {},
+ status=202,
+ server_id=self.server_id,
+ volume_id=self.FAKE_COMMON_VOLUME['volumeId']
+ )
+
+ def test_show_volume_attachment_with_str_body(self):
+ self._test_show_volume_attachment()
+
+ def test_show_volume_attachment_with_bytes_body(self):
+ self._test_show_volume_attachment(True)
+
+ def _test_show_volume_attachment(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.show_volume_attachment,
+ 'tempest.common.service_client.ServiceClient.get',
+ {'volumeAttachment': self.FAKE_COMMON_VOLUME},
+ server_id=self.server_id,
+ attach_id='fake-attach-id'
+ )
+
+ def test_list_volume_attachments_with_str_body(self):
+ self._test_list_volume_attachments()
+
+ def test_list_volume_attachments_with_bytes_body(self):
+ self._test_list_volume_attachments(True)
+
+ def _test_list_volume_attachments(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.list_volume_attachments,
+ 'tempest.common.service_client.ServiceClient.get',
+ {'volumeAttachments': [self.FAKE_COMMON_VOLUME]},
+ server_id=self.server_id
+ )
+
+ def test_add_security_group_with_str_body(self):
+ self._test_add_security_group()
+
+ def test_add_security_group_with_bytes_body(self):
+ self._test_add_security_group(True)
+
+ def _test_add_security_group(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.add_security_group,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id,
+ name='fake-name'
+ )
+
+ def test_remove_security_group_with_str_body(self):
+ self._test_remove_security_group()
+
+ def test_remove_security_group_with_bytes_body(self):
+ self._test_remove_security_group(True)
+
+ def _test_remove_security_group(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.remove_security_group,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id,
+ name='fake-name'
+ )
+
+ def test_live_migrate_server_with_str_body(self):
+ self._test_live_migrate_server()
+
+ def test_live_migrate_server_with_bytes_body(self):
+ self._test_live_migrate_server(True)
+
+ def _test_live_migrate_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.live_migrate_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_migrate_server_with_str_body(self):
+ self._test_migrate_server()
+
+ def test_migrate_server_with_bytes_body(self):
+ self._test_migrate_server(True)
+
+ def _test_migrate_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.migrate_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_lock_server_with_str_body(self):
+ self._test_lock_server()
+
+ def test_lock_server_with_bytes_body(self):
+ self._test_lock_server(True)
+
+ def _test_lock_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.lock_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_unlock_server_with_str_body(self):
+ self._test_unlock_server()
+
+ def test_unlock_server_with_bytes_body(self):
+ self._test_unlock_server(True)
+
+ def _test_unlock_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.unlock_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_suspend_server_with_str_body(self):
+ self._test_suspend_server()
+
+ def test_suspend_server_with_bytes_body(self):
+ self._test_suspend_server(True)
+
+ def _test_suspend_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.suspend_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_resume_server_with_str_body(self):
+ self._test_resume_server()
+
+ def test_resume_server_with_bytes_body(self):
+ self._test_resume_server(True)
+
+ def _test_resume_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.resume_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_pause_server_with_str_body(self):
+ self._test_pause_server()
+
+ def test_pause_server_with_bytes_body(self):
+ self._test_pause_server(True)
+
+ def _test_pause_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.pause_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_unpause_server_with_str_body(self):
+ self._test_unpause_server()
+
+ def test_unpause_server_with_bytes_body(self):
+ self._test_unpause_server(True)
+
+ def _test_unpause_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.unpause_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_reset_state_with_str_body(self):
+ self._test_reset_state()
+
+ def test_reset_state_with_bytes_body(self):
+ self._test_reset_state(True)
+
+ def _test_reset_state(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.reset_state,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id,
+ state='fake-state'
+ )
+
+ def test_shelve_server_with_str_body(self):
+ self._test_shelve_server()
+
+ def test_shelve_server_with_bytes_body(self):
+ self._test_shelve_server(True)
+
+ def _test_shelve_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.shelve_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_unshelve_server_with_str_body(self):
+ self._test_unshelve_server()
+
+ def test_unshelve_server_with_bytes_body(self):
+ self._test_unshelve_server(True)
+
+ def _test_unshelve_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.unshelve_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_shelve_offload_server_with_str_body(self):
+ self._test_shelve_offload_server()
+
+ def test_shelve_offload_server_with_bytes_body(self):
+ self._test_shelve_offload_server(True)
+
+ def _test_shelve_offload_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.shelve_offload_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_get_console_output_with_str_body(self):
+ self._test_get_console_output()
+
+ def test_get_console_output_with_bytes_body(self):
+ self._test_get_console_output(True)
+
+ def _test_get_console_output(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.get_console_output,
+ 'tempest.common.service_client.ServiceClient.post',
+ {'output': 'fake-output'},
+ server_id=self.server_id,
+ length='fake-length'
+ )
+
+ def test_list_virtual_interfaces_with_str_body(self):
+ self._test_list_virtual_interfaces()
+
+ def test_list_virtual_interfaces_with_bytes_body(self):
+ self._test_list_virtual_interfaces(True)
+
+ def _test_list_virtual_interfaces(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.list_virtual_interfaces,
+ 'tempest.common.service_client.ServiceClient.get',
+ {'virtual_interfaces': [self.FAKE_VIRTUAL_INTERFACES]},
+ server_id=self.server_id
+ )
+
+ def test_rescue_server_with_str_body(self):
+ self._test_rescue_server()
+
+ def test_rescue_server_with_bytes_body(self):
+ self._test_rescue_server(True)
+
+ def _test_rescue_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.rescue_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {'adminPass': 'fake-admin-pass'},
+ server_id=self.server_id
+ )
+
+ def test_unrescue_server_with_str_body(self):
+ self._test_unrescue_server()
+
+ def test_unrescue_server_with_bytes_body(self):
+ self._test_unrescue_server(True)
+
+ def _test_unrescue_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.unrescue_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_show_server_diagnostics_with_str_body(self):
+ self._test_show_server_diagnostics()
+
+ def test_show_server_diagnostics_with_bytes_body(self):
+ self._test_show_server_diagnostics(True)
+
+ def _test_show_server_diagnostics(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.show_server_diagnostics,
+ 'tempest.common.service_client.ServiceClient.get',
+ self.FAKE_SERVER_DIAGNOSTICS,
+ status=200,
+ server_id=self.server_id
+ )
+
+ def test_list_instance_actions_with_str_body(self):
+ self._test_list_instance_actions()
+
+ def test_list_instance_actions_with_bytes_body(self):
+ self._test_list_instance_actions(True)
+
+ def _test_list_instance_actions(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.list_instance_actions,
+ 'tempest.common.service_client.ServiceClient.get',
+ {'instanceActions': [self.FAKE_INSTANCE_ACTIONS]},
+ server_id=self.server_id
+ )
+
+ def test_show_instance_action_with_str_body(self):
+ self._test_show_instance_action()
+
+ def test_show_instance_action_with_bytes_body(self):
+ self._test_show_instance_action(True)
+
+ def _test_show_instance_action(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.show_instance_action,
+ 'tempest.common.service_client.ServiceClient.get',
+ {'instanceAction': self.FAKE_INSTANCE_WITH_EVENTS},
+ server_id=self.server_id,
+ request_id='fake-request-id'
+ )
+
+ def test_force_delete_server_with_str_body(self):
+ self._test_force_delete_server()
+
+ def test_force_delete_server_with_bytes_body(self):
+ self._test_force_delete_server(True)
+
+ def _test_force_delete_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.force_delete_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_restore_soft_deleted_server_with_str_body(self):
+ self._test_restore_soft_deleted_server()
+
+ def test_restore_soft_deleted_server_with_bytes_body(self):
+ self._test_restore_soft_deleted_server(True)
+
+ def _test_restore_soft_deleted_server(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.restore_soft_deleted_server,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_reset_network_with_str_body(self):
+ self._test_reset_network()
+
+ def test_reset_network_with_bytes_body(self):
+ self._test_reset_network(True)
+
+ def _test_reset_network(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.reset_network,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_inject_network_info_with_str_body(self):
+ self._test_inject_network_info()
+
+ def test_inject_network_info_with_bytes_body(self):
+ self._test_inject_network_info(True)
+
+ def _test_inject_network_info(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.inject_network_info,
+ 'tempest.common.service_client.ServiceClient.post',
+ {},
+ status=202,
+ server_id=self.server_id
+ )
+
+ def test_get_vnc_console_with_str_body(self):
+ self._test_get_vnc_console()
+
+ def test_get_vnc_console_with_bytes_body(self):
+ self._test_get_vnc_console(True)
+
+ def _test_get_vnc_console(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.get_vnc_console,
+ 'tempest.common.service_client.ServiceClient.post',
+ {'console': self.FAKE_VNC_CONSOLE},
+ server_id=self.server_id,
+ console_type='fake-console-type'
+ )
diff --git a/tempest/tests/test_glance_http.py b/tempest/tests/test_glance_http.py
index 105caec..ed886da 100644
--- a/tempest/tests/test_glance_http.py
+++ b/tempest/tests/test_glance_http.py
@@ -13,14 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
-import socket
-
import mock
-from oslo_serialization import jsonutils as json
from oslotest import mockpatch
import six
from six.moves import http_client as httplib
-from tempest_lib import exceptions as lib_exc
from tempest.common import glance_http
from tempest import exceptions
@@ -56,60 +52,6 @@
'getresponse', return_value=resp))
return resp
- def test_json_request_without_content_type_header_in_response(self):
- self._set_response_fixture({}, 200, 'fake_response_body')
- self.assertRaises(lib_exc.InvalidContentType,
- self.client.json_request, 'GET', '/images')
-
- def test_json_request_with_xml_content_type_header_in_request(self):
- self.assertRaises(lib_exc.InvalidContentType,
- self.client.json_request, 'GET', '/images',
- headers={'Content-Type': 'application/xml'})
-
- def test_json_request_with_xml_content_type_header_in_response(self):
- self._set_response_fixture({'content-type': 'application/xml'},
- 200, 'fake_response_body')
- self.assertRaises(lib_exc.InvalidContentType,
- self.client.json_request, 'GET', '/images')
-
- def test_json_request_with_json_content_type_header_only_in_resp(self):
- self._set_response_fixture({'content-type': 'application/json'},
- 200, 'fake_response_body')
- resp, body = self.client.json_request('GET', '/images')
- self.assertEqual(200, resp.status)
- self.assertEqual('fake_response_body', body)
-
- def test_json_request_with_json_content_type_header_in_req_and_resp(self):
- self._set_response_fixture({'content-type': 'application/json'},
- 200, 'fake_response_body')
- resp, body = self.client.json_request('GET', '/images', headers={
- 'Content-Type': 'application/json'})
- self.assertEqual(200, resp.status)
- self.assertEqual('fake_response_body', body)
-
- def test_json_request_fails_to_json_loads(self):
- self._set_response_fixture({'content-type': 'application/json'},
- 200, 'fake_response_body')
- self.useFixture(mockpatch.PatchObject(json, 'loads',
- side_effect=ValueError()))
- resp, body = self.client.json_request('GET', '/images')
- self.assertEqual(200, resp.status)
- self.assertEqual(body, 'fake_response_body')
-
- def test_json_request_socket_timeout(self):
- self.useFixture(mockpatch.PatchObject(httplib.HTTPConnection,
- 'request',
- side_effect=socket.timeout()))
- self.assertRaises(exceptions.TimeoutException,
- self.client.json_request, 'GET', '/images')
-
- def test_json_request_endpoint_not_found(self):
- self.useFixture(mockpatch.PatchObject(httplib.HTTPConnection,
- 'request',
- side_effect=socket.gaierror()))
- self.assertRaises(exceptions.EndpointNotFound,
- self.client.json_request, 'GET', '/images')
-
def test_raw_request(self):
self._set_response_fixture({}, 200, 'fake_response_body')
resp, body = self.client.raw_request('GET', '/images')
@@ -141,22 +83,22 @@
self.assertEqual(call_count - 1, req_body.tell())
def test_get_connection_class_for_https(self):
- conn_class = self.client.get_connection_class('https')
+ conn_class = self.client._get_connection_class('https')
self.assertEqual(glance_http.VerifiedHTTPSConnection, conn_class)
def test_get_connection_class_for_http(self):
- conn_class = (self.client.get_connection_class('http'))
+ conn_class = (self.client._get_connection_class('http'))
self.assertEqual(httplib.HTTPConnection, conn_class)
def test_get_connection_http(self):
- self.assertTrue(isinstance(self.client.get_connection(),
+ self.assertTrue(isinstance(self.client._get_connection(),
httplib.HTTPConnection))
def test_get_connection_https(self):
endpoint = 'https://fake_url.com'
self.fake_auth.base_url = mock.MagicMock(return_value=endpoint)
self.client = glance_http.HTTPClient(self.fake_auth, {})
- self.assertTrue(isinstance(self.client.get_connection(),
+ self.assertTrue(isinstance(self.client._get_connection(),
glance_http.VerifiedHTTPSConnection))
def test_get_connection_url_not_fount(self):
@@ -164,22 +106,22 @@
side_effect=httplib.InvalidURL()
))
self.assertRaises(exceptions.EndpointNotFound,
- self.client.get_connection)
+ self.client._get_connection)
def test_get_connection_kwargs_default_for_http(self):
- kwargs = self.client.get_connection_kwargs('http')
+ kwargs = self.client._get_connection_kwargs('http')
self.assertEqual(600, kwargs['timeout'])
self.assertEqual(1, len(kwargs.keys()))
def test_get_connection_kwargs_set_timeout_for_http(self):
- kwargs = self.client.get_connection_kwargs('http', timeout=10,
- ca_certs='foo')
+ kwargs = self.client._get_connection_kwargs('http', timeout=10,
+ ca_certs='foo')
self.assertEqual(10, kwargs['timeout'])
# nothing more than timeout is evaluated for http connections
self.assertEqual(1, len(kwargs.keys()))
def test_get_connection_kwargs_default_for_https(self):
- kwargs = self.client.get_connection_kwargs('https')
+ kwargs = self.client._get_connection_kwargs('https')
self.assertEqual(600, kwargs['timeout'])
self.assertEqual(None, kwargs['ca_certs'])
self.assertEqual(None, kwargs['cert_file'])
@@ -189,12 +131,12 @@
self.assertEqual(6, len(kwargs.keys()))
def test_get_connection_kwargs_set_params_for_https(self):
- kwargs = self.client.get_connection_kwargs('https', timeout=10,
- ca_certs='foo',
- cert_file='/foo/bar.cert',
- key_file='/foo/key.pem',
- insecure=True,
- ssl_compression=False)
+ kwargs = self.client._get_connection_kwargs('https', timeout=10,
+ ca_certs='foo',
+ cert_file='/foo/bar.cert',
+ key_file='/foo/key.pem',
+ insecure=True,
+ ssl_compression=False)
self.assertEqual(10, kwargs['timeout'])
self.assertEqual('foo', kwargs['ca_certs'])
self.assertEqual('/foo/bar.cert', kwargs['cert_file'])
diff --git a/tools/check_uuid.py b/tools/check_uuid.py
deleted file mode 100755
index a71ad39..0000000
--- a/tools/check_uuid.py
+++ /dev/null
@@ -1,358 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright 2014 Mirantis, Inc.
-#
-# 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 argparse
-import ast
-import importlib
-import inspect
-import os
-import sys
-import unittest
-import urllib
-import uuid
-
-DECORATOR_MODULE = 'test'
-DECORATOR_NAME = 'idempotent_id'
-DECORATOR_IMPORT = 'tempest.%s' % DECORATOR_MODULE
-IMPORT_LINE = 'from tempest import %s' % DECORATOR_MODULE
-DECORATOR_TEMPLATE = "@%s.%s('%%s')" % (DECORATOR_MODULE,
- DECORATOR_NAME)
-UNIT_TESTS_EXCLUDE = 'tempest.tests'
-
-
-class SourcePatcher(object):
-
- """"Lazy patcher for python source files"""
-
- def __init__(self):
- self.source_files = None
- self.patches = None
- self.clear()
-
- def clear(self):
- """Clear inner state"""
- self.source_files = {}
- self.patches = {}
-
- @staticmethod
- def _quote(s):
- return urllib.quote(s)
-
- @staticmethod
- def _unquote(s):
- return urllib.unquote(s)
-
- def add_patch(self, filename, patch, line_no):
- """Add lazy patch"""
- if filename not in self.source_files:
- with open(filename) as f:
- self.source_files[filename] = self._quote(f.read())
- patch_id = str(uuid.uuid4())
- if not patch.endswith('\n'):
- patch += '\n'
- self.patches[patch_id] = self._quote(patch)
- lines = self.source_files[filename].split(self._quote('\n'))
- lines[line_no - 1] = ''.join(('{%s:s}' % patch_id, lines[line_no - 1]))
- self.source_files[filename] = self._quote('\n').join(lines)
-
- def _save_changes(self, filename, source):
- print('%s fixed' % filename)
- with open(filename, 'w') as f:
- f.write(source)
-
- def apply_patches(self):
- """Apply all patches"""
- for filename in self.source_files:
- patched_source = self._unquote(
- self.source_files[filename].format(**self.patches)
- )
- self._save_changes(filename, patched_source)
- self.clear()
-
-
-class TestChecker(object):
-
- def __init__(self, package):
- self.package = package
- self.base_path = os.path.abspath(os.path.dirname(package.__file__))
-
- def _path_to_package(self, path):
- relative_path = path[len(self.base_path) + 1:]
- if relative_path:
- return '.'.join((self.package.__name__,) +
- tuple(relative_path.split('/')))
- else:
- return self.package.__name__
-
- def _modules_search(self):
- """Recursive search for python modules in base package"""
- modules = []
- for root, dirs, files in os.walk(self.base_path):
- if not os.path.exists(os.path.join(root, '__init__.py')):
- continue
- root_package = self._path_to_package(root)
- for item in files:
- if item.endswith('.py'):
- module_name = '.'.join((root_package,
- os.path.splitext(item)[0]))
- if not module_name.startswith(UNIT_TESTS_EXCLUDE):
- modules.append(module_name)
- return modules
-
- @staticmethod
- def _get_idempotent_id(test_node):
- # Return key-value dict with all metadata from @test.idempotent_id
- # decorators for test method
- idempotent_id = None
- for decorator in test_node.decorator_list:
- if (hasattr(decorator, 'func') and
- hasattr(decorator.func, 'attr') and
- decorator.func.attr == DECORATOR_NAME and
- hasattr(decorator.func, 'value') and
- decorator.func.value.id == DECORATOR_MODULE):
- for arg in decorator.args:
- idempotent_id = ast.literal_eval(arg)
- return idempotent_id
-
- @staticmethod
- def _is_decorator(line):
- return line.strip().startswith('@')
-
- @staticmethod
- def _is_def(line):
- return line.strip().startswith('def ')
-
- def _add_uuid_to_test(self, patcher, test_node, source_path):
- with open(source_path) as src:
- src_lines = src.read().split('\n')
- lineno = test_node.lineno
- insert_position = lineno
- while True:
- if (self._is_def(src_lines[lineno - 1]) or
- (self._is_decorator(src_lines[lineno - 1]) and
- (DECORATOR_TEMPLATE.split('(')[0] <=
- src_lines[lineno - 1].strip().split('(')[0]))):
- insert_position = lineno
- break
- lineno += 1
- patcher.add_patch(
- source_path,
- ' ' * test_node.col_offset + DECORATOR_TEMPLATE % uuid.uuid4(),
- insert_position
- )
-
- @staticmethod
- def _is_test_case(module, node):
- if (node.__class__ is ast.ClassDef and
- hasattr(module, node.name) and
- inspect.isclass(getattr(module, node.name))):
- return issubclass(getattr(module, node.name), unittest.TestCase)
-
- @staticmethod
- def _is_test_method(node):
- return (node.__class__ is ast.FunctionDef
- and node.name.startswith('test_'))
-
- @staticmethod
- def _next_node(body, node):
- if body.index(node) < len(body):
- return body[body.index(node) + 1]
-
- @staticmethod
- def _import_name(node):
- if type(node) == ast.Import:
- return node.names[0].name
- elif type(node) == ast.ImportFrom:
- return '%s.%s' % (node.module, node.names[0].name)
-
- def _add_import_for_test_uuid(self, patcher, src_parsed, source_path):
- with open(source_path) as f:
- src_lines = f.read().split('\n')
- line_no = 0
- tempest_imports = [node for node in src_parsed.body
- if self._import_name(node) and
- 'tempest.' in self._import_name(node)]
- if not tempest_imports:
- import_snippet = '\n'.join(('', IMPORT_LINE, ''))
- else:
- for node in tempest_imports:
- if self._import_name(node) < DECORATOR_IMPORT:
- continue
- else:
- line_no = node.lineno
- import_snippet = IMPORT_LINE
- break
- else:
- line_no = tempest_imports[-1].lineno
- while True:
- if (not src_lines[line_no - 1] or
- getattr(self._next_node(src_parsed.body,
- tempest_imports[-1]),
- 'lineno') == line_no or
- line_no == len(src_lines)):
- break
- line_no += 1
- import_snippet = '\n'.join((IMPORT_LINE, ''))
- patcher.add_patch(source_path, import_snippet, line_no)
-
- def get_tests(self):
- """Get test methods with sources from base package with metadata"""
- tests = {}
- for module_name in self._modules_search():
- tests[module_name] = {}
- module = importlib.import_module(module_name)
- source_path = '.'.join(
- (os.path.splitext(module.__file__)[0], 'py')
- )
- with open(source_path, 'r') as f:
- source = f.read()
- tests[module_name]['source_path'] = source_path
- tests[module_name]['tests'] = {}
- source_parsed = ast.parse(source)
- tests[module_name]['ast'] = source_parsed
- tests[module_name]['import_valid'] = (
- hasattr(module, DECORATOR_MODULE) and
- inspect.ismodule(getattr(module, DECORATOR_MODULE))
- )
- test_cases = (node for node in source_parsed.body
- if self._is_test_case(module, node))
- for node in test_cases:
- for subnode in filter(self._is_test_method, node.body):
- test_name = '%s.%s' % (node.name, subnode.name)
- tests[module_name]['tests'][test_name] = subnode
- return tests
-
- @staticmethod
- def _filter_tests(function, tests):
- """Filter tests with condition 'function(test_node) == True'"""
- result = {}
- for module_name in tests:
- for test_name in tests[module_name]['tests']:
- if function(module_name, test_name, tests):
- if module_name not in result:
- result[module_name] = {
- 'ast': tests[module_name]['ast'],
- 'source_path': tests[module_name]['source_path'],
- 'import_valid': tests[module_name]['import_valid'],
- 'tests': {}
- }
- result[module_name]['tests'][test_name] = \
- tests[module_name]['tests'][test_name]
- return result
-
- def find_untagged(self, tests):
- """Filter all tests without uuid in metadata"""
- def check_uuid_in_meta(module_name, test_name, tests):
- idempotent_id = self._get_idempotent_id(
- tests[module_name]['tests'][test_name])
- return not idempotent_id
- return self._filter_tests(check_uuid_in_meta, tests)
-
- def report_collisions(self, tests):
- """Reports collisions if there are any.
-
- Returns true if collisions exist.
- """
- uuids = {}
-
- def report(module_name, test_name, tests):
- test_uuid = self._get_idempotent_id(
- tests[module_name]['tests'][test_name])
- if not test_uuid:
- return
- if test_uuid in uuids:
- error_str = "%s:%s\n uuid %s collision: %s<->%s\n%s:%s" % (
- tests[module_name]['source_path'],
- tests[module_name]['tests'][test_name].lineno,
- test_uuid,
- test_name,
- uuids[test_uuid]['test_name'],
- uuids[test_uuid]['source_path'],
- uuids[test_uuid]['test_node'].lineno,
- )
- print(error_str)
- print("cannot automatically resolve the collision, please "
- "manually remove the duplicate value on the new test.")
- return True
- else:
- uuids[test_uuid] = {
- 'module': module_name,
- 'test_name': test_name,
- 'test_node': tests[module_name]['tests'][test_name],
- 'source_path': tests[module_name]['source_path']
- }
- return bool(self._filter_tests(report, tests))
-
- def report_untagged(self, tests):
- """Reports untagged tests if there are any.
-
- Returns true if untagged tests exist.
- """
- def report(module_name, test_name, tests):
- error_str = "%s:%s\nmissing @test.idempotent_id('...')\n%s\n" % (
- tests[module_name]['source_path'],
- tests[module_name]['tests'][test_name].lineno,
- test_name
- )
- print(error_str)
- return True
- return bool(self._filter_tests(report, tests))
-
- def fix_tests(self, tests):
- """Add uuids to all tests specified in tests and fix it"""
- patcher = SourcePatcher()
- for module_name in tests:
- add_import_once = True
- for test_name in tests[module_name]['tests']:
- if not tests[module_name]['import_valid'] and add_import_once:
- self._add_import_for_test_uuid(
- patcher,
- tests[module_name]['ast'],
- tests[module_name]['source_path']
- )
- add_import_once = False
- self._add_uuid_to_test(
- patcher, tests[module_name]['tests'][test_name],
- tests[module_name]['source_path'])
- patcher.apply_patches()
-
-
-def run():
- parser = argparse.ArgumentParser()
- parser.add_argument('--package', action='store', dest='package',
- default='tempest', type=str,
- help='Package with tests')
- parser.add_argument('--fix', action='store_true', dest='fix_tests',
- help='Attempt to fix tests without UUIDs')
- args = parser.parse_args()
- sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
- pkg = importlib.import_module(args.package)
- checker = TestChecker(pkg)
- errors = False
- tests = checker.get_tests()
- untagged = checker.find_untagged(tests)
- errors = checker.report_collisions(tests) or errors
- if args.fix_tests and untagged:
- checker.fix_tests(untagged)
- else:
- errors = checker.report_untagged(untagged) or errors
- if errors:
- sys.exit("@test.idempotent_id existence and uniqueness checks failed\n"
- "Run 'tox -v -euuidgen' to automatically fix tests with\n"
- "missing @test.idempotent_id decorators.")
-
-if __name__ == '__main__':
- run()
diff --git a/tools/use_tempest_lib.sh b/tools/use_tempest_lib.sh
new file mode 100755
index 0000000..ca62c4a
--- /dev/null
+++ b/tools/use_tempest_lib.sh
@@ -0,0 +1,141 @@
+#!/bin/bash
+#
+# Use this script to use interfaces/files from tempest-lib.
+# Many files have been migrated to tempest-lib and tempest has
+# its own copy too.
+# This script helps to remove those from tempest and make use of tempest-lib.
+# It adds the change-id of each file on which they were migrated in lib.
+# This should only be done for files which were migrated to lib with
+# "Migrated" in commit message as done by tempest-lib/tools/migrate_from_tempest.sh script.
+# "Migrated" keyword is used to fetch the migration commit history from lib.
+# To use:
+# 1. Create a new branch in the tempest repo so not to destroy your current
+# working branch
+# 2. Run the script from the repo dir and specify the file paths relative to
+# the root tempest dir(only code and unit tests):
+#
+# tools/use_tempest_lib.sh.sh tempest/file1.py tempest/file2.py
+
+
+function usage {
+ echo "Usage: $0 [OPTION] file1 file2 .."
+ echo "Use files from tempest-lib"
+ echo -e "Input files should be tempest files with path. \n Example- tempest/file1.py tempest/file2.py .."
+ echo ""
+ echo "-s, --service_client Specify if files are service clients."
+ echo "-u, --tempest_lib_git_url Specify the repo to clone tempest-lib from."
+}
+
+function check_all_files_valid {
+ failed=0
+ for file in $files; do
+ # Get the latest change-id for each file
+ latest_commit_id=`git log -n1 -- $file | grep "^commit" | awk '{print $2}'`
+ cd $tmpdir
+ filename=`basename $file`
+ lib_path=`find ./ -name $filename`
+ if [ -z $lib_path ]; then
+ echo "ERROR: $filename does not exist in tempest-lib."
+ failed=$(( failed + 1))
+ cd - > /dev/null
+ continue
+ fi
+ # Get the CHANGE_ID of tempest-lib patch where file was migrated
+ migration_change_id=`git log -n1 --grep "Migrated" -- $lib_path | grep "Change-Id: " | awk '{print $2}'`
+ MIGRATION_IDS=`echo -e "$MIGRATION_IDS\n * $filename: $migration_change_id"`
+ # Get tempest CHANGE_ID of file which was migrated to lib
+ migrated_change_id=`git log -n1 --grep "Migrated" -- $lib_path | grep "* $filename"`
+ migrated_change_id=${migrated_change_id#*:}
+ cd - > /dev/null
+ # Get the commit-id of tempest which was migrated to tempest-lib
+ migrated_commit_id=`git log --grep "$migrated_change_id" -- $file | grep "^commit" | awk '{print $2}'`
+ DIFF=$(git diff $latest_commit_id $migrated_commit_id $file)
+ if [ "$DIFF" != "" ]; then
+ echo "ERROR: $filename in tempest has been updated after migration to tempest-lib. First sync the file to tempest-lib."
+ failed=$(( failed + 1))
+ fi
+ done
+ if [[ $failed -gt 0 ]]; then
+ echo "$failed files had issues"
+ exit $failed
+ fi
+}
+
+set -e
+
+service_client=0
+file_list=''
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -h|--help) usage; exit;;
+ -u|--tempest_lib_git_url) tempest_lib_git_url="$2"; shift;;
+ -s|--service_client) service_client=1;;
+ *) files="$files $1";;
+ esac
+ shift
+done
+
+if [ -z "$files" ]; then
+ usage; exit
+fi
+
+TEMPEST_LIB_GIT_URL=${tempest_lib_git_url:-git://git.openstack.org/openstack/tempest-lib}
+
+tmpdir=$(mktemp -d -t use-tempest-lib.XXXX)
+
+# Clone tempest-lib
+git clone $TEMPEST_LIB_GIT_URL $tmpdir
+
+# Checks all provided files are present in lib and
+# not updated in tempest after migration to lib.
+check_all_files_valid
+
+for file in $files; do
+ rm -f $file
+ tempest_dir=`pwd`
+ tempest_dir="$tempest_dir/tempest/"
+ tempest_dirname=`dirname $file`
+ lib_dirname=`echo $tempest_dirname | sed s@tempest\/@tempest_lib/\@`
+ # Convert tempest dirname to import string
+ tempest_import="${tempest_dirname//\//.}"
+ tempest_import=${tempest_import:2:${#tempest_import}}
+ if [ $service_client -eq 1 ]; then
+ # Remove /json path because tempest-lib supports JSON only without XML
+ lib_dirname=`echo $lib_dirname | sed s@\/json@@`
+ fi
+ # Convert tempest-lib dirname to import string
+ tempest_lib_import="${lib_dirname//\//.}"
+ tempest_lib_import=${tempest_lib_import:2:${#tempest_lib_import}}
+ module_name=`basename $file .py`
+ tempest_import1="from $tempest_import.$module_name"
+ tempest_lib_import1="from $tempest_lib_import.$module_name"
+ tempest_import2="from $tempest_import import $module_name"
+ tempest_lib_import2="from $tempest_lib_import import $module_name"
+ set +e
+ grep -rl "$tempest_import1" $tempest_dir | xargs sed -i'' s/"$tempest_import1"/"$tempest_lib_import1"/g 2> /dev/null
+ grep -rl "$tempest_import2" $tempest_dir | xargs sed -i'' s/"$tempest_import2"/"$tempest_lib_import2"/g 2> /dev/null
+ set -e
+ if [[ -z "$file_list" ]]; then
+ file_list="$module_name"
+ else
+ tmp_file_list="$file_list, $module_name"
+ char_size=`echo $tmp_file_list | wc -c`
+ if [ $char_size -lt 27 ]; then
+ file_list="$file_list, $module_name"
+ fi
+ fi
+done
+
+rm -rf $tmpdir
+echo "Completed. Run pep8 and fix error if any"
+
+git add -A tempest/
+# Generate a migration commit
+commit_message="Use $file_list from tempest-lib"
+pre_list=$"The files below have been migrated to tempest-lib\n"
+pre_list=`echo -e $pre_list`
+post_list=$"Now Tempest-lib provides those as stable interfaces. So Tempest should\nstart using those from lib and remove its own copy."
+post_list=`echo -e $post_list`
+
+git commit -m "$commit_message" -m "$pre_list" -m "$MIGRATION_IDS" -m "$post_list"
diff --git a/tox.ini b/tox.ini
index ecd4f24..41eece1 100644
--- a/tox.ini
+++ b/tox.ini
@@ -114,11 +114,11 @@
[testenv:pep8]
commands =
flake8 {posargs}
- python tools/check_uuid.py
+ check-uuid
[testenv:uuidgen]
commands =
- python tools/check_uuid.py --fix
+ check-uuid --fix
[hacking]
local-check-factory = tempest.hacking.checks.factory