Exemplo n.º 1
0
    def setupBridge(self, interfaces=[], stp=True):
        bridge = "br0"
        self.runBridgeCmd("add-br %s" % bridge)
        if stp:
            self.runBridgeCmd("set bridge  %s stp=true" % bridge)
        for eth in interfaces:
            self.runBridgeCmd("add-port %s %s" % (bridge, eth))

        cli = self.cli()
        cli.runCmd("sudo ifconfig %s up" % bridge)
        for eth in interfaces:
            cli.runCmd("sudo ifconfig %s up" % eth)
Exemplo n.º 2
0
 def revertToInitialSnapshot(self, logLevel=logging.INFO):
     log.info("=== Reverting to initial snapshot on node %s", self.name())
     if self.imageMode() == "snapshot":
         self.revertToSnapshot("initial", logLevel)
         self.serialLogin(logLevel)
         cli = bigtest.cli.Cli(self.serialConsole(logLevel), self.imageType())
         cli.runCmd("sudo hwclock -s -u")
     elif self.imageMode() == "persistent":
         self.powerOff()
         bigtest.run("rm -f %s" % self.image())
         bigtest.run("cp %s.initial %s" % (self.image(), self.image()))
         self.powerOn()
     log.info("=== Finished reverting to initial snapshot on node %s", self.name())
Exemplo n.º 3
0
 def revertToInitialSnapshot(self, logLevel=logging.INFO):
     log.info("=== Reverting to initial snapshot on node %s", self.name())
     if self.imageMode() == "snapshot":
         self.revertToSnapshot("initial", logLevel)
         self.serialLogin(logLevel)
         cli = bigtest.cli.Cli(self.serialConsole(logLevel),
                               self.imageType())
         cli.runCmd("sudo hwclock -s -u")
     elif self.imageMode() == "persistent":
         self.powerOff()
         bigtest.run("rm -f %s" % self.image())
         bigtest.run("cp %s.initial %s" % (self.image(), self.image()))
         self.powerOn()
     log.info("=== Finished reverting to initial snapshot on node %s",
              self.name())
Exemplo n.º 4
0
    def startVm(self, name, spec, datastore, wait_for_migration=False):
        cli = self.cli()
        
        # create vm folder
        vm_dir = os.path.join(datastore, name)
        cli.runCmd("sudo mkdir -p %s" % vm_dir)

        # copy vmdk file
        defaultMount = os.path.join("/mnt", spec.nfsHost,
                                    os.path.basename(spec.nfsShare))
        mount = self.mountNas(spec.nfsHost, spec.nfsShare, defaultMount)
        srcVmdk = os.path.join(mount, spec.vmdkPath)
        dstVmdk = os.path.join(vm_dir, os.path.basename(spec.vmdkPath))
        cli.runCmd("sudo cp %s %s" % (srcVmdk, dstVmdk))
        
        # serial
        serial = self.serialCounter()
        self.setSerialCounter(serial + 1)
        monitor = self.monitorCounter()
        self.setMonitorCounter(monitor + 1)

        # network
        mac = "52:54:00:%02x:%02x:%02x" % ((hash(name) >> 16) & 0xff,
                                           (hash(name) >> 8) & 0xff,
                                           hash(name) & 0xff)
        ifup = "/etc/ovs-ifup" # ovs-br0
        ifdown = "/etc/ovs-ifdown" # ovs-br0

        # start kvm
        cmdline = ("sudo kvm "
                         "-name %s "
                         "-daemonize "
                         "-nographic "
                         "-serial telnet::%d,server,nowait "
                         "-qmp telnet::%d,server,nowait "
                         "-m %s "
                         "-hda %s " 
                         "-net nic,macaddr=%s "
                         "-net tap,script=%s,downscript=%s "
                         % (name, serial, monitor, spec.memory, dstVmdk,
                            mac, ifup, ifdown))
        if wait_for_migration:
            cmdline += " -incoming tcp:0:%d " % (monitor+1000)
        self.setCmdline(cmdline)
        ret = cli.runCmd(cmdline)
        self.setCreatedVms((self.createdVms()) + [name])
        return (ret, serial)
Exemplo n.º 5
0
 def getIPFromSerial(self, logLevel=logging.DEBUG):
     self.serialLogin(logLevel)
     cli = bigtest.cli.Cli(self.serialConsole(logLevel))
     cli.gotoBashMode()
     output = cli.runCmd("ifconfig eth0")
     m = re.search(r"inet addr:([^\s]+)", output, re.M)
     bigtest.Assert(m and m.group(1) != "")
     return m.group(1)
Exemplo n.º 6
0
 def getIPFromSerial(self, logLevel=logging.DEBUG):
     self.serialLogin(logLevel)
     cli = bigtest.cli.Cli(self.serialConsole(logLevel))
     cli.gotoBashMode()
     output = cli.runCmd("ifconfig eth0")
     m = re.search(r"inet addr:([^\s]+)", output, re.M)
     bigtest.Assert(m and m.group(1) != "")
     return m.group(1)
Exemplo n.º 7
0
 def runSerialCmd(self, cmd, interval=5, timeout=600):
     exception = Exception("Unknown exception in runSerialCmd()")
     timeout_ = time.time() + timeout
     while time.time() < timeout_:
         try:
             console = self.serialConsole()
             username = self.username()
             self.doSerialLogin(console, username, r"\r\n[-.\w]+ login: "******"linux")
             return cli.runCmd(cmd)
         except Exception, e:
             exception = e
             self.serialConsole_ = None
             bigtest.log.error("runSerialCmd() failed...")
         time.sleep(interval)
Exemplo n.º 8
0
 def mountNas(self, server, share, mount):
     cli = self.cli()
     # check if already mounted
     pat = re.compile(r"%s:%s on ([^\s]+)" % (re.escape(server),
                                              re.escape(share)))
     for line in cli.runCmd("mount").split("\n"):
         m = pat.search(line)
         if m:
             return m.group(1)
     cli.runCmd("sudo mkdir -p %s" % mount)
     cli.runCmd("sudo sh -c 'echo \"%s:%s %s nfs rw 0 0\" >> /etc/fstab'" \
                 % (server, share, mount))
     cli.runCmd("sudo mount -a")
     return mount
Exemplo n.º 9
0
 def shutdown(self, delay=0, waitForState=False):
     cli = self.cli(logging.DEBUG)
     cli.gotoBashMode()
     cli.runCmd("sudo shutdown -h %d" % delay)
     if waitForState:
         bigtest.waitForProcessToStop(self.pid())
Exemplo n.º 10
0
 def reboot(self):
     cli = self.cli(logging.DEBUG)
     cli.gotoBashMode()
     cli.runCmd("sudo reboot")
Exemplo n.º 11
0
 def reboot(self):
     cli = self.cli(logging.DEBUG)
     cli.gotoBashMode()
     cli.runCmd("sudo reboot")
Exemplo n.º 12
0
 def shutdown(self, delay=0):
     cli = self.cli(logging.DEBUG)
     cli.gotoBashMode()
     cli.runCmd("sudo shutdown -h %d" % delay)
Exemplo n.º 13
0
 def runBridgeCmd(self, cmd):
     cli = self.cli()
     return cli.runCmd("sudo ovs-vsctl --no-wait %s" % cmd)
Exemplo n.º 14
0
 def runOVSCmd(self, cmd):
     cli = self.cli()
     return cli.runCmd("sudo ovs-vsctl %s" % cmd)
Exemplo n.º 15
0
 def shutdown(self, delay=0, waitForState=False):
     cli = self.cli(logging.DEBUG)
     cli.gotoBashMode()
     cli.runCmd("sudo shutdown -h %d" % delay)
     if waitForState:
         bigtest.waitForProcessToStop(self.pid())