Beispiel #1
0
 def _shell(self, cmd):
     log(cmd)
     
     try:
         return shell3(cmd)
     except Exception:
         log("error executing command: %s" % cmd)
         raise
Beispiel #2
0
 def action_run(self):
     if self.resource.creates:
         if os.path.exists(self.resource.creates):
             return
     
     utils.log("Executing %s" % self.resource)
     ret = utils.shell3(self.resource.path)[1]
     # TODO: use cwd and env
     # subprocess.call(self.resource.path, shell=True, cwd=self.resource.cwd, env=self.resource.env)
     #, preexec_fn=_preexec_fn(self.resource))
     
     if self.resource.returns and ret not in self.resource.returns:
         raise Fail("%s failed, returned %d instead of %s" % (self, ret, self.resource.returns))
     
     self.resource.updated()
Beispiel #3
0
    def _exec_cmd(self, cmd, expect=None):
        if cmd != "status":
            utils.log("%s command '%s'" % (self.resource, cmd))

        custom_cmd = getattr(self.resource, "%s_cmd" % cmd, None)
        if custom_cmd:
            utils.log("%s executing '%s'" % (self.resource, custom_cmd))

            if hasattr(custom_cmd, "__call__"):
                if custom_cmd():
                    ret = 0
                else:
                    ret = 1
            else:
                print custom_cmd
                ret = utils.shell3(custom_cmd)[1]
                # subprocess.call(custom_cmd, shell=True)#, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        else:
            ret = self._init_cmd(cmd)

        if expect is not None and expect != ret:
            raise Fail("%r command %s for service %s failed" % (self, cmd, self.resource.name))

        return ret