adding execute method

This commit is contained in:
yolanda.robla@canonical.com 2014-01-08 14:49:25 +01:00
parent 3e3c40d615
commit 0356870144
3 changed files with 38 additions and 3 deletions

View File

@ -180,3 +180,38 @@ def enable_ssl(ssl_key, ssl_cert, ssl_port):
{"ssl_port": ssl_port,
"ssl_cert_file": ssl_cert_file,
"ssl_key_file": ssl_key_file}))
def execute(cmd, die=False, echo=False):
""" Executes a command
if die=True, script will exit(1) if command does not return 0
if echo=True, output of command will be printed to stdout
returns a tuple: (stdout, stderr, return code)
"""
p = subprocess.Popen(cmd.split(" "),
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout = ""
stderr = ""
def print_line(l):
if echo:
print l.strip('\n')
sys.stdout.flush()
for l in iter(p.stdout.readline, ''):
print_line(l)
stdout += l
for l in iter(p.stderr.readline, ''):
print_line(l)
stderr += l
p.communicate()
rc = p.returncode
if die and rc != 0:
error_out("ERROR: command %s return non-zero.\n" % cmd)
return (stdout, stderr, rc)

View File

@ -35,7 +35,7 @@ def install():
# ensure user + permissions for peer relations that
# may be syncing data there via SSH_USER.
unison.ensure_user(user=rabbit.SSH_USER, group='rabbit')
execute("chmod -R g+wrx %s" % rabbit.LIB_PATH)
rabbit_utils.execute("chmod -R g+wrx %s" % rabbit.LIB_PATH)
def amqp_changed(relation_id=None, remote_unit=None, needs_leader=True):
@ -316,7 +316,7 @@ MAN_PLUGIN = 'rabbitmq_management'
def config_changed():
unison.ensure_user(user=rabbit.SSH_USER, group='rabbit')
execute("chmod -R g+wrx %s" % rabbit.LIB_PATH)
rabbit_utils.execute("chmod -R g+wrx %s" % rabbit.LIB_PATH)
if utils.config_get('management_plugin') is True:
rabbit.enable_plugin(MAN_PLUGIN)

View File

@ -1 +1 @@
105
106