1111# under the License.
1212
1313import os
14- import re
1514import shlex
1615import subprocess
1716
3029def execute (cmd , fail_ok = False , merge_stderr = False ):
3130 """Executes specified command for the given action."""
3231 cmdlist = shlex .split (cmd )
33- result = ''
34- result_err = ''
3532 stdout = subprocess .PIPE
3633 stderr = subprocess .STDOUT if merge_stderr else subprocess .PIPE
3734 proc = subprocess .Popen (cmdlist , stdout = stdout , stderr = stderr )
@@ -43,29 +40,33 @@ def execute(cmd, fail_ok=False, merge_stderr=False):
4340 return result
4441
4542
46- def is_service_enabled (service ):
47- """Ask client cloud if service is available"""
48- try :
49- ret = execute ('openstack service show -f value -c enabled ' + service )
50- except exceptions .CommandFailed :
51- # We get here for multiple reasons, all of them mean that a working
52- # service is not available
53- return False
54-
55- return "True" in ret
56-
57-
5843class TestCase (testtools .TestCase ):
5944
60- delimiter_line = re .compile ('^\+\-[\+\-]+\-\+$' )
61-
6245 @classmethod
6346 def openstack (cls , cmd , cloud = ADMIN_CLOUD , fail_ok = False ):
6447 """Executes openstackclient command for the given action."""
6548 return execute (
6649 'openstack --os-cloud={cloud} ' .format (cloud = cloud ) +
6750 cmd , fail_ok = fail_ok )
6851
52+ @classmethod
53+ def is_service_enabled (cls , service ):
54+ """Ask client cloud if service is available"""
55+ cmd = ('service show -f value -c enabled {service}'
56+ .format (service = service ))
57+ try :
58+ return "True" in cls .openstack (cmd )
59+ except exceptions .CommandFailed as e :
60+ if "No service with a type, name or ID of" in str (e ):
61+ return False
62+ else :
63+ raise # Unable to determine if service is enabled
64+
65+ @classmethod
66+ def is_extension_enabled (cls , alias ):
67+ """Ask client cloud if extension is enabled"""
68+ return alias in cls .openstack ('extension list -f value -c Alias' )
69+
6970 @classmethod
7071 def get_openstack_configuration_value (cls , configuration ):
7172 opts = cls .get_opts ([configuration ])
0 commit comments