summaryrefslogtreecommitdiff
path: root/openstackclient/tests/functional/base.py
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/tests/functional/base.py
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/tests/functional/base.py')
-rw-r--r--openstackclient/tests/functional/base.py35
1 files changed, 18 insertions, 17 deletions
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)