From: Thierry Parmentelat Date: Tue, 8 Apr 2008 12:02:32 +0000 (+0000) Subject: open up traffic to qemu nodes + miscell X-Git-Tag: tests-4.2-4~79 X-Git-Url: http://git.onelab.eu/?p=tests.git;a=commitdiff_plain;h=2d879db75bed7f76fb868c566cbc2f4a8aba1c8c open up traffic to qemu nodes + miscell --- diff --git a/system/TestMain.py b/system/TestMain.py index 4e9b1fb..db30776 100755 --- a/system/TestMain.py +++ b/system/TestMain.py @@ -22,8 +22,8 @@ class TestMain: 'configure', 'start', SEP, 'store_keys', 'clear_known_hosts', 'initscripts', SEP, 'sites', 'nodes', 'slices', 'nodegroups', SEP, - 'init_node','bootcd', 'configure_qemu', SEP, - 'kill_all_qemus', 'start_nodes', SEP, + 'init_node','bootcd', 'configure_qemu', + 'kill_all_qemus', 'reinstall_node','start_node', SEP, 'standby_20', SEP, 'nodes_booted', 'nodes_ssh', 'check_slices', 'check_initscripts', 'check_tcp',SEP, diff --git a/system/TestNode.py b/system/TestNode.py index 6ac9316..13c1a16 100644 --- a/system/TestNode.py +++ b/system/TestNode.py @@ -115,7 +115,8 @@ class TestNode: options = [] if self.is_qemu(): options=['serial'] - encoded=self.test_plc.apiserver.GetBootMedium(self.test_plc.auth_root(), self.name(), 'node-iso', '', options) + encoded=self.test_plc.apiserver.GetBootMedium(self.test_plc.auth_root(), + self.name(), 'node-iso', '', options) if (encoded == ''): raise Exception, 'GetBootmedium failed' @@ -127,12 +128,18 @@ class TestNode: else: file(filename,'w').write(base64.b64decode(encoded)) return True + + def reinstall_node (self): + self.test_plc.apiserver.UpdateNode(self.test_plc.auth_root(), + self.name(),{'boot_state':'rins'}) + return True def configure_qemu(self): if not self.is_qemu(): return mac=self.node_spec['network_fields']['mac'] hostname=self.node_spec['node_fields']['hostname'] + ip=self.node_spec['network_fields']['ip'] auth=self.test_plc.auth_root() target_arch=self.test_plc.apiserver.GetPlcRelease(auth)['build']['target-arch'] conf_filename="%s/qemu.conf"%(self.nodedir()) @@ -144,6 +151,7 @@ class TestNode: file.write('MACADDR=%s\n'%mac) file.write('NODE_ISO=%s.iso\n'%self.name()) file.write('HOSTNAME=%s\n'%hostname) + file.write('IP=%s\n'%ip) file.write('TARGET_ARCH=%s\n'%target_arch) file.close() @@ -153,15 +161,16 @@ class TestNode: utils.header ("Transferring configuration files for node %s onto %s"%(self.name(),self.host_box())) return self.test_box().copy(self.nodedir(),recursive=True)==0 - def start_node (self,options): + def start_node (self): model=self.node_spec['node_fields']['model'] #starting the Qemu nodes before if self.is_qemu(): - self.start_qemu(options) + self.start_qemu() else: utils.header("TestNode.start_node : %s model %s taken as real node"%(self.name(),model)) - def start_qemu (self, options): + def start_qemu (self): + options = self.test_plc.options test_box = self.test_box() utils.header("Starting qemu node %s on %s"%(self.name(),test_box.hostname())) diff --git a/system/TestPlc.py b/system/TestPlc.py index df4d431..6fb76eb 100644 --- a/system/TestPlc.py +++ b/system/TestPlc.py @@ -528,6 +528,8 @@ class TestPlc: def bootcd (self): pass @node_mapper def configure_qemu (self): pass + @node_mapper + def reinstall_node (self): pass def do_check_initscripts(self): overall = True @@ -581,11 +583,8 @@ class TestPlc: @node_mapper def clear_known_hosts (self): pass - def start_nodes (self): - utils.header("Starting nodes") - for site_spec in self.plc_spec['sites']: - TestSite(self,site_spec).start_nodes (self.options) - return True + @node_mapper + def start_node (self) : pass def locate_first_sliver (self): slice_spec = self.plc_spec['slices'][0] diff --git a/system/TestSite.py b/system/TestSite.py index c774908..ca2977f 100644 --- a/system/TestSite.py +++ b/system/TestSite.py @@ -54,9 +54,5 @@ class TestSite: return node raise Exception,"Cannot locate node %s"%nodename - def start_nodes (self,options): - for node_spec in self.site_spec['nodes']: - TestNode(self.test_plc, self, node_spec).start_node(options) - return True diff --git a/system/TestSsh.py b/system/TestSsh.py index 3c61a4b..9ddb52e 100644 --- a/system/TestSsh.py +++ b/system/TestSsh.py @@ -80,9 +80,7 @@ class TestSsh: def run(self, command,background=False): local_command = self.actual_command(command) - if background: - local_command += " &" - return utils.system(local_command) + return utils.system(local_command,background) def clean_dir (self,dirname): if self.is_local(): diff --git a/system/run b/system/run new file mode 120000 index 0000000..23360cc --- /dev/null +++ b/system/run @@ -0,0 +1 @@ +TestMain.py \ No newline at end of file diff --git a/system/template-qemu/iptables.py b/system/template-qemu/iptables.py new file mode 100644 index 0000000..bd0b087 --- /dev/null +++ b/system/template-qemu/iptables.py @@ -0,0 +1,35 @@ +#!/usr/bin/python + +import sys +import re + +def main (): + fin=open(sys.argv[1]) + fou=open(sys.argv[2],"w") + ip=sys.argv[3] + + found=False + lo_matcher=re.compile("\A(?P.+)\s+-i\s+lo\s+-j\s+ACCEPT") + ip_matcher=re.compile("--(source|destination) %s"%ip) + for line in fin.readlines(): + attempt=lo_matcher.match(line) + if attempt: + fou.write(line) + # open-up for this IP + fou.write("%s --source %s -j ACCEPT\n"%(attempt.group('left'),ip)) + fou.write("%s --destination %s -j ACCEPT\n"%(attempt.group('left'),ip)) + found=True + else: + attempt = ip_matcher.match(line) + # do not rewrite old lines for this ip + if not attempt: + fou.write(line) + + fin.close() + fou.close() + if found : return 0 + else : return 1 + +if __name__ == '__main__': + main() + diff --git a/system/template-qemu/qemu-bridge-init b/system/template-qemu/qemu-bridge-init index 7b3c016..d8844ff 100755 --- a/system/template-qemu/qemu-bridge-init +++ b/system/template-qemu/qemu-bridge-init @@ -8,6 +8,7 @@ # COMMAND=$(basename $0) +cd $(dirname $0) # constant INTERFACE_BRIDGE=br0 @@ -80,11 +81,6 @@ start () { echo "Configuring the IP Gateway @:" $gateway route add default gw $gateway - # xxx this is *wrong* - # wipe the host firewall otherwise the guest qemu can't access the LAN - # echo "Wiping the firewall..." - # iptables -F - } #Adding a new interface to the bridge: this is used by qemu-ifup @@ -99,6 +95,19 @@ add () { echo "Adding $INTERFACE_LAN to $INTERFACE_BRIDGE" brctl addif $INTERFACE_BRIDGE $INTERFACE_LAN + # turn off filtering on this interface + ########## from the test environment + # expected vars are MACADDR, NODE_ISO, HOSTNAME, IP and TARGET_ARCH + CONFIG=qemu.conf + [ -f "$CONFIG" ] || { echo "Config file for qemu $CONFIG not found in $(pwd)" ; exit 1 ; } + . $CONFIG + + echo "Tweaking iptables" + iptables-save > iptables.pre + # rewrite a new config - quick and dirty + ./iptables.py iptables.pre iptables.post $IP + iptables-restore < iptables.post + } #Stop the bridge and restore the original setting @@ -117,6 +126,7 @@ stop () { /sbin/ifconfig $INTERFACE_BRIDGE down brctl delbr $INTERFACE_BRIDGE /sbin/service network restart + /sbin/service iptables restart } # diff --git a/system/template-qemu/qemu-ifup b/system/template-qemu/qemu-ifup index 877496e..206f149 100755 --- a/system/template-qemu/qemu-ifup +++ b/system/template-qemu/qemu-ifup @@ -2,4 +2,5 @@ # use the bridge as set up by qemu-bridge-init start -qemu-bridge-init add $1 +cd $(dirname $0) +./qemu-bridge-init add $1 diff --git a/system/template-qemu/qemu-kill-node b/system/template-qemu/qemu-kill-node index a4a00d0..5d591f9 100755 --- a/system/template-qemu/qemu-kill-node +++ b/system/template-qemu/qemu-kill-node @@ -51,10 +51,16 @@ function kill_pids () { kill_from_file $nodedir/qemu.pid done else - echo "Killing all processes mathing $COMMANDS_TO_KILL" - for command in $COMMANDS_TO_KILL ; do - pkill -x $command - done + pids=$(list_pids) + if [ -n "$pids" ] ; then + echo "Killing all processes matching $COMMANDS_TO_KILL" + for pid in $pids; do + echo Killing $pid + kill $pid + done + else + echo "No process found that match $COMMANDS_TO_KILL" + fi fi } diff --git a/system/template-qemu/qemu-start-node b/system/template-qemu/qemu-start-node index 29f465c..a6610c0 100755 --- a/system/template-qemu/qemu-start-node +++ b/system/template-qemu/qemu-start-node @@ -13,12 +13,9 @@ SCRIPT=qemu-ifup TAP="tap,script=$SCRIPT" ########## from the test environment -# expected vars are MACADDR, NODE_ISO, HOSTNAME and TARGET_ARCH +# expected vars are MACADDR, NODE_ISO, HOSTNAME, IP and TARGET_ARCH CONFIG=qemu.conf -if [ ! -e ${CONFIG} ];then - echo "File for node_iso version not found" - exit 1 -fi +[ -f "$CONFIG" ] || { echo "Config file for qemu $CONFIG not found in $(pwd)" ; exit 1 ; } . $CONFIG # the launcher, depending on local/target archs