diff options
| author | Zuul <zuul@review.openstack.org> | 2019-03-15 15:52:51 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2019-03-15 15:52:51 +0000 |
| commit | 17a2c67de92d0d2bc9650aa0f21766cd2595369e (patch) | |
| tree | 9f087a96e9e96729e1f2e603d202f4461154b66d /openstackclient/tests/functional/base.py | |
| parent | 25ea59e8d0d1d15ef5d044254dc539e72f6df492 (diff) | |
| parent | 7741347041b078ca4d687597897194d7797d202d (diff) | |
| download | python-openstackclient-17a2c67de92d0d2bc9650aa0f21766cd2595369e.tar.gz | |
Merge "Fix service discovery in functional tests"
Diffstat (limited to 'openstackclient/tests/functional/base.py')
| -rw-r--r-- | openstackclient/tests/functional/base.py | 35 |
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) |
