def reachable(self, addr): try: retval, out, err = \ util.basic_run_process( 'ping -c 1 -W 1 {addr}'.format(addr=addr)) except Exception: log.exception('Process execution failed:') raise else: log.debug('Process STDOUT:\n%s', out) log.debug('Process STDERR:\n%s', err) log.debug('Process exit code: %d', retval) return (retval == 0)
def reachable(self, **node_spec): addr = ib.main_info_broker.get('node.address', **node_spec) try: retval, out, err = \ util.basic_run_process( 'ping -c 1 -W 1 {addr}'.format(addr=addr)) except Exception: log.exception('Process execution failed:') raise else: log.debug('Process STDOUT:\n%s', out) log.debug('Process STDERR:\n%s', err) log.debug('Process exit code: %d', retval) return (retval == 0)
def execute_command(endpoint, auth_data, *args, **kwargs): """ Execute a custom command towards the target. """ cmd = ["occi", "-X", "-n", "x509", "-x", auth_data['proxy'], "-e", endpoint] cmd.extend(args) log.debug("Command is: %r", " ".join(cmd)) ret, out, err = basic_run_process(" ".join(cmd), input_data=kwargs.get('stdin')) #if 'stdin' in kwargs: #p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) #p.stdin.write(kwargs.get('stdin')) #else: #p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #out, err = p.communicate() log.debug("Command response is: %r", out) log.debug("Command stderr response is: %r", err) #p.wait() return out
def execute_command(endpoint, auth_data, *args, **kwargs): """ Execute a custom command towards the target. """ cmd = ["occi", "-X", "-n", "x509", "-x", auth_data["proxy"], "-e", endpoint] cmd.extend(args) log.debug("Command is: %r", " ".join(cmd)) ret, out, err = basic_run_process(" ".join(cmd), input_data=kwargs.get("stdin")) # if 'stdin' in kwargs: # p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) # p.stdin.write(kwargs.get('stdin')) # else: # p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # out, err = p.communicate() log.debug("Command response is: %r", out) log.debug("Command stderr response is: %r", err) # p.wait() return out
def test_run_process(self): data='stuffstuff' rc, stdout, stderr = util.basic_run_process('cat', data) self.assertEqual(rc, 0) self.assertEqual(stdout, data)
def test_run_process(self): data = 'stuffstuff' rc, stdout, stderr = util.basic_run_process('cat', data) self.assertEqual(rc, 0) self.assertEqual(stdout, data)