From 2793331d01d17ff95b5111048c249f7e06ed7f62 Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Thu, 17 Sep 2015 14:45:20 +0300 Subject: [PATCH] Specify api_version for functional tests Most of functional tests are written for V2.0/V2.1 API version, but launched on "latest" compute api version('--os-compute-api-version' flag is not ovveriden + default value of it is "latest"). This patch adds "COMPUTE_API_VERSION" parameter for base TestCase, which sets --os-compute-api-version flag while running "nova" shell. Change-Id: I5d711438addaba5282a15fd2b9dde1800f7d7b91 --- novaclient/tests/functional/base.py | 11 ++++++++--- novaclient/tests/functional/test_fixedips.py | 8 ++------ novaclient/tests/functional/test_instances.py | 2 ++ novaclient/tests/functional/test_keypairs.py | 6 +++--- novaclient/tests/functional/test_quotas.py | 2 ++ novaclient/tests/functional/test_readonly_nova.py | 2 ++ novaclient/tests/functional/test_servers.py | 4 ++++ novaclient/tests/functional/test_volumes_api.py | 2 ++ 8 files changed, 25 insertions(+), 12 deletions(-) diff --git a/novaclient/tests/functional/base.py b/novaclient/tests/functional/base.py index 0f73aff17..b4aca058d 100644 --- a/novaclient/tests/functional/base.py +++ b/novaclient/tests/functional/base.py @@ -70,6 +70,8 @@ class ClientTestBase(testtools.TestCase): * initially just check return codes, and later test command outputs """ + COMPUTE_API_VERSION = None + log_format = ('%(asctime)s %(process)d %(levelname)-8s ' '[%(name)s] %(message)s') @@ -170,9 +172,12 @@ class ClientTestBase(testtools.TestCase): uri=auth_url, cli_dir=cli_dir) - def nova(self, *args, **kwargs): - return self.cli_clients.nova(*args, - **kwargs) + def nova(self, action, flags='', params='', fail_ok=False, + endpoint_type='publicURL', merge_stderr=False): + if self.COMPUTE_API_VERSION: + flags += " --os-compute-api-version %s " % self.COMPUTE_API_VERSION + return self.cli_clients.nova(action, flags, params, fail_ok, + endpoint_type, merge_stderr) def wait_for_volume_status(self, volume, status, timeout=60, poll_interval=1): diff --git a/novaclient/tests/functional/test_fixedips.py b/novaclient/tests/functional/test_fixedips.py index f6983070f..095492470 100644 --- a/novaclient/tests/functional/test_fixedips.py +++ b/novaclient/tests/functional/test_fixedips.py @@ -20,11 +20,7 @@ from novaclient.v2 import shell class TestFixedIPsNovaClient(base.ClientTestBase): """FixedIPs functional tests.""" - API_VERSION = '2.1' - - def nova(self, *args, **kwargs): - flags = '--os-compute-api-version %s ' % self.API_VERSION - return self.cli_clients.nova(flags=flags, *args, **kwargs) + COMPUTE_API_VERSION = '2.1' def _create_server(self): name = self.name_generate(prefix='server') @@ -61,7 +57,7 @@ class TestFixedIPsNovaClient(base.ClientTestBase): class TestFixedIPsNovaClientV24(TestFixedIPsNovaClient): """FixedIPs functional tests for v2.4 nova-api microversion.""" - API_VERSION = '2.4' + COMPUTE_API_VERSION = '2.4' def test_fixedip_get(self): self._test_fixedip_get(expect_reserved=True) diff --git a/novaclient/tests/functional/test_instances.py b/novaclient/tests/functional/test_instances.py index 749f34a79..d512106ec 100644 --- a/novaclient/tests/functional/test_instances.py +++ b/novaclient/tests/functional/test_instances.py @@ -15,6 +15,8 @@ from novaclient.tests.functional import base class TestInstanceCLI(base.ClientTestBase): + COMPUTE_API_VERSION = "2.1" + def test_attach_volume(self): """Test we can attach a volume via the cli. diff --git a/novaclient/tests/functional/test_keypairs.py b/novaclient/tests/functional/test_keypairs.py index 1d5b09e64..f980349bb 100644 --- a/novaclient/tests/functional/test_keypairs.py +++ b/novaclient/tests/functional/test_keypairs.py @@ -23,6 +23,8 @@ class TestKeypairsNovaClient(base.ClientTestBase): """Keypairs functional tests. """ + COMPUTE_API_VERSION = "2.1" + def _serialize_kwargs(self, kwargs): kwargs_pairs = ['--%(key)s %(val)s' % {'key': key.replace('_', '-'), 'val': val} @@ -96,9 +98,7 @@ class TestKeypairsNovaClientV22(TestKeypairsNovaClient): """Keypairs functional tests for v2.2 nova-api microversion. """ - def nova(self, *args, **kwargs): - return self.cli_clients.nova(flags='--os-compute-api-version 2.2 ', - *args, **kwargs) + COMPUTE_API_VERSION = "2.2" def test_create_keypair(self): keypair = super(TestKeypairsNovaClientV22, self).test_create_keypair() diff --git a/novaclient/tests/functional/test_quotas.py b/novaclient/tests/functional/test_quotas.py index cd6392fd5..d0ee710a2 100644 --- a/novaclient/tests/functional/test_quotas.py +++ b/novaclient/tests/functional/test_quotas.py @@ -17,6 +17,8 @@ class TestQuotasNovaClient(base.ClientTestBase): """Nova quotas functional tests. """ + COMPUTE_API_VERSION = "2.1" + _quota_resources = ['instances', 'cores', 'ram', 'floating_ips', 'fixed_ips', 'metadata_items', 'injected_files', 'injected_file_content_bytes', diff --git a/novaclient/tests/functional/test_readonly_nova.py b/novaclient/tests/functional/test_readonly_nova.py index 17cfc3097..d7a183e56 100644 --- a/novaclient/tests/functional/test_readonly_nova.py +++ b/novaclient/tests/functional/test_readonly_nova.py @@ -24,6 +24,8 @@ class SimpleReadOnlyNovaClientTest(base.ClientTestBase): This only exercises client commands that are read only. """ + COMPUTE_API_VERSION = "2.1" + def test_admin_fake_action(self): self.assertRaises(exceptions.CommandFailed, self.nova, diff --git a/novaclient/tests/functional/test_servers.py b/novaclient/tests/functional/test_servers.py index 75be3f472..a29021342 100644 --- a/novaclient/tests/functional/test_servers.py +++ b/novaclient/tests/functional/test_servers.py @@ -20,6 +20,8 @@ class TestServersBootNovaClient(base.ClientTestBase): """Servers boot functional tests. """ + COMPUTE_API_VERSION = "2.1" + def test_boot_server_with_legacy_bdm(self): volume_size = 1 volume_name = str(uuid.uuid4()) @@ -44,6 +46,8 @@ class TestServersListNovaClient(base.ClientTestBase): """Servers list functional tests. """ + COMPUTE_API_VERSION = "2.1" + def _create_servers(self, name, number): network = self.client.networks.list()[0] servers = [] diff --git a/novaclient/tests/functional/test_volumes_api.py b/novaclient/tests/functional/test_volumes_api.py index fcfd9f122..b574ad783 100644 --- a/novaclient/tests/functional/test_volumes_api.py +++ b/novaclient/tests/functional/test_volumes_api.py @@ -32,6 +32,8 @@ def wait_for_delete(test, name, thing, get_func): class TestVolumesAPI(base.ClientTestBase): + COMPUTE_API_VERSION = "2.1" + def test_volumes_snapshots_types_create_get_list_delete(self): # Create a volume volume = self.client.volumes.create(1)