Merge "Tag test_create_server_invalid_bdm_in_2nd_dict as needing cinder"
diff --git a/tempest/api/compute/admin/test_hypervisor.py b/tempest/api/compute/admin/test_hypervisor.py
index 4637024..e0e5a29 100644
--- a/tempest/api/compute/admin/test_hypervisor.py
+++ b/tempest/api/compute/admin/test_hypervisor.py
@@ -104,7 +104,7 @@
try:
uptime = (self.client.show_hypervisor_uptime(hyper['id'])
['hypervisor'])
- if len(uptime) > 0:
+ if uptime:
has_valid_uptime = True
break
except Exception:
diff --git a/tempest/api/compute/servers/test_novnc.py b/tempest/api/compute/servers/test_novnc.py
index 6354c57..90b0665 100644
--- a/tempest/api/compute/servers/test_novnc.py
+++ b/tempest/api/compute/servers/test_novnc.py
@@ -82,7 +82,7 @@
"""Verify we can connect to novnc and do the websocket connection."""
# Turn the Socket into a WebSocket to do the communication
data = self._websocket.receive_frame()
- self.assertFalse(data is None or len(data) == 0,
+ self.assertFalse(data is None or not data,
'Token must be invalid because the connection '
'closed.')
# Parse the RFB version from the data to make sure it is valid
@@ -181,6 +181,6 @@
self._websocket = compute.create_websocket(url)
# Make sure the novncproxy rejected the connection and closed it
data = self._websocket.receive_frame()
- self.assertTrue(data is None or len(data) == 0,
+ self.assertTrue(data is None or not data,
"The novnc proxy actually sent us some data, but we "
"expected it to close the connection.")
diff --git a/tempest/api/compute/test_extensions.py b/tempest/api/compute/test_extensions.py
index f87bf6d..3b41775 100644
--- a/tempest/api/compute/test_extensions.py
+++ b/tempest/api/compute/test_extensions.py
@@ -31,7 +31,7 @@
@decorators.idempotent_id('3bb27738-b759-4e0d-a5fa-37d7a6df07d1')
def test_list_extensions(self):
# List of all extensions
- if len(CONF.compute_feature_enabled.api_extensions) == 0:
+ if not CONF.compute_feature_enabled.api_extensions:
raise self.skipException('There are not any extensions configured')
extensions = self.extensions_client.list_extensions()['extensions']
ext = CONF.compute_feature_enabled.api_extensions[0]
diff --git a/tempest/api/identity/base.py b/tempest/api/identity/base.py
index 9d794b5..06cc120 100644
--- a/tempest/api/identity/base.py
+++ b/tempest/api/identity/base.py
@@ -47,7 +47,7 @@
else:
users = cls.users_client.list_users()['users']
user = [u for u in users if u['name'] == name]
- if len(user) > 0:
+ if user:
return user[0]
@classmethod
@@ -57,14 +57,14 @@
except AttributeError:
tenants = cls.projects_client.list_projects()['projects']
tenant = [t for t in tenants if t['name'] == name]
- if len(tenant) > 0:
+ if tenant:
return tenant[0]
@classmethod
def get_role_by_name(cls, name):
roles = cls.roles_client.list_roles()['roles']
role = [r for r in roles if r['name'] == name]
- if len(role) > 0:
+ if role:
return role[0]
def create_test_user(self, **kwargs):
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index a724dc9..7ceeb50 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -106,7 +106,7 @@
# Clean up metering label rules
# Not all classes in the hierarchy have the client class variable
- if len(cls.metering_label_rules) > 0:
+ if cls.metering_label_rules:
label_rules_client = cls.admin_metering_label_rules_client
for metering_label_rule in cls.metering_label_rules:
test_utils.call_and_ignore_notfound_exc(
diff --git a/tempest/api/volume/test_extensions.py b/tempest/api/volume/test_extensions.py
index 91bfa33..39ce00c 100644
--- a/tempest/api/volume/test_extensions.py
+++ b/tempest/api/volume/test_extensions.py
@@ -32,7 +32,7 @@
# List of all extensions
extensions = (self.volumes_extension_client.list_extensions()
['extensions'])
- if len(CONF.volume_feature_enabled.api_extensions) == 0:
+ if not CONF.volume_feature_enabled.api_extensions:
raise self.skipException('There are not any extensions configured')
extension_list = [extension.get('alias') for extension in extensions]
LOG.debug("Cinder extensions: %s", ','.join(extension_list))
diff --git a/tempest/api/volume/test_volumes_list.py b/tempest/api/volume/test_volumes_list.py
index ea9ddca..9787160 100644
--- a/tempest/api/volume/test_volumes_list.py
+++ b/tempest/api/volume/test_volumes_list.py
@@ -46,7 +46,7 @@
fetched_list = [fieldsgetter(item) for item in fetched_list]
missing_vols = [v for v in expected_list if v not in fetched_list]
- if len(missing_vols) == 0:
+ if not missing_vols:
return
def str_vol(vol):
diff --git a/tempest/cmd/cleanup_service.py b/tempest/cmd/cleanup_service.py
index a632726..f1c0a3e 100644
--- a/tempest/cmd/cleanup_service.py
+++ b/tempest/cmd/cleanup_service.py
@@ -105,7 +105,7 @@
def _filter_by_tenant_id(self, item_list):
if (item_list is None
- or len(item_list) == 0
+ or not item_list
or not hasattr(self, 'tenant_id')
or self.tenant_id is None
or 'tenant_id' not in item_list[0]):
diff --git a/tempest/common/compute.py b/tempest/common/compute.py
index 38daffe..9587ffe 100644
--- a/tempest/common/compute.py
+++ b/tempest/common/compute.py
@@ -258,7 +258,7 @@
while True:
header = self._socket.recv(2)
# If we didn't receive any data, just return None
- if len(header) == 0:
+ if not header:
return None
# We will make the assumption that we are only dealing with
# frames less than 125 bytes here (for the negotiation) and
@@ -313,6 +313,6 @@
self._socket.sendall(reqdata.encode('utf8'))
self.response = data = self._socket.recv(4096)
# Loop through & concatenate all of the data in the response body
- while len(data) > 0 and self.response.find(b'\r\n\r\n') < 0:
+ while data and self.response.find(b'\r\n\r\n') < 0:
data = self._socket.recv(4096)
self.response += data
diff --git a/tempest/common/preprov_creds.py b/tempest/common/preprov_creds.py
index a92d16a..8053cac 100644
--- a/tempest/common/preprov_creds.py
+++ b/tempest/common/preprov_creds.py
@@ -241,7 +241,7 @@
def _get_creds(self, roles=None):
useable_hashes = self._get_match_hash_list(roles)
- if len(useable_hashes) == 0:
+ if not useable_hashes:
msg = 'No users configured for type/roles %s' % roles
raise lib_exc.InvalidCredentials(msg)
free_hash = self._get_free_hash(useable_hashes)
diff --git a/tempest/lib/auth.py b/tempest/lib/auth.py
index 83aa405..ab4308f 100644
--- a/tempest/lib/auth.py
+++ b/tempest/lib/auth.py
@@ -539,18 +539,18 @@
# Select entries with matching service type
service_catalog = [ep for ep in catalog if ep['type'] == service]
- if len(service_catalog) > 0:
+ if service_catalog:
if name is not None:
service_catalog = (
[ep for ep in service_catalog if ep['name'] == name])
- if len(service_catalog) > 0:
+ if service_catalog:
service_catalog = service_catalog[0]['endpoints']
else:
raise exceptions.EndpointNotFound(name)
else:
service_catalog = service_catalog[0]['endpoints']
else:
- if len(catalog) == 0 and service == 'identity':
+ if not catalog and service == 'identity':
# NOTE(andreaf) If there's no catalog at all and the service
# is identity, it's a valid use case. Having a non-empty
# catalog with no identity in it is not valid instead.
@@ -571,13 +571,13 @@
# Filter by endpoint type (interface)
filtered_catalog = [ep for ep in service_catalog if
ep['interface'] == endpoint_type]
- if len(filtered_catalog) == 0:
+ if not filtered_catalog:
# No matching type, keep all and try matching by region at least
filtered_catalog = service_catalog
# Filter by region
filtered_catalog = [ep for ep in filtered_catalog if
ep['region'] == region]
- if len(filtered_catalog) == 0:
+ if not filtered_catalog:
# No matching region (or name), take the first endpoint
filtered_catalog = [service_catalog[0]]
# There should be only one match. If not take the first.
diff --git a/tempest/lib/cli/output_parser.py b/tempest/lib/cli/output_parser.py
index 716f374..2edd5c1 100644
--- a/tempest/lib/cli/output_parser.py
+++ b/tempest/lib/cli/output_parser.py
@@ -114,7 +114,7 @@
label = line
else:
LOG.warning('Invalid line between tables: %s', line)
- if len(table_) > 0:
+ if table_:
LOG.warning('Missing end of table')
return tables_
diff --git a/tempest/lib/exceptions.py b/tempest/lib/exceptions.py
index dea3289..68ce57a 100644
--- a/tempest/lib/exceptions.py
+++ b/tempest/lib/exceptions.py
@@ -32,7 +32,7 @@
except Exception:
# at least get the core message out if something happened
self._error_string = self.message
- if len(args) > 0:
+ if args:
# If there is a non-kwarg parameter, assume it's the error
# message or reason description and tack it on to the end
# of the exception message
diff --git a/tempest/lib/services/clients.py b/tempest/lib/services/clients.py
index 1c8f443..cd3bab0 100644
--- a/tempest/lib/services/clients.py
+++ b/tempest/lib/services/clients.py
@@ -72,15 +72,15 @@
:raise PluginRegistrationException: if a plugin exposes a service_version
already defined by Tempest or another plugin.
- Examples:
+ Examples::
- >>> from tempest import config
- >>> params = {}
- >>> for service_version in available_modules():
- >>> service = service_version.split('.')[0]
- >>> params[service] = config.service_client_config(service)
- >>> service_clients = ServiceClients(creds, identity_uri,
- >>> client_parameters=params)
+ from tempest import config
+ params = {}
+ for service_version in available_modules():
+ service = service_version.split('.')[0]
+ params[service] = config.service_client_config(service)
+ service_clients = ServiceClients(creds, identity_uri,
+ client_parameters=params)
"""
extra_service_versions = set([])
_tempest_modules = set(tempest_modules())
@@ -163,17 +163,17 @@
parameters cannot be deleted.
:raise ImportError if the specified module_path cannot be imported
- Example:
+ Example::
- >>> # Get credentials and an auth_provider
- >>> clients = ClientsFactory(
- >>> module_path='my_service.my_service_clients',
- >>> client_names=['ServiceClient1', 'ServiceClient2'],
- >>> auth_provider=auth_provider,
- >>> service='my_service',
- >>> region='region1')
- >>> my_api_client = clients.MyApiClient()
- >>> my_api_client_region2 = clients.MyApiClient(region='region2')
+ # Get credentials and an auth_provider
+ clients = ClientsFactory(
+ module_path='my_service.my_service_clients',
+ client_names=['ServiceClient1', 'ServiceClient2'],
+ auth_provider=auth_provider,
+ service='my_service',
+ region='region1')
+ my_api_client = clients.MyApiClient()
+ my_api_client_region2 = clients.MyApiClient(region='region2')
"""
# Import the module. If it's not importable, the raised exception
@@ -244,19 +244,19 @@
It hides some of the complexity from the authorization and configuration
layers.
- Examples:
+ Examples::
- >>> # johndoe is a tempest.lib.auth.Credentials type instance
- >>> johndoe_clients = clients.ServiceClients(johndoe, identity_uri)
- >>>
- >>> # List servers in default region
- >>> johndoe_servers_client = johndoe_clients.compute.ServersClient()
- >>> johndoe_servers = johndoe_servers_client.list_servers()
- >>>
- >>> # List servers in Region B
- >>> johndoe_servers_client_B = johndoe_clients.compute.ServersClient(
- >>> region='B')
- >>> johndoe_servers = johndoe_servers_client_B.list_servers()
+ # johndoe is a tempest.lib.auth.Credentials type instance
+ johndoe_clients = clients.ServiceClients(johndoe, identity_uri)
+
+ # List servers in default region
+ johndoe_servers_client = johndoe_clients.compute.ServersClient()
+ johndoe_servers = johndoe_servers_client.list_servers()
+
+ # List servers in Region B
+ johndoe_servers_client_B = johndoe_clients.compute.ServersClient(
+ region='B')
+ johndoe_servers = johndoe_servers_client_B.list_servers()
"""
# NOTE(andreaf) This class does not depend on tempest configuration
@@ -305,14 +305,14 @@
Registry automatically for all service client (Tempest stable ones
and plugins).
- Examples:
+ Examples::
- >>> identity_params = config.service_client_config('identity')
- >>> params = {
- >>> 'identity': identity_params,
- >>> 'compute': {'region': 'region2'}}
- >>> manager = lib_manager.Manager(
- >>> my_creds, identity_uri, client_parameters=params)
+ identity_params = config.service_client_config('identity')
+ params = {
+ 'identity': identity_params,
+ 'compute': {'region': 'region2'}}
+ manager = lib_manager.Manager(
+ my_creds, identity_uri, client_parameters=params)
:param credentials: An instance of `auth.Credentials`
:param identity_uri: URI of the identity API. This should be a
@@ -328,7 +328,6 @@
name, as declared in `service_clients.available_modules()` except
for the version. Values are dictionaries of parameters that are
going to be passed to all clients in the service client module.
-
"""
self._registered_services = set([])
self.credentials = credentials
diff --git a/tempest/lib/services/image/v1/images_client.py b/tempest/lib/services/image/v1/images_client.py
index faafb4a..42f8cf2 100644
--- a/tempest/lib/services/image/v1/images_client.py
+++ b/tempest/lib/services/image/v1/images_client.py
@@ -118,7 +118,7 @@
if 'changes_since' in kwargs:
kwargs['changes-since'] = kwargs.pop('changes_since')
- if len(kwargs) > 0:
+ if kwargs:
url += '?%s' % urllib.urlencode(kwargs)
resp, body = self.get(url)
diff --git a/tempest/test.py b/tempest/test.py
index 8b015cd..10cc1cf 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -126,7 +126,7 @@
'object': CONF.object_storage_feature_enabled.discoverable_apis,
'identity': CONF.identity_feature_enabled.api_extensions
}
- if len(config_dict[service]) == 0:
+ if not config_dict[service]:
return False
if config_dict[service][0] == 'all':
return True
@@ -147,7 +147,7 @@
"""
filters = CONF.compute_feature_enabled.scheduler_available_filters
- if len(filters) == 0:
+ if not filters:
return False
if 'all' in filters:
return True
@@ -621,7 +621,7 @@
"""
if msg is None:
msg = "sequence or collection is not empty: %s" % items
- self.assertEqual(0, len(items), msg)
+ self.assertFalse(items, msg)
def assertNotEmpty(self, items, msg=None):
"""Asserts whether a sequence or collection is not empty
@@ -632,4 +632,4 @@
"""
if msg is None:
msg = "sequence or collection is empty."
- self.assertGreater(len(items), 0, msg)
+ self.assertTrue(items, msg)
diff --git a/tempest/test_discover/plugins.py b/tempest/test_discover/plugins.py
index 613ab92..9f75962 100644
--- a/tempest/test_discover/plugins.py
+++ b/tempest/test_discover/plugins.py
@@ -51,36 +51,37 @@
:param ConfigOpts conf: The conf object that can be used to register
additional options on.
- Example:
- >>> # Config options are defined in a config.py module
- >>> service_option = cfg.BoolOpt(
- >>> "my_service",
- >>> default=True,
- >>> help="Whether or not my service is available")
- >>>
- >>> # Note: as long as the group is listed in get_opt_lists,
- >>> # it will be possible to access its optins in the plugin code
- >>> # via ("-" in the group name are replaces with "_"):
- >>> # CONF.my_service.<option_name>
- >>> my_service_group = cfg.OptGroup(name="my-service",
- >>> title="My service options")
- >>>
- >>> MyServiceGroup = [<list of options>]
- >>> # (...) More groups and options...
- >>>
- >>> # Plugin is implemented in a plugin.py module
- >>> from my_plugin import config as my_config
- >>>
- >>> def register_opts(self, conf):
- >>> conf.register_opt(my_config.service_option,
- >>> group='service_available')
- >>> conf.register_group(my_config.my_service_group)
- >>> conf.register_opts(my_config.MyService +
- >>> my_config.my_service_group)
- >>>
- >>> conf.register_group(my_config.my_service_feature_group)
- >>> conf.register_opts(my_config.MyServiceFeaturesGroup,
- >>> my_config.my_service_feature_group)
+ Example::
+
+ # Config options are defined in a config.py module
+ service_option = cfg.BoolOpt(
+ "my_service",
+ default=True,
+ help="Whether or not my service is available")
+
+ # Note: as long as the group is listed in get_opt_lists,
+ # it will be possible to access its optins in the plugin code
+ # via ("-" in the group name are replaces with "_"):
+ # CONF.my_service.<option_name>
+ my_service_group = cfg.OptGroup(name="my-service",
+ title="My service options")
+
+ MyServiceGroup = [<list of options>]
+ # (...) More groups and options...
+
+ # Plugin is implemented in a plugin.py module
+ from my_plugin import config as my_config
+
+ def register_opts(self, conf):
+ conf.register_opt(my_config.service_option,
+ group='service_available')
+ conf.register_group(my_config.my_service_group)
+ conf.register_opts(my_config.MyService +
+ my_config.my_service_group)
+
+ conf.register_group(my_config.my_service_feature_group)
+ conf.register_opts(my_config.MyServiceFeaturesGroup,
+ my_config.my_service_feature_group)
"""
return
@@ -107,37 +108,41 @@
of `service_clients.ServiceClients.register_service_client_module`.
:rtype: list of dictionaries
- Example:
+ Example implementation with one service client::
- >>> # Example implementation with one service client
- >>> myservice_config = config.service_client_config('myservice')
- >>> params = {
- >>> 'name': 'myservice',
- >>> 'service_version': 'myservice',
- >>> 'module_path': 'myservice_tempest_tests.services',
- >>> 'client_names': ['API1Client', 'API2Client'],
- >>> }
- >>> params.update(myservice_config)
- >>> return [params]
+ def get_service_clients(self):
+ # Example implementation with one service client
+ myservice_config = config.service_client_config('myservice')
+ params = {
+ 'name': 'myservice',
+ 'service_version': 'myservice',
+ 'module_path': 'myservice_tempest_tests.services',
+ 'client_names': ['API1Client', 'API2Client'],
+ }
+ params.update(myservice_config)
+ return [params]
- >>> # Example implementation with two service clients
- >>> foo1_config = config.service_client_config('foo')
- >>> params_foo1 = {
- >>> 'name': 'foo_v1',
- >>> 'service_version': 'foo.v1',
- >>> 'module_path': 'bar_tempest_tests.services.foo.v1',
- >>> 'client_names': ['API1Client', 'API2Client'],
- >>> }
- >>> params_foo1.update(foo_config)
- >>> foo2_config = config.service_client_config('foo')
- >>> params_foo2 = {
- >>> 'name': 'foo_v2',
- >>> 'service_version': 'foo.v2',
- >>> 'module_path': 'bar_tempest_tests.services.foo.v2',
- >>> 'client_names': ['API1Client', 'API2Client'],
- >>> }
- >>> params_foo2.update(foo2_config)
- >>> return [params_foo1, params_foo2]
+ Example implementation with two service clients::
+
+ def get_service_clients(self):
+ # Example implementation with two service clients
+ foo1_config = config.service_client_config('foo')
+ params_foo1 = {
+ 'name': 'foo_v1',
+ 'service_version': 'foo.v1',
+ 'module_path': 'bar_tempest_tests.services.foo.v1',
+ 'client_names': ['API1Client', 'API2Client'],
+ }
+ params_foo1.update(foo_config)
+ foo2_config = config.service_client_config('foo')
+ params_foo2 = {
+ 'name': 'foo_v2',
+ 'service_version': 'foo.v2',
+ 'module_path': 'bar_tempest_tests.services.foo.v2',
+ 'client_names': ['API1Client', 'API2Client'],
+ }
+ params_foo2.update(foo2_config)
+ return [params_foo1, params_foo2]
"""
return []