summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorGlenn Van de Water <glenn.van_de_water@nuagenetworks.net>2019-03-08 16:31:23 +0100
committerGlenn Van de Water <glenn.van_de_water@nuagenetworks.net>2019-03-13 16:16:24 +0100
commit7741347041b078ca4d687597897194d7797d202d (patch)
treea8f7d26920c0b2d00f55676b90a816663131d77e /openstackclient
parent28c06d06885b3ae93da07eb14411d92c3df7e792 (diff)
downloadpython-openstackclient-7741347041b078ca4d687597897194d7797d202d.tar.gz
Fix service discovery in functional tests
If a required service is not enabled then we skip the test. The discovery is done by tests/functional/base.py:is_service_enabled but this method is broken, credentials are not passed to the 'openstack service show' command so every call will fail and every test that relies on it will be skipped. This commit fixed that method and the issues that popped up when re-enabling tests. Network segment range: - issue where we assumed network-segment-range extension is always present - issue where we compare integers and string representations of numbers Subnet: - issue where we try to deepcopy an uncopyable object in UnsetSubnet Change-Id: Id3cc907c1ed2a25b49cf6f4a7233e0401a02383a Story: 2005169 Task: 29908
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/subnet.py19
-rw-r--r--openstackclient/tests/functional/base.py35
-rw-r--r--openstackclient/tests/functional/common/test_extension.py2
-rw-r--r--openstackclient/tests/functional/common/test_quota.py2
-rw-r--r--openstackclient/tests/functional/compute/v2/test_server.py3
-rw-r--r--openstackclient/tests/functional/network/v2/common.py2
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_segment_range.py14
-rw-r--r--openstackclient/tests/functional/object/v1/common.py2
-rw-r--r--openstackclient/tests/functional/volume/v1/common.py3
9 files changed, 41 insertions, 41 deletions
diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py
index 5f8113bb..0733f37c 100644
--- a/openstackclient/network/v2/subnet.py
+++ b/openstackclient/network/v2/subnet.py
@@ -681,29 +681,30 @@ class UnsetSubnet(command.Command):
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_subnet(parsed_args.subnet, ignore_missing=False)
- tmp_obj = copy.deepcopy(obj)
+
attrs = {}
if parsed_args.dns_nameservers:
- _update_arguments(tmp_obj.dns_nameservers,
+ attrs['dns_nameservers'] = copy.deepcopy(obj.dns_nameservers)
+ _update_arguments(attrs['dns_nameservers'],
parsed_args.dns_nameservers,
'dns-nameserver')
- attrs['dns_nameservers'] = tmp_obj.dns_nameservers
if parsed_args.host_routes:
+ attrs['host_routes'] = copy.deepcopy(obj.host_routes)
_update_arguments(
- tmp_obj.host_routes,
+ attrs['host_routes'],
convert_entries_to_nexthop(parsed_args.host_routes),
'host-route')
- attrs['host_routes'] = tmp_obj.host_routes
if parsed_args.allocation_pools:
- _update_arguments(tmp_obj.allocation_pools,
+ attrs['allocation_pools'] = copy.deepcopy(obj.allocation_pools)
+ _update_arguments(attrs['allocation_pools'],
parsed_args.allocation_pools,
'allocation-pool')
- attrs['allocation_pools'] = tmp_obj.allocation_pools
+
if parsed_args.service_types:
- _update_arguments(tmp_obj.service_types,
+ attrs['service_types'] = copy.deepcopy(obj.service_types)
+ _update_arguments(attrs['service_types'],
parsed_args.service_types,
'service-type')
- attrs['service_types'] = tmp_obj.service_types
if attrs:
client.update_subnet(obj, **attrs)
diff --git a/openstackclient/tests/functional/base.py b/openstackclient/tests/functional/base.py
index 7705c655..1414e6bb 100644
--- a/openstackclient/tests/functional/base.py
+++ b/openstackclient/tests/functional/base.py
@@ -11,7 +11,6 @@
# under the License.
import os
-import re
import shlex
import subprocess
@@ -30,8 +29,6 @@ ADMIN_CLOUD = os.environ.get('OS_ADMIN_CLOUD', 'devstack-admin')
def execute(cmd, fail_ok=False, merge_stderr=False):
"""Executes specified command for the given action."""
cmdlist = shlex.split(cmd)
- result = ''
- result_err = ''
stdout = subprocess.PIPE
stderr = subprocess.STDOUT if merge_stderr else subprocess.PIPE
proc = subprocess.Popen(cmdlist, stdout=stdout, stderr=stderr)
@@ -43,22 +40,8 @@ def execute(cmd, fail_ok=False, merge_stderr=False):
return result
-def is_service_enabled(service):
- """Ask client cloud if service is available"""
- try:
- ret = execute('openstack service show -f value -c enabled ' + service)
- except exceptions.CommandFailed:
- # We get here for multiple reasons, all of them mean that a working
- # service is not available
- return False
-
- return "True" in ret
-
-
class TestCase(testtools.TestCase):
- delimiter_line = re.compile('^\+\-[\+\-]+\-\+$')
-
@classmethod
def openstack(cls, cmd, cloud=ADMIN_CLOUD, fail_ok=False):
"""Executes openstackclient command for the given action."""
@@ -67,6 +50,24 @@ class TestCase(testtools.TestCase):
cmd, fail_ok=fail_ok)
@classmethod
+ def is_service_enabled(cls, service):
+ """Ask client cloud if service is available"""
+ cmd = ('service show -f value -c enabled {service}'
+ .format(service=service))
+ try:
+ return "True" in cls.openstack(cmd)
+ except exceptions.CommandFailed as e:
+ if "No service with a type, name or ID of" in str(e):
+ return False
+ else:
+ raise # Unable to determine if service is enabled
+
+ @classmethod
+ def is_extension_enabled(cls, alias):
+ """Ask client cloud if extension is enabled"""
+ return alias in cls.openstack('extension list -f value -c Alias')
+
+ @classmethod
def get_openstack_configuration_value(cls, configuration):
opts = cls.get_opts([configuration])
return cls.openstack('configuration show ' + opts)
diff --git a/openstackclient/tests/functional/common/test_extension.py b/openstackclient/tests/functional/common/test_extension.py
index db50855f..92efabef 100644
--- a/openstackclient/tests/functional/common/test_extension.py
+++ b/openstackclient/tests/functional/common/test_extension.py
@@ -26,7 +26,7 @@ class ExtensionTests(base.TestCase):
@classmethod
def setUpClass(cls):
super(ExtensionTests, cls).setUpClass()
- cls.haz_network = base.is_service_enabled('network')
+ cls.haz_network = cls.is_service_enabled('network')
def test_extension_list_compute(self):
"""Test compute extension list"""
diff --git a/openstackclient/tests/functional/common/test_quota.py b/openstackclient/tests/functional/common/test_quota.py
index 85942281..9c057460 100644
--- a/openstackclient/tests/functional/common/test_quota.py
+++ b/openstackclient/tests/functional/common/test_quota.py
@@ -27,7 +27,7 @@ class QuotaTests(base.TestCase):
@classmethod
def setUpClass(cls):
super(QuotaTests, cls).setUpClass()
- cls.haz_network = base.is_service_enabled('network')
+ cls.haz_network = cls.is_service_enabled('network')
cls.PROJECT_NAME =\
cls.get_openstack_configuration_value('auth.project_name')
diff --git a/openstackclient/tests/functional/compute/v2/test_server.py b/openstackclient/tests/functional/compute/v2/test_server.py
index 3cb72d9f..c8fb44d3 100644
--- a/openstackclient/tests/functional/compute/v2/test_server.py
+++ b/openstackclient/tests/functional/compute/v2/test_server.py
@@ -16,7 +16,6 @@ import uuid
from tempest.lib import exceptions
-from openstackclient.tests.functional import base
from openstackclient.tests.functional.compute.v2 import common
from openstackclient.tests.functional.volume.v2 import common as volume_common
@@ -27,7 +26,7 @@ class ServerTests(common.ComputeTestCase):
@classmethod
def setUpClass(cls):
super(ServerTests, cls).setUpClass()
- cls.haz_network = base.is_service_enabled('network')
+ cls.haz_network = cls.is_service_enabled('network')
def test_server_list(self):
"""Test server list, set"""
diff --git a/openstackclient/tests/functional/network/v2/common.py b/openstackclient/tests/functional/network/v2/common.py
index a18bc48f..5243ecd0 100644
--- a/openstackclient/tests/functional/network/v2/common.py
+++ b/openstackclient/tests/functional/network/v2/common.py
@@ -22,7 +22,7 @@ class NetworkTests(base.TestCase):
@classmethod
def setUpClass(cls):
super(NetworkTests, cls).setUpClass()
- cls.haz_network = base.is_service_enabled('network')
+ cls.haz_network = cls.is_service_enabled('network')
class NetworkTagTests(NetworkTests):
diff --git a/openstackclient/tests/functional/network/v2/test_network_segment_range.py b/openstackclient/tests/functional/network/v2/test_network_segment_range.py
index 95402dcb..c42f8744 100644
--- a/openstackclient/tests/functional/network/v2/test_network_segment_range.py
+++ b/openstackclient/tests/functional/network/v2/test_network_segment_range.py
@@ -28,6 +28,8 @@ class NetworkSegmentRangeTests(common.NetworkTests):
# Nothing in this class works with Nova Network
if not self.haz_network:
self.skipTest("No Network service present")
+ if not self.is_extension_enabled('network-segment-range'):
+ self.skipTest("No network-segment-range extension present")
self.PROJECT_NAME = uuid.uuid4().hex
def test_network_segment_range_create_delete(self):
@@ -83,7 +85,7 @@ class NetworkSegmentRangeTests(common.NetworkTests):
)
json_output = json.loads(self.openstack(
- 'network segment list -f json'
+ 'network segment range list -f json'
))
item_map = {
item.get('ID'): item.get('Name') for item in json_output
@@ -117,13 +119,11 @@ class NetworkSegmentRangeTests(common.NetworkTests):
json_output["project_id"],
)
- new_minimum = '2010'
- new_maximum = '2060'
+ new_minimum = 2010
+ new_maximum = 2060
cmd_output = self.openstack(
- 'network segment range set ' +
- '--minimum ' + new_minimum + ' ' +
- '--maximum ' + new_maximum + ' ' +
- name
+ 'network segment range set --minimum {min} --maximum {max} {name}'
+ .format(min=new_minimum, max=new_maximum, name=name)
)
self.assertOutput('', cmd_output)
diff --git a/openstackclient/tests/functional/object/v1/common.py b/openstackclient/tests/functional/object/v1/common.py
index 44771aaa..b0133430 100644
--- a/openstackclient/tests/functional/object/v1/common.py
+++ b/openstackclient/tests/functional/object/v1/common.py
@@ -19,4 +19,4 @@ class ObjectStoreTests(base.TestCase):
@classmethod
def setUpClass(cls):
super(ObjectStoreTests, cls).setUpClass()
- cls.haz_object_store = base.is_service_enabled('object-store')
+ cls.haz_object_store = cls.is_service_enabled('object-store')
diff --git a/openstackclient/tests/functional/volume/v1/common.py b/openstackclient/tests/functional/volume/v1/common.py
index bb3c674e..04eb1f48 100644
--- a/openstackclient/tests/functional/volume/v1/common.py
+++ b/openstackclient/tests/functional/volume/v1/common.py
@@ -12,7 +12,6 @@
import fixtures
-from openstackclient.tests.functional import base
from openstackclient.tests.functional.volume import base as volume_base
@@ -25,7 +24,7 @@ class BaseVolumeTests(volume_base.BaseVolumeTests):
# TODO(dtroyer): This needs to be updated to specifically check for
# Volume v1 rather than just 'volume', but for now
# that is enough until we get proper version negotiation
- cls.haz_volume_v1 = base.is_service_enabled('volume')
+ cls.haz_volume_v1 = cls.is_service_enabled('volume')
def setUp(self):
super(BaseVolumeTests, self).setUp()