[Collab-qa-commits] r655 - in debcluster/scripts: . bin tasks

lucas at alioth.debian.org lucas at alioth.debian.org
Fri Jan 18 12:39:26 UTC 2008


Author: lucas
Date: 2008-01-18 12:39:25 +0000 (Fri, 18 Jan 2008)
New Revision: 655

Added:
   debcluster/scripts/bin/
   debcluster/scripts/bin/dc-addnodes
   debcluster/scripts/bin/dc-mountnfs
   debcluster/scripts/bin/dc-startcluster
   debcluster/scripts/bin/dc-startnodes
Removed:
   debcluster/scripts/masternode-virt.rb
   debcluster/scripts/tasks/preparenode-virt.rb
Modified:
   debcluster/scripts/masternode.rb
   debcluster/scripts/tasks/preparenode.rb
Log:
cleanup ; merged virtualization support in main scripts

Added: debcluster/scripts/bin/dc-addnodes
===================================================================
--- debcluster/scripts/bin/dc-addnodes	                        (rev 0)
+++ debcluster/scripts/bin/dc-addnodes	2008-01-18 12:39:25 UTC (rev 655)
@@ -0,0 +1,30 @@
+#!/usr/bin/ruby -w
+
+require 'socket'
+
+TCPPORT=36363
+
+class DebMessage
+  attr_accessor :type, :param
+end
+
+if ENV['GOOD_NODES'] != nil
+  f = ENV['GOOD_NODES']
+elsif ENV['OAR_NODEFILE']
+  f = ENV['OAR_NODEFILE']
+else
+  puts "No nodes file."
+  exit(1)
+end
+
+hostname = ARGV[0]
+nodes = IO::read(f).split(/\n/).sort.uniq
+
+nodes.each do |node|
+  s = TCPSocket::new(hostname, TCPPORT)
+  m = DebMessage::new
+  m.type = :add_node
+  m.param = node
+  Marshal::dump(m, s)
+  s.close
+end


Property changes on: debcluster/scripts/bin/dc-addnodes
___________________________________________________________________
Name: svn:executable
   + *

Added: debcluster/scripts/bin/dc-mountnfs
===================================================================
--- debcluster/scripts/bin/dc-mountnfs	                        (rev 0)
+++ debcluster/scripts/bin/dc-mountnfs	2008-01-18 12:39:25 UTC (rev 655)
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+set -e
+
+echo "Starting dc-mountnfs -- $(date)"
+
+apt-get update
+export DEBIAN_FRONTEND=noninteractive
+apt-get -y install nfs-common initscripts sysvinit-utils
+
+umount -l /idpotscratch &>/dev/null || true
+mkdir /idpotscratch &>/dev/null || true
+rm -f /debcluster-data /debcluster-scripts  &>/dev/null || true
+mount -t nfs -o rw,hard,intr,async,nfsvers=3,rsize=32768,wsize=32768 idpot.grenoble.grid5000.fr:/nfs-scratch /idpotscratch
+ln -sf /idpotscratch/grenoble/lnussbaum/debcluster-data /debcluster-data
+ln -sf /idpotscratch/grenoble/lnussbaum/collab-qa/debcluster /debcluster-scripts
+
+echo "Finishing dc-mountnfs -- $(date)"


Property changes on: debcluster/scripts/bin/dc-mountnfs
___________________________________________________________________
Name: svn:executable
   + *

Added: debcluster/scripts/bin/dc-startcluster
===================================================================
--- debcluster/scripts/bin/dc-startcluster	                        (rev 0)
+++ debcluster/scripts/bin/dc-startcluster	2008-01-18 12:39:25 UTC (rev 655)
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+# Script called by katapult to prepare the head node and start masternode.rb
+
+LOGIN=root
+SSHOPTS="-o BatchMode=yes -o StrictHostKeyChecking=no"
+
+if [ $# -lt 1 ]; then
+	echo "Usage: startcluster.bash jobsfile"
+	echo "GOOD_NODES or OAR_NODEFILE must point to the nodes list"
+	echo "First node is used as head node."
+	exit 1
+fi
+
+TASKLIST=$1
+LNFILE=
+if [ "$GOOD_NODES" ]; then
+	LNFILE=$GOOD_NODES
+elif [ "$OAR_NODEFILE" ]; then
+	LNFILE=$OAR_NODEFILE
+fi
+HNODE=$(head -1 $LNFILE)
+
+shift
+
+echo "Head node: $HNODE"
+
+F1=$(ssh root@$HNODE mktemp /tmp/nodeslist.XXXXXX)
+scp $LNFILE $LOGIN@$HNODE:$F1
+
+F2=$(ssh root@$HNODE mktemp /tmp/tasklist.XXXXXX)
+if [ -f $TASKLIST ]; then
+	scp $TASKLIST $LOGIN@$HNODE:$F2
+fi
+
+scp $SSHOPTS ~/bin/dc-mountnfs $LOGIN@$HNODE:/root/dc-mountnfs
+ssh $SSHOPTS $LOGIN@$HNODE "/root/dc-mountnfs"
+
+exec ssh $LOGIN@$HNODE "cd /debcluster-scripts/scripts/ && ./masternode.rb $F1 $F2 $*"


Property changes on: debcluster/scripts/bin/dc-startcluster
___________________________________________________________________
Name: svn:executable
   + *

Added: debcluster/scripts/bin/dc-startnodes
===================================================================
--- debcluster/scripts/bin/dc-startnodes	                        (rev 0)
+++ debcluster/scripts/bin/dc-startnodes	2008-01-18 12:39:25 UTC (rev 655)
@@ -0,0 +1,34 @@
+#!/usr/bin/ruby -w
+
+require 'thread'
+
+LOGIN='root'
+SSHOPTS=['-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=no']
+
+if ENV['GOOD_NODES']
+  LNFILE = ENV['GOOD_NODES']
+elsif ENV['OAR_NODEFILE']
+  LNFILE = ENV['GOOD_NODES']
+else
+  puts "Could not find node list"
+  exit(1)
+end
+
+ths = []
+nodes = IO::read(LNFILE).split.sort.uniq
+nodes.each do |n|
+  ths << Thread::new(n) do |node|
+    system("scp #{SSHOPTS.join(' ')} ~/bin/dc-mountnfs #{LOGIN}@#{node}:/root/dc-mountnfs")
+    system("ssh #{SSHOPTS.join(' ')} #{LOGIN}@#{node} /root/dc-mountnfs")
+    system("ssh #{SSHOPTS.join(' ')} #{LOGIN}@#{node} \"/debcluster-scripts/scripts/tasks/preparenode.rb --log /debcluster-data/logs/preparenode/#{node}.$(date --iso)\"")
+  end
+end
+ths.each do |t|
+  t.join
+end
+if ARGV.length > 0
+  puts "Executing '#{ARGV}' on #{nodes[0]}..."
+  c = ['/usr/bin/ssh'] + SSHOPTS + [ "#{LOGIN}@#{nodes[0]}" ] + ARGV
+  fork { exec(*c) }
+  Process::wait
+end


Property changes on: debcluster/scripts/bin/dc-startnodes
___________________________________________________________________
Name: svn:executable
   + *

Deleted: debcluster/scripts/masternode-virt.rb
===================================================================
--- debcluster/scripts/masternode-virt.rb	2008-01-18 10:17:41 UTC (rev 654)
+++ debcluster/scripts/masternode-virt.rb	2008-01-18 12:39:25 UTC (rev 655)
@@ -1,389 +0,0 @@
-#!/usr/bin/ruby1.8 -w
-
-require 'thread'
-require 'thwait'
-require 'debtask'
-require 'socket'
-require 'time'
-require 'ipaddr'
-
-Thread::abort_on_exception = true
-
-class IPAddr
-  def next
-    raise "next: Not supported for IPv6!" if self.ipv6?
-    IPAddr::from_int(self.to_i + 1)
-  end
-
-  def IPAddr::from_int(i)
-    s = [ (i & 0xff000000) >> 24, (i & 0xff0000) >> 16, (i & 0xff00) >> 8, i & 0xff].join('.')
-    return IPAddr::new(s)
-  end
-
-  def +(i)
-    if i > 1
-      return self.next + (i-1)
-    else
-      return self.next
-    end
-  end
-
-  def to_masked
-    inspect.split(':')[2].split('>')[0].gsub('/',':')
-  end
-end
-
-
-DEFAULT_TASKS_PER_NODE = 4
-
-NBNODES = [
-  [ /^heliostest.*/, 4 ]
-]
-
-# https://www.grid5000.fr/mediawiki/index.php/Network_interlink#IP.27s_for_virtual_machines
-NET_GW = {
- 'sophia' => '10.167.255.254'
-}
-NET_NS = {
- 'sophia' => '138.96.20.225'
-}
-NET_ADDR = {
- 'sophia' => '10.164.0.1'
-}
-$first_addr = {}
-
-SSHOPTS="-o BatchMode=yes -o StrictHostKeyChecking=no"
-DEBUG_PREP = true
-SLEEPTIME = 10
-TCPPORT=36363
-
-# Convenient for testing: set false
-SHORTERLAST=false
-
-$nodes = {}
-$wtasks = []
-$nbfinished = 0
-$tottime = 0.0
-$mutex = Mutex::new
-$ths = []
-$masternode = "Unknown"
-$started = false
-$ready = false
-$interactive = false
-
-def preparenode(n, vn)
-  puts "Preparing #{n}..." if DEBUG_PREP
-  system("ssh #{SSHOPTS} #{n} exit 42")
-  if $?.exitstatus != 42
-    puts "E:Public key auth on #{n} failed."
-    return false
-  end
-  # remove proxy
-  system("ssh #{SSHOPTS} #{n} \"sed -i 's/.*http_proxy.*//' /etc/environment\"")
-  # mount /debcluster
-  system("ssh #{SSHOPTS} #{n} \"apt-get update && apt-get install -y nfs-common initscripts sysvinit-utils\" &>/dev/null")
-  if `ssh #{SSHOPTS} #{n} \"mount | grep /idpotscratch | wc -l\"`.to_i == 0
-    system("ssh #{SSHOPTS} #{n} \"mkdir /idpotscratch  &>/dev/null; rm -f /debcluster-data /debcluster-scripts &>/dev/null\"")
-    ret = system("ssh #{SSHOPTS} #{n} mount -t nfs -o rw,hard,intr,async,nfsvers=3,rsize=32768,wsize=32768 idpot.grenoble.grid5000.fr:/nfs-scratch /idpotscratch")
-    if not ret
-      puts "E:Failed to mount /idpotscratch on #{n} failed."
-      return false
-    end
-  end
-  system("ssh #{SSHOPTS} #{n} \"rm -f /debcluster-data /debcluster-scripts ; ln -sf /idpotscratch/grenoble/lnussbaum/debcluster-data /debcluster-data ; ln -sf /idpotscratch/grenoble/lnussbaum/collab-qa/debcluster /debcluster-scripts\"")
-  vns = vn.join(' -m ')
-  ret = system("ssh #{SSHOPTS} #{n} \"/debcluster-scripts/scripts/tasks/preparenode-virt.rb --log /debcluster-data/logs/preparenode/#{n}.$(date --iso) -m #{vns}\"")
-  if not ret
-    puts "E:preparenode-virt.rb failed on #{n}."
-    return false
-  else
-    return true
-  end
-end
-
-def tcpserver
-  s = TCPServer::new(TCPPORT)
-  while true do
-    sc = s.accept
-    m = Marshal.load(sc)
-    case m.type
-    when :add_task
-      $mutex.synchronize do
-        if m.param.class == Array
-          m.param.each do |t|
-            $wtasks << t
-          end
-        else
-          $wtasks << m.param
-        end
-      end
-    when :sort_tasks
-      $mutex.synchronize do
-        $wtasks.sort!
-	$wtasks.reverse! if not SHORTERLAST
-      end
-    when :list_tasks
-      $mutex.synchronize do
-        Marshal::dump($wtasks, sc)
-      end
-    when :del_task
-      $mutex.synchronize do
-        $wtasks.delete_if { |t| t.id =~ m.param }
-      end
-    when :add_node
-      $mutex.synchronize do
-        $ths << Thread::new(m.param) { |n| managenode(n) }
-      end
-    end
-    sc.close
-  end
-end
-
-def showtop
-  while true do
-    sleep SLEEPTIME
-    $mutex.synchronize do
-      if $nbfinished > 0
-        avg = $tottime / $nbfinished
-      else
-        avg = 0
-      end
-      puts "*" * 75
-      puts "  Time: #{Time::now.iso8601.gsub(/T/,' ').gsub(/\+.*/,'')}"
-      puts "  Masternode: #{$masternode}"
-      puts "  Tasks finished: #{$nbfinished} (tot: #{$tottime}s ; avg: #{avg}s)"
-      puts "  Nodes: #{$nodes.length}"
-      puts "  Tasks waiting: #{$wtasks.length} (total ETA: #{$wtasks.length * avg}s, realtime ETA: #{$wtasks.length * avg.to_f / $nodes.length.to_f})" 
-      n = $nodes.to_a.sort do |a,b|
-        ret = nil
-        if a[1] == b[1] and a[1] == :free
-          ret = 0
-        elsif a[1] == :free
-          ret = 1
-        elsif b[1] == :free
-          ret = -1
-        else
-          ret = a[1].starttime <=> b[1].starttime
-        end
-        ret
-      end
-      n.each do |i|
-        if i[1] == :free
-          puts "  #{i[0]}: Free"
-        else
-          puts "  #{i[0]}: #{i[1]} since #{Time::now - i[1].starttime}"
-        end
-      end
-      STDOUT.flush
-    end
-  end
-end
-
-def runtask(node, command)
-  ret = nil
-  thtask = Thread::new(node, command) do |node, command|
-    cmd = "ssh #{SSHOPTS} #{node} -- #{command} &> /tmp/log.ssh.#{node}"
-    ret = system(cmd)
-    if ret != true
-      puts "#{node}: system() returned #{ret} / $? == #{$?}"
-    end
-  end
-  thmonitor = Thread::new(node) do |node|
-    ok = true
-    while ok
-      s = `ssh #{SSHOPTS} #{node} "(cd /debcluster-scripts/scripts/ && hostname) 2>&1"`
-      if s.chomp != node
-        p s.chomp
-        p node
-        ok = false
-      else
-        sleep SLEEPTIME
-      end
-    end
-    puts "Monitoring thread for #{node} exiting."
-  end
-  thw = ThreadsWait::new(thtask, thmonitor)
-  fin = thw.next_wait
-  if fin == thtask and ret == true
-    thmonitor.kill
-    # dernieres verifications...
-    s = `ssh #{SSHOPTS} #{node} "(cd /debcluster-scripts/scripts/ && hostname) 2>&1"`
-    if s.chomp == node
-      s = `ssh #{SSHOPTS} #{node} "runlevel | cut -d ' ' -f 2 2>&1"`.chomp
-      if s == "2"
-        return true
-      else
-        puts "Wrong runlevel"
-        p s
-        return false
-      end
-    else
-      puts "Wrong hostname"
-      p s
-      return false
-    end
-  elsif fin == thtask
-    thmonitor.kill
-    return false
-  else
-    thtask.kill
-    return false
-  end
-end
-
-class Node
-  attr_accessor :hostname, :ident
-
-  def initialize(hostname, ident)
-    @hostname = hostname
-    @ident = ident
-  end
-
-  def to_s
-    "#{@hostname}-#{@ident}"
-  end
-end
-
-def managenode(nodehost)
-  puts "aaaaz"
-  # nodehost is just the node name in text.
-  nbsubnodes = DEFAULT_TASKS_PER_NODE # default value
-  NBNODES.each do |t|
-    if nodehost =~ t[0]
-      nbsubnodes = t[1]
-    end
-  end
-  if nodehost !~ /\.(\w+)\.grid5000\.fr$/
-    puts "INCORRECT NODE: #{nodehost}"
-    return
-  end
-  cluster = $1
-  if $first_addr[cluster].nil?
-    $first_addr[cluster] = IPAddr::new(NET_ADDR[cluster])
-  end
-  vn = []
-  (1..4).each do |i|
-    vn << $first_addr[cluster]
-    $first_addr[cluster] = $first_addr[cluster].next
-  end
-  return if not preparenode(nodehost, vn)
-  vn.each do |i|
-    node = Node::new(nodehost, i)
-    Thread::new(node) { |node| manageworker(node) }
-  end
-end
-
-def manageworker(node)
-  # node is a Node object
-  $mutex.synchronize do
-    $nodes[node] = :free
-  end
-  while not $ready
-    puts "#{node}: We are not ready yet."
-    sleep SLEEPTIME
-  end
-  asleep = false
-  running = true
-  while running do
-    t = nil
-    $mutex.synchronize do
-      # Take the last element, that is, the bigger.
-      t = $wtasks.pop
-    end
-    if t.nil?
-      puts "#{node}: no task, waiting for #{SLEEPTIME} seconds" if not asleep
-      asleep = true
-      sleep SLEEPTIME
-    else
-      $mutex.synchronize do
-        $nodes[node] = t
-        t.starttime = Time::now
-        puts "#{node}: running #{t}"
-      end
-      ret = runtask(node.hostname, t.command)
-      $mutex.synchronize do
-        if ret
-          puts "#{node}: finished #{t}"
-          $nodes[node] = :free
-          $nbfinished += 1
-          $tottime += Time::now - t.starttime
-        else
-          puts "Something really wrong happend with #{node}. Removing it."
-          $nodes.delete(node)
-          running = false
-          $wtasks.unshift(t)
-        end
-      end
-    end
-  end
-end
-
-Thread::new { tcpserver }
-Thread::new { showtop }
-
-# read and start nodes
-nodes = IO::read(ARGV[0]).split(/\n/).map { |l| l.chomp }
-$masternode = nodes[0]
-nodes = (nodes.sort.uniq - [nodes[0]]).sort.uniq # removing head node.
-nodes.each do |n|
-  $ths << Thread::new(n) { |n| managenode(n) }
-end
-
-# Tasks
-if File::exists?(ARGV[1])
-  begin
-    tasks = Marshal::load(IO::read(ARGV[1]))
-  rescue
-    puts "Something really wrong happend while reading tasks list, setting interactive mode."
-    $interactive = true
-    tasks = []
-  end
-  $mutex.synchronize do
-    tasks.each do |t|
-      $wtasks << t
-    end
-    $wtasks.sort!
-    $wtasks.reverse! if not SHORTERLAST
-  end
-else
-  puts "Task list not found, ignoring."
-  $interactive = true
-end
-
-# Preparation of master node + chroots
-ret = system("/debcluster-scripts/scripts/tasks/preparenode.rb --log /debcluster-data/logs/preparenode/MASTER-#{$masternode}.$(date --iso)")
-if not ret
-  puts "preparenode.rb FAILED on masternode. exiting."
-  exit(1)
-end
-# run apt-get update inside chroots
-# [ 'etch32-source', 'etch64-source', 'etch32-piuparts-source', 'sid32-source', 'sid64-source' ].each do |c|
-[ ].each do |c|
-  puts "Updating #{c}:"
-  ret = system("cd / && schroot -c #{c} -- sh -c \"apt-get update && apt-get -y dist-upgrade && apt-get clean\"")
-  if not ret
-    puts "Update of #{c} FAILED. exiting."
-    exit(1)
-  end
-end
-$ready = true
-
-continue = true
-while continue
-  $mutex.synchronize do
-    if $wtasks.length > 0 and not $started
-      $started = true
-    end
-    if $started and $wtasks.length == 0 and (not $interactive)
-      # no tasks remaining.
-      busy = $nodes.keys.inject(0) { |a, b| a + ($nodes[b] == :free ? 0 : 1) }
-      if busy == 0
-        puts "### No tasks, no nodes busy. Exiting."
-        exit 0
-      else
-        puts "### No tasks, but #{busy} nodes busy."
-      end
-    end
-  end
-  sleep SLEEPTIME
-end

Modified: debcluster/scripts/masternode.rb
===================================================================
--- debcluster/scripts/masternode.rb	2008-01-18 10:17:41 UTC (rev 654)
+++ debcluster/scripts/masternode.rb	2008-01-18 12:39:25 UTC (rev 655)
@@ -5,19 +5,56 @@
 require 'debtask'
 require 'socket'
 require 'time'
+require 'optparse'
+require 'ipaddr'
 
 Thread::abort_on_exception = true
 
-DEFAULT_TASKS_PER_NODE = 1
+$default_tasks_per_node = 1
+$virt = false
+$subnodes = false
 
+opts = OptionParser::new do |opts|
+  opts.banner = "Usage: ./preparenode.rb [options]"
+  opts.separator ""
+  opts.separator "Options:"
+  opts.on("-s", "--subnodes NUMB", "Number of tasks per node") do |l|
+    $default_tasks_per_node = l.to_i
+    $subnodes = true
+  end
+  opts.on("-v", "--virtual", "use QEMU nodes") do |l|
+    $virt = true
+  end
+end
+opts.parse!(ARGV)
+
+### Constants
+NBNODES = [
+  [ /^heliostest.*/, 4 ]
+]
+# https://www.grid5000.fr/mediawiki/index.php/Network_interlink#IP.27s_for_virtual_machines
+NET_GW = {
+ 'rennes' => '10.159.255.254',
+ 'sophia' => '10.167.255.254'
+}
+NET_NS = {
+ 'rennes' => '131.254.202.5',
+ 'sophia' => '138.96.20.225'
+}
+NET_ADDR = {
+ 'rennes' => '10.156.0.1',
+ 'sophia' => '10.164.0.1'
+}
+$first_addr = {}
+
 SSHOPTS="-o BatchMode=yes -o StrictHostKeyChecking=no"
 DEBUG_PREP = true
 SLEEPTIME = 10
 TCPPORT=36363
-
 # Convenient for testing: set false
 SHORTERLAST=true
 
+# Global state
 $nodes = {}
 $wtasks = []
 $nbfinished = 0
@@ -29,27 +66,42 @@
 $ready = false
 $interactive = false
 
-def preparenode(n)
+# Modified classes
+# Extend class IPAddr with functions to get next IP
+class IPAddr
+  def next
+    raise "next: Not supported for IPv6!" if self.ipv6?
+    IPAddr::from_int(self.to_i + 1)
+  end
+
+  def IPAddr::from_int(i)
+    s = [ (i & 0xff000000) >> 24, (i & 0xff0000) >> 16, (i & 0xff00) >> 8, i & 0xff].join('.')
+    return IPAddr::new(s)
+  end
+
+  def +(i)
+    if i > 1
+      return self.next + (i-1)
+    else
+      return self.next
+    end
+  end
+
+  def to_masked
+    inspect.split(':')[2].split('>')[0].gsub('/',':')
+  end
+end
+
+def preparenode(n, vn, ns, gw)
   puts "Preparing #{n}..." if DEBUG_PREP
   system("ssh #{SSHOPTS} #{n} exit 42")
   if $?.exitstatus != 42
     puts "E:Public key auth on #{n} failed."
     return false
   end
-  # remove proxy
-  system("ssh #{SSHOPTS} #{n} \"sed -i 's/.*http_proxy.*//' /etc/environment\"")
-  # mount /debcluster
-  system("ssh #{SSHOPTS} #{n} \"apt-get update && apt-get install -y nfs-common initscripts sysvinit-utils\" &>/dev/null")
-  if `ssh #{SSHOPTS} #{n} \"mount | grep /idpotscratch | wc -l\"`.to_i == 0
-    system("ssh #{SSHOPTS} #{n} \"mkdir /idpotscratch  &>/dev/null; rm -f /debcluster-data /debcluster-scripts &>/dev/null\"")
-    ret = system("ssh #{SSHOPTS} #{n} mount -t nfs -o rw,hard,intr,async,nfsvers=3,rsize=32768,wsize=32768 idpot.grenoble.grid5000.fr:/nfs-scratch /idpotscratch")
-    if not ret
-      puts "E:Failed to mount /idpotscratch on #{n} failed."
-      return false
-    end
-  end
-  system("ssh #{SSHOPTS} #{n} \"rm -f /debcluster-data /debcluster-scripts ; ln -sf /idpotscratch/grenoble/lnussbaum/debcluster-data /debcluster-data ; ln -sf /idpotscratch/grenoble/lnussbaum/collab-qa/debcluster /debcluster-scripts\"")
-  ret = system("ssh #{SSHOPTS} #{n} \"/debcluster-scripts/scripts/tasks/preparenode.rb --log /debcluster-data/logs/preparenode/#{n}.$(date --iso)\"")
+  system("scp #{SSHOPTS} /debcluster-scripts/scripts/bin/dc-mountnfs #{n}:/root/dc-mountnfs")
+  system("ssh #{SSHOPTS} #{n} \"/root/dc-mountnfs\" &> /root/mountnfs.log.#{n}") 
+    ret = system("ssh #{SSHOPTS} #{n} \"/debcluster-scripts/scripts/tasks/preparenode.rb --log /debcluster-data/logs/preparenode/#{n}.$(date --iso)\"")
   if not ret
     puts "E:preparenode.rb failed on #{n}."
     return false
@@ -201,20 +253,39 @@
   end
 end
 
-NBNODES = [
-  [ /^heliostest.*/, 4 ]
-]
 def managenode(nodehost)
   # nodehost is just the node name in text.
-  return if not preparenode(nodehost)
-  nbsubnodes = DEFAULT_TASKS_PER_NODE # default value
+  nbsubnodes = $default_tasks_per_node # default value
   NBNODES.each do |t|
     if nodehost =~ t[0]
       nbsubnodes = t[1]
     end
   end
-  (1..nbsubnodes).each do |i|
-    node = Node::new(nodehost, i)
+  if nodehost !~ /\.(\w+)\.grid5000\.fr$/
+    puts "INCORRECT NODE: #{nodehost}"
+    return
+  end
+  cluster = $1
+  p cluster
+  if $first_addr[cluster].nil?
+    $first_addr[cluster] = IPAddr::new(NET_ADDR[cluster])
+  end
+  vn = []
+  if $virt
+    (1..nbsubnodes).each do |i|
+    
+      vn << $first_addr[cluster]
+      $first_addr[cluster] = $first_addr[cluster].next
+    end
+  end
+  return if not preparenode(nodehost, vn, NET_NS['cluster'], NET_GW['cluster'])
+  if $virt
+    vn.each do |i|
+      node = Node::new(nodehost, i)
+      Thread::new(node) { |node| manageworker(node) }
+    end
+  else
+    node = Node::new(nodehost, '1')
     Thread::new(node) { |node| manageworker(node) }
   end
 end

Deleted: debcluster/scripts/tasks/preparenode-virt.rb
===================================================================
--- debcluster/scripts/tasks/preparenode-virt.rb	2008-01-18 10:17:41 UTC (rev 654)
+++ debcluster/scripts/tasks/preparenode-virt.rb	2008-01-18 12:39:25 UTC (rev 655)
@@ -1,99 +0,0 @@
-#!/usr/bin/ruby1.8 -w
-
-require 'optparse'
-
-logfile = nil
-vn = []
-opts = OptionParser::new do |opts|
-  opts.banner = "Usage: ./preparenode.rb [options]"
-  opts.separator ""
-  opts.separator "Options:"
-  opts.on("-l", "--log LOGFILE", "Specify log file") do |l|
-    logfile = l
-  end
-  opts.on("-m", "--machine MACHINE", "Specify VM") do |l|
-    vn << l 
-  end
-end
-opts.parse!(ARGV)
-
-if logfile != nil
-  f = File::new(logfile, 'w')
-  STDOUT.reopen(f)
-  STDERR.reopen(f)
-end
-
-File::open('/etc/apt/sources.list', 'w') do |f|
-  f.puts "deb http://idpot.grenoble.grid5000.fr/mirrors/debian lenny main contrib non-free"
-  f.puts "deb http://idpot.grenoble.grid5000.fr/mirrors/debian sid main contrib non-free"
-  f.puts "deb-src http://idpot.grenoble.grid5000.fr/mirrors/debian sid main contrib non-free"
-  f.puts "deb-src http://idpot.grenoble.grid5000.fr/mirrors/debian etch main contrib non-free"
-end
-system("echo \"debconf debconf/frontend select noninteractive\" | debconf-set-selections")
-system("echo \"debconf debconf/priority select critical\" | debconf-set-selections")
-ENV['DEBIAN_FRONTEND'] = 'noninteractive'
-system("apt-get update")
-system("apt-get install -y pbuilder nullmailer sbuild schroot debootstrap fakeroot piuparts python nfs-common initscripts sysvinit-utils apache2 linux32")
-system("dpkg -i /debcluster-data/piuparts/piuparts*deb")
-system("apt-get -f install")
-system("apt-get install -y sbuild")
-
-# configure apache2 as proxy
-system("cp /debcluster-scripts/configs/{disk_cache.conf,mem_cache.conf,proxy.conf} /etc/apache2/mods-available/")
-[ 'cache.load', 'disk_cache.conf', 'disk_cache.load', 'mem_cache.conf', 'mem_cache.load', 'proxy.conf', 'proxy.load', 'proxy_http.load' ].each do |f|
-  system("cd /etc/apache2/mods-enabled/ && ln -s ../mods-available/#{f}")
-end
-system("/etc/init.d/apache2 restart")
-system("htcacheclean -d15 -n -l1500M -p/var/cache/apache2/mod_disk_cache")
-system("echo 'http_proxy=http://localhost:81/' > /etc/environment")
-system("echo 'DEBIAN_FRONTEND=noninteractive' >> /etc/environment")
-ENV['http_proxy'] = 'http://localhost:81/'
-
-# do rest of config
-system("rm -rf /etc/schroot ; cp -r /debcluster-scripts/configs/schroot /etc/schroot")
-
-# find location of scratch:
-scratch = `df |grep -e tmp -e scratch |grep -v "^tmpfs" |grep -v idpot |grep -v nfs | sort -r -n -k 2 | awk '{print $6}'`.chomp
-if scratch != '/scratch' and scratch != '/tmp'
-  puts "ERROR: scratch found: #{scratch}. Using /tmp instead."
-  scratch = '/tmp'
-end
-
-# cleanup scratch
-system("for i in $(ls #{scratch} | grep -v lost+found | grep -v \".(ICE|X11)-unix)\" | grep -v \"$ssh-\"); do rm -rf $i; done")
-
-system("rm -f /debscratch")
-system("ln -s #{scratch} /debscratch")
-
-system("rm -rf /var/lib/schroot")
-system("mkdir #{scratch}/schroot")
-system("ln -s #{scratch}/schroot /var/lib/schroot")
-
-system("mkdir -p /var/lib/schroot/mount /var/lib/schroot/session")
-
-#system("cp /debcluster-scripts/configs/piuparts /usr/sbin/piuparts")
-system("cp /debcluster-scripts/configs/etcsbuild.conf /etc/sbuild/sbuild.conf")
-system("cp /debcluster-scripts/configs/dotsbuildrc /root/.sbuildrc")
-
-system("echo 'Defaults:root env_keep+=\"APT_CONFIG DEBIAN_FRONTEND SHELL\"' >> /etc/sudoers")
-system("[ -d /tmp/build ] || mkdir /tmp/build")
-system("adduser --home /home/user --uid 1001 --ingroup sbuild --disabled-password --gecos User user")
-system("/usr/sbin/sbuild-adduser user")
-system("cp /debcluster-scripts/configs/dotsbuildrc /home/user/.sbuildrc")
-system("ls -la /home/user/.sbuildrc")
-
-# VIRT-specific stuff
-system("apt-get -y build-dep qemu")
-system("apt-get -y install pkg-config bridge-utils screen")
-system("cd /debcluster-data/qemu/qemu && make install")
-system("rsync -avzP lnussbaum at idpot.grenoble.grid5000.fr:debcluster-data/qemu/hda-mips.qcow2 /debscratch/hda-mips.qcow2")
-system("cp /debcluster-data/qemu/{initrd.gz,vmlinux-2.6.18-5-qemu} /debscratch")
-system("cat /debcluster-data/qemu/bridge.interfaces >> /etc/network/interfaces")
-system("ifdown eth0 ; ifup br0")
-vn.each do |v|
-  system("cd /debscratch && screen -d -m \"qemu-system-mips -kernel vmlinux-2.6.18-5-qemu -initrd initrd.gz -hda hda-mips.qcow2 -append \\\"root=/dev/hda1 console=ttyS0 ip=#{v} mask=255.252.0.0 ns=138.96.20.225 gw=10.167.255.254\\\" -nographic -net nic -net tap,script=/debcluster-scripts/configs/qemu-ifup -m 256 -snapshot\"")
-end
-sleep 30
-
-
-exit 0

Modified: debcluster/scripts/tasks/preparenode.rb
===================================================================
--- debcluster/scripts/tasks/preparenode.rb	2008-01-18 10:17:41 UTC (rev 654)
+++ debcluster/scripts/tasks/preparenode.rb	2008-01-18 12:39:25 UTC (rev 655)
@@ -3,6 +3,10 @@
 require 'optparse'
 
 logfile = nil
+virt = false
+vn = []
+ns = nil
+gw = nil
 
 opts = OptionParser::new do |opts|
   opts.banner = "Usage: ./preparenode.rb [options]"
@@ -11,6 +15,18 @@
   opts.on("-l", "--log LOGFILE", "Specify log file") do |l|
     logfile = l
   end
+  opts.on("-v", "--virtual", "Setup virtual nodes") do |l|
+    virt = true 
+  end
+  opts.on("-m", "--machine MACHINE", "Specify VM") do |l|
+    vn << l 
+  end
+  opts.on("-n", "--ns MACHINE", "Specify NS") do |l|
+    ns = l 
+  end
+  opts.on("-g", "--gw MACHINE", "Specify GW") do |l|
+    gw = l
+  end
 end
 opts.parse!(ARGV)
 
@@ -20,6 +36,15 @@
   STDERR.reopen(f)
 end
 
+puts "Starting preparenode.rb -- #{Time::now}"
+
+# SSH
+system("mkdir ~/.ssh &>/dev/null")
+system("cp /debcluster-data/ssh/* ~/.ssh/")
+
+# APT
+system("sed -i 's/.*http_proxy.*//' /etc/environment")
+ENV['http_proxy'] = ''
 File::open('/etc/apt/sources.list', 'w') do |f|
   f.puts "deb http://idpot.grenoble.grid5000.fr/mirrors/debian lenny main contrib non-free"
   f.puts "deb http://idpot.grenoble.grid5000.fr/mirrors/debian sid main contrib non-free"
@@ -30,17 +55,18 @@
 system("echo \"debconf debconf/priority select critical\" | debconf-set-selections")
 ENV['DEBIAN_FRONTEND'] = 'noninteractive'
 system("apt-get update")
-system("apt-get install -y pbuilder nullmailer sbuild schroot debootstrap fakeroot piuparts python nfs-common initscripts sysvinit-utils apache2 linux32")
+
+# basic packages
+system("apt-get install -y pbuilder nullmailer sbuild schroot debootstrap fakeroot piuparts python nfs-common initscripts sysvinit-utils apache2 linux32 sbuild")
 system("dpkg -i /debcluster-data/piuparts/piuparts*deb")
 system("apt-get -f install")
-system("apt-get install -y sbuild")
 
 # configure apache2 as proxy
 system("cp /debcluster-scripts/configs/{disk_cache.conf,mem_cache.conf,proxy.conf} /etc/apache2/mods-available/")
 [ 'cache.load', 'disk_cache.conf', 'disk_cache.load', 'mem_cache.conf', 'mem_cache.load', 'proxy.conf', 'proxy.load', 'proxy_http.load' ].each do |f|
-  system("cd /etc/apache2/mods-enabled/ && ln -s ../mods-available/#{f}")
+  system("cd /etc/apache2/mods-enabled/ && ln -sf ../mods-available/#{f}")
 end
-system("/etc/init.d/apache2 restart")
+system("/etc/init.d/apache2 stop ; /etc/init.d/apache2 start")
 system("htcacheclean -d15 -n -l1500M -p/var/cache/apache2/mod_disk_cache")
 system("echo 'http_proxy=http://localhost:81/' > /etc/environment")
 system("echo 'DEBIAN_FRONTEND=noninteractive' >> /etc/environment")
@@ -60,15 +86,14 @@
 system("for i in $(ls #{scratch} | grep -v lost+found | grep -v \".(ICE|X11)-unix)\" | grep -v \"$ssh-\"); do rm -rf $i; done")
 
 system("rm -f /debscratch")
-system("ln -s #{scratch} /debscratch")
+system("ln -sf #{scratch} /debscratch")
 
 system("rm -rf /var/lib/schroot")
-system("mkdir #{scratch}/schroot")
-system("ln -s #{scratch}/schroot /var/lib/schroot")
+system("mkdir #{scratch}/schroot &>/dev/null")
+system("ln -sf #{scratch}/schroot /var/lib/schroot")
 
 system("mkdir -p /var/lib/schroot/mount /var/lib/schroot/session")
 
-#system("cp /debcluster-scripts/configs/piuparts /usr/sbin/piuparts")
 system("cp /debcluster-scripts/configs/etcsbuild.conf /etc/sbuild/sbuild.conf")
 system("cp /debcluster-scripts/configs/dotsbuildrc /root/.sbuildrc")
 
@@ -78,4 +103,22 @@
 system("/usr/sbin/sbuild-adduser user")
 system("cp /debcluster-scripts/configs/dotsbuildrc /home/user/.sbuildrc")
 system("ls -la /home/user/.sbuildrc")
+
+if virt
+# VIRT-specific stuff
+  system("apt-get -y build-dep qemu")
+  system("apt-get -y install pkg-config bridge-utils screen")
+  system("cat /debcluster-data/qemu/bridge.interfaces >> /etc/network/interfaces ; cp /debcluster-data/qemu/setupbridge.bash /root")
+  system("cd /root ; ./setupbridge.bash < /dev/null &>/root/iflog ; cat /root/iflog")
+  system("rsync -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' -avzP lnussbaum at idpot.grenoble.grid5000.fr:debcluster-data/qemu/hda-mips.qcow2 /debscratch/hda-mips.qcow2")
+  system("cd /debcluster-data/qemu/qemu && make install")
+  system("cp /debcluster-data/qemu/{initrd.gz,vmlinux-2.6.18-5-qemu} /debscratch")
+  vn.each do |v|
+    system("cd /debscratch && screen -d -m \"qemu-system-mips -kernel vmlinux-2.6.18-5-qemu -initrd initrd.gz -hda hda-mips.qcow2 -append \\\"root=/dev/hda1 console=ttyS0 ip=#{v} mask=255.252.0.0 ns=138.96.20.225 gw=10.167.255.254\\\" -nographic -net nic -net tap,script=/debcluster-scripts/configs/qemu-ifup -m 256 -snapshot\"")
+  end
+  puts "Sleeping 30 seconds to let qemu nodes the time to boot."
+  sleep 30
+end
+
+puts "Finishing preparenode.rb -- #{Time::now}"
 exit 0




More information about the Collab-qa-commits mailing list