Beispiel #1
0
def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
    if 'fake' in ip:
        return fakeprovider.FakeSSHClient()
    # HPcloud may return ECONNREFUSED or EHOSTUNREACH
    # for about 30 seconds after adding the IP
    for count in iterate_timeout(timeout, exceptions.SSHTimeoutException,
                                 "ssh access"):
        try:
            client = SSHClient(ip, username, **connect_kwargs)
            break
        except paramiko.SSHException as e:
            # NOTE(pabelanger): Currently paramiko only returns a string with
            # error code. If we want finer granularity we'll need to regex the
            # string.
            log.exception('Failed to negotiate SSH: %s' % (e))
        except paramiko.AuthenticationException as e:
            # This covers the case where the cloud user is created
            # after sshd is up (Fedora for example)
            log.info('Auth exception for %s@%s. Try number %i...' %
                     (username, ip, count))
        except socket.error as e:
            if e[0] not in [errno.ECONNREFUSED, errno.EHOSTUNREACH, None]:
                log.exception('Exception while testing ssh access to %s:' % ip)

    out = client.ssh("test ssh access", "echo access okay", output=True)
    if "access okay" in out:
        return client
    return None
Beispiel #2
0
def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
    if 'fake' in ip:
        return fakeprovider.FakeSSHClient()
    # HPcloud may return ECONNREFUSED or EHOSTUNREACH
    # for about 30 seconds after adding the IP
    for count in iterate_timeout(
            timeout, exceptions.SSHTimeoutException, "ssh access"):
        try:
            client = SSHClient(ip, username, **connect_kwargs)
            break
        except paramiko.SSHException as e:
            # NOTE(pabelanger): Currently paramiko only returns a string with
            # error code. If we want finer granularity we'll need to regex the
            # string.
            log.exception('Failed to negotiate SSH: %s' % (e))
        except paramiko.AuthenticationException as e:
            # This covers the case where the cloud user is created
            # after sshd is up (Fedora for example)
            log.info('Auth exception for %s@%s. Try number %i...' %
                     (username, ip, count))
        except socket.error as e:
            if e[0] not in [errno.ECONNREFUSED, errno.EHOSTUNREACH, None]:
                log.exception(
                    'Exception while testing ssh access to %s:' % ip)

    out = client.ssh("test ssh access", "echo access okay", output=True)
    if "access okay" in out:
        return client
    return None
Beispiel #3
0
def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
    # HPcloud may return errno 111 for about 30 seconds after adding the IP
    for count in iterate_timeout(timeout, "ssh access"):
        try:
            client = SSHClient(ip, username, **connect_kwargs)
            break
        except socket.error as e:
            print "While testing ssh access:", e
            time.sleep(5)

    ret, out = client.ssh("echo access okay")
    if "access okay" in out:
        return client
    return None
Beispiel #4
0
def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
    # HPcloud may return errno 111 for about 30 seconds after adding the IP
    for count in iterate_timeout(timeout, "ssh access"):
        try:
            client = SSHClient(ip, username, **connect_kwargs)
            break
        except socket.error as e:
            print "While testing ssh access:", e
            time.sleep(5)

    ret, out = client.ssh("echo access okay")
    if "access okay" in out:
        return client
    return None
Beispiel #5
0
def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
    for count in iterate_timeout(timeout, "ssh access"):
        try:
            log.debug('Connecting to ssh to %s with user %s' % (ip, username))
            client = SSHClient(ip, username, log=log, **connect_kwargs)
            break
        except paramiko.AuthenticationException as e:
            # This covers the case where the cloud user is created
            # after sshd is up (Fedora for example)
            log.info('Password auth exception. Try number %i...' % count)
            log.debug(str(e))
        except socket.error as e:
            if e[0] not in [errno.ECONNREFUSED, errno.EHOSTUNREACH]:
                log.exception('Exception while testing ssh access:')

    out = client.ssh("test ssh access", "echo access okay", output=True)
    if "access okay" in out:
        return client
    return None
Beispiel #6
0
def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
    if ip == 'fake':
        return fakeprovider.FakeSSHClient()
    # HPcloud may return ECONNREFUSED or EHOSTUNREACH
    # for about 30 seconds after adding the IP
    for count in iterate_timeout(timeout, "ssh access"):
        try:
            client = SSHClient(ip, username, **connect_kwargs)
            break
        except paramiko.AuthenticationException as e:
            # This covers the case where the cloud user is created
            # after sshd is up (Fedora for example)
            log.info('Password auth exception. Try number %i...' % count)
        except socket.error as e:
            if e[0] not in [errno.ECONNREFUSED, errno.EHOSTUNREACH]:
                log.exception('Exception while testing ssh access:')

    out = client.ssh("test ssh access", "echo access okay", output=True)
    if "access okay" in out:
        return client
    return None
Beispiel #7
0
def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
    if 'fake' in ip:
        return fakeprovider.FakeSSHClient()
    # HPcloud may return ECONNREFUSED or EHOSTUNREACH
    # for about 30 seconds after adding the IP
    for count in iterate_timeout(timeout, "ssh access"):
        try:
            client = SSHClient(ip, username, **connect_kwargs)
            break
        except paramiko.AuthenticationException as e:
            # This covers the case where the cloud user is created
            # after sshd is up (Fedora for example)
            log.info('Password auth exception. Try number %i...' % count)
        except socket.error as e:
            if e[0] not in [errno.ECONNREFUSED, errno.EHOSTUNREACH, None]:
                log.exception('Exception while testing ssh access:')

    out = client.ssh("test ssh access", "echo access okay", output=True)
    if "access okay" in out:
        return client
    return None
Beispiel #8
0
def configure_server(server, branches):
    client = SSHClient(utils.get_public_ip(server), 'jenkins')
    client.ssh('make file cache directory', 'mkdir -p ~/cache/files')
    client.ssh('make pip cache directory', 'mkdir -p ~/cache/pip')
    client.ssh(
        'install build-essential', 'sudo DEBIAN_FRONTEND=noninteractive '
        'apt-get --option "Dpkg::Options::=--force-confold"'
        ' --assume-yes install build-essential python-dev '
        'linux-headers-virtual linux-headers-`uname -r`')

    for branch_data in branches:
        if branch_data['debs']:
            client.ssh(
                'cache debs for branch %s' % branch_data['name'],
                'sudo apt-get -y -d install %s' %
                ' '.join(branch_data['debs']))

        if branch_data['pips']:
            venv = client.ssh('get temp dir for venv', 'mktemp -d').strip()
            client.ssh('create venv',
                       'virtualenv --no-site-packages %s' % venv)
            client.ssh(
                'cache pips for branch %s' % branch_data['name'],
                'source %s/bin/activate && '
                'PIP_DOWNLOAD_CACHE=~/cache/pip pip install %s' %
                (venv, ' '.join(branch_data['pips'])))
            client.ssh('remove venv', 'rm -fr %s' % venv)

        for url in branch_data['images']:
            fname = url.split('/')[-1]
            try:
                client.ssh('check for %s' % fname,
                           'ls ~/cache/files/%s' % fname)
            except:
                client.ssh('download image %s' % fname,
                           'wget -c %s -O ~/cache/files/%s' % (url, fname))

    client.ssh('clear workspace', 'rm -rf ~/workspace-cache')
    client.ssh('make workspace', 'mkdir -p ~/workspace-cache')
    for project in PROJECTS:
        sp = project.split('/')[0]
        client.ssh(
            'clone %s' % project, 'cd ~/workspace-cache && '
            'git clone https://review.openstack.org/p/%s' % project)

    script = os.environ.get('DEVSTACK_GATE_CUSTOM_SCRIPT', '')
    if script and os.path.isfile(script):
        bn = os.path.basename(script)
        client.scp(script, '/tmp/%s' % bn)
        client.ssh('run custom script %s' % bn,
                   'chmod +x /tmp/%s && /tmp/%s' % (bn, bn))

    client.ssh('sync', 'sync && sleep 5')
def configure_server(server, branches):
    client = SSHClient(utils.get_public_ip(server), "jenkins")
    client.ssh("make file cache directory", "mkdir -p ~/cache/files")
    client.ssh("make pip cache directory", "mkdir -p ~/cache/pip")
    client.ssh(
        "install build-essential",
        "sudo DEBIAN_FRONTEND=noninteractive "
        'apt-get --option "Dpkg::Options::=--force-confold"'
        " --assume-yes install build-essential python-dev "
        "linux-headers-virtual linux-headers-`uname -r`",
    )

    for branch_data in branches:
        if branch_data["debs"]:
            client.ssh(
                "cache debs for branch %s" % branch_data["name"],
                "sudo apt-get -y -d install %s" % " ".join(branch_data["debs"]),
            )

        if branch_data["pips"]:
            venv = client.ssh("get temp dir for venv", "mktemp -d").strip()
            client.ssh("create venv", "virtualenv --no-site-packages %s" % venv)
            client.ssh(
                "cache pips for branch %s" % branch_data["name"],
                "source %s/bin/activate && "
                "PIP_DOWNLOAD_CACHE=~/cache/pip pip install %s" % (venv, " ".join(branch_data["pips"])),
            )
            client.ssh("remove venv", "rm -fr %s" % venv)

        for url in branch_data["images"]:
            fname = url.split("/")[-1]
            try:
                client.ssh("check for %s" % fname, "ls ~/cache/files/%s" % fname)
            except:
                client.ssh("download image %s" % fname, "wget -nv -c %s -O ~/cache/files/%s" % (url, fname))

    client.ssh("clear workspace", "rm -rf ~/workspace-cache")
    client.ssh("make workspace", "mkdir -p ~/workspace-cache")
    for project in PROJECTS:
        client.ssh(
            "clone %s" % project, "cd ~/workspace-cache && " "git clone https://review.openstack.org/p/%s" % project
        )

    script = os.environ.get("DEVSTACK_GATE_CUSTOM_SCRIPT", "")
    if script and os.path.isfile(script):
        bn = os.path.basename(script)
        client.scp(script, "/tmp/%s" % bn)
        client.ssh("run custom script %s" % bn, "chmod +x /tmp/%s && sudo /tmp/%s" % (bn, bn))

    client.ssh("sync", "sync && sleep 5")
def configure_server(server, branches):
    client = SSHClient(utils.get_public_ip(server), 'jenkins')
    client.ssh('make file cache directory', 'mkdir -p ~/cache/files')
    client.ssh('make pip cache directory', 'mkdir -p ~/cache/pip')
    client.ssh('install build-essential',
               'sudo DEBIAN_FRONTEND=noninteractive '
               'apt-get --option "Dpkg::Options::=--force-confold"'
               ' --assume-yes install build-essential python-dev '
               'linux-headers-virtual linux-headers-`uname -r`')

    for branch_data in branches:
        if branch_data['debs']:
            client.ssh('cache debs for branch %s' % branch_data['name'],
                       'sudo apt-get -y -d install %s' %
                       ' '.join(branch_data['debs']))

        if branch_data['pips']:
            venv = client.ssh('get temp dir for venv', 'mktemp -d').strip()
            client.ssh('create venv',
                       'virtualenv --no-site-packages %s' % venv)
            client.ssh('cache pips for branch %s' % branch_data['name'],
                       'source %s/bin/activate && '
                       'PIP_DOWNLOAD_CACHE=~/cache/pip pip install %s' %
                       (venv, ' '.join(branch_data['pips'])))
            client.ssh('remove venv', 'rm -fr %s' % venv)

        for url in branch_data['images']:
            fname = url.split('/')[-1]
            try:
                client.ssh('check for %s' % fname,
                           'ls ~/cache/files/%s' % fname)
            except:
                client.ssh('download image %s' % fname,
                    'wget -nv -c %s -O ~/cache/files/%s' % (url, fname))

    client.ssh('clear workspace', 'rm -rf ~/workspace-cache')
    client.ssh('make workspace', 'mkdir -p ~/workspace-cache')
    for project in PROJECTS:
        sp = project.split('/')[0]
        client.ssh('clone %s' % project,
            'cd ~/workspace-cache && '
            'git clone https://review.openstack.org/p/%s' % project)

    script = os.environ.get('DEVSTACK_GATE_CUSTOM_SCRIPT', '')
    if script and os.path.isfile(script):
        bn = os.path.basename(script)
        client.scp(script, '/tmp/%s' % bn)
        client.ssh('run custom script %s' % bn,
            'chmod +x /tmp/%s && sudo /tmp/%s' % (bn, bn))

    client.ssh('sync', 'sync && sleep 5')