Merge "Fix compute baremetal service client tests"
diff --git a/tempest/api/compute/admin/test_keypairs_v210.py b/tempest/api/compute/admin/test_keypairs_v210.py
index dfa7c39..9011433 100644
--- a/tempest/api/compute/admin/test_keypairs_v210.py
+++ b/tempest/api/compute/admin/test_keypairs_v210.py
@@ -32,9 +32,9 @@
key_list = list()
for i in range(2):
k_name = data_utils.rand_name('keypair')
- keypair = self._create_keypair(k_name,
- keypair_type='ssh',
- user_id=user_id)
+ keypair = self.create_keypair(k_name,
+ keypair_type='ssh',
+ user_id=user_id)
self.assertEqual(k_name, keypair['name'],
"The created keypair name is not equal "
"to the requested name!")
@@ -56,8 +56,7 @@
self.assertEqual(user_id, keypair_detail['user_id'],
"The fetched keypair is not for requested user!")
# Create a admin keypair
- admin_k_name = data_utils.rand_name('keypair')
- admin_keypair = self._create_keypair(admin_k_name, keypair_type='ssh')
+ admin_keypair = self.create_keypair(keypair_type='ssh')
admin_keypair.pop('private_key', None)
admin_keypair.pop('user_id')
diff --git a/tempest/api/compute/keypairs/base.py b/tempest/api/compute/keypairs/base.py
index ad7f958..21f504b 100644
--- a/tempest/api/compute/keypairs/base.py
+++ b/tempest/api/compute/keypairs/base.py
@@ -14,6 +14,7 @@
# under the License.
from tempest.api.compute import base
+from tempest.common.utils import data_utils
class BaseKeypairTest(base.BaseV2ComputeTest):
@@ -27,9 +28,12 @@
def _delete_keypair(self, keypair_name, **params):
self.client.delete_keypair(keypair_name, **params)
- def _create_keypair(self, keypair_name,
- pub_key=None, keypair_type=None,
- user_id=None):
+ def create_keypair(self, keypair_name=None,
+ pub_key=None, keypair_type=None,
+ user_id=None):
+ if keypair_name is None:
+ keypair_name = data_utils.rand_name(
+ self.__class__.__name__ + '-keypair')
kwargs = {'name': keypair_name}
delete_params = {}
if pub_key:
diff --git a/tempest/api/compute/keypairs/test_keypairs.py b/tempest/api/compute/keypairs/test_keypairs.py
index 562a508..8acc25a 100644
--- a/tempest/api/compute/keypairs/test_keypairs.py
+++ b/tempest/api/compute/keypairs/test_keypairs.py
@@ -27,8 +27,7 @@
# Create 3 keypairs
key_list = list()
for i in range(3):
- k_name = data_utils.rand_name('keypair')
- keypair = self._create_keypair(k_name)
+ keypair = self.create_keypair()
# Need to pop these keys so that our compare doesn't fail later,
# as the keypair dicts from list API doesn't have them.
keypair.pop('private_key')
@@ -51,7 +50,7 @@
def test_keypair_create_delete(self):
# Keypair should be created, verified and deleted
k_name = data_utils.rand_name('keypair')
- keypair = self._create_keypair(k_name)
+ keypair = self.create_keypair(k_name)
private_key = keypair['private_key']
key_name = keypair['name']
self.assertEqual(key_name, k_name,
@@ -64,7 +63,7 @@
def test_get_keypair_detail(self):
# Keypair should be created, Got details by name and deleted
k_name = data_utils.rand_name('keypair')
- self._create_keypair(k_name)
+ self.create_keypair(k_name)
keypair_detail = self.client.show_keypair(k_name)['keypair']
self.assertIn('name', keypair_detail)
self.assertIn('public_key', keypair_detail)
@@ -88,7 +87,7 @@
"LOeB1kYMOBaiUPLQTWXR3JpckqFIQwhIH0zoHlJvZE8hh90"
"XcPojYN56tI0OlrGqojbediJYD0rUsJu4weZpbn8vilb3JuDY+jws"
"snSA8wzBx3A/8y9Pp1B nova@ubuntu")
- keypair = self._create_keypair(k_name, pub_key)
+ keypair = self.create_keypair(k_name, pub_key)
self.assertNotIn('private_key', keypair,
"Field private_key is not empty!")
key_name = keypair['name']
diff --git a/tempest/api/compute/keypairs/test_keypairs_negative.py b/tempest/api/compute/keypairs/test_keypairs_negative.py
index 2a6139b..f5ffa19 100644
--- a/tempest/api/compute/keypairs/test_keypairs_negative.py
+++ b/tempest/api/compute/keypairs/test_keypairs_negative.py
@@ -25,10 +25,9 @@
@test.idempotent_id('29cca892-46ae-4d48-bc32-8fe7e731eb81')
def test_keypair_create_with_invalid_pub_key(self):
# Keypair should not be created with a non RSA public key
- k_name = data_utils.rand_name('keypair')
pub_key = "ssh-rsa JUNK nova@ubuntu"
self.assertRaises(lib_exc.BadRequest,
- self._create_keypair, k_name, pub_key)
+ self.create_keypair, pub_key=pub_key)
@test.attr(type=['negative'])
@test.idempotent_id('7cc32e47-4c42-489d-9623-c5e2cb5a2fa5')
@@ -42,19 +41,17 @@
@test.idempotent_id('dade320e-69ca-42a9-ba4a-345300f127e0')
def test_create_keypair_with_empty_public_key(self):
# Keypair should not be created with an empty public key
- k_name = data_utils.rand_name("keypair")
pub_key = ' '
- self.assertRaises(lib_exc.BadRequest, self._create_keypair,
- k_name, pub_key)
+ self.assertRaises(lib_exc.BadRequest, self.create_keypair,
+ pub_key=pub_key)
@test.attr(type=['negative'])
@test.idempotent_id('fc100c19-2926-4b9c-8fdc-d0589ee2f9ff')
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 = data_utils.rand_name("keypair")
pub_key = 'ssh-rsa ' + 'A' * 2048 + ' openstack@ubuntu'
- self.assertRaises(lib_exc.BadRequest, self._create_keypair,
- k_name, pub_key)
+ self.assertRaises(lib_exc.BadRequest, self.create_keypair,
+ pub_key=pub_key)
@test.attr(type=['negative'])
@test.idempotent_id('0359a7f1-f002-4682-8073-0c91e4011b7c')
@@ -63,7 +60,7 @@
k_name = data_utils.rand_name('keypair')
self.client.create_keypair(name=k_name)
# Now try the same keyname to create another key
- self.assertRaises(lib_exc.Conflict, self._create_keypair,
+ self.assertRaises(lib_exc.Conflict, self.create_keypair,
k_name)
self.client.delete_keypair(k_name)
@@ -71,7 +68,7 @@
@test.idempotent_id('1398abe1-4a84-45fb-9294-89f514daff00')
def test_create_keypair_with_empty_name_string(self):
# Keypairs with name being an empty string should not be created
- self.assertRaises(lib_exc.BadRequest, self._create_keypair,
+ self.assertRaises(lib_exc.BadRequest, self.create_keypair,
'')
@test.attr(type=['negative'])
@@ -79,7 +76,7 @@
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')
- self.assertRaises(lib_exc.BadRequest, self._create_keypair,
+ self.assertRaises(lib_exc.BadRequest, self.create_keypair,
k_name)
@test.attr(type=['negative'])
@@ -87,5 +84,5 @@
def test_create_keypair_invalid_name(self):
# Keypairs with name being an invalid name should not be created
k_name = 'key_/.\@:'
- self.assertRaises(lib_exc.BadRequest, self._create_keypair,
+ self.assertRaises(lib_exc.BadRequest, self.create_keypair,
k_name)
diff --git a/tempest/api/compute/keypairs/test_keypairs_v22.py b/tempest/api/compute/keypairs/test_keypairs_v22.py
index 997ef9b..4bd1a40 100644
--- a/tempest/api/compute/keypairs/test_keypairs_v22.py
+++ b/tempest/api/compute/keypairs/test_keypairs_v22.py
@@ -28,7 +28,7 @@
def _test_keypairs_create_list_show(self, keypair_type=None):
k_name = data_utils.rand_name('keypair')
- keypair = self._create_keypair(k_name, keypair_type=keypair_type)
+ keypair = self.create_keypair(k_name, keypair_type=keypair_type)
# Verify whether 'type' is present in keypair create response of
# version 2.2 and it is with default value 'ssh'.
self._check_keypair_type(keypair, keypair_type)
diff --git a/tempest/api/compute/security_groups/base.py b/tempest/api/compute/security_groups/base.py
index f70f6d3..cb18775 100644
--- a/tempest/api/compute/security_groups/base.py
+++ b/tempest/api/compute/security_groups/base.py
@@ -14,6 +14,11 @@
# under the License.
from tempest.api.compute import base
+from tempest.common.utils import data_utils
+from tempest import config
+from tempest import test
+
+CONF = config.CONF
class BaseSecurityGroupsTest(base.BaseV2ComputeTest):
@@ -23,3 +28,11 @@
# A network and a subnet will be created for these tests
cls.set_network_resources(network=True, subnet=True)
super(BaseSecurityGroupsTest, cls).setup_credentials()
+
+ @staticmethod
+ def generate_random_security_group_id():
+ if (CONF.service_available.neutron and
+ test.is_extension_enabled('security-group', 'network')):
+ return data_utils.rand_uuid()
+ else:
+ return data_utils.rand_int_id(start=999)
diff --git a/tempest/api/compute/security_groups/test_security_group_rules_negative.py b/tempest/api/compute/security_groups/test_security_group_rules_negative.py
index 32b3ea3..78c19ca 100644
--- a/tempest/api/compute/security_groups/test_security_group_rules_negative.py
+++ b/tempest/api/compute/security_groups/test_security_group_rules_negative.py
@@ -15,20 +15,9 @@
from tempest.api.compute.security_groups import base
from tempest.common.utils import data_utils
-from tempest import config
from tempest.lib import exceptions as lib_exc
from tempest import test
-CONF = config.CONF
-
-
-def not_existing_id():
- if (CONF.service_available.neutron and
- test.is_extension_enabled('security-group', 'network')):
- return data_utils.rand_uuid()
- else:
- return data_utils.rand_int_id(start=999)
-
class SecurityGroupRulesNegativeTestJSON(base.BaseSecurityGroupsTest):
@@ -44,7 +33,7 @@
# Negative test: Creation of Security Group rule should FAIL
# with non existent Parent group id
# Adding rules to the non existent Security Group id
- parent_group_id = not_existing_id()
+ parent_group_id = self.generate_random_security_group_id()
ip_protocol = 'tcp'
from_port = 22
to_port = 22
@@ -179,7 +168,7 @@
def test_delete_security_group_rule_with_non_existent_id(self):
# Negative test: Deletion of Security Group rule should be FAIL
# with non existent id
- non_existent_rule_id = not_existing_id()
+ non_existent_rule_id = self.generate_random_security_group_id()
self.assertRaises(lib_exc.NotFound,
self.rules_client.delete_security_group_rule,
non_existent_rule_id)
diff --git a/tempest/api/compute/security_groups/test_security_groups_negative.py b/tempest/api/compute/security_groups/test_security_groups_negative.py
index e6abf28..bcada1e 100644
--- a/tempest/api/compute/security_groups/test_security_groups_negative.py
+++ b/tempest/api/compute/security_groups/test_security_groups_negative.py
@@ -37,29 +37,13 @@
super(SecurityGroupsNegativeTestJSON, cls).resource_setup()
cls.neutron_available = CONF.service_available.neutron
- def _generate_a_non_existent_security_group_id(self):
- security_group_id = []
- body = self.client.list_security_groups()['security_groups']
- for i in range(len(body)):
- security_group_id.append(body[i]['id'])
- # Generate a non-existent security group id
- while True:
- if (self.neutron_available and
- test.is_extension_enabled('security-group', 'network')):
- non_exist_id = data_utils.rand_uuid()
- else:
- non_exist_id = data_utils.rand_int_id(start=999)
- if non_exist_id not in security_group_id:
- break
- return non_exist_id
-
@test.attr(type=['negative'])
@test.idempotent_id('673eaec1-9b3e-48ed-bdf1-2786c1b9661c')
@test.services('network')
def test_security_group_get_nonexistent_group(self):
# Negative test:Should not be able to GET the details
# of non-existent Security Group
- non_exist_id = self._generate_a_non_existent_security_group_id()
+ non_exist_id = self.generate_random_security_group_id()
self.assertRaises(lib_exc.NotFound, self.client.show_security_group,
non_exist_id)
@@ -139,7 +123,7 @@
@test.services('network')
def test_delete_nonexistent_security_group(self):
# Negative test:Deletion of a non-existent Security Group should fail
- non_exist_id = self._generate_a_non_existent_security_group_id()
+ non_exist_id = self.generate_random_security_group_id()
self.assertRaises(lib_exc.NotFound,
self.client.delete_security_group, non_exist_id)
@@ -204,7 +188,7 @@
@test.services('network')
def test_update_non_existent_security_group(self):
# Update a non-existent Security Group should Fail
- non_exist_id = self._generate_a_non_existent_security_group_id()
+ non_exist_id = self.generate_random_security_group_id()
s_name = data_utils.rand_name('sg')
s_description = data_utils.rand_name('description')
self.assertRaises(lib_exc.NotFound,
diff --git a/tempest/api/compute/volumes/test_attach_volume.py b/tempest/api/compute/volumes/test_attach_volume.py
index 30549ec..fa465af 100644
--- a/tempest/api/compute/volumes/test_attach_volume.py
+++ b/tempest/api/compute/volumes/test_attach_volume.py
@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-import logging
+from oslo_log import log as logging
import testtools
from tempest.api.compute import base
diff --git a/tempest/config.py b/tempest/config.py
index 68f2667..fe8c175 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -16,7 +16,6 @@
from __future__ import print_function
import functools
-import logging as std_logging
import os
import tempfile
@@ -1199,7 +1198,7 @@
register_opts()
self._set_attrs()
if parse_conf:
- _CONF.log_opt_values(LOG, std_logging.DEBUG)
+ _CONF.log_opt_values(LOG, logging.DEBUG)
class TempestConfigProxy(object):
@@ -1207,14 +1206,14 @@
_path = None
_extra_log_defaults = [
- ('paramiko.transport', std_logging.INFO),
- ('requests.packages.urllib3.connectionpool', std_logging.WARN),
+ ('paramiko.transport', logging.INFO),
+ ('requests.packages.urllib3.connectionpool', logging.WARN),
]
def _fix_log_levels(self):
"""Tweak the oslo log defaults."""
for name, level in self._extra_log_defaults:
- std_logging.getLogger(name).setLevel(level)
+ logging.getLogger(name).logger.setLevel(level)
def __getattr__(self, attr):
if not self._config:
diff --git a/tempest/lib/cli/base.py b/tempest/lib/cli/base.py
index 5d7fbe3..5468a7b 100644
--- a/tempest/lib/cli/base.py
+++ b/tempest/lib/cli/base.py
@@ -13,11 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
-import logging
import os
import shlex
import subprocess
+from oslo_log import log as logging
import six
from tempest.lib import base
diff --git a/tempest/lib/cli/output_parser.py b/tempest/lib/cli/output_parser.py
index c71c7a7..716f374 100644
--- a/tempest/lib/cli/output_parser.py
+++ b/tempest/lib/cli/output_parser.py
@@ -15,9 +15,10 @@
"""Collection of utilities for parsing CLI clients output."""
-import logging
import re
+from oslo_log import log as logging
+
from tempest.lib import exceptions
diff --git a/tempest/lib/common/rest_client.py b/tempest/lib/common/rest_client.py
index 31d2ba5..b49f331 100644
--- a/tempest/lib/common/rest_client.py
+++ b/tempest/lib/common/rest_client.py
@@ -16,7 +16,6 @@
import collections
import email.utils
-import logging as real_logging
import re
import time
@@ -455,7 +454,7 @@
# Also look everything at DEBUG if you want to filter this
# out, don't run at debug.
- if self.LOG.isEnabledFor(real_logging.DEBUG):
+ if self.LOG.isEnabledFor(logging.DEBUG):
self._log_request_full(resp, req_headers, req_body,
resp_body, extra)
diff --git a/tempest/lib/services/clients.py b/tempest/lib/services/clients.py
index ec0aaff..445e8bd 100644
--- a/tempest/lib/services/clients.py
+++ b/tempest/lib/services/clients.py
@@ -17,7 +17,8 @@
import copy
import importlib
import inspect
-import logging
+
+from oslo_log import log as logging
from tempest.lib import auth
from tempest.lib.common.utils import misc
diff --git a/tempest/test_discover/plugins.py b/tempest/test_discover/plugins.py
index e9f59af..abe2b73 100644
--- a/tempest/test_discover/plugins.py
+++ b/tempest/test_discover/plugins.py
@@ -13,8 +13,8 @@
# under the License.
import abc
-import logging
+from oslo_log import log as logging
import six
import stevedore