def shell(self, nodes, command, worker, timeout, stderr, gw_invoke_cmd): """command execution through channel""" self.logger.debug("shell nodes=%s timeout=%f worker=%s" % \ (nodes, timeout, id(worker))) self.workers[id(worker)] = worker ctl = ControlMessage(id(worker)) ctl.action = 'shell' ctl.target = nodes info = self.task._info.copy() info['debug'] = False ctl_data = { 'cmd': command, 'invoke_gateway': gw_invoke_cmd, # XXX 'taskinfo': info, #self.task._info, 'stderr': stderr, 'timeout': timeout, } ctl.data_encode(ctl_data) self._history['ctl_id'] = ctl.msgid if self.current_state == self.states['STATE_CTL']: # send now if channel state is CTL self.send(ctl) else: self._sendq.append(ctl)
def shell(self, nodes, command, worker, timeout, stderr, gw_invoke_cmd, remote): """command execution through channel""" self.logger.debug("shell nodes=%s timeout=%s worker=%s remote=%s", nodes, timeout, id(worker), remote) self.workers[id(worker)] = worker ctl = ControlMessage(id(worker)) ctl.action = 'shell' ctl.target = nodes # keep only valid task info pairs info = dict((k, v) for k, v in self.task._info.items() if k not in DEFAULTS._task_info_pkeys_bl) ctl_data = { 'cmd': command, 'invoke_gateway': gw_invoke_cmd, # XXX 'taskinfo': info, 'stderr': stderr, 'timeout': timeout, 'remote': remote, } ctl.data_encode(ctl_data) self.send_queued(ctl)
def shell(self, nodes, command, worker, timeout, stderr, gw_invoke_cmd, remote): """command execution through channel""" self.logger.debug("shell nodes=%s timeout=%s worker=%s remote=%s", nodes, timeout, id(worker), remote) self.workers[id(worker)] = worker ctl = ControlMessage(id(worker)) ctl.action = 'shell' ctl.target = nodes # copy only subset of task info dict info = dict((k, self.task._info[k]) for k in self.task._std_info_pkeys) ctl_data = { 'cmd': command, 'invoke_gateway': gw_invoke_cmd, # XXX 'taskinfo': info, #self.task._info, 'stderr': stderr, 'timeout': timeout, 'remote': remote, } ctl.data_encode(ctl_data) self._history['ctl_id'] = ctl.msgid self.send_queued(ctl)
def set_write_eof(self, nodes, worker): """send EOF through channel to specified nodes""" self.logger.debug("set_write_eof") assert id(worker) in self.workers ctl = ControlMessage(id(worker)) ctl.action = 'eof' ctl.target = nodes self.send_queued(ctl)
def gen_ctl(): """return a generic control message instance""" msg = ControlMessage() msg.msgid = 0 msg.action = 'shell' msg.target = 'node[0-10]' params = {'cmd': 'uname -a'} msg.data_encode(params) return msg
def set_write_eof(self, nodes, worker): """send EOF through channel to specified nodes""" self.logger.debug("set_write_eof") assert id(worker) in self.workers ctl = ControlMessage(id(worker)) ctl.action = 'eof' ctl.target = nodes self._history['ctl_id'] = ctl.msgid if self.current_state == self.states['STATE_CTL']: # send now if channel state is CTL self.send(ctl) else: self._sendq.append(ctl)
def write(self, nodes, buf, worker): """write buffer through channel to nodes on standard input""" self.logger.debug("write buflen=%d", len(buf)) assert id(worker) in self.workers ctl = ControlMessage(id(worker)) ctl.action = 'write' ctl.target = nodes ctl_data = { 'buf': buf, } ctl.data_encode(ctl_data) self._cfg_write_hist.appendleft((ctl.msgid, nodes, len(buf), worker)) self.send_queued(ctl)
def write(self, nodes, buf, worker): """write buffer through channel to nodes on standard input""" self.logger.debug("write buflen=%d", len(buf)) assert id(worker) in self.workers ctl = ControlMessage(id(worker)) ctl.action = 'write' ctl.target = nodes ctl_data = { 'buf': buf, } ctl.data_encode(ctl_data) self._history['ctl_id'] = ctl.msgid if self.current_state == self.states['STATE_CTL']: # send now if channel state is CTL self.send(ctl) else: self._sendq.append(ctl)
def _check_channel_ctl_shell(self, command, target, stderr, remote, reply_msg_class, reply_pattern, write_buf=None, timeout=-1, replycnt=1, reply_rc=0): """helper to check channel shell action""" self.channel_send_start() msg = self.recvxml(StartMessage) self.channel_send_cfg('n1') msg = self.recvxml(ACKMessage) # prepare a remote shell command request... workertree = TreeWorker(nodes=target, handler=None, timeout=timeout, command=command) # code snippet from PropagationChannel.shell() ctl = ControlMessage(id(workertree)) ctl.action = 'shell' ctl.target = NodeSet(target) info = task_self()._info.copy() info['debug'] = False ctl_data = { 'cmd': command, 'invoke_gateway': workertree.invoke_gateway, 'taskinfo': info, 'stderr': stderr, 'timeout': timeout, 'remote': remote } ctl.data_encode(ctl_data) self.gateway.send(ctl.xml()) self.recvxml(ACKMessage) if write_buf: ctl = ControlMessage(id(workertree)) ctl.action = 'write' ctl.target = NodeSet(target) ctl_data = { 'buf': write_buf, } # Send write message ctl.data_encode(ctl_data) self.gateway.send(ctl.xml()) self.recvxml(ACKMessage) # Send EOF message ctl = ControlMessage(id(workertree)) ctl.action = 'eof' ctl.target = NodeSet(target) self.gateway.send(ctl.xml()) self.recvxml(ACKMessage) while replycnt > 0: msg = self.recvxml(reply_msg_class) replycnt -= len(NodeSet(msg.nodes)) self.assertTrue(msg.nodes in ctl.target) if msg.has_payload or reply_pattern: msg_data = msg.data_decode() try: if not reply_pattern.search(msg_data): self.assertEqual( msg.data, reply_pattern, 'Pattern "%s" not found in data="%s"' % (reply_pattern.pattern, msg_data)) except AttributeError: # not a regexp self.assertEqual(msg_data, reply_pattern) if timeout <= 0: msg = self.recvxml(RetcodeMessage) self.assertEqual(msg.retcode, reply_rc) self.channel_send_stop() self.gateway.wait() self.gateway.close()