2828
2929def execute (cmd , fail_ok = False , merge_stderr = False ):
3030 """Executes specified command for the given action."""
31- cmd = shlex .split (cmd .encode ('utf-8' ))
31+ cmdlist = shlex .split (cmd .encode ('utf-8' ))
3232 result = ''
3333 result_err = ''
3434 stdout = subprocess .PIPE
3535 stderr = subprocess .STDOUT if merge_stderr else subprocess .PIPE
36- proc = subprocess .Popen (cmd , stdout = stdout , stderr = stderr )
36+ proc = subprocess .Popen (cmdlist , stdout = stdout , stderr = stderr )
3737 result , result_err = proc .communicate ()
3838 if not fail_ok and proc .returncode != 0 :
3939 raise exceptions .CommandFailed (proc .returncode , cmd , result ,
@@ -50,6 +50,33 @@ def openstack(cls, cmd, fail_ok=False):
5050 """Executes openstackclient command for the given action."""
5151 return execute ('openstack ' + cmd , fail_ok = fail_ok )
5252
53+ @classmethod
54+ def get_show_opts (cls , fields = []):
55+ return ' -f value ' + ' ' .join (['-c ' + it for it in fields ])
56+
57+ @classmethod
58+ def get_list_opts (cls , headers = []):
59+ opts = ' -f csv --quote none '
60+ opts = opts + ' ' .join (['-c ' + it for it in headers ])
61+ return opts
62+
63+ @classmethod
64+ def assertOutput (cls , expected , actual ):
65+ if expected != actual :
66+ raise Exception (expected + ' != ' + actual )
67+
68+ @classmethod
69+ def assertInOutput (cls , expected , actual ):
70+ if expected not in actual :
71+ raise Exception (expected + ' not in ' + actual )
72+
73+ @classmethod
74+ def cleanup_tmpfile (cls , filename ):
75+ try :
76+ os .remove (filename )
77+ except OSError :
78+ pass
79+
5380 def assert_table_structure (self , items , field_names ):
5481 """Verify that all items have keys listed in field_names."""
5582 for item in items :
0 commit comments