Skip to content
Snippets Groups Projects
Select Git revision
  • 91dd60fd82b38675f0acfb173735098ee2bd3c82
  • develop default protected
  • feature/NAT-1258_prefix_list_checker
  • fix/resolve-import-failure-unexcpected-redis-error-2
  • fix/sbp-template
  • feature/randepeer
  • feature/nat-1210-edgeports
  • feature/nat-996-dsc0
  • feature/nat-1010-ubfd
  • fix/pe-specific-fixes
  • milos-nat-697-sbp
  • feature/NAT_485_switch_base_config
  • fix/huge-tree
  • v1.0.x
  • add_SR2-se_support
  • fix/iptrunk-ttl-expired
  • Add-ipv4-ipv6-add-fam-in-p-only
  • feature/redundancy_sync
  • fix/twamp-role-update
  • fix/aaa-health-check
  • cleanup
  • 1.1.116
  • 1.1.115
  • 1.1.114
  • 1.1.113
  • 1.1.112
  • 1.1.109
  • 1.1.107
  • 1.1.106
  • 1.1.104
  • 1.1.103
  • 1.1.102
  • 1.1.99
  • 1.1.98
  • 1.1.96
  • 1.1.95
  • 1.1.94
  • 1.1.93
  • 1.1.91
  • 1.1.90
  • 1.1.89
41 results

merge_vars.py

Blame
  • install-sdist-to-test.py 2.44 KiB
    from getpass import getpass
    import os
    import logging
    import threading
    
    import click
    from paramiko import SSHClient
    from scp import SCPClient
    
    DEFAULT_HOSTNAMES = [
        'test-inventory-provider01.geant.org',
        'test-inventory-provider02.geant.org'
    ]
    
    
    def _install_proc(hostname, username, password, sdist):
    
        logging.info(f'installing on {hostname}')
    
        scp_destination = f'/tmp/{os.path.basename(sdist)}'
    
        ssh = SSHClient()
        ssh.load_system_host_keys()
        ssh.connect(hostname=hostname, username=username, password=password)
        scp = SCPClient(ssh.get_transport())
        scp.put(sdist, scp_destination)
    
        channel = ssh.invoke_shell()
        stdin = channel.makefile('wb')
        stdout = channel.makefile('rb')
    
        pip = '/home/inventory/venv/bin/pip'
        commands = [
            f'sudo su - -c \'{pip} uninstall -y inventory\'',
            f'sudo su - -c \'{pip} install {scp_destination}\'',
            f'rm {scp_destination}',
            'sudo su - -c \'chown -R inventory.inventory /home/inventory/venv\'',
            'exit'
        ]
        stdin.write('\n'.join(commands) + '\n')
        print('\n'.join(commands))
        print(stdout.read())
        stdout.close()
        stdin.close()
    
        processes = [
            'inventory-provider.service',
            'inventory-worker.service',
            'inventory-monitor.service'
        ]
        restart_cmd = 'sudo su - -c \'systemctl restart ' \
            + ' '.join(processes) + '\''
        stdin, stdout, _ = ssh.exec_command(restart_cmd)
        output = stdout.read()
        status = stdout.channel.recv_exit_status()
        logging.debug(f'status: {status}, output: {output}')
    
        ssh.close()
    
        logging.info(f'finished installing on {hostname}')
    
    
    @click.command()
    @click.option(
        "--hostname",
        multiple=True,
        default=DEFAULT_HOSTNAMES,
        type=click.STRING,
        help="hostname [%r]"
             % str(DEFAULT_HOSTNAMES))
    @click.option(
        "--user",
        default=None,
        type=click.STRING,
        help="ssh username")
    @click.option(
        "--sdist",
        required=True,
        type=click.Path(exists=True, dir_okay=False),
        help="sdist filename")
    def cli(hostname, user, sdist):
        password = getpass(prompt='Password: ', stream=None)
    
        def _make_thread(h):
            t = threading.Thread(
                target=_install_proc,
                args=[h, user, password, sdist])
            t.start()
            return t
    
        threads = [_make_thread(h) for h in hostname]
    
        for t in threads:
            t.join()
    
    
    if __name__ == '__main__':
        logging.basicConfig(level=logging.INFO)
        cli()