예제 #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)
예제 #2
0
        logs_dir = JIRA_LOGS_DIR + "/" + jira_id
    else:
        logs_dir = args.path

    if dest_ip:
        user = getpass.getuser()
        passwd = getpass.getpass()

    cont0_ssh_conn = SSHClient(log_path=sys.stdout)
    cont0_ssh_conn.connect(hostname=src_ip,
                           username=WRSROOT_USERNAME,
                           password=WRSROOT_PASSWORD)

    tarball = cont0_ssh_conn.collect_logs()
    # Remove .tgz extension and add .gz
    tarball = os.path.splitext(tarball)[0] + '.gz'

    dest_server_conn = SSHClient()
    dest_server_conn.connect(hostname=dest_ip, username=user, password=passwd)

    ssh_key = cont0_ssh_conn.get_ssh_key()
    dest_server_conn.deploy_ssh_key(ssh_key)

    dest_server_conn.sendline("mkdir -p " + logs_dir)
    dest_server_conn.find_prompt()
    cont0_ssh_conn.rsync(tarball, user, dest_ip, logs_dir)
    dest_server_conn.sendline("chmod -R 775 " + logs_dir)
    dest_server_conn.find_prompt()

    sys.exit(0)