~chris-gondolin/charm-helpers/upstart-stop-start

« back to all changes in this revision

Viewing changes to charmhelpers/contrib/amulet/utils.py

  [r=lazypower] Chris Holcombe 2016-03-18 Add parameters to the run action utility in amulet

Show diffs side-by-side

added added

removed removed

Lines of Context:
782
782
 
783
783
# amulet juju action helpers:
784
784
    def run_action(self, unit_sentry, action,
785
 
                   _check_output=subprocess.check_output):
 
785
                   _check_output=subprocess.check_output,
 
786
                   params=None):
786
787
        """Run the named action on a given unit sentry.
787
788
 
 
789
        params a dict of parameters to use
788
790
        _check_output parameter is used for dependency injection.
789
791
 
790
792
        @return action_id.
791
793
        """
792
794
        unit_id = unit_sentry.info["unit_name"]
793
795
        command = ["juju", "action", "do", "--format=json", unit_id, action]
 
796
        if params is not None:
 
797
            for key, value in params.iteritems():
 
798
                command.append("{}={}".format(key, value))
794
799
        self.log.info("Running command: %s\n" % " ".join(command))
795
800
        output = _check_output(command, universal_newlines=True)
796
801
        data = json.loads(output)