Ejemplo n.º 1
0
    def get_console_prompt(self):
        if self.get_lpar_state() != OpHmcState.RUNNING:
            raise OpTestError('LPAR is not in Running State. Please check!')
        log.info("De-activating the console")

        self.deactivate_lpar_console()
        command = "sshpass -p %s ssh -p 22 -l %s %s -o PubkeyAuthentication=no"\
                  " -o afstokenpassing=no -q -o 'UserKnownHostsFile=/dev/null'"\
                  " -o 'StrictHostKeyChecking=no'"
        self.lpar_con = OPexpect.spawn(command %
                                       (self.passwd, self.user, self.hmc_ip))
        self.wait_lpar_state()
        log.info("Opening the LPAR console")
        self.vterm = True
        self.lpar_con.sendline("mkvterm -m %s -p %s" %
                               (self.system, self.lpar_name))
        self.lpar_con.send('\r')
        time.sleep(STALLTIME)
        i = self.lpar_con.expect(["Open Completed.", pexpect.TIMEOUT],
                                 timeout=60)
        self.lpar_con.logfile = sys.stdout
        self.lpar_con.logfile_read = OpTestLogger.FileLikeLogger(log)
        if i == 0:
            time.sleep(STALLTIME)
            return self.lpar_con
        else:
            raise OpTestError("Check the lpar activate command")
Ejemplo n.º 2
0
    def connect(self):
        if self.state == ConsoleState.CONNECTED:
            self.console.terminate()
            self.state = ConsoleState.DISCONNECTED

        cmd = ("sshpass -p %s " % (self.password)
               + " ssh"
               + " -p %s" % str(self.port)
               + " -l %s %s" % (self.username, self.host)
               + " -o PubkeyAuthentication=no"
               )

        if not self.check_ssh_keys:
            cmd = (cmd
                    + " -q"
                    + " -o 'UserKnownHostsFile=/dev/null' "
                    + " -o 'StrictHostKeyChecking=no'"
                    )
        elif self.known_hosts_file:
            cmd = (cmd + " -o UserKnownHostsFile=" + self.known_hosts_file)

        print cmd
        consoleChild = OPexpect.spawn(cmd,logfile=self.logfile,
                failure_callback=set_system_to_UNKNOWN,
                failure_callback_data=self.system)
        self.state = ConsoleState.CONNECTED
        self.console = consoleChild
        # Users expecting "Host IPMI" will reference console.sol so make it available
        self.sol = self.console
        self.set_unique_prompt(consoleChild)
        return consoleChild
Ejemplo n.º 3
0
    def connect(self):
        if self.state == ConsoleState.CONNECTED:
            self.sol.terminate()
            self.state = ConsoleState.DISCONNECTED

        print "#Qemu Console CONNECT"

        cmd = ("%s" % (self.qemu_binary)
               + " -M powernv -m 4G"
               + " -nographic"
               + " -bios %s" % (self.skiboot)
               + " -kernel %s" % (self.kernel)
           )
        if self.initramfs is not None:
            cmd = cmd + " -initrd %s" % (self.initramfs)
        if self.hda is not None:
            cmd = cmd + " -hda %s" % (self.hda)
        if self.ubuntu_cdrom is not None:
            cmd = cmd + " -cdrom %s" % (self.ubuntu_cdrom)
        cmd = cmd + " -netdev user,id=u1 -device e1000,netdev=u1"

        print cmd
        solChild = OPexpect.spawn(cmd,logfile=self.logfile)
        self.state = ConsoleState.CONNECTED
        self.sol = solChild
        return solChild
Ejemplo n.º 4
0
    def connect(self):
        if self.state == ConsoleState.CONNECTED:
            self.sol.terminate()
            self.state = ConsoleState.DISCONNECTED

        print "#Qemu Console CONNECT"

        cmd = ("%s" % (self.qemu_binary)
               + " -M powernv -m 4G"
               + " -nographic"
               + " -bios %s" % (self.skiboot)
               + " -kernel %s" % (self.kernel)
           )
        if self.initramfs is not None:
            cmd = cmd + " -initrd %s" % (self.initramfs)
        if self.hda is not None:
            cmd = cmd + " -hda %s" % (self.hda)
        if self.ubuntu_cdrom is not None:
            cmd = cmd + " -cdrom %s" % (self.ubuntu_cdrom)
        cmd = cmd + " -netdev user,id=u1 -device e1000,netdev=u1"
        cmd = cmd + " -device ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10"
        print cmd
        solChild = OPexpect.spawn(cmd,logfile=self.logfile)
        self.state = ConsoleState.CONNECTED
        self.sol = solChild
        return solChild
Ejemplo n.º 5
0
    def connect(self):
        if self.state == IPMIConsoleState.CONNECTED:
            self.sol.terminate()
            self.state = IPMIConsoleState.DISCONNECTED

        print "#IPMI SOL CONNECT"
        try:
            self.ipmitool.run('sol deactivate')
        except OpTestError:
            print 'SOL already deactivated'

        cmd = self.ipmitool.binary_name() + self.ipmitool.arguments() + ' sol activate'
        print cmd
        solChild = OPexpect.spawn(cmd,logfile=self.logfile,
                                  failure_callback=set_system_to_UNKNOWN,
                                  failure_callback_data=self.system)
        self.state = IPMIConsoleState.CONNECTED
        self.sol = solChild
        if self.delaybeforesend:
	    self.sol.delaybeforesend = self.delaybeforesend
        self.sol.expect_exact('[SOL Session operational.  Use ~? for help]')
        # we pause for a moment to allow ipmitool to catch up with
        # itself and to start accepting input
        time.sleep(0.2)
        return solChild
Ejemplo n.º 6
0
    def connect(self):
        if self.state == ConsoleState.CONNECTED:
            return self.sol
        else:
            self.util.clear_state(self) # clear when coming in DISCONNECTED

        log.debug("#Qemu Console CONNECT")

        cmd = ("%s" % (self.qemu_binary)
               + " -machine powernv -m 4G"
               + " -nographic -nodefaults"
           )
        if self.pnor:
            cmd = cmd + " -drive file={},format=raw,if=mtd".format(self.pnor)
        if self.skiboot:
            cmd = cmd + " -bios %s" % (self.skiboot)
        if self.kernel:
            cmd = cmd + " -kernel %s" % (self.kernel)
            if self.initramfs is not None:
                cmd = cmd + " -initrd %s" % (self.initramfs)

        if self.hda is not None:
            # Put the disk on the first PHB
            cmd = (cmd
                    + " -drive file={},id=disk01,if=none".format(self.hda)
                    + " -device virtio-blk-pci,drive=disk01,id=virtio01,bus=pcie.0,addr=0"
                )
        if self.cdrom is not None:
            # Put the CDROM on the second PHB
            cmd = (cmd
                    + " -drive file={},id=cdrom01,if=none,media=cdrom".format(self.cdrom)
                    + " -device virtio-blk-pci,drive=cdrom01,id=virtio02,bus=pcie.1,addr=0"
                )
        # typical host ip=10.0.2.2 and typical skiroot 10.0.2.15
        # use skiroot as the source, no sshd in skiroot
        cmd = cmd + " -nic user,model=virtio-net-pci"
        cmd = cmd + " -device ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10"
        cmd = cmd + " -serial none -device isa-serial,chardev=s1 -chardev stdio,id=s1,signal=off"
        print cmd
        try:
          solChild = OPexpect.spawn(cmd,logfile=self.logfile)
        except Exception as e:
          self.state = ConsoleState.DISCONNECTED
          raise CommandFailed('OPexpect.spawn',
                  'OPexpect.spawn encountered a problem: ' + str(e), -1)

        self.state = ConsoleState.CONNECTED
        solChild.setwinsize(1000,1000)
        self.sol = solChild
        self.console = solChild
        if self.delaybeforesend:
          self.sol.delaybeforesend = self.delaybeforesend

        if self.system.SUDO_set != 1 or self.system.LOGIN_set != 1 or self.system.PS1_set != 1:
          self.util.setup_term(self.system, self.sol, None, self.system.block_setup_term)

        time.sleep(0.2)
        return solChild
Ejemplo n.º 7
0
    def connect(self, logger=None):
        if self.state == ConsoleState.CONNECTED:
            rc_child = self.close()
            self.state = ConsoleState.DISCONNECTED
        else:
            self.util.clear_state(self)  # clear when coming in DISCONNECTED

        cmd = ("sshpass -p %s " % (self.password) + " ssh" +
               " -p %s" % str(self.port) + " -l %s %s" %
               (self.username, self.host) +
               " -o PubkeyAuthentication=no -o afstokenpassing=no")

        if not self.check_ssh_keys:
            cmd = (cmd + " -q" + " -o 'UserKnownHostsFile=/dev/null' " +
                   " -o 'StrictHostKeyChecking=no'")
        elif self.known_hosts_file:
            cmd = (cmd + " -o UserKnownHostsFile=" + self.known_hosts_file)

        # For multi threades SSH sessions use individual logger and file handlers per session.
        if logger:
            self.log = logger
        elif self.use_parent_logger:
            self.log = log
        else:
            self.log = OpTestLogger.optest_logger_glob.get_custom_logger(
                __name__)

        self.log.debug(cmd)

        try:
            self.pty = OPexpect.spawn(
                cmd,
                logfile=self.logfile,
                failure_callback=set_system_to_UNKNOWN_BAD,
                failure_callback_data=self.system)
        except Exception as e:
            self.state = ConsoleState.DISCONNECTED
            raise CommandFailed("OPexepct.spawn encountered a problem", e, -1)

        self.state = ConsoleState.CONNECTED
        # set for bash, otherwise it takes the 24x80 default
        self.pty.setwinsize(1000, 1000)
        if self.delaybeforesend:
            self.pty.delaybeforesend = self.delaybeforesend
        self.pty.logfile_read = OpTestLogger.FileLikeLogger(self.log)
        time.sleep(
            2
        )  # delay here in case messages like afstokenpassing unsupported show up which mess up setup_term
        self.check_set_term()
        log.debug("CONNECT starts Expect Buffer ID={}".format(hex(id(
            self.pty))))
        return self.pty
Ejemplo n.º 8
0
    def connect(self, logger=None):
        if self.state == ConsoleState.CONNECTED:
            rc_child = self.close()
            self.state = ConsoleState.DISCONNECTED
        else:
            self.util.clear_state(self) # clear when coming in DISCONNECTED

        cmd = ("sshpass -p %s " % (self.password)
               + " ssh"
               + " -p %s" % str(self.port)
               + " -l %s %s" % (self.username, self.host)
               + " -o PubkeyAuthentication=no -o afstokenpassing=no"
               )

        if not self.check_ssh_keys:
            cmd = (cmd
                    + " -q"
                    + " -o 'UserKnownHostsFile=/dev/null' "
                    + " -o 'StrictHostKeyChecking=no'"
                    )
        elif self.known_hosts_file:
            cmd = (cmd + " -o UserKnownHostsFile=" + self.known_hosts_file)

        # For multi threades SSH sessions use individual logger and file handlers per session.
        if logger:
            self.log = logger
        elif self.use_parent_logger:
            self.log = log
        else:
            self.log = OpTestLogger.optest_logger_glob.get_custom_logger(__name__)

        self.log.debug(cmd)

        try:
          self.pty = OPexpect.spawn(cmd,
                                    logfile=self.logfile,
                failure_callback=set_system_to_UNKNOWN_BAD,
                failure_callback_data=self.system)
        except Exception as e:
          self.state = ConsoleState.DISCONNECTED
          raise CommandFailed("OPexepct.spawn encountered a problem", e, -1)

        self.state = ConsoleState.CONNECTED
        # set for bash, otherwise it takes the 24x80 default
        self.pty.setwinsize(1000,1000)
        if self.delaybeforesend:
          self.pty.delaybeforesend = self.delaybeforesend
        self.pty.logfile_read = OpTestLogger.FileLikeLogger(self.log)
        time.sleep(2) # delay here in case messages like afstokenpassing unsupported show up which mess up setup_term
        self.check_set_term()
        log.debug("CONNECT starts Expect Buffer ID={}".format(hex(id(self.pty))))
        return self.pty
Ejemplo n.º 9
0
    def connect(self):
        if self.state == ConsoleState.CONNECTED:
            self.sol.terminate()
            self.state = ConsoleState.DISCONNECTED

        print "#OpenBMC Console CONNECT"

        cmd = ("sshpass -p %s " % (self.password) + " ssh -q" +
               " -o'RSAAuthentication=no' -o 'PubkeyAuthentication=no'" +
               " -o 'StrictHostKeyChecking=no'" +
               " -o 'UserKnownHostsFile=/dev/null' " +
               " -p %s" % str(self.port) + " -l %s %s" %
               (self.username, self.host))
        print cmd
        solChild = OPexpect.spawn(cmd, logfile=self.logfile)
        self.state = ConsoleState.CONNECTED
        self.sol = solChild
        return solChild
Ejemplo n.º 10
0
    def connect(self):
        if self.state == ConsoleState.CONNECTED:
            rc_child = self.close()
            self.state = ConsoleState.DISCONNECTED
        else:
            self.util.clear_state(self)  # clear when coming in DISCONNECTED

        cmd = ("sshpass -p %s " % (self.password) + " ssh" +
               " -p %s" % str(self.port) + " -l %s %s" %
               (self.username, self.host) +
               " -o PubkeyAuthentication=no -o afstokenpassing=no")

        if not self.check_ssh_keys:
            cmd = (cmd + " -q" + " -o 'UserKnownHostsFile=/dev/null' " +
                   " -o 'StrictHostKeyChecking=no'")
        elif self.known_hosts_file:
            cmd = (cmd + " -o UserKnownHostsFile=" + self.known_hosts_file)

        log.debug(cmd)

        try:
            consoleChild = OPexpect.spawn(
                cmd,
                logfile=self.logfile,
                failure_callback=set_system_to_UNKNOWN_BAD,
                failure_callback_data=self.system)
        except Exception as e:
            self.state = ConsoleState.DISCONNECTED
            raise CommandFailed('OPexepct.spawn encountered a problem', -1)

        self.state = ConsoleState.CONNECTED
        # set for bash, otherwise it takes the 24x80 default
        consoleChild.setwinsize(1000, 1000)
        self.console = consoleChild
        if self.delaybeforesend:
            self.console.delaybeforesend = self.delaybeforesend
        # Users expecting "Host IPMI" will reference console.sol so make it available
        self.sol = self.console
        consoleChild.logfile_read = OpTestLogger.FileLikeLogger(log)
        time.sleep(
            2
        )  # delay here in case messages like afstokenpassing unsupported show up which mess up setup_term
        self.check_set_term()
        return consoleChild
Ejemplo n.º 11
0
    def connect(self):
        if self.state == ConsoleState.CONNECTED:
            return self.sol
        else:
            self.util.clear_state(self)  # clear when coming in DISCONNECTED

        print "#Qemu Console CONNECT"

        cmd = ("%s" % (self.qemu_binary) + " -machine powernv -m 4G" +
               " -nographic -nodefaults" + " -bios %s" % (self.skiboot) +
               " -kernel %s" % (self.kernel))
        if self.initramfs is not None:
            cmd = cmd + " -initrd %s" % (self.initramfs)
        if self.hda is not None:
            cmd = cmd + " -hda %s" % (self.hda)
        if self.cdrom is not None:
            cmd = cmd + " -cdrom %s" % (self.cdrom)
        # typical host ip=10.0.2.2 and typical skiroot 10.0.2.15
        # use skiroot as the source, no sshd in skiroot
        cmd = cmd + " -nic user,model=virtio-net-pci"
        cmd = cmd + " -device ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10"
        cmd = cmd + " -serial none -device isa-serial,chardev=s1 -chardev stdio,id=s1,signal=off"
        print cmd
        try:
            solChild = OPexpect.spawn(cmd, logfile=self.logfile)
        except Exception as e:
            self.state = ConsoleState.DISCONNECTED
            raise CommandFailed('OPexpect.spawn',
                                'OPexpect.spawn encountered a problem', -1)

        self.state = ConsoleState.CONNECTED
        solChild.setwinsize(1000, 1000)
        self.sol = solChild
        self.console = solChild
        solChild.logfile_read = self.logfile
        if self.delaybeforesend:
            self.sol.delaybeforesend = self.delaybeforesend

        if self.system.SUDO_set != 1 or self.system.LOGIN_set != 1 or self.system.PS1_set != 1:
            self.util.setup_term(self.system, self.sol, None,
                                 self.system.block_setup_term)

        time.sleep(0.2)
        return solChild
Ejemplo n.º 12
0
    def connect(self):
        if self.state == IPMIConsoleState.CONNECTED:
            self.sol.terminate()
            self.state = IPMIConsoleState.DISCONNECTED

        print "#IPMI SOL CONNECT"
        try:
            self.ipmitool.run('sol deactivate')
        except OpTestError:
            print 'SOL already deactivated'

        cmd = self.ipmitool.binary_name() + self.ipmitool.arguments() + ' sol activate'
        print cmd
        solChild = OPexpect.spawn(cmd,logfile=self.logfile)
        self.state = IPMIConsoleState.CONNECTED
        self.sol = solChild
        if self.delaybeforesend:
	    self.sol.delaybeforesend = self.delaybeforesend
        self.sol.expect_exact('[SOL Session operational.  Use ~? for help]')
        # we pause for a moment to allow ipmitool to catch up with
        # itself and to start accepting input
        time.sleep(0.2)
        return solChild