예제 #1
0
    def launch_controller0(self):
        # Launch first virtual controller
        cumulus_tis_conn = self.ssh_conn
        rc, output = cumulus_tis_conn.exec_cmd(
            "./instances/launch_virtual-controller-0.sh")
        if rc is not 0:
            msg = " Fail to launch a virtual controller-0."
            self.log.error(msg)
            wr_exit()._exit(1, msg)

        # wait 5 minutes until the controller-0 boot up and then attempt to set up ssh connection
        # using the default 10.10.10.3 oam ip. If success, reset password

        floatingip = self.floating_ips[0]

        time.sleep(180)

        controller0_ssh_conn = SSHClient(log_path=self.output_dir +
                                         "/controller-0.ssh.log")
        controller0_ip = self.get_floating_ip("EXTERNALOAMC0")

        cmd = "ping -w {} -c 4 {}".format(PING_TIMEOUT, controller0_ip)
        ping = 0

        while ping < MAX_LOGIN_ATTEMPTS:

            self.log.info('Pinging controller-0 with ip address {}'.format(
                controller0_ip))
            rc, output = cumulus_tis_conn.exec_cmd(cmd)
            if rc:
                self.log.info("Sleeping for 180 seconds...")
                time.sleep(180)
                ping += 1
            else:
                break

        if ping == MAX_LOGIN_ATTEMPTS:
            msg = 'Waited 1200 seconds and the controller did not respond'
            self.log.error(msg)
            wr_exit()._exit(1, msg)

        ssh_key_fpath = os.path.expanduser(KNOWN_HOSTS_PATH)
        if os.path.isfile(ssh_key_fpath):
            exec_cmd(
                REMOVE_HOSTS_SSH_KEY_CMD.format(ssh_key_fpath,
                                                controller0_ip).split())

        cmd = 'ssh wrsroot@' + controller0_ip
        controller0_ssh_conn._spawn(cmd)
        #controller0_ssh_conn.expect("(yes/no)?")
        controller0_ssh_conn.expect(".*\(yes/no\)\? ?$")
        controller0_ssh_conn.sendline("yes")
        controller0_ssh_conn.expect(PASSWORD_PROMPT)
        controller0_ssh_conn.sendline(WRSROOT_DEFAULT_PASSWORD)
        controller0_ssh_conn.expect(PASSWORD_PROMPT)
        controller0_ssh_conn.sendline(WRSROOT_DEFAULT_PASSWORD)
        controller0_ssh_conn.expect(PASSWORD_PROMPT)
        controller0_ssh_conn.sendline(WRSROOT_PASSWORD)
        controller0_ssh_conn.expect(PASSWORD_PROMPT)
        controller0_ssh_conn.sendline(WRSROOT_PASSWORD)
        time.sleep(5)