Merge "Sync latest setup.py from oslo."
diff --git a/cli/__init__.py b/cli/__init__.py
index cea0b62..e97fe3e 100644
--- a/cli/__init__.py
+++ b/cli/__init__.py
@@ -16,8 +16,11 @@
# under the License.
import logging
+import shlex
+import subprocess
from tempest.openstack.common import cfg
+import tempest.test
LOG = logging.getLogger(__name__)
@@ -34,3 +37,45 @@
cli_group = cfg.OptGroup(name='cli', title="cli Configuration Options")
CONF.register_group(cli_group)
CONF.register_opts(cli_opts, group=cli_group)
+
+
+class ClientTestBase(tempest.test.BaseTestCase):
+ @classmethod
+ def setUpClass(cls):
+ if not CONF.cli.enabled:
+ msg = "cli testing disabled"
+ raise cls.skipException(msg)
+ cls.identity = cls.config.identity
+ super(ClientTestBase, cls).setUpClass()
+
+ def __init__(self, *args, **kwargs):
+ super(ClientTestBase, self).__init__(*args, **kwargs)
+
+ def nova(self, action, flags='', params='', admin=True, fail_ok=False):
+ """Executes nova command for the given action."""
+ return self.cmd_with_auth(
+ 'nova', action, flags, params, admin, fail_ok)
+
+ def cmd_with_auth(self, cmd, action, flags='', params='',
+ admin=True, fail_ok=False):
+ """Executes given command with auth attributes appended."""
+ #TODO(jogo) make admin=False work
+ creds = ('--os-username %s --os-tenant-name %s --os-password %s '
+ '--os-auth-url %s ' % (self.identity.admin_username,
+ self.identity.admin_tenant_name, self.identity.admin_password,
+ self.identity.uri))
+ flags = creds + ' ' + flags
+ return self.cmd(cmd, action, flags, params, fail_ok)
+
+ def cmd(self, cmd, action, flags='', params='', fail_ok=False):
+ """Executes specified command for the given action."""
+ cmd = ' '.join([CONF.cli.cli_dir + cmd,
+ flags, action, params])
+ LOG.info("running: '%s'" % cmd)
+ cmd = shlex.split(cmd)
+ try:
+ result = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
+ except subprocess.CalledProcessError, e:
+ LOG.error("command output:\n%s" % e.output)
+ raise
+ return result
diff --git a/cli/simple_read_only/test_compute.py b/cli/simple_read_only/test_compute.py
index 073fde1..849ed6f 100644
--- a/cli/simple_read_only/test_compute.py
+++ b/cli/simple_read_only/test_compute.py
@@ -16,14 +16,12 @@
# under the License.
import logging
-import shlex
import subprocess
import testtools
import cli
-from tempest import config
from tempest.openstack.common import cfg
@@ -33,7 +31,7 @@
LOG = logging.getLogger(__name__)
-class SimpleReadOnlyNovaCLientTest(testtools.TestCase):
+class SimpleReadOnlyNovaClientTest(cli.ClientTestBase):
"""
This is a first pass at a simple read only python-novaclient test. This
@@ -47,33 +45,6 @@
"""
- @classmethod
- def setUpClass(cls):
- if not CONF.cli.enabled:
- msg = "cli testing disabled"
- raise cls.skipException(msg)
- cls.identity = config.TempestConfig().identity
- super(SimpleReadOnlyNovaCLientTest, cls).setUpClass()
-
- #NOTE(jogo): This should eventually be moved into a base class
- def nova(self, action, flags='', params='', admin=True, fail_ok=False):
- """Executes nova command for the given action."""
- #TODO(jogo) make admin=False work
- creds = ('--os-username %s --os-tenant-name %s --os-password %s '
- '--os-auth-url %s ' % (self.identity.admin_username,
- self.identity.admin_tenant_name, self.identity.admin_password,
- self.identity.uri))
- flags = creds + ' ' + flags
- cmd = ' '.join([CONF.cli.cli_dir + 'nova', flags, action, params])
- LOG.info("running: '%s'" % cmd)
- cmd = shlex.split(cmd)
- try:
- result = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
- except subprocess.CalledProcessError, e:
- LOG.error("command output:\n%s" % e.output)
- raise
- return result
-
def test_admin_fake_action(self):
self.assertRaises(subprocess.CalledProcessError,
self.nova,
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index 9dca609..a70a7ab 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -88,6 +88,9 @@
# Number of seconds to wait to authenticate to an instance
ssh_timeout = 300
+# Number of seconds to wait for output from ssh channel
+ssh_channel_timeout = 60
+
# The type of endpoint for a Compute API service. Unless you have a
# custom Keystone service catalog implementation, you probably want to leave
# this value as "compute"
@@ -238,20 +241,20 @@
#Image materials for S3 upload
# ALL content of the specified directory will be uploaded to S3
-s3_materials_path = /opt/stack/devstack/files/images/s3-materials/cirros-0.3.0
+s3_materials_path = /opt/stack/devstack/files/images/s3-materials/cirros-0.3.1
# The manifest.xml files, must be in the s3_materials_path directory
# Subdirectories not allowed!
# The filenames will be used as a Keys in the S3 Buckets
#ARI Ramdisk manifest. Must be in the above s3_materials_path
-ari_manifest = cirros-0.3.0-x86_64-initrd.manifest.xml
+ari_manifest = cirros-0.3.1-x86_64-initrd.manifest.xml
#AMI Machine Image manifest. Must be in the above s3_materials_path
-ami_manifest = cirros-0.3.0-x86_64-blank.img.manifest.xml
+ami_manifest = cirros-0.3.1-x86_64-blank.img.manifest.xml
#AKI Kernel Image manifest, Must be in the above s3_materials_path
-aki_manifest = cirros-0.3.0-x86_64-vmlinuz.manifest.xml
+aki_manifest = cirros-0.3.1-x86_64-vmlinuz.manifest.xml
#Instance type
instance_type = m1.tiny
diff --git a/stress/config.py b/stress/config.py
index ca86ce5..25cb910 100755
--- a/stress/config.py
+++ b/stress/config.py
@@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import ConfigParser
-
class StressConfig(object):
"""Provides configuration information for whitebox stress tests."""
@@ -21,33 +19,27 @@
def __init__(self, conf):
self.conf = conf
- def get(self, item_name, default_value=None):
- try:
- return self.conf.get("stress", item_name)
- except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
- return default_value
-
@property
def host_private_key_path(self):
"""Path to ssh key for logging into compute nodes."""
- return self.get("host_private_key_path", None)
+ return self.conf.compute.path_to_private_key
@property
def host_admin_user(self):
"""Username for logging into compute nodes."""
- return self.get("host_admin_user", None)
+ return self.conf.compute.ssh_user
@property
def nova_logdir(self):
"""Directory containing log files on the compute nodes."""
- return self.get("nova_logdir", None)
+ return self.conf.stress.nova_logdir
@property
def controller(self):
"""Controller host."""
- return self.get("controller", None)
+ return self.conf.stress.controller
@property
def max_instances(self):
"""Maximum number of instances to create during test."""
- return self.get("max_instances", 16)
+ return self.conf.stress.max_instances
diff --git a/stress/driver.py b/stress/driver.py
index 8dc88cf..f80e765 100644
--- a/stress/driver.py
+++ b/stress/driver.py
@@ -18,6 +18,7 @@
import datetime
import random
import time
+from urlparse import urlparse
from config import StressConfig
from state import ClusterState
@@ -162,7 +163,7 @@
(default: 32)
`seed` = random seed (default: None)
"""
- stress_config = StressConfig(manager.config._conf)
+ stress_config = StressConfig(manager.config)
# get keyword arguments
duration = kwargs.get('duration', datetime.timedelta(seconds=10))
seed = kwargs.get('seed', None)
@@ -173,7 +174,8 @@
keypath = stress_config.host_private_key_path
user = stress_config.host_admin_user
logdir = stress_config.nova_logdir
- computes = _get_compute_nodes(keypath, user, manager.config.identity.host)
+ host = urlparse(manager.config.identity.uri).hostname
+ computes = _get_compute_nodes(keypath, user, host)
stress.utils.execute_on_all(keypath, user, computes,
"rm -f %s/*.log" % logdir)
random.seed(seed)
diff --git a/tempest/clients.py b/tempest/clients.py
index 7d314f3..ef07d9c 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -25,6 +25,7 @@
from tempest.services.compute.json.flavors_client import FlavorsClientJSON
from tempest.services.compute.json.floating_ips_client import \
FloatingIPsClientJSON
+from tempest.services.compute.json.hosts_client import HostsClientJSON
from tempest.services.compute.json.images_client import ImagesClientJSON
from tempest.services.compute.json.keypairs_client import KeyPairsClientJSON
from tempest.services.compute.json.limits_client import LimitsClientJSON
@@ -211,6 +212,7 @@
msg = "Unsupported interface type `%s'" % interface
raise exceptions.InvalidConfiguration(msg)
self.network_client = NetworkClient(*client_args)
+ self.hosts_client = HostsClientJSON(*client_args)
self.account_client = AccountClient(*client_args)
self.image_client = ImageClientJSON(*client_args)
self.container_client = ContainerClient(*client_args)
diff --git a/tempest/common/rest_client.py b/tempest/common/rest_client.py
index 170a137..c582826 100644
--- a/tempest/common/rest_client.py
+++ b/tempest/common/rest_client.py
@@ -338,6 +338,11 @@
return self.check_over_limit(resp_body, method, url, headers, body,
depth, wait)
+ if resp.status == 422:
+ if parse_resp:
+ resp_body = self._parse_resp(resp_body)
+ raise exceptions.UnprocessableEntity(resp_body)
+
if resp.status in (500, 501):
message = resp_body
if parse_resp:
diff --git a/tempest/common/utils/linux/remote_client.py b/tempest/common/utils/linux/remote_client.py
index b501df4..fd5d3d0 100644
--- a/tempest/common/utils/linux/remote_client.py
+++ b/tempest/common/utils/linux/remote_client.py
@@ -15,6 +15,7 @@
ssh_timeout = TempestConfig().compute.ssh_timeout
network = TempestConfig().compute.network_for_ssh
ip_version = TempestConfig().compute.ip_version_for_ssh
+ ssh_channel_timeout = TempestConfig().compute.ssh_channel_timeout
if isinstance(server, basestring):
ip_address = server
else:
@@ -27,7 +28,8 @@
raise ServerUnreachable()
self.ssh_client = Client(ip_address, username, password, ssh_timeout,
- pkey=pkey)
+ pkey=pkey,
+ channel_timeout=ssh_channel_timeout)
if not self.ssh_client.test_connection_auth():
raise SSHTimeout()
diff --git a/tempest/config.py b/tempest/config.py
index c982dee..856be16 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -149,8 +149,12 @@
help="User name used to authenticate to an instance."),
cfg.IntOpt('ssh_timeout',
default=300,
- help="Timeout in seconds to wait for authentcation to "
+ help="Timeout in seconds to wait for authentication to "
"succeed."),
+ cfg.IntOpt('ssh_channel_timeout',
+ default=60,
+ help="Timeout in seconds to wait for output from ssh "
+ "channel."),
cfg.StrOpt('network_for_ssh',
default='public',
help="Network used for SSH connections."),
@@ -382,6 +386,26 @@
for opt in BotoConfig:
conf.register_opt(opt, group='boto')
+stress_group = cfg.OptGroup(name='stress', title='Stress Test Options')
+
+StressGroup = [
+ cfg.StrOpt('nova_logdir',
+ default=None,
+ help='Directory containing log files on the compute nodes'),
+ cfg.IntOpt('max_instances',
+ default=16,
+ help='Maximum number of instances to create during test.'),
+ cfg.StrOpt('controller',
+ default=None,
+ help='Controller host.')
+]
+
+
+def register_stress_opts(conf):
+ conf.register_group(stress_group)
+ for opt in StressGroup:
+ conf.register_opt(opt, group='stress')
+
@singleton
class TempestConfig:
@@ -426,6 +450,7 @@
register_object_storage_opts(cfg.CONF)
register_boto_opts(cfg.CONF)
register_compute_admin_opts(cfg.CONF)
+ register_stress_opts(cfg.CONF)
self.compute = cfg.CONF.compute
self.whitebox = cfg.CONF.whitebox
self.identity = cfg.CONF.identity
@@ -435,6 +460,7 @@
self.object_storage = cfg.CONF['object-storage']
self.boto = cfg.CONF.boto
self.compute_admin = cfg.CONF['compute-admin']
+ self.stress = cfg.CONF.stress
if not self.compute_admin.username:
self.compute_admin.username = self.identity.admin_username
self.compute_admin.password = self.identity.admin_password
diff --git a/tempest/exceptions.py b/tempest/exceptions.py
index 577aa13..235a2e7 100644
--- a/tempest/exceptions.py
+++ b/tempest/exceptions.py
@@ -94,6 +94,10 @@
message = "Bad request"
+class UnprocessableEntity(RestClientException):
+ message = "Unprocessable entity"
+
+
class AuthenticationFailure(RestClientException):
message = ("Authentication with user %(user)s and password "
"%(password)s failed")
diff --git a/tempest/services/botoclients.py b/tempest/services/botoclients.py
index 143257a..0870c96 100644
--- a/tempest/services/botoclients.py
+++ b/tempest/services/botoclients.py
@@ -17,7 +17,6 @@
import ConfigParser
import contextlib
-import re
import types
import urlparse
diff --git a/tempest/services/image/json/image_client.py b/tempest/services/image/json/image_client.py
index e9276aa..277075e 100644
--- a/tempest/services/image/json/image_client.py
+++ b/tempest/services/image/json/image_client.py
@@ -25,7 +25,6 @@
from tempest.common import glance_http
from tempest.common.rest_client import RestClient
from tempest import exceptions
-from tempest import manager
class ImageClientJSON(RestClient):
@@ -97,11 +96,11 @@
return None
def _get_http(self):
- temp_manager = manager.DefaultClientManager()
- keystone = temp_manager._get_identity_client()
- token = keystone.auth_token
- endpoint = keystone.service_catalog.url_for(service_type='image',
- endpoint_type='publicURL')
+ token, endpoint = self.keystone_auth(self.user,
+ self.password,
+ self.auth_url,
+ self.service,
+ self.tenant_name)
dscv = self.config.identity.disable_ssl_certificate_validation
return glance_http.HTTPClient(endpoint=endpoint, token=token,
insecure=dscv)
@@ -170,17 +169,23 @@
def delete_image(self, image_id):
url = 'v1/images/%s' % image_id
- try:
- self.delete(url)
- except exceptions.Unauthorized:
- url = '/' + url
- self.http.raw_request('DELETE', url)
+ self.delete(url)
- def image_list(self, params=None):
+ def image_list(self, **kwargs):
url = 'v1/images'
- if params:
- url += '?%s' % urllib.urlencode(params)
+ if len(kwargs) > 0:
+ url += '?%s' % urllib.urlencode(kwargs)
+
+ resp, body = self.get(url)
+ body = json.loads(body)
+ return resp, body['images']
+
+ def image_list_detail(self, **kwargs):
+ url = 'v1/images/detail'
+
+ if len(kwargs) > 0:
+ url += '?%s' % urllib.urlencode(kwargs)
resp, body = self.get(url)
body = json.loads(body)
diff --git a/tempest/test.py b/tempest/test.py
index 90793ac..e0639b6 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -58,12 +58,11 @@
class TestCase(BaseTestCase):
-
- """
- Base test case class for all Tempest tests
+ """Base test case class for all Tempest tests
Contains basic setup and convenience methods
"""
+
manager_class = None
@classmethod
diff --git a/tempest/testboto.py b/tempest/testboto.py
index 5625841..cee8843 100644
--- a/tempest/testboto.py
+++ b/tempest/testboto.py
@@ -17,16 +17,21 @@
from contextlib import closing
import logging
+import os
import re
+import urlparse
import boto
from boto import ec2
from boto import exception
from boto import s3
+import keystoneclient.exceptions
+import tempest.clients
+from tempest.common.utils.file_utils import have_effective_read_access
+import tempest.config
from tempest import exceptions
import tempest.test
-import tempest.tests.boto
from tempest.tests.boto.utils.wait import re_search_wait
from tempest.tests.boto.utils.wait import state_wait
from tempest.tests.boto.utils.wait import wait_exception
@@ -34,6 +39,71 @@
LOG = logging.getLogger(__name__)
+def decision_maker():
+ A_I_IMAGES_READY = True # ari,ami,aki
+ S3_CAN_CONNECT_ERROR = None
+ EC2_CAN_CONNECT_ERROR = None
+ secret_matcher = re.compile("[A-Za-z0-9+/]{32,}") # 40 in other system
+ id_matcher = re.compile("[A-Za-z0-9]{20,}")
+
+ def all_read(*args):
+ return all(map(have_effective_read_access, args))
+
+ config = tempest.config.TempestConfig()
+ materials_path = config.boto.s3_materials_path
+ ami_path = materials_path + os.sep + config.boto.ami_manifest
+ aki_path = materials_path + os.sep + config.boto.aki_manifest
+ ari_path = materials_path + os.sep + config.boto.ari_manifest
+
+ A_I_IMAGES_READY = all_read(ami_path, aki_path, ari_path)
+ boto_logger = logging.getLogger('boto')
+ level = boto_logger.level
+ boto_logger.setLevel(logging.CRITICAL) # suppress logging for these
+
+ def _cred_sub_check(connection_data):
+ if not id_matcher.match(connection_data["aws_access_key_id"]):
+ raise Exception("Invalid AWS access Key")
+ if not secret_matcher.match(connection_data["aws_secret_access_key"]):
+ raise Exception("Invalid AWS secret Key")
+ raise Exception("Unknown (Authentication?) Error")
+ openstack = tempest.clients.Manager()
+ try:
+ if urlparse.urlparse(config.boto.ec2_url).hostname is None:
+ raise Exception("Failed to get hostname from the ec2_url")
+ ec2client = openstack.ec2api_client
+ try:
+ ec2client.get_all_regions()
+ except exception.BotoServerError as exc:
+ if exc.error_code is None:
+ raise Exception("EC2 target does not looks EC2 service")
+ _cred_sub_check(ec2client.connection_data)
+
+ except keystoneclient.exceptions.Unauthorized:
+ EC2_CAN_CONNECT_ERROR = "AWS credentials not set," +\
+ " faild to get them even by keystoneclient"
+ except Exception as exc:
+ EC2_CAN_CONNECT_ERROR = str(exc)
+
+ try:
+ if urlparse.urlparse(config.boto.s3_url).hostname is None:
+ raise Exception("Failed to get hostname from the s3_url")
+ s3client = openstack.s3_client
+ try:
+ s3client.get_bucket("^INVALID*#()@INVALID.")
+ except exception.BotoServerError as exc:
+ if exc.status == 403:
+ _cred_sub_check(s3client.connection_data)
+ except Exception as exc:
+ S3_CAN_CONNECT_ERROR = str(exc)
+ except keystoneclient.exceptions.Unauthorized:
+ S3_CAN_CONNECT_ERROR = "AWS credentials not set," +\
+ " faild to get them even by keystoneclient"
+ boto_logger.setLevel(level)
+ return {'A_I_IMAGES_READY': A_I_IMAGES_READY,
+ 'S3_CAN_CONNECT_ERROR': S3_CAN_CONNECT_ERROR,
+ 'EC2_CAN_CONNECT_ERROR': EC2_CAN_CONNECT_ERROR}
+
+
class BotoExceptionMatcher(object):
STATUS_RE = r'[45]\d\d'
CODE_RE = '.*' # regexp makes sense in group match
@@ -121,7 +191,7 @@
class BotoTestCase(tempest.test.BaseTestCase):
"""Recommended to use as base class for boto related test."""
- conclusion = tempest.tests.boto.generic_setup_package()
+ conclusion = decision_maker()
@classmethod
def setUpClass(cls):
@@ -130,13 +200,13 @@
cls._resource_trash_bin = {}
cls._sequence = -1
if (hasattr(cls, "EC2") and
- tempest.tests.boto.EC2_CAN_CONNECT_ERROR is not None):
+ cls.conclusion['EC2_CAN_CONNECT_ERROR'] is not None):
raise cls.skipException("EC2 " + cls.__name__ + ": " +
- tempest.tests.boto.EC2_CAN_CONNECT_ERROR)
+ cls.conclusion['EC2_CAN_CONNECT_ERROR'])
if (hasattr(cls, "S3") and
- tempest.tests.boto.S3_CAN_CONNECT_ERROR is not None):
+ cls.conclusion['S3_CAN_CONNECT_ERROR'] is not None):
raise cls.skipException("S3 " + cls.__name__ + ": " +
- tempest.tests.boto.S3_CAN_CONNECT_ERROR)
+ cls.conclusion['S3_CAN_CONNECT_ERROR'])
@classmethod
def addResourceCleanUp(cls, function, *args, **kwargs):
diff --git a/tempest/tests/boto/__init__.py b/tempest/tests/boto/__init__.py
index dd224d6..e69de29 100644
--- a/tempest/tests/boto/__init__.py
+++ b/tempest/tests/boto/__init__.py
@@ -1,94 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2012 OpenStack, LLC
-# 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 logging
-import os
-import re
-import urlparse
-
-import boto.exception
-import keystoneclient.exceptions
-
-import tempest.clients
-from tempest.common.utils.file_utils import have_effective_read_access
-import tempest.config
-
-A_I_IMAGES_READY = True # ari,ami,aki
-S3_CAN_CONNECT_ERROR = None
-EC2_CAN_CONNECT_ERROR = None
-
-
-def generic_setup_package():
- global A_I_IMAGES_READY
- global S3_CAN_CONNECT_ERROR
- global EC2_CAN_CONNECT_ERROR
- secret_matcher = re.compile("[A-Za-z0-9+/]{32,}") # 40 in other system
- id_matcher = re.compile("[A-Za-z0-9]{20,}")
-
- def all_read(*args):
- return all(map(have_effective_read_access, args))
-
- config = tempest.config.TempestConfig()
- materials_path = config.boto.s3_materials_path
- ami_path = materials_path + os.sep + config.boto.ami_manifest
- aki_path = materials_path + os.sep + config.boto.aki_manifest
- ari_path = materials_path + os.sep + config.boto.ari_manifest
-
- A_I_IMAGES_READY = all_read(ami_path, aki_path, ari_path)
- boto_logger = logging.getLogger('boto')
- level = boto_logger.level
- boto_logger.setLevel(logging.CRITICAL) # suppress logging for these
-
- def _cred_sub_check(connection_data):
- if not id_matcher.match(connection_data["aws_access_key_id"]):
- raise Exception("Invalid AWS access Key")
- if not secret_matcher.match(connection_data["aws_secret_access_key"]):
- raise Exception("Invalid AWS secret Key")
- raise Exception("Unknown (Authentication?) Error")
- openstack = tempest.clients.Manager()
- try:
- if urlparse.urlparse(config.boto.ec2_url).hostname is None:
- raise Exception("Failed to get hostname from the ec2_url")
- ec2client = openstack.ec2api_client
- try:
- ec2client.get_all_regions()
- except boto.exception.BotoServerError as exc:
- if exc.error_code is None:
- raise Exception("EC2 target does not looks EC2 service")
- _cred_sub_check(ec2client.connection_data)
-
- except keystoneclient.exceptions.Unauthorized:
- EC2_CAN_CONNECT_ERROR = "AWS credentials not set," +\
- " faild to get them even by keystoneclient"
- except Exception as exc:
- EC2_CAN_CONNECT_ERROR = str(exc)
-
- try:
- if urlparse.urlparse(config.boto.s3_url).hostname is None:
- raise Exception("Failed to get hostname from the s3_url")
- s3client = openstack.s3_client
- try:
- s3client.get_bucket("^INVALID*#()@INVALID.")
- except boto.exception.BotoServerError as exc:
- if exc.status == 403:
- _cred_sub_check(s3client.connection_data)
- except Exception as exc:
- S3_CAN_CONNECT_ERROR = str(exc)
- except keystoneclient.exceptions.Unauthorized:
- S3_CAN_CONNECT_ERROR = "AWS credentials not set," +\
- " faild to get them even by keystoneclient"
- boto_logger.setLevel(level)
diff --git a/tempest/tests/boto/test_ec2_instance_run.py b/tempest/tests/boto/test_ec2_instance_run.py
index 6b61c11..09bfc10 100644
--- a/tempest/tests/boto/test_ec2_instance_run.py
+++ b/tempest/tests/boto/test_ec2_instance_run.py
@@ -17,15 +17,15 @@
import logging
-from boto.exception import EC2ResponseError
+from boto import exception
import testtools
from tempest import clients
from tempest.common.utils.data_utils import rand_name
from tempest.common.utils.linux.remote_client import RemoteClient
+from tempest import exceptions
from tempest.test import attr
from tempest.testboto import BotoTestCase
-import tempest.tests.boto
from tempest.tests.boto.utils.s3 import s3_upload_dir
from tempest.tests.boto.utils.wait import re_search_wait
from tempest.tests.boto.utils.wait import state_wait
@@ -39,7 +39,7 @@
@classmethod
def setUpClass(cls):
super(InstanceRunTest, cls).setUpClass()
- if not tempest.tests.boto.A_I_IMAGES_READY:
+ if not cls.conclusion['A_I_IMAGES_READY']:
raise cls.skipException("".join(("EC2 ", cls.__name__,
": requires ami/aki/ari manifest")))
cls.os = clients.Manager()
@@ -86,7 +86,8 @@
if state != "available":
for _image in cls.images.itervalues():
cls.ec2_client.deregister_image(_image["image_id"])
- raise EC2RegisterImageException(image_id=image["image_id"])
+ raise exceptions.EC2RegisterImageException(image_id=
+ image["image_id"])
@attr(type='smoke')
def test_run_stop_terminate_instance(self):
@@ -129,7 +130,7 @@
instance.update(validate=True)
except ValueError:
pass
- except EC2ResponseError as exc:
+ except exception.EC2ResponseError as exc:
if self.ec2_error_code.\
client.InvalidInstanceID.NotFound.match(exc):
pass
@@ -141,6 +142,7 @@
#NOTE(afazekas): doctored test case,
# with normal validation it would fail
@attr("slow", type='smoke')
+ @testtools.skip("Skipped until the Bug #1117555 is resolved")
def test_integration_1(self):
# EC2 1. integration test (not strict)
image_ami = self.ec2_client.get_image(self.images["ami"]["image_id"])
diff --git a/tempest/tests/boto/test_s3_ec2_images.py b/tempest/tests/boto/test_s3_ec2_images.py
index 1088b00..4068aba 100644
--- a/tempest/tests/boto/test_s3_ec2_images.py
+++ b/tempest/tests/boto/test_s3_ec2_images.py
@@ -23,7 +23,6 @@
from tempest.common.utils.data_utils import rand_name
from tempest.test import attr
from tempest.testboto import BotoTestCase
-import tempest.tests.boto
from tempest.tests.boto.utils.s3 import s3_upload_dir
from tempest.tests.boto.utils.wait import state_wait
@@ -34,7 +33,7 @@
@classmethod
def setUpClass(cls):
super(S3ImagesTest, cls).setUpClass()
- if not tempest.tests.boto.A_I_IMAGES_READY:
+ if not cls.conclusion['A_I_IMAGES_READY']:
raise cls.skipException("".join(("EC2 ", cls.__name__,
": requires ami/aki/ari manifest")))
cls.os = clients.Manager()
diff --git a/tempest/tests/compute/admin/test_quotas.py b/tempest/tests/compute/admin/test_quotas.py
index d63f72f..7430a7c 100644
--- a/tempest/tests/compute/admin/test_quotas.py
+++ b/tempest/tests/compute/admin/test_quotas.py
@@ -152,6 +152,19 @@
#TODO(afazekas): Add test that tried to update the quota_set as a regular user
+ @attr(type='negative')
+ def test_create_server_when_instances_quota_is_full(self):
+ #Once instances quota limit is reached, disallow server creation
+ resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
+ default_instances_quota = quota_set['instances']
+ instances_quota = 0 # Set quota to zero to disallow server creation
+
+ self.adm_client.update_quota_set(self.demo_tenant_id,
+ instances=instances_quota)
+ self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
+ instances=default_instances_quota)
+ self.assertRaises(exceptions.OverLimit, self.create_server)
+
class QuotasAdminTestXML(QuotasAdminTestJSON):
_interface = 'xml'
diff --git a/tempest/tests/compute/base.py b/tempest/tests/compute/base.py
index 2e5b4fe..94fff13 100644
--- a/tempest/tests/compute/base.py
+++ b/tempest/tests/compute/base.py
@@ -173,36 +173,21 @@
cls.clear_isolated_creds()
@classmethod
- def create_server(cls, image_id=None, flavor=None):
+ def create_server(cls, **kwargs):
"""Wrapper utility that returns a test server."""
- server_name = rand_name(cls.__name__ + "-instance")
-
- if not flavor:
- flavor = cls.flavor_ref
- if not image_id:
- image_id = cls.image_ref
+ name = rand_name(cls.__name__ + "-instance")
+ if 'name' in kwargs:
+ name = kwargs.pop('name')
+ flavor = kwargs.get('flavor', cls.flavor_ref)
+ image_id = kwargs.get('image_id', cls.image_ref)
resp, server = cls.servers_client.create_server(
- server_name, image_id, flavor)
- cls.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
- cls.servers.append(server)
- return server
+ name, image_id, flavor, **kwargs)
- @classmethod
- def create_server_with_extras(cls, name, image_id=None,
- flavor=None, **kwargs):
- # TODO(sdague) transitional function because many
- # server tests were using extra args and resp so can't
- # easily be ported to create_server. Will be merged
- # later
- if not flavor:
- flavor = cls.flavor_ref
- if not image_id:
- image_id = cls.image_ref
+ if 'wait_until' in kwargs:
+ cls.servers_client.wait_for_server_status(
+ server['id'], kwargs['wait_until'])
- resp, server = cls.servers_client.create_server(name,
- image_id, flavor,
- **kwargs)
cls.servers.append(server)
return resp, server
diff --git a/tempest/tests/compute/floating_ips/test_floating_ips_actions.py b/tempest/tests/compute/floating_ips/test_floating_ips_actions.py
index ffff1f7..0ff81e1 100644
--- a/tempest/tests/compute/floating_ips/test_floating_ips_actions.py
+++ b/tempest/tests/compute/floating_ips/test_floating_ips_actions.py
@@ -114,42 +114,26 @@
# Negative test:Deletion of a nonexistent floating IP
# from project should fail
- #Deleting the non existent floating IP
- try:
- resp, body = self.client.delete_floating_ip(self.non_exist_id)
- except Exception:
- pass
- else:
- self.fail('Should not be able to delete a nonexistent floating IP')
+ # Deleting the non existent floating IP
+ self.assertRaises(exceptions.NotFound, self.client.delete_floating_ip,
+ self.non_exist_id)
@attr(type='negative')
def test_associate_nonexistant_floating_ip(self):
# Negative test:Association of a non existent floating IP
# to specific server should fail
- #Associating non existent floating IP
- try:
- resp, body = \
- self.client.associate_floating_ip_to_server("0.0.0.0",
- self.server_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to associate'
- ' a nonexistent floating IP')
+ # Associating non existent floating IP
+ self.assertRaises(exceptions.NotFound,
+ self.client.associate_floating_ip_to_server,
+ "0.0.0.0", self.server_id)
@attr(type='negative')
def test_dissociate_nonexistant_floating_ip(self):
# Negative test:Dissociation of a non existent floating IP should fail
- #Dissociating non existent floating IP
- try:
- resp, body = \
- self.client.disassociate_floating_ip_from_server("0.0.0.0",
- self.server_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to dissociate'
- ' a nonexistent floating IP')
+ # Dissociating non existent floating IP
+ self.assertRaises(exceptions.NotFound,
+ self.client.disassociate_floating_ip_from_server,
+ "0.0.0.0", self.server_id)
@attr(type='positive')
def test_associate_already_associated_floating_ip(self):
@@ -171,38 +155,25 @@
self.client.associate_floating_ip_to_server(self.floating_ip,
self.new_server_id)
- #Make sure no longer associated with old server
- try:
- self.client.disassociate_floating_ip_from_server(
- self.floating_ip,
- self.server_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('The floating IP should be associated to the second '
- 'server')
+ self.addCleanup(self.servers_client.delete_server, self.new_server_id)
if (resp['status'] is not None):
- #Dissociation of the floating IP associated in this method
- resp, _ = \
- self.client.disassociate_floating_ip_from_server(
- self.floating_ip,
- self.new_server_id)
- #Deletion of server created in this method
- resp, body = self.servers_client.delete_server(self.new_server_id)
+ self.addCleanup(self.client.disassociate_floating_ip_from_server,
+ self.floating_ip,
+ self.new_server_id)
+
+ # Make sure no longer associated with old server
+ self.assertRaises((exceptions.NotFound,
+ exceptions.UnprocessableEntity),
+ self.client.disassociate_floating_ip_from_server,
+ self.floating_ip, self.server_id)
@attr(type='negative')
def test_associate_ip_to_server_without_passing_floating_ip(self):
# Negative test:Association of empty floating IP to specific server
# should raise NotFound exception
- try:
- resp, body =\
- self.client.associate_floating_ip_to_server('',
- self.server_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Association of floating IP to specific server'
- ' with out passing floating IP should raise BadRequest')
+ self.assertRaises(exceptions.NotFound,
+ self.client.associate_floating_ip_to_server,
+ '', self.server_id)
class FloatingIPsTestXML(FloatingIPsTestJSON):
diff --git a/tempest/tests/compute/floating_ips/test_list_floating_ips.py b/tempest/tests/compute/floating_ips/test_list_floating_ips.py
index 11b9465..b795909 100644
--- a/tempest/tests/compute/floating_ips/test_list_floating_ips.py
+++ b/tempest/tests/compute/floating_ips/test_list_floating_ips.py
@@ -90,14 +90,8 @@
non_exist_id = rand_name('999')
if non_exist_id not in floating_ip_id:
break
- try:
- resp, body = \
- self.client.get_floating_ip_details(non_exist_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to GET the details from a'
- 'nonexistant floating IP')
+ self.assertRaises(exceptions.NotFound,
+ self.client.get_floating_ip_details, non_exist_id)
class FloatingIPDetailsTestXML(FloatingIPDetailsTestJSON):
diff --git a/tempest/tests/compute/images/test_image_metadata.py b/tempest/tests/compute/images/test_image_metadata.py
index fa69395..311ee8e 100644
--- a/tempest/tests/compute/images/test_image_metadata.py
+++ b/tempest/tests/compute/images/test_image_metadata.py
@@ -111,68 +111,41 @@
def test_list_nonexistant_image_metadata(self):
# Negative test: List on nonexistant image
# metadata should not happen
- try:
- resp, resp_metadata = self.client.list_image_metadata(999)
- except exceptions.NotFound:
- pass
- else:
- self.fail('List on nonexistant image metadata should'
- 'not happen')
+ self.assertRaises(exceptions.NotFound, self.client.list_image_metadata,
+ 999)
@attr(type='negative')
def test_update_nonexistant_image_metadata(self):
# Negative test:An update should not happen for a nonexistant image
meta = {'key1': 'alt1', 'key2': 'alt2'}
- try:
- resp, metadata = self.client.update_image_metadata(999, meta)
- except exceptions.NotFound:
- pass
- else:
- self.fail('An update shouldnt happen for nonexistant image')
+ self.assertRaises(exceptions.NotFound,
+ self.client.update_image_metadata, 999, meta)
@attr(type='negative')
def test_get_nonexistant_image_metadata_item(self):
# Negative test: Get on nonexistant image should not happen
- try:
- resp, metadata = self.client.get_image_metadata_item(999, 'key2')
- except exceptions.NotFound:
- pass
- else:
- self.fail('Get on nonexistant image should not happen')
+ self.assertRaises(exceptions.NotFound,
+ self.client.get_image_metadata_item, 999, 'key2')
@attr(type='negative')
def test_set_nonexistant_image_metadata(self):
# Negative test: Metadata should not be set to a nonexistant image
meta = {'key1': 'alt1', 'key2': 'alt2'}
- try:
- resp, meta = self.client.set_image_metadata(999, meta)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Metadata should not be set to a nonexistant image')
+ self.assertRaises(exceptions.NotFound, self.client.set_image_metadata,
+ 999, meta)
@attr(type='negative')
def test_set_nonexistant_image_metadata_item(self):
# Negative test: Metadata item should not be set to a
# nonexistant image
meta = {'key1': 'alt'}
- try:
- resp, body = self.client.set_image_metadata_item(999, 'key1', meta)
- resp, metadata = self.client.list_image_metadata(999)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Metadata item should not be set to a nonexistant image')
+ self.assertRaises(exceptions.NotFound,
+ self.client.set_image_metadata_item, 999, 'key1',
+ meta)
@attr(type='negative')
def test_delete_nonexistant_image_metadata_item(self):
# Negative test: Shouldnt be able to delete metadata
- # item from nonexistant image
- try:
- resp, body = self.client.delete_image_metadata_item(999, 'key1')
- resp, metadata = self.client.list_image_metadata(999)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to delete metadata item from a'
- 'nonexistant image')
+ # item from nonexistant image
+ self.assertRaises(exceptions.NotFound,
+ self.client.delete_image_metadata_item, 999, 'key1')
diff --git a/tempest/tests/compute/images/test_images.py b/tempest/tests/compute/images/test_images.py
index d8d38aa..a61cef6 100644
--- a/tempest/tests/compute/images/test_images.py
+++ b/tempest/tests/compute/images/test_images.py
@@ -51,12 +51,6 @@
def tearDown(self):
"""Terminate test instances created after a test is executed."""
- for server in self.servers:
- resp, body = self.servers_client.delete_server(server['id'])
- if resp['status'] == '204':
- self.servers.remove(server)
- self.servers_client.wait_for_server_termination(server['id'])
-
for image_id in self.image_ids:
self.client.delete_image(image_id)
self.image_ids.remove(image_id)
@@ -65,11 +59,7 @@
@attr(type='negative')
def test_create_image_from_deleted_server(self):
# An image should not be created if the server instance is removed
- server_name = rand_name('server')
- resp, server = self.servers_client.create_server(server_name,
- self.image_ref,
- self.flavor_ref)
- self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(wait_until='ACTIVE')
# Delete server before trying to create server
self.servers_client.delete_server(server['id'])
@@ -114,7 +104,7 @@
@attr(type='negative')
def test_create_image_when_server_is_terminating(self):
# Return an error when creating image of server that is terminating
- server = self.create_server()
+ resp, server = self.create_server(wait_until='ACTIVE')
self.servers_client.delete_server(server['id'])
snapshot_name = rand_name('test-snap-')
@@ -124,11 +114,7 @@
@attr(type='negative')
def test_create_image_when_server_is_building(self):
# Return error when creating an image of a server that is building
- server_name = rand_name('test-vm-')
- resp, server = self.servers_client.create_server(server_name,
- self.image_ref,
- self.flavor_ref)
- self.servers.append(server)
+ resp, server = self.create_server(wait_until='BUILD')
snapshot_name = rand_name('test-snap-')
self.assertRaises(exceptions.Duplicate, self.client.create_image,
server['id'], snapshot_name)
@@ -137,7 +123,7 @@
@attr(type='negative')
def test_create_image_when_server_is_rebooting(self):
# Return error when creating an image of server that is rebooting
- server = self.create_server()
+ resp, server = self.create_server()
self.servers_client.reboot(server['id'], 'HARD')
snapshot_name = rand_name('test-snap-')
@@ -147,40 +133,24 @@
@attr(type='negative')
def test_create_image_specify_uuid_35_characters_or_less(self):
# Return an error if Image ID passed is 35 characters or less
- try:
- snapshot_name = rand_name('test-snap-')
- test_uuid = ('a' * 35)
- self.assertRaises(exceptions.NotFound, self.client.create_image,
- test_uuid, snapshot_name)
- except Exception:
- self.fail("Should return 404 Not Found if server uuid is 35"
- " characters or less")
+ snapshot_name = rand_name('test-snap-')
+ test_uuid = ('a' * 35)
+ self.assertRaises(exceptions.NotFound, self.client.create_image,
+ test_uuid, snapshot_name)
@attr(type='negative')
def test_create_image_specify_uuid_37_characters_or_more(self):
# Return an error if Image ID passed is 37 characters or more
- try:
- snapshot_name = rand_name('test-snap-')
- test_uuid = ('a' * 37)
- self.assertRaises(exceptions.NotFound, self.client.create_image,
- test_uuid, snapshot_name)
- except Exception:
- self.fail("Should return 404 Not Found if server uuid is 37"
- " characters or more")
+ snapshot_name = rand_name('test-snap-')
+ test_uuid = ('a' * 37)
+ self.assertRaises(exceptions.NotFound, self.client.create_image,
+ test_uuid, snapshot_name)
@attr(type='negative')
def test_delete_image_with_invalid_image_id(self):
# An image should not be deleted with invalid image id
- try:
- # Delete an image with invalid image id
- resp, _ = self.client.delete_image('!@$%^&*()')
-
- except exceptions.NotFound:
- pass
-
- else:
- self.fail("DELETE image request should rasie NotFound exception "
- "when requested with invalid image")
+ self.assertRaises(exceptions.NotFound, self.client.delete_image,
+ '!@$%^&*()')
@attr(type='negative')
def test_delete_non_existent_image(self):
@@ -193,44 +163,25 @@
@attr(type='negative')
def test_delete_image_blank_id(self):
# Return an error while trying to delete an image with blank Id
-
- try:
- self.assertRaises(exceptions.NotFound, self.client.delete_image,
- '')
- except Exception:
- self.fail("Did not return HTTP 404 NotFound for blank image id")
+ self.assertRaises(exceptions.NotFound, self.client.delete_image, '')
@attr(type='negative')
def test_delete_image_non_hex_string_id(self):
# Return an error while trying to delete an image with non hex id
-
image_id = '11a22b9-120q-5555-cc11-00ab112223gj'
- try:
- self.assertRaises(exceptions.NotFound, self.client.delete_image,
- image_id)
- except Exception:
- self.fail("Did not return HTTP 404 NotFound for non hex image")
+ self.assertRaises(exceptions.NotFound, self.client.delete_image,
+ image_id)
@attr(type='negative')
def test_delete_image_negative_image_id(self):
# Return an error while trying to delete an image with negative id
-
- try:
- self.assertRaises(exceptions.NotFound, self.client.delete_image,
- -1)
- except Exception:
- self.fail("Did not return HTTP 404 NotFound for negative image id")
+ self.assertRaises(exceptions.NotFound, self.client.delete_image, -1)
@attr(type='negative')
def test_delete_image_id_is_over_35_character_limit(self):
# Return an error while trying to delete image with id over limit
-
- try:
- self.assertRaises(exceptions.NotFound, self.client.delete_image,
- '11a22b9-120q-5555-cc11-00ab112223gj-3fac')
- except Exception:
- self.fail("Did not return HTTP 404 NotFound for image id that "
- "exceeds 35 character ID length limit")
+ self.assertRaises(exceptions.NotFound, self.client.delete_image,
+ '11a22b9-120q-5555-cc11-00ab112223gj-3fac')
class ImagesTestXML(ImagesTestJSON):
diff --git a/tempest/tests/compute/images/test_images_oneserver.py b/tempest/tests/compute/images/test_images_oneserver.py
index 34ea868..d89b6dd 100644
--- a/tempest/tests/compute/images/test_images_oneserver.py
+++ b/tempest/tests/compute/images/test_images_oneserver.py
@@ -41,7 +41,7 @@
super(ImagesOneServerTestJSON, cls).setUpClass()
cls.client = cls.images_client
cls.servers_client = cls.servers_client
- cls.server = cls.create_server()
+ resp, cls.server = cls.create_server(wait_until='ACTIVE')
cls.image_ids = []
@@ -61,40 +61,28 @@
@testtools.skip("Until Bug 1006725 is fixed")
def test_create_image_specify_multibyte_character_image_name(self):
# Return an error if the image name has multi-byte characters
- try:
- snapshot_name = rand_name('\xef\xbb\xbf')
- self.assertRaises(exceptions.BadRequest,
- self.client.create_image, self.server['id'],
- snapshot_name)
- except Exception:
- self.fail("Should return 400 Bad Request if multi byte characters"
- " are used for image name")
+ snapshot_name = rand_name('\xef\xbb\xbf')
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_image, self.server['id'],
+ snapshot_name)
@attr(type='negative')
@testtools.skip("Until Bug 1005423 is fixed")
def test_create_image_specify_invalid_metadata(self):
# Return an error when creating image with invalid metadata
- try:
- snapshot_name = rand_name('test-snap-')
- meta = {'': ''}
- self.assertRaises(exceptions.BadRequest, self.client.create_image,
- self.server['id'], snapshot_name, meta)
-
- except Exception:
- self.fail("Should raise 400 Bad Request if meta data is invalid")
+ snapshot_name = rand_name('test-snap-')
+ meta = {'': ''}
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ self.server['id'], snapshot_name, meta)
@attr(type='negative')
@testtools.skip("Until Bug 1005423 is fixed")
def test_create_image_specify_metadata_over_limits(self):
# Return an error when creating image with meta data over 256 chars
- try:
- snapshot_name = rand_name('test-snap-')
- meta = {'a' * 260: 'b' * 260}
- self.assertRaises(exceptions.OverLimit, self.client.create_image,
- self.server['id'], snapshot_name, meta)
-
- except Exception:
- self.fail("Should raise 413 Over Limit if meta data was too long")
+ snapshot_name = rand_name('test-snap-')
+ meta = {'a' * 260: 'b' * 260}
+ self.assertRaises(exceptions.OverLimit, self.client.create_image,
+ self.server['id'], snapshot_name, meta)
@attr(type='negative')
@testtools.skipUnless(compute.MULTI_USER,
@@ -151,38 +139,28 @@
def test_create_second_image_when_first_image_is_being_saved(self):
# Disallow creating another image when first image is being saved
- try:
- # Create first snapshot
- snapshot_name = rand_name('test-snap-')
- resp, body = self.client.create_image(self.server['id'],
- snapshot_name)
- self.assertEqual(202, resp.status)
- image_id = parse_image_id(resp['location'])
- self.image_ids.append(image_id)
+ # Create first snapshot
+ snapshot_name = rand_name('test-snap-')
+ resp, body = self.client.create_image(self.server['id'],
+ snapshot_name)
+ self.assertEqual(202, resp.status)
+ image_id = parse_image_id(resp['location'])
+ self.image_ids.append(image_id)
- # Create second snapshot
- alt_snapshot_name = rand_name('test-snap-')
- self.client.create_image(self.server['id'],
- alt_snapshot_name)
- except exceptions.Duplicate:
- self.client.wait_for_image_status(image_id, 'ACTIVE')
-
- else:
- self.fail("Should not allow creating an image when another image "
- "of the server is still being saved")
+ # Create second snapshot
+ alt_snapshot_name = rand_name('test-snap-')
+ self.assertRaises(exceptions.Duplicate, self.client.create_image,
+ self.server['id'], alt_snapshot_name)
+ self.client.wait_for_image_status(image_id, 'ACTIVE')
@attr(type='negative')
@testtools.skip("Until Bug 1004564 is fixed")
def test_create_image_specify_name_over_256_chars(self):
# Return an error if snapshot name over 256 characters is passed
- try:
- snapshot_name = rand_name('a' * 260)
- self.assertRaises(exceptions.BadRequest, self.client.create_image,
- self.server['id'], snapshot_name)
- except Exception:
- self.fail("Should return 400 Bad Request if image name is over 256"
- " characters")
+ snapshot_name = rand_name('a' * 260)
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ self.server['id'], snapshot_name)
@attr(type='negative')
def test_delete_image_that_is_not_yet_active(self):
diff --git a/tempest/tests/compute/images/test_list_image_filters.py b/tempest/tests/compute/images/test_list_image_filters.py
index 56f388d..472f7fb 100644
--- a/tempest/tests/compute/images/test_list_image_filters.py
+++ b/tempest/tests/compute/images/test_list_image_filters.py
@@ -30,16 +30,10 @@
super(ListImageFiltersTest, cls).setUpClass()
cls.client = cls.images_client
- name = rand_name('server')
- resp, cls.server1 = cls.servers_client.create_server(name,
- cls.image_ref,
- cls.flavor_ref)
- name = rand_name('server')
- resp, cls.server2 = cls.servers_client.create_server(name,
- cls.image_ref,
- cls.flavor_ref)
+ resp, cls.server1 = cls.create_server()
+ resp, cls.server2 = cls.create_server(wait_until='ACTIVE')
+ # NOTE(sdague) this is faster than doing the sync wait_util on both
cls.servers_client.wait_for_server_status(cls.server1['id'], 'ACTIVE')
- cls.servers_client.wait_for_server_status(cls.server2['id'], 'ACTIVE')
# Create images to be used in the filter tests
image1_name = rand_name('image')
@@ -71,8 +65,6 @@
cls.client.delete_image(cls.image1_id)
cls.client.delete_image(cls.image2_id)
cls.client.delete_image(cls.image3_id)
- cls.servers_client.delete_server(cls.server1['id'])
- cls.servers_client.delete_server(cls.server2['id'])
super(ListImageFiltersTest, cls).tearDownClass()
@attr(type='negative')
@@ -233,9 +225,4 @@
@attr(type='negative')
def test_get_nonexistant_image(self):
# Negative test: GET on non existant image should fail
- try:
- resp, image = self.client.get_image(999)
- except Exception:
- pass
- else:
- self.fail('GET on non existant image should fail')
+ self.assertRaises(exceptions.NotFound, self.client.get_image, 999)
diff --git a/tempest/tests/compute/keypairs/test_keypairs.py b/tempest/tests/compute/keypairs/test_keypairs.py
index aefc5ff..b48b439 100644
--- a/tempest/tests/compute/keypairs/test_keypairs.py
+++ b/tempest/tests/compute/keypairs/test_keypairs.py
@@ -134,48 +134,32 @@
# Keypair should not be created with a non RSA public key
k_name = rand_name('keypair-')
pub_key = "ssh-rsa JUNK nova@ubuntu"
- try:
- resp, _ = self.client.create_keypair(k_name, pub_key)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Expected BadRequest for invalid public key')
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_keypair, k_name, pub_key)
@attr(type='negative')
@testtools.skip("Skipped until the Bug #1086980 is resolved")
def test_keypair_delete_nonexistant_key(self):
# Non-existant key deletion should throw a proper error
k_name = rand_name("keypair-non-existant-")
- try:
- resp, _ = self.client.delete_keypair(k_name)
- except exceptions.NotFound:
- pass
- else:
- self.fail('nonexistent key')
+ self.assertRaises(exceptions.NotFound, self.client.delete_keypair,
+ k_name)
@attr(type='negative')
def test_create_keypair_with_empty_public_key(self):
# Keypair should not be created with an empty public key
k_name = rand_name("keypair-")
pub_key = ' '
- try:
- resp, _ = self.client.create_keypair(k_name, pub_key)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Expected BadRequest for empty public key')
+ self.assertRaises(exceptions.BadRequest, self.client.create_keypair,
+ k_name, pub_key)
@attr(type='negative')
def test_create_keypair_when_public_key_bits_exceeds_maximum(self):
# Keypair should not be created when public key bits are too long
k_name = rand_name("keypair-")
pub_key = 'ssh-rsa ' + 'A' * 2048 + ' openstack@ubuntu'
- try:
- resp, _ = self.client.create_keypair(k_name, pub_key)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Expected BadRequest for too long public key')
+ self.assertRaises(exceptions.BadRequest, self.client.create_keypair,
+ k_name, pub_key)
@attr(type='negative')
def test_create_keypair_with_duplicate_name(self):
@@ -184,47 +168,30 @@
resp, _ = self.client.create_keypair(k_name)
self.assertEqual(200, resp.status)
#Now try the same keyname to ceate another key
- try:
- resp, _ = self.client.create_keypair(k_name)
- #Expect a HTTP 409 Conflict Error
- except exceptions.Duplicate:
- pass
- else:
- self.fail('duplicate name')
+ self.assertRaises(exceptions.Duplicate, self.client.create_keypair,
+ k_name)
resp, _ = self.client.delete_keypair(k_name)
self.assertEqual(202, resp.status)
@attr(type='negative')
def test_create_keypair_with_empty_name_string(self):
# Keypairs with name being an empty string should not be created
- try:
- resp, _ = self.client.create_keypair('')
- except exceptions.BadRequest:
- pass
- else:
- self.fail('empty string')
+ self.assertRaises(exceptions.BadRequest, self.client.create_keypair,
+ '')
@attr(type='negative')
def test_create_keypair_with_long_keynames(self):
# Keypairs with name longer than 255 chars should not be created
k_name = 'keypair-'.ljust(260, '0')
- try:
- resp, _ = self.client.create_keypair(k_name)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('too long')
+ self.assertRaises(exceptions.BadRequest, self.client.create_keypair,
+ k_name)
@attr(type='negative')
def test_create_keypair_invalid_name(self):
# Keypairs with name being an invalid name should not be created
k_name = 'key_/.\@:'
- try:
- resp, _ = self.client.create_keypair(k_name)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('invalid name')
+ self.assertRaises(exceptions.BadRequest, self.client.create_keypair,
+ k_name)
class KeyPairsTestXML(KeyPairsTestJSON):
diff --git a/tempest/tests/compute/security_groups/test_security_group_rules.py b/tempest/tests/compute/security_groups/test_security_group_rules.py
index 5063fd3..32ac52b 100644
--- a/tempest/tests/compute/security_groups/test_security_group_rules.py
+++ b/tempest/tests/compute/security_groups/test_security_group_rules.py
@@ -135,21 +135,14 @@
def test_security_group_rules_create_with_invalid_id(self):
# Negative test: Creation of Security Group rule should FAIL
# with invalid Parent group id
- #Adding rules to the invalid Security Group id
+ # Adding rules to the invalid Security Group id
parent_group_id = rand_name('999')
ip_protocol = 'tcp'
from_port = 22
to_port = 22
- try:
- resp, rule =\
- self.client.create_security_group_rule(parent_group_id,
- ip_protocol,
- from_port, to_port)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Security Group rule should not be created '
- 'with invalid parent group id')
+ self.assertRaises(exceptions.NotFound,
+ self.client.create_security_group_rule,
+ parent_group_id, ip_protocol, from_port, to_port)
@attr(type='negative')
def test_security_group_rules_create_with_invalid_ip_protocol(self):
@@ -165,18 +158,11 @@
ip_protocol = rand_name('999')
from_port = 22
to_port = 22
- try:
- resp, rule =\
- self.client.create_security_group_rule(parent_group_id,
- ip_protocol,
- from_port, to_port)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group rule should not be created '
- 'with invalid ip_protocol')
- #Deleting the Security Group created in this method
- resp, _ = self.client.delete_security_group(securitygroup['id'])
+
+ self.addCleanup(self.client.delete_security_group, securitygroup['id'])
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group_rule,
+ parent_group_id, ip_protocol, from_port, to_port)
@attr(type='negative')
def test_security_group_rules_create_with_invalid_from_port(self):
@@ -192,18 +178,10 @@
ip_protocol = 'tcp'
from_port = rand_name('999')
to_port = 22
- try:
- resp, rule =\
- self.client.create_security_group_rule(parent_group_id,
- ip_protocol,
- from_port, to_port)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group rule should not be created'
- 'with invalid from_port')
- #Deleting the Security Group created in this method
- resp, _ = self.client.delete_security_group(securitygroup['id'])
+ self.addCleanup(self.client.delete_security_group, securitygroup['id'])
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group_rule,
+ parent_group_id, ip_protocol, from_port, to_port)
@attr(type='negative')
def test_security_group_rules_create_with_invalid_to_port(self):
@@ -219,30 +197,18 @@
ip_protocol = 'tcp'
from_port = 22
to_port = rand_name('999')
- try:
- resp, rule =\
- self.client.create_security_group_rule(parent_group_id,
- ip_protocol,
- from_port, to_port)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group rule should not be created'
- 'with invalid from_port')
- #Deleting the Security Group created in this method
- resp, _ = self.client.delete_security_group(securitygroup['id'])
+ self.addCleanup(self.client.delete_security_group, securitygroup['id'])
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group_rule,
+ parent_group_id, ip_protocol, from_port, to_port)
@attr(type='negative')
def test_security_group_rules_delete_with_invalid_id(self):
# Negative test: Deletion of Security Group rule should be FAIL
# with invalid rule id
- try:
- self.client.delete_security_group_rule(rand_name('999'))
- except exceptions.NotFound:
- pass
- else:
- self.fail('Security Group Rule should not be deleted '
- 'with nonexistant rule id')
+ self.assertRaises(exceptions.NotFound,
+ self.client.delete_security_group_rule,
+ rand_name('999'))
class SecurityGroupRulesTestXML(SecurityGroupRulesTestJSON):
diff --git a/tempest/tests/compute/security_groups/test_security_groups.py b/tempest/tests/compute/security_groups/test_security_groups.py
index c086280..e5b0380 100644
--- a/tempest/tests/compute/security_groups/test_security_groups.py
+++ b/tempest/tests/compute/security_groups/test_security_groups.py
@@ -116,100 +116,60 @@
non_exist_id = rand_name('999')
if non_exist_id not in security_group_id:
break
- try:
- resp, body = \
- self.client.get_security_group(non_exist_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to GET the details from a '
- 'nonexistant Security Group')
+ self.assertRaises(exceptions.NotFound, self.client.get_security_group,
+ non_exist_id)
@attr(type='negative')
def test_security_group_create_with_invalid_group_name(self):
# Negative test: Security Group should not be created with group name
# as an empty string/with white spaces/chars more than 255
s_description = rand_name('description-')
- #Create Security Group with empty string as group name
- try:
- resp, _ = self.client.create_security_group("", s_description)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with EMPTY Name')
- #Create Security Group with white space in group name
- try:
- resp, _ = self.client.create_security_group(" ", s_description)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with WHITE SPACE in Name')
- #Create Security Group with group name longer than 255 chars
+ # Create Security Group with empty string as group name
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, "", s_description)
+ # Create Security Group with white space in group name
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, " ",
+ s_description)
+ # Create Security Group with group name longer than 255 chars
s_name = 'securitygroup-'.ljust(260, '0')
- try:
- resp, _ = self.client.create_security_group(s_name, s_description)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with more than 255 chars in Name')
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, s_name,
+ s_description)
@attr(type='negative')
def test_security_group_create_with_invalid_group_description(self):
# Negative test:Security Group should not be created with description
# as an empty string/with white spaces/chars more than 255
s_name = rand_name('securitygroup-')
- #Create Security Group with empty string as description
- try:
- resp, _ = self.client.create_security_group(s_name, "")
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with EMPTY Description')
- #Create Security Group with white space in description
- try:
- resp, _ = self.client.create_security_group(s_name, " ")
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with WHITE SPACE in Description')
- #Create Security Group with group description longer than 255 chars
+ # Create Security Group with empty string as description
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, s_name, "")
+ # Create Security Group with white space in description
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, s_name, " ")
+ # Create Security Group with group description longer than 255 chars
s_description = 'description-'.ljust(260, '0')
- try:
- resp, _ = self.client.create_security_group(s_name, s_description)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with more than 255 chars in Description')
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, s_name,
+ s_description)
@attr(type='negative')
def test_security_group_create_with_duplicate_name(self):
# Negative test:Security Group with duplicate name should not
# be created
- try:
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
- resp, security_group =\
+ s_name = rand_name('securitygroup-')
+ s_description = rand_name('description-')
+ resp, security_group =\
self.client.create_security_group(s_name, s_description)
- self.assertEqual(200, resp.status)
- #Now try the Security Group with the same 'Name'
- try:
- resp, _ =\
- self.client.create_security_group(s_name, s_description)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with duplicate Group Name')
- finally:
- #Delete the Security Group created in this method
- resp, _ = self.client.delete_security_group(security_group['id'])
- self.assertEqual(202, resp.status)
+ self.assertEqual(200, resp.status)
+
+ self.addCleanup(self.client.delete_security_group,
+ security_group['id'])
+ # Now try the Security Group with the same 'Name'
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, s_name,
+ s_description)
@attr(type='negative')
def test_delete_nonexistant_security_group(self):
@@ -223,25 +183,15 @@
non_exist_id = rand_name('999')
if non_exist_id not in security_group_id:
break
- try:
- resp, body = self.client.delete_security_group(non_exist_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to delete a nonexistant '
- 'Security Group')
+ self.assertRaises(exceptions.NotFound,
+ self.client.delete_security_group, non_exist_id)
@attr(type='negative')
def test_delete_security_group_without_passing_id(self):
# Negative test:Deletion of a Security Group with out passing ID
# should Fail
- try:
- resp, body = self.client.delete_security_group('')
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to delete a Security Group'
- 'with out passing ID')
+ self.assertRaises(exceptions.NotFound,
+ self.client.delete_security_group, '')
def test_server_security_groups(self):
# Checks that security groups may be added and linked to a server
diff --git a/tempest/tests/compute/servers/test_create_server.py b/tempest/tests/compute/servers/test_create_server.py
index 3c8aeda..aaab9fa 100644
--- a/tempest/tests/compute/servers/test_create_server.py
+++ b/tempest/tests/compute/servers/test_create_server.py
@@ -46,24 +46,17 @@
personality = [{'path': '/test.txt',
'contents': base64.b64encode(file_contents)}]
cls.client = cls.servers_client
- cli_resp = cls.client.create_server(cls.name,
- cls.image_ref,
- cls.flavor_ref,
- meta=cls.meta,
- accessIPv4=cls.accessIPv4,
- accessIPv6=cls.accessIPv6,
- personality=personality,
- disk_config=cls.disk_config)
+ cli_resp = cls.create_server(name=cls.name,
+ meta=cls.meta,
+ accessIPv4=cls.accessIPv4,
+ accessIPv6=cls.accessIPv6,
+ personality=personality,
+ disk_config=cls.disk_config)
cls.resp, cls.server_initial = cli_resp
cls.password = cls.server_initial['adminPass']
cls.client.wait_for_server_status(cls.server_initial['id'], 'ACTIVE')
resp, cls.server = cls.client.get_server(cls.server_initial['id'])
- @classmethod
- def tearDownClass(cls):
- cls.client.delete_server(cls.server_initial['id'])
- super(ServersTestJSON, cls).tearDownClass()
-
@attr(type='smoke')
def test_create_server_response(self):
# Check that the required fields are returned with values
diff --git a/tempest/tests/compute/servers/test_disk_config.py b/tempest/tests/compute/servers/test_disk_config.py
index 671abf9..3a1ec20 100644
--- a/tempest/tests/compute/servers/test_disk_config.py
+++ b/tempest/tests/compute/servers/test_disk_config.py
@@ -37,14 +37,8 @@
@attr(type='positive')
def test_rebuild_server_with_manual_disk_config(self):
# A server should be rebuilt using the manual disk config option
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name,
- self.image_ref,
- self.flavor_ref,
- disk_config='AUTO')
-
- #Wait for the server to become active
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(disk_config='AUTO',
+ wait_until='ACTIVE')
#Verify the specified attributes are set correctly
resp, server = self.client.get_server(server['id'])
@@ -67,14 +61,8 @@
@attr(type='positive')
def test_rebuild_server_with_auto_disk_config(self):
# A server should be rebuilt using the auto disk config option
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name,
- self.image_ref,
- self.flavor_ref,
- disk_config='MANUAL')
-
- #Wait for the server to become active
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(disk_config='MANUAL',
+ wait_until='ACTIVE')
#Verify the specified attributes are set correctly
resp, server = self.client.get_server(server['id'])
@@ -98,14 +86,8 @@
@testtools.skipUnless(compute.RESIZE_AVAILABLE, 'Resize not available.')
def test_resize_server_from_manual_to_auto(self):
# A server should be resized from manual to auto disk config
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name,
- self.image_ref,
- self.flavor_ref,
- disk_config='MANUAL')
-
- #Wait for the server to become active
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(disk_config='MANUAL',
+ wait_until='ACTIVE')
#Resize with auto option
self.client.resize(server['id'], self.flavor_ref_alt,
@@ -124,14 +106,8 @@
@testtools.skipUnless(compute.RESIZE_AVAILABLE, 'Resize not available.')
def test_resize_server_from_auto_to_manual(self):
# A server should be resized from auto to manual disk config
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name,
- self.image_ref,
- self.flavor_ref,
- disk_config='AUTO')
-
- #Wait for the server to become active
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(disk_config='AUTO',
+ wait_until='ACTIVE')
#Resize with manual option
self.client.resize(server['id'], self.flavor_ref_alt,
diff --git a/tempest/tests/compute/servers/test_list_servers_negative.py b/tempest/tests/compute/servers/test_list_servers_negative.py
index 320f920..01b11e0 100644
--- a/tempest/tests/compute/servers/test_list_servers_negative.py
+++ b/tempest/tests/compute/servers/test_list_servers_negative.py
@@ -78,10 +78,10 @@
cls.existing_fixtures = []
cls.deleted_fixtures = []
for x in xrange(2):
- srv = cls.create_server()
+ resp, srv = cls.create_server()
cls.existing_fixtures.append(srv)
- srv = cls.create_server()
+ resp, srv = cls.create_server()
cls.client.delete_server(srv['id'])
# We ignore errors on termination because the server may
# be put into ERROR status on a quick spawn, then delete,
diff --git a/tempest/tests/compute/servers/test_server_actions.py b/tempest/tests/compute/servers/test_server_actions.py
index bc8e843..5046ec2 100644
--- a/tempest/tests/compute/servers/test_server_actions.py
+++ b/tempest/tests/compute/servers/test_server_actions.py
@@ -257,13 +257,9 @@
def rebuild_servers(cls):
# Destroy any existing server and creates a new one
cls.clear_servers()
- cls.name = rand_name('server')
- resp, server = cls.create_server_with_extras(cls.name,
- cls.image_ref,
- cls.flavor_ref)
+ resp, server = cls.create_server(wait_until='ACTIVE')
cls.server_id = server['id']
cls.password = server['adminPass']
- cls.client.wait_for_server_status(cls.server_id, 'ACTIVE')
class ServerActionsTestXML(ServerActionsTestJSON):
diff --git a/tempest/tests/compute/servers/test_server_addresses.py b/tempest/tests/compute/servers/test_server_addresses.py
index b811d52..c69f68d 100644
--- a/tempest/tests/compute/servers/test_server_addresses.py
+++ b/tempest/tests/compute/servers/test_server_addresses.py
@@ -43,26 +43,15 @@
@attr(type='negative', category='server-addresses')
def test_list_server_addresses_invalid_server_id(self):
# List addresses request should fail if server id not in system
-
- try:
- self.client.list_addresses('999')
- except exceptions.NotFound:
- pass
- else:
- self.fail('The server rebuild for a non existing server should not'
- ' be allowed')
+ self.assertRaises(exceptions.NotFound, self.client.list_addresses,
+ '999')
@attr(type='negative', category='server-addresses')
def test_list_server_addresses_by_network_neg(self):
# List addresses by network should fail if network name not valid
-
- try:
- self.client.list_addresses_by_network(self.server['id'], 'invalid')
- except exceptions.NotFound:
- pass
- else:
- self.fail('The server rebuild for a non existing server should not'
- ' be allowed')
+ self.assertRaises(exceptions.NotFound,
+ self.client.list_addresses_by_network,
+ self.server['id'], 'invalid')
@attr(type='smoke', category='server-addresses')
def test_list_server_addresses(self):
diff --git a/tempest/tests/compute/servers/test_server_metadata.py b/tempest/tests/compute/servers/test_server_metadata.py
index 7896466..4b17fa2 100644
--- a/tempest/tests/compute/servers/test_server_metadata.py
+++ b/tempest/tests/compute/servers/test_server_metadata.py
@@ -83,11 +83,9 @@
for sz in [256, 257, 511, 1023]:
key = "k" * sz
meta = {key: 'data1'}
- name = rand_name('server')
self.assertRaises(exceptions.OverLimit,
- self.create_server_with_extras,
- name, self.image_ref,
- self.flavor_ref, meta=meta)
+ self.create_server,
+ meta=meta)
# no teardown - all creates should fail
@@ -95,11 +93,9 @@
def test_create_metadata_key_error(self):
# Blank key should trigger an error.
meta = {'': 'data1'}
- name = rand_name('server')
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- name, self.image_ref,
- self.flavor_ref, meta=meta)
+ self.create_server,
+ meta=meta)
def test_update_server_metadata(self):
# The server's metadata values should be updated to the
@@ -233,3 +229,12 @@
self.assertRaises(exceptions.OverLimit,
self.client.update_server_metadata,
self.server_id, req_metadata)
+
+ @attr(type='negative')
+ def test_update_all_metadata_field_error(self):
+ # Raise a bad request error for blank key.
+ # set_server_metadata will replace all metadata with new value
+ meta = {'': 'data1'}
+ self.assertRaises(exceptions.BadRequest,
+ self.client.set_server_metadata,
+ self.server_id, meta=meta)
diff --git a/tempest/tests/compute/servers/test_server_personality.py b/tempest/tests/compute/servers/test_server_personality.py
index 816ca76..0bafc2c 100644
--- a/tempest/tests/compute/servers/test_server_personality.py
+++ b/tempest/tests/compute/servers/test_server_personality.py
@@ -35,7 +35,6 @@
def test_personality_files_exceed_limit(self):
# Server creation should fail if greater than the maximum allowed
# number of files are injected into the server.
- name = rand_name('server')
file_contents = 'This is a test file.'
personality = []
max_file_limit = \
@@ -45,9 +44,7 @@
personality.append({'path': path,
'contents': base64.b64encode(file_contents)})
try:
- self.create_server_with_extras(name, self.image_ref,
- self.flavor_ref,
- personality=personality)
+ self.create_server(personality=personality)
except exceptions.OverLimit:
pass
else:
@@ -58,7 +55,6 @@
# Server should be created successfully if maximum allowed number of
# files is injected into the server during creation.
try:
- name = rand_name('server')
file_contents = 'This is a test file.'
max_file_limit = \
@@ -71,9 +67,7 @@
'path': path,
'contents': base64.b64encode(file_contents),
})
- resp, server = self.create_server_with_extras(name, self.image_ref,
- self.flavor_ref,
- personality=person)
+ resp, server = self.create_server(personality=person)
self.assertEqual('202', resp['status'])
#Teardown
diff --git a/tempest/tests/compute/servers/test_servers.py b/tempest/tests/compute/servers/test_servers.py
index a912652..a8d28df 100644
--- a/tempest/tests/compute/servers/test_servers.py
+++ b/tempest/tests/compute/servers/test_servers.py
@@ -35,11 +35,7 @@
try:
server = None
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name, self.image_ref,
- self.flavor_ref,
- adminPass='test'
- 'password')
+ resp, server = self.create_server(adminPass='testpassword')
#Verify the password is set correctly in the response
self.assertEqual('testpassword', server['adminPass'])
@@ -52,19 +48,16 @@
def test_create_with_existing_server_name(self):
# Creating a server with a name that already exists is allowed
+ # TODO(sdague): clear out try, we do cleanup one layer up
try:
id1 = None
id2 = None
server_name = rand_name('server')
- resp, server = self.create_server_with_extras(server_name,
- self.image_ref,
- self.flavor_ref)
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(name=server_name,
+ wait_until='ACTIVE')
id1 = server['id']
- resp, server = self.create_server_with_extras(server_name,
- self.image_ref,
- self.flavor_ref)
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(name=server_name,
+ wait_until='ACTIVE')
id2 = server['id']
self.assertNotEqual(id1, id2, "Did not create a new server")
resp, server = self.client.get_server(id1)
@@ -86,11 +79,7 @@
key_name = rand_name('key')
resp, keypair = self.keypairs_client.create_keypair(key_name)
resp, body = self.keypairs_client.list_keypairs()
- server_name = rand_name('server')
- resp, server = self.create_server_with_extras(server_name,
- self.image_ref,
- self.flavor_ref,
- key_name=key_name)
+ resp, server = self.create_server(key_name=key_name)
self.assertEqual('202', resp['status'])
self.client.wait_for_server_status(server['id'], 'ACTIVE')
resp, server = self.client.get_server(server['id'])
@@ -104,10 +93,7 @@
# The server name should be changed to the the provided value
try:
server = None
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name, self.image_ref,
- self.flavor_ref)
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(wait_until='ACTIVE')
#Update the server with a new name
resp, server = self.client.update_server(server['id'],
@@ -129,10 +115,7 @@
# The server's access addresses should reflect the provided values
try:
server = None
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name, self.image_ref,
- self.flavor_ref)
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(wait_until='ACTIVE')
#Update the IPv4 and IPv6 access addresses
resp, body = self.client.update_server(server['id'],
@@ -153,10 +136,7 @@
def test_delete_server_while_in_building_state(self):
# Delete a server while it's VM state is Building
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name, self.image_ref,
- self.flavor_ref)
- self.client.wait_for_server_status(server['id'], 'BUILD')
+ resp, server = self.create_server(wait_until='BUILD')
resp, _ = self.client.delete_server(server['id'])
self.assertEqual('204', resp['status'])
diff --git a/tempest/tests/compute/servers/test_servers_negative.py b/tempest/tests/compute/servers/test_servers_negative.py
index 80358ec..366b630 100644
--- a/tempest/tests/compute/servers/test_servers_negative.py
+++ b/tempest/tests/compute/servers/test_servers_negative.py
@@ -41,8 +41,8 @@
# Create a server with name parameter empty
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- '', self.image_ref, self.flavor_ref)
+ self.create_server,
+ name='')
@attr(type='negative')
def test_personality_file_contents_not_encoded(self):
@@ -53,8 +53,7 @@
'contents': file_contents}]
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- 'fail', self.image_ref, self.flavor_ref,
+ self.create_server,
personality=person)
@attr(type='negative')
@@ -62,16 +61,16 @@
# Create a server with an unknown image
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- 'fail', -1, self.flavor_ref)
+ self.create_server,
+ image_id=-1)
@attr(type='negative')
def test_create_with_invalid_flavor(self):
# Create a server with an unknown flavor
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- 'fail', self.image_ref, -1)
+ self.create_server,
+ flavor=-1,)
@attr(type='negative')
def test_invalid_access_ip_v4_address(self):
@@ -79,8 +78,7 @@
IPv4 = '1.1.1.1.1.1'
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras, "fail",
- self.image_ref, self.flavor_ref, accessIPv4=IPv4)
+ self.create_server, accessIPv4=IPv4)
@attr(type='negative')
def test_invalid_ip_v6_address(self):
@@ -89,18 +87,13 @@
IPv6 = 'notvalid'
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras, "fail",
- self.image_ref, self.flavor_ref, accessIPv6=IPv6)
+ self.create_server, accessIPv6=IPv6)
@attr(type='negative')
def test_reboot_deleted_server(self):
# Reboot a deleted server
-
- self.name = rand_name('server')
- resp, create_server = self.create_server_with_extras(self.name,
- self.image_ref,
- self.flavor_ref)
- self.server_id = create_server['id']
+ resp, server = self.create_server()
+ self.server_id = server['id']
self.client.delete_server(self.server_id)
self.client.wait_for_server_termination(self.server_id)
self.assertRaises(exceptions.NotFound, self.client.reboot,
@@ -110,11 +103,8 @@
def test_rebuild_deleted_server(self):
# Rebuild a deleted server
- self.name = rand_name('server')
- resp, create_server = self.create_server_with_extras(self.name,
- self.image_ref,
- self.flavor_ref)
- self.server_id = create_server['id']
+ resp, server = self.create_server()
+ self.server_id = server['id']
self.client.delete_server(self.server_id)
self.client.wait_for_server_termination(self.server_id)
@@ -128,8 +118,8 @@
server_name = 12345
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- server_name, self.image_ref, self.flavor_ref)
+ self.create_server,
+ name=server_name)
@attr(type='negative')
def test_create_server_name_length_exceeds_256(self):
@@ -137,19 +127,17 @@
server_name = 'a' * 256
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- server_name, self.image_ref, self.flavor_ref)
+ self.create_server,
+ name=server_name)
@attr(type='negative')
def test_create_with_invalid_network_uuid(self):
# Pass invalid network uuid while creating a server
- server_name = rand_name('server')
networks = [{'fixed_ip': '10.0.1.1', 'uuid': 'a-b-c-d-e-f-g-h-i-j'}]
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- server_name, self.image_ref, self.flavor_ref,
+ self.create_server,
networks=networks)
@attr(type='negative')
@@ -157,21 +145,17 @@
# Pass a non existant keypair while creating a server
key_name = rand_name('key')
- server_name = rand_name('server')
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- server_name, self.image_ref, self.flavor_ref,
+ self.create_server,
key_name=key_name)
@attr(type='negative')
def test_create_server_metadata_exceeds_length_limit(self):
# Pass really long metadata while creating a server
- server_name = rand_name('server')
metadata = {'a': 'b' * 260}
self.assertRaises(exceptions.OverLimit,
- self.create_server_with_extras,
- server_name, self.image_ref, self.flavor_ref,
+ self.create_server,
meta=metadata)
@attr(type='negative')
@@ -252,8 +236,7 @@
security_groups = [{'name': 'does_not_exist'}]
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras, 'fail',
- self.image_ref, self.flavor_ref,
+ self.create_server,
security_groups=security_groups)
@attr(type='negative')
diff --git a/tempest/tests/compute/test_live_block_migration.py b/tempest/tests/compute/test_live_block_migration.py
index 078026a..f2ec753 100644
--- a/tempest/tests/compute/test_live_block_migration.py
+++ b/tempest/tests/compute/test_live_block_migration.py
@@ -22,14 +22,12 @@
from tempest import config
from tempest import exceptions
-from tempest.services.compute.json.hosts_client import HostsClientJSON
-from tempest.services.compute.json.servers_client import ServersClientJSON
from tempest.test import attr
from tempest.tests.compute import base
@attr(category='live-migration')
-class LiveBlockMigrationTest(base.BaseComputeTest):
+class LiveBlockMigrationTest(base.BaseComputeAdminTest):
_interface = 'json'
live_migration_available = (
@@ -42,12 +40,8 @@
def setUpClass(cls):
super(LiveBlockMigrationTest, cls).setUpClass()
- tenant_name = cls.config.compute_admin.tenant_name
- cls.admin_hosts_client = HostsClientJSON(
- *cls._get_client_args(), tenant_name=tenant_name)
-
- cls.admin_servers_client = ServersClientJSON(
- *cls._get_client_args(), tenant_name=tenant_name)
+ cls.admin_hosts_client = cls.os_adm.hosts_client
+ cls.admin_servers_client = cls.os_adm.servers_client
cls.created_server_ids = []
@@ -92,7 +86,7 @@
if 'ACTIVE' == self._get_server_status(server_id):
return server_id
else:
- server = self.create_server()
+ _, server = self.create_server(wait_until="ACTIVE")
server_id = server['id']
self.password = server['adminPass']
self.password = 'password'
@@ -102,7 +96,7 @@
@attr(type='positive')
@testtools.skipIf(not live_migration_available,
'Block Live migration not available')
- def test_001_live_block_migration(self):
+ def test_live_block_migration(self):
# Live block migrate an instance to another host
if len(self._get_compute_hostnames()) < 2:
raise self.skipTest(
@@ -114,11 +108,10 @@
self.servers_client.wait_for_server_status(server_id, 'ACTIVE')
self.assertEquals(target_host, self._get_host_for_server(server_id))
- @attr(type='positive', bug='lp1051881')
@testtools.skip('Until bug 1051881 is dealt with.')
@testtools.skipIf(not live_migration_available,
'Block Live migration not available')
- def test_002_invalid_host_for_migration(self):
+ def test_invalid_host_for_migration(self):
# Migrating to an invalid host should not change the status
server_id = self._get_an_active_server()
diff --git a/tempest/tests/compute/volumes/test_volumes_negative.py b/tempest/tests/compute/volumes/test_volumes_negative.py
index c0fa565..306b93b 100644
--- a/tempest/tests/compute/volumes/test_volumes_negative.py
+++ b/tempest/tests/compute/volumes/test_volumes_negative.py
@@ -39,18 +39,13 @@
non_exist_id = rand_name('999')
if non_exist_id not in volume_id_list:
break
- #Trying to GET a non existant volume
- try:
- resp, body = self.client.get_volume(non_exist_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to GET the details from a '
- 'nonexistant volume')
+ # Trying to GET a non existant volume
+ self.assertRaises(exceptions.NotFound, self.client.get_volume,
+ non_exist_id)
def test_volume_delete_nonexistant_volume_id(self):
# Negative: Should not be able to delete nonexistant Volume
- #Creating nonexistant volume id
+ # Creating nonexistant volume id
volume_id_list = list()
resp, body = self.client.list_volumes()
for i in range(len(body)):
@@ -59,13 +54,9 @@
non_exist_id = rand_name('999')
if non_exist_id not in volume_id_list:
break
- #Trying to DELETE a non existant volume
- try:
- resp, body = self.client.delete_volume(non_exist_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to DELETE a nonexistant volume')
+ # Trying to DELETE a non existant volume
+ self.assertRaises(exceptions.NotFound, self.client.delete_volume,
+ non_exist_id)
def test_create_volume_with_invalid_size(self):
# Negative: Should not be able to create volume with invalid size
diff --git a/tempest/tests/identity/admin/test_roles.py b/tempest/tests/identity/admin/test_roles.py
index 46db4fb..f71bed0 100644
--- a/tempest/tests/identity/admin/test_roles.py
+++ b/tempest/tests/identity/admin/test_roles.py
@@ -20,11 +20,12 @@
from tempest.tests.identity import base
-class RolesTestBase(object):
+class RolesTestJSON(base.BaseIdentityAdminTest):
+ _interface = 'json'
- @staticmethod
+ @classmethod
def setUpClass(cls):
-
+ super(RolesTestJSON, cls).setUpClass()
for _ in xrange(5):
resp, role = cls.client.create_role(rand_name('role-'))
cls.data.roles.append(role)
@@ -37,6 +38,13 @@
role = self.get_role_by_name(self.data.test_role)
return (user, tenant, role)
+ def assert_role_in_role_list(self, role, roles):
+ found = False
+ for user_role in roles:
+ if user_role['id'] == role['id']:
+ found = True
+ self.assertTrue(found, "assigned role was not in list")
+
def test_list_roles(self):
# Return a list of all roles
resp, body = self.client.list_roles()
@@ -87,43 +95,9 @@
role1_id = body.get('id')
self.assertTrue('status' in resp)
self.assertTrue(resp['status'].startswith('2'))
-
- try:
- resp, body = self.client.create_role(role_name)
- # this should raise an exception
- self.fail('Should not be able to create a duplicate role name.'
- ' %s' % role_name)
- except exceptions.Duplicate:
- pass
- self.client.delete_role(role1_id)
-
-
-class RolesTestJSON(base.BaseIdentityAdminTestJSON,
- RolesTestBase):
-
- @classmethod
- def setUpClass(cls):
- super(RolesTestJSON, cls).setUpClass()
- RolesTestBase.setUpClass(cls)
-
-
-class RolesTestXML(base.BaseIdentityAdminTestXML,
- RolesTestBase):
-
- @classmethod
- def setUpClass(cls):
- super(RolesTestXML, cls).setUpClass()
- RolesTestBase.setUpClass(cls)
-
-
-class UserRolesTestBase(RolesTestBase):
-
- def assert_role_in_role_list(self, role, roles):
- found = False
- for user_role in roles:
- if user_role['id'] == role['id']:
- found = True
- self.assertTrue(found, "assigned role was not in list")
+ self.addCleanup(self.client.delete_role, role1_id)
+ self.assertRaises(exceptions.Duplicate, self.client.create_role,
+ role_name)
def test_assign_user_role(self):
# Assign a role to a user on a tenant
@@ -267,17 +241,5 @@
tenant['id'], 'junk-role-aabbcc11')
-class UserRolesTestJSON(RolesTestJSON,
- UserRolesTestBase):
-
- @classmethod
- def setUpClass(cls):
- super(UserRolesTestJSON, cls).setUpClass()
-
-
-class UserRolesTestXML(RolesTestXML,
- UserRolesTestBase):
-
- @classmethod
- def setUpClass(cls):
- super(UserRolesTestXML, cls).setUpClass()
+class RolesTestXML(RolesTestJSON):
+ _interface = 'xml'
diff --git a/tempest/tests/identity/admin/test_services.py b/tempest/tests/identity/admin/test_services.py
index 77c8e83..caf57bd 100644
--- a/tempest/tests/identity/admin/test_services.py
+++ b/tempest/tests/identity/admin/test_services.py
@@ -21,7 +21,8 @@
from tempest.tests.identity import base
-class ServicesTestBase(object):
+class ServicesTestJSON(base.BaseIdentityAdminTest):
+ _interface = 'json'
def test_create_get_delete_service(self):
# GET Service
@@ -91,14 +92,5 @@
self.assertFalse(any(found), 'Services failed to delete')
-class ServicesTestJSON(base.BaseIdentityAdminTestJSON, ServicesTestBase):
- @classmethod
- def setUpClass(cls):
- super(ServicesTestJSON, cls).setUpClass()
-
-
-class ServicesTestXML(base.BaseIdentityAdminTestXML,
- ServicesTestBase):
- @classmethod
- def setUpClass(cls):
- super(ServicesTestXML, cls).setUpClass()
+class ServicesTestXML(ServicesTestJSON):
+ _interface = 'xml'
diff --git a/tempest/tests/identity/admin/test_tenants.py b/tempest/tests/identity/admin/test_tenants.py
index 6385cec..8155eb5 100644
--- a/tempest/tests/identity/admin/test_tenants.py
+++ b/tempest/tests/identity/admin/test_tenants.py
@@ -21,7 +21,8 @@
from tempest.tests.identity import base
-class TenantsTestBase(object):
+class TenantsTestJSON(base.BaseIdentityAdminTest):
+ _interface = 'json'
def test_list_tenants_by_unauthorized_user(self):
# Non-admin user should not be able to list tenants
@@ -150,14 +151,10 @@
self.data.tenants.append(tenant)
tenant1_id = body.get('id')
- try:
- resp, body = self.client.create_tenant(tenant_name)
- # this should have raised an exception
- self.fail('Should not be able to create a duplicate tenant name')
- except exceptions.Duplicate:
- pass
- self.client.delete_tenant(tenant1_id)
- self.data.tenants.remove(tenant)
+ self.addCleanup(self.client.delete_tenant, tenant1_id)
+ self.addCleanup(self.data.tenants.remove, tenant)
+ self.assertRaises(exceptions.Duplicate, self.client.create_tenant,
+ tenant_name)
@attr(type='negative')
def test_create_tenant_by_unauthorized_user(self):
@@ -272,16 +269,5 @@
self.data.tenants.remove(tenant)
-class TenantsTestJSON(base.BaseIdentityAdminTestJSON,
- TenantsTestBase):
-
- @classmethod
- def setUpClass(cls):
- super(TenantsTestJSON, cls).setUpClass()
-
-
-class TenantsTestXML(base.BaseIdentityAdminTestXML, TenantsTestBase):
-
- @classmethod
- def setUpClass(cls):
- super(TenantsTestXML, cls).setUpClass()
+class TenantsTestXML(TenantsTestJSON):
+ _interface = 'xml'
diff --git a/tempest/tests/identity/admin/test_users.py b/tempest/tests/identity/admin/test_users.py
index 67b2517..224272e 100644
--- a/tempest/tests/identity/admin/test_users.py
+++ b/tempest/tests/identity/admin/test_users.py
@@ -23,7 +23,8 @@
from testtools.matchers._basic import Contains
-class UsersTestBase(object):
+class UsersTestJSON(base.BaseIdentityAdminTest):
+ _interface = 'json'
alt_user = rand_name('test_user_')
alt_password = rand_name('pass_')
@@ -338,14 +339,5 @@
'tenant ids %s' % fail)
-class UsersTestJSON(base.BaseIdentityAdminTestJSON,
- UsersTestBase):
- @classmethod
- def setUpClass(cls):
- super(UsersTestJSON, cls).setUpClass()
-
-
-class UsersTestXML(base.BaseIdentityAdminTestXML, UsersTestBase):
- @classmethod
- def setUpClass(cls):
- super(UsersTestXML, cls).setUpClass()
+class UsersTestXML(UsersTestJSON):
+ _interface = 'xml'
diff --git a/tempest/tests/identity/base.py b/tempest/tests/identity/base.py
index 2c4162c..168b2ff 100644
--- a/tempest/tests/identity/base.py
+++ b/tempest/tests/identity/base.py
@@ -21,7 +21,7 @@
import tempest.test
-class BaseIdAdminTest(tempest.test.BaseTestCase):
+class BaseIdentityAdminTest(tempest.test.BaseTestCase):
@classmethod
def setUpClass(cls):
@@ -68,22 +68,6 @@
return role[0]
-class BaseIdentityAdminTestJSON(BaseIdAdminTest):
- @classmethod
- def setUpClass(cls):
- cls._interface = "json"
- super(BaseIdentityAdminTestJSON, cls).setUpClass()
-
-BaseIdentityAdminTest = BaseIdentityAdminTestJSON
-
-
-class BaseIdentityAdminTestXML(BaseIdAdminTest):
- @classmethod
- def setUpClass(cls):
- cls._interface = "xml"
- super(BaseIdentityAdminTestXML, cls).setUpClass()
-
-
class DataGenerator(object):
def __init__(self, client):
diff --git a/tempest/tests/image/test_images.py b/tempest/tests/image/test_images.py
index 6ac852e..84bb650 100644
--- a/tempest/tests/image/test_images.py
+++ b/tempest/tests/image/test_images.py
@@ -16,15 +16,11 @@
# under the License.
import cStringIO as StringIO
-import random
-
-import tempest.test
-
-from tempest.test import attr
-
from tempest import clients
from tempest import exceptions
+import tempest.test
+from tempest.test import attr
class CreateRegisterImagesTest(tempest.test.BaseTestCase):
@@ -47,21 +43,13 @@
@attr(type='negative')
def test_register_with_invalid_container_format(self):
# Negative tests for invalid data supplied to POST /images
- try:
- resp, body = self.client.create_image('test', 'wrong', 'vhd')
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Invalid container format should not be accepted')
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ 'test', 'wrong', 'vhd')
@attr(type='negative')
def test_register_with_invalid_disk_format(self):
- try:
- resp, body = self.client.create_image('test', 'bare', 'wrong')
- except exceptions.BadRequest:
- pass
- else:
- self.fail("Invalid disk format should not be accepted")
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ 'test', 'bare', 'wrong')
@attr(type='image')
def test_register_then_upload(self):
@@ -121,12 +109,27 @@
# We add a few images here to test the listing functionality of
# the images API
- for x in xrange(0, 10):
- # We make even images remote and odd images standard
- if x % 2 == 0:
- cls.created_images.append(cls._create_remote_image(x))
- else:
- cls.created_images.append(cls._create_standard_image(x))
+ img1 = cls._create_remote_image('one', 'bare', 'raw')
+ img2 = cls._create_remote_image('two', 'ami', 'ami')
+ img3 = cls._create_remote_image('dup', 'bare', 'raw')
+ img4 = cls._create_remote_image('dup', 'bare', 'raw')
+ img5 = cls._create_standard_image('1', 'ami', 'ami', 42)
+ img6 = cls._create_standard_image('2', 'ami', 'ami', 142)
+ img7 = cls._create_standard_image('33', 'bare', 'raw', 142)
+ img8 = cls._create_standard_image('33', 'bare', 'raw', 142)
+ cls.created_set = set(cls.created_images)
+ # 4x-4x remote image
+ cls.remote_set = set((img1, img2, img3, img4))
+ cls.standard_set = set((img5, img6, img7, img8))
+ # 5x bare, 3x ami
+ cls.bare_set = set((img1, img3, img4, img7, img8))
+ cls.ami_set = set((img2, img5, img6))
+ # 1x with size 42
+ cls.size42_set = set((img5,))
+ # 3x with size 142
+ cls.size142_set = set((img6, img7, img8))
+ # dup named
+ cls.dup_set = set((img3, img4))
@classmethod
def tearDownClass(cls):
@@ -135,31 +138,36 @@
cls.client.wait_for_resource_deletion(image_id)
@classmethod
- def _create_remote_image(cls, x):
+ def _create_remote_image(cls, name, container_format, disk_format):
"""
Create a new remote image and return the ID of the newly-registered
image
"""
- name = 'New Remote Image %s' % x
- location = 'http://example.com/someimage_%s.iso' % x
- resp, body = cls.client.create_image(name, 'bare', 'raw',
- is_public=True,
- location=location)
- image_id = body['id']
+ name = 'New Remote Image %s' % name
+ location = 'http://example.com/someimage_%s.iso' % name
+ resp, image = cls.client.create_image(name,
+ container_format, disk_format,
+ is_public=True,
+ location=location)
+ image_id = image['id']
+ cls.created_images.append(image_id)
return image_id
@classmethod
- def _create_standard_image(cls, x):
+ def _create_standard_image(cls, name, container_format,
+ disk_format, size):
"""
Create a new standard image and return the ID of the newly-registered
image. Note that the size of the new image is a random number between
1024 and 4096
"""
- image_file = StringIO.StringIO('*' * random.randint(1024, 4096))
- name = 'New Standard Image %s' % x
- resp, body = cls.client.create_image(name, 'bare', 'raw',
- is_public=True, data=image_file)
- image_id = body['id']
+ image_file = StringIO.StringIO('*' * size)
+ name = 'New Standard Image %s' % name
+ resp, image = cls.client.create_image(name,
+ container_format, disk_format,
+ is_public=True, data=image_file)
+ image_id = image['id']
+ cls.created_images.append(image_id)
return image_id
@attr(type='image')
@@ -168,5 +176,69 @@
resp, images_list = self.client.image_list()
self.assertEqual(resp['status'], '200')
image_list = map(lambda x: x['id'], images_list)
- for image in self.created_images:
- self.assertTrue(image in image_list)
+ for image_id in self.created_images:
+ self.assertTrue(image_id in image_list)
+
+ @attr(type='image')
+ def test_index_disk_format(self):
+ resp, images_list = self.client.image_list(disk_format='ami')
+ self.assertEqual(resp['status'], '200')
+ for image in images_list:
+ self.assertEqual(image['disk_format'], 'ami')
+ result_set = set(map(lambda x: x['id'], images_list))
+ self.assertTrue(self.ami_set <= result_set)
+ self.assertFalse(self.created_set - self.ami_set <= result_set)
+
+ @attr(type='image')
+ def test_index_container_format(self):
+ resp, images_list = self.client.image_list(container_format='bare')
+ self.assertEqual(resp['status'], '200')
+ for image in images_list:
+ self.assertEqual(image['container_format'], 'bare')
+ result_set = set(map(lambda x: x['id'], images_list))
+ self.assertTrue(self.bare_set <= result_set)
+ self.assertFalse(self.created_set - self.bare_set <= result_set)
+
+ @attr(type='image')
+ def test_index_max_size(self):
+ resp, images_list = self.client.image_list(size_max=42)
+ self.assertEqual(resp['status'], '200')
+ for image in images_list:
+ self.assertTrue(image['size'] <= 42)
+ result_set = set(map(lambda x: x['id'], images_list))
+ self.assertTrue(self.size42_set <= result_set)
+ self.assertFalse(self.created_set - self.size42_set <= result_set)
+
+ @attr(type='image')
+ def test_index_min_size(self):
+ resp, images_list = self.client.image_list(size_min=142)
+ self.assertEqual(resp['status'], '200')
+ for image in images_list:
+ self.assertTrue(image['size'] >= 142)
+ result_set = set(map(lambda x: x['id'], images_list))
+ self.assertTrue(self.size142_set <= result_set)
+ self.assertFalse(self.size42_set <= result_set)
+
+ @attr(type='image')
+ def test_index_status_active_detail(self):
+ resp, images_list = self.client.image_list_detail(status='active',
+ sort_key='size',
+ sort_dir='desc')
+ self.assertEqual(resp['status'], '200')
+ top_size = images_list[0]['size'] # We have non-zero sized images
+ for image in images_list:
+ size = image['size']
+ self.assertTrue(size <= top_size)
+ top_size = size
+ self.assertEqual(image['status'], 'active')
+
+ @attr(type='image')
+ def test_index_name(self):
+ resp, images_list = self.client.image_list_detail(
+ name='New Remote Image dup')
+ self.assertEqual(resp['status'], '200')
+ result_set = set(map(lambda x: x['id'], images_list))
+ for image in images_list:
+ self.assertEqual(image['name'], 'New Remote Image dup')
+ self.assertTrue(self.dup_set <= result_set)
+ self.assertFalse(self.created_set - self.dup_set <= result_set)
diff --git a/tools/install_venv_common.py b/tools/install_venv_common.py
index 8f91251..fd9076f 100644
--- a/tools/install_venv_common.py
+++ b/tools/install_venv_common.py
@@ -21,20 +21,12 @@
Synced in from openstack-common
"""
+import argparse
import os
import subprocess
import sys
-possible_topdir = os.getcwd()
-if os.path.exists(os.path.join(possible_topdir, "tempest",
- "__init__.py")):
- sys.path.insert(0, possible_topdir)
-
-
-from tempest.openstack.common import cfg
-
-
class InstallVenv(object):
def __init__(self, root, venv, pip_requires, test_requires, py_version,
@@ -139,17 +131,12 @@
def parse_args(self, argv):
"""Parses command-line arguments."""
- cli_opts = [
- cfg.BoolOpt('no-site-packages',
- default=False,
- short='n',
- help="Do not inherit packages from global Python"
- "install"),
- ]
- CLI = cfg.ConfigOpts()
- CLI.register_cli_opts(cli_opts)
- CLI(argv[1:])
- return CLI
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-n', '--no-site-packages',
+ action='store_true',
+ help="Do not inherit packages from global Python "
+ "install")
+ return parser.parse_args(argv[1:])
class Distro(InstallVenv):
diff --git a/tools/pip-requires b/tools/pip-requires
index 5c45a49..220f1a6 100644
--- a/tools/pip-requires
+++ b/tools/pip-requires
@@ -1,7 +1,7 @@
anyjson
nose
httplib2>=0.7.0
-testtools
+testtools>=0.9.29
lxml
boto>=2.2.1
paramiko
diff --git a/tools/test-requires b/tools/test-requires
index d3c7a1e..4801391 100644
--- a/tools/test-requires
+++ b/tools/test-requires
@@ -2,3 +2,5 @@
pylint==0.19
# Needed for whitebox testing
sqlalchemy
+MySQL-python
+psycopg2