Browse Source

Bay test cleanup

Removed some COE tests that duplicate the functional-api tests.
Consolidated duplicate code around certificates and made BayTest
always create and delete a bay so that the COE api tests can all
work off of a single bay per class.

Change-Id: I2ff7e2fd587657fb4dd171c1470c5bb208c331b5
Closes-Bug: 1544196
changes/17/277217/2
Corey O'Brien 6 years ago
parent
commit
7dff331a96
  1. 2
      magnum/common/docker_utils.py
  2. 43
      magnum/tests/functional/k8s/test_k8s_python_client.py
  3. 19
      magnum/tests/functional/mesos/test_mesos_python_client.py
  4. 111
      magnum/tests/functional/python_client_base.py
  5. 46
      magnum/tests/functional/swarm/test_swarm_python_client.py

2
magnum/common/docker_utils.py

@ -27,7 +27,7 @@ from magnum import objects
docker_opts = [
cfg.StrOpt('docker_remote_api_version',
default='1.17',
default='1.20',
help='Docker remote api version. Override it according to '
'specific docker api version in your environment.'),
cfg.IntOpt('default_timeout',

43
magnum/tests/functional/k8s/test_k8s_python_client.py

@ -12,50 +12,21 @@
from magnum.common.pythonk8sclient.swagger_client import api_client
from magnum.common.pythonk8sclient.swagger_client.apis import apiv_api
from magnum.tests.functional.python_client_base import BayAPITLSTest
from magnum.tests.functional.python_client_base import BayTest
class TestBayModelResource(BayTest):
class TestKubernetesAPIs(BayTest):
coe = 'kubernetes'
baymodel_kwargs = {
"tls_disabled": False,
"network_driver": 'flannel',
"volume_driver": 'cinder',
"fixed_network": '192.168.0.0/24'
}
def test_baymodel_create_and_delete(self):
self._test_baymodel_create_and_delete('test_k8s_baymodel')
class TestBayResource(BayTest):
coe = 'kubernetes'
def test_bay_create_and_delete(self):
baymodel_uuid = self._test_baymodel_create_and_delete(
'test_k8s_baymodel', delete=False, tls_disabled=True)
self._test_bay_create_and_delete('test_k8s_bay', baymodel_uuid)
class TestKubernetesAPIs(BayAPITLSTest):
@classmethod
def setUpClass(cls):
super(TestKubernetesAPIs, cls).setUpClass()
cls.baymodel = cls._create_baymodel('testk8sAPI',
coe='kubernetes',
tls_disabled=False,
network_driver='flannel',
volume_driver='cinder',
fixed_network='192.168.0.0/24',
)
cls.bay = cls._create_bay('testk8sAPI', cls.baymodel.uuid)
config_contents = """[req]
distinguished_name = req_distinguished_name
req_extensions = req_ext
prompt = no
[req_distinguished_name]
CN = Your Name
[req_ext]
extendedKeyUsage = clientAuth
"""
cls._create_tls_ca_files(config_contents)
cls.kube_api_url = cls.cs.bays.get(cls.bay.uuid).api_address
k8s_client = api_client.ApiClient(cls.kube_api_url,
key_file=cls.key_file,

19
magnum/tests/functional/mesos/test_mesos_python_client.py

@ -13,20 +13,13 @@
from magnum.tests.functional.python_client_base import BayTest
class TestBayModelResource(BayTest):
coe = 'mesos'
def test_baymodel_create_and_delete(self):
self._test_baymodel_create_and_delete('test_mesos_baymodel',
network_driver='docker',
volume_driver='rexray')
class TestBayResource(BayTest):
coe = 'mesos'
baymodel_kwargs = {
"tls_disabled": True,
"network_driver": 'docker',
"volume_driver": 'rexray'
}
def test_bay_create_and_delete(self):
baymodel_uuid = self._test_baymodel_create_and_delete(
'test_mesos_baymodel', delete=False, tls_disabled=True,
network_driver='docker', volume_driver='rexray')
self._test_bay_create_and_delete('test_mesos_bay', baymodel_uuid)
pass

111
magnum/tests/functional/python_client_base.py

@ -160,6 +160,17 @@ class BaseMagnumClient(base.TestCase):
def _delete_bay(cls, bay_uuid):
cls.cs.bays.delete(bay_uuid)
try:
cls._wait_on_status(cls.bay,
["CREATE_COMPLETE",
"DELETE_IN_PROGRESS", "CREATE_FAILED"],
["DELETE_FAILED", "DELETE_COMPLETE"])
except exceptions.NotFound:
pass
else:
if cls._show_bay(cls.bay.uuid).status == 'DELETE_FAILED':
raise Exception("bay %s delete failed" % cls.bay.uuid)
def _copy_logs(self, exec_info):
if not self.copy_logs:
return
@ -181,6 +192,39 @@ class BayTest(BaseMagnumClient):
# NOTE (eliqiao) coe should be specified in subclasses
coe = None
baymodel_kwargs = {}
config_contents = """[req]
distinguished_name = req_distinguished_name
req_extensions = req_ext
prompt = no
[req_distinguished_name]
CN = Your Name
[req_ext]
extendedKeyUsage = clientAuth
"""
ca_dir = None
bay = None
baymodel = None
@classmethod
def setUpClass(cls):
super(BayTest, cls).setUpClass()
cls.baymodel = cls._create_baymodel(
cls.__name__, coe=cls.coe, **cls.baymodel_kwargs)
cls.bay = cls._create_bay(cls.__name__, cls.baymodel.uuid)
if not cls.baymodel_kwargs.get('tls_disabled', False):
cls._create_tls_ca_files(cls.config_contents)
@classmethod
def tearDownClass(cls):
if cls.ca_dir:
rmtree_without_raise(cls.ca_dir)
if cls.bay:
cls._delete_bay(cls.bay.uuid)
if cls.baymodel:
cls._delete_baymodel(cls.baymodel.uuid)
super(BayTest, cls).tearDownClass()
def setUp(self):
super(BayTest, self).setUp()
@ -194,73 +238,6 @@ class BayTest(BaseMagnumClient):
if test_timeout > 0:
self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
def _test_baymodel_create_and_delete(self, baymodel_name,
delete=True, **kwargs):
baymodel = self._create_baymodel(baymodel_name, coe=self.coe, **kwargs)
list = [item.uuid for item in self.cs.baymodels.list()]
self.assertIn(baymodel.uuid, list)
if not delete:
return baymodel
else:
self.cs.baymodels.delete(baymodel.uuid)
list = [item.uuid for item in self.cs.baymodels.list()]
self.assertNotIn(baymodel.uuid, list)
def _test_bay_create_and_delete(self, bay_name, baymodel):
# NOTE(eliqiao): baymodel will be deleted after this testing
bay = self._create_bay(bay_name, baymodel.uuid)
list = [item.uuid for item in self.cs.bays.list()]
self.assertIn(bay.uuid, list)
try:
self.assertIn(self.cs.bays.get(bay.uuid).status,
["CREATED", "CREATE_COMPLETE"])
finally:
# Ensure we delete whether the assert above is true or false
self.cs.bays.delete(bay.uuid)
try:
self._wait_on_status(bay,
["CREATE_COMPLETE",
"DELETE_IN_PROGRESS", "CREATE_FAILED"],
["DELETE_FAILED",
"DELETE_COMPLETE"])
except exceptions.NotFound:
# if bay/get fails, the bay has been deleted already
pass
try:
self.cs.baymodels.delete(baymodel.uuid)
except exceptions.BadRequest:
pass
class BayAPITLSTest(BaseMagnumClient):
"""Base class of TLS enabled test case."""
def setUp(self):
super(BayAPITLSTest, self).setUp()
self.addOnException(self._copy_logs)
@classmethod
def tearDownClass(cls):
if cls.ca_dir:
rmtree_without_raise(cls.ca_dir)
cls._delete_bay(cls.bay.uuid)
try:
cls._wait_on_status(cls.bay,
["CREATE_COMPLETE",
"DELETE_IN_PROGRESS", "CREATE_FAILED"],
["DELETE_FAILED", "DELETE_COMPLETE"])
except exceptions.NotFound:
pass
cls._delete_baymodel(cls.baymodel.uuid)
super(BayAPITLSTest, cls).tearDownClass()
@classmethod
def _create_tls_ca_files(cls, client_conf_contents):
"""Creates ca files by client_conf_contents."""

46
magnum/tests/functional/swarm/test_swarm_python_client.py

@ -15,7 +15,6 @@ from requests import exceptions as req_exceptions
import time
from magnum.common import docker_utils
from magnum.tests.functional.python_client_base import BayAPITLSTest
from magnum.tests.functional.python_client_base import BayTest
from magnumclient.openstack.common.apiclient import exceptions
@ -27,49 +26,26 @@ CONF.import_opt('default_timeout', 'magnum.common.docker_utils',
group='docker')
class TestBayModelResource(BayTest):
coe = 'swarm'
def test_baymodel_create_and_delete(self):
self._test_baymodel_create_and_delete(
'test_swarm_baymodel',
network_driver=None,
volume_driver=None)
class TestSwarmAPIs(BayAPITLSTest):
class TestSwarmAPIs(BayTest):
"""This class will cover swarm bay basic functional testing.
Will test all kinds of container action with tls_disabled=False mode.
"""
coe = "swarm"
baymodel_kwargs = {
"tls_disabled": False,
"network_driver": None,
"volume_driver": None,
"fixed_network": '192.168.0.0/24',
"dns_nameserver": '8.8.8.8',
"labels": {}
}
@classmethod
def setUpClass(cls):
super(TestSwarmAPIs, cls).setUpClass()
cls.baymodel = cls._create_baymodel('testSwarmApi',
coe='swarm',
tls_disabled=False,
network_driver=None,
volume_driver=None,
docker_volume_size=3,
labels={},
fixed_network='192.168.0.0/24',
dns_nameserver='8.8.8.8')
cls.bay = cls._create_bay('testSwarmApi', cls.baymodel.uuid)
config_contents = """[req]
distinguished_name = req_distinguished_name
req_extensions = req_ext
prompt = no
[req_distinguished_name]
CN = Your Name
[req_ext]
extendedKeyUsage = clientAuth
"""
url = cls.cs.bays.get(cls.bay.uuid).api_address
cls._create_tls_ca_files(config_contents)
# Note(eliqiao): docker_utils.CONF.docker.default_timeout is 10,
# tested this default configure option not works on gate, it will

Loading…
Cancel
Save