From 2e2aaa64a678681fe0735730fa0451356d4ed90d Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Wed, 9 Apr 2008 22:11:16 +0000 Subject: [PATCH] -fixed logic for executing commands on nodes booted with qemu. Added ssh '-q' option. - Added 'host_rootkey'to Node.fields --- qaapi/qa/Nodes.py | 27 +++++++++++++++++++++++++-- qaapi/qa/Remote.py | 28 +++++++--------------------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/qaapi/qa/Nodes.py b/qaapi/qa/Nodes.py index 379f14a..8aeae1e 100644 --- a/qaapi/qa/Nodes.py +++ b/qaapi/qa/Nodes.py @@ -1,5 +1,6 @@ import utils import os +import re from Remote import Remote from Table import Table @@ -10,13 +11,14 @@ class Node(dict, Remote): 'plcs': ['TestPLC'], 'hostname': None, # Node Hostname 'host': 'localhost', # host where node lives - 'redir_port': None, # Port on host where ssh is redirected to virtual node + 'redir_ssh_port': '51022', # Port on host where ssh is redirected to virtual node 'vserver': None, # vserver where this node lives 'type': 'vm', # type of node 'model': '/minhw', 'nodenetworks': [], # node networks 'homedir': '/var/VirtualMachines/', - 'rootkey': None # path to root ssh key + 'rootkey': None, # path to root ssh key + 'host_rootkey': None } def __init__(self, config, fields = {}): @@ -28,6 +30,26 @@ class Node(dict, Remote): self.update(fields) self.config = config + get_host_command = Remote.get_remote_command + + def get_remote_command(self, command, user = 'root', key = None): + if key is None: + key = self['rootkey'] + options = " -q " + options += " -o StrictHostKeyChecking=no " + options += " -i %(key)s" % locals() + host = self['hostname'] + if 'type' in self and self['type'] in ['vm']: + if 'redir_ssh_port' in self and self['redir_ssh_port']: + options += " -p %s " % self['redir_ssh_port'] + ip_command = "/sbin/ifconfig eth0 | grep -v inet6 | grep inet | awk '{print$2;}'" + (status, output) = self.host_commands(ip_command) + host = re.findall(r'[0-9\.]+', output)[0] + + command = "ssh %(options)s %(user)s@%(host)s \'%(command)s\'" % locals() + return self.get_host_command(command) + + def host_popen(self, command, fatal = True): command = self.get_host_command(command) return utils.popen(command, fatal, self.config.verbose) @@ -39,6 +61,7 @@ class Node(dict, Remote): def host_commands(self, command, fatal = True): command = self.get_host_command(command) return utils.commands(command, fatal, self.config.verbose) + class Nodes(list, Table): diff --git a/qaapi/qa/Remote.py b/qaapi/qa/Remote.py index 46a327a..34f04c9 100644 --- a/qaapi/qa/Remote.py +++ b/qaapi/qa/Remote.py @@ -18,7 +18,6 @@ class Remote: return path def get_command(self, command): - options = " -o StrictHostKeyChecking=no " # Chroot if necessary if 'chroot' in self and self['chroot']: command = " chroot %s %s" % (self['chroot'], command) @@ -27,29 +26,16 @@ class Remote: if 'vserver' in self and self['vserver']: command = " vserver %s exec %s " % (self['vserver'], command) - # Use root key if necessary - if 'host' in self and self['host'] not in ['localhost', self.config.hostname]: - if 'rootkey' in self and self['rootkey']: - options += " -i %s " % self['rootkey'] - - return (command, options) - - def get_host_command(self, command): - (command, options) = self.get_command(command) - if 'host' in self and self['host'] not in ['localhost', self.config.hostname]: - command = "ssh %s root@%s \"%s\" " % (options, self['host'], command) return command def get_remote_command(self, command): - (command, options) = self.get_command(command) - if 'type' in self and self['type'] in ['vm']: - if 'redir_port' in self and self['redir_port']: - options += " -p %s " % self['redir_port'] - - # attempt ssh self['host'] is not the machine we are running on or - # if this is a virtual node - if 'host' in self and self['host'] not in ['localhost', self.config.hostname] or \ - 'type' in self and self['type'] in ['vm']: + (command) = self.get_command(command) + + if 'host' in self and self['host'] not in ['localhost', self.config.hostname, self.config.ip]: + options = " -q " + options += " -o StrictHostKeyChecking=no " + if 'host_rootkey' in self and self['host_rootkey']: + options += " -i %s " % self['host_rootkey'] command = "ssh %s root@%s \"%s\" " % (options, self['host'], command) return command -- 2.47.0