Esempio n. 1
0
def swift_restart():
    global running_hosts

    while not rexists("/etc/swift/swift.conf"):
        log_info("Still need swift.conf...")
        sleep(2)
    while not rexists("/etc/swift/account.ring.gz"):
        log_info("Still need account.ring.gz...")
        sleep(2)
    while not rexists("/etc/swift/container.ring.gz"):
        log_info("Still need container.ring.gz...")
        sleep(2)
    while not rexists("/etc/swift/object.ring.gz"):
        log_info("Still need object.ring.gz...")
        sleep(2)

    run("swift-init stop all; true")
    run("swift-init start all; true")

    log_success("Restarted!")
    running_hosts.value += 1

    while running_hosts.value < len(env.hosts):
        log_info("%d/%d hosts running" % (running_hosts.value, len(env.hosts)))
        sleep(1)
Esempio n. 2
0
def upload_proxy_config():
    if not current_role('proxy'):
        return
    address = get_address(env.host, private=True)

    # Upload proxy configs

    if not rexists("/etc/swift/swift.conf"):
        # Generate a secure secret server-side
        log_info("Not swift.conf found, generating ring!")
        hash_prefix = local("od -t x4 -N 8 -A n </dev/random"
                            "| sed -e 's/ //g'", capture=True)
    else:
        hash_prefix = run("grep swift_hash_path_suffix /etc/swift/swift.conf "
                          "| sed -e 's/.*=[[:space:]]*//'")

    swift_sync_key = hash_prefix
    super_admin_key = hash_prefix

    upload_template("config/dispersion.conf", "/etc/swift/dispersion.conf",
                    {'private_address': address}, backup=False)
    upload_template("config/proxy-server.conf", "/etc/swift/proxy-server.conf",
                    {'private_address': address,
                     'host': env.host,
                     'swift_sync_key': swift_sync_key,
                     'super_admin_key': super_admin_key,
                     'host_prefix': env.host_prefix,
                     'host_short': get_short_name(env.host)}, backup=False)
    upload_template("config/swift.conf", "/etc/swift/swift.conf",
                    {'hash_prefix': hash_prefix}, backup=False)
    prefix = ''
    if current_profile() == 'freebsd':
        prefix = '/usr/local'
    upload_template("config/rsyslog.conf", "{prefix}/etc/rsyslog.conf".format(
        prefix=prefix), backup=False)
Esempio n. 3
0
def system_base():
    packages = config('system_packages')
    with settings(hide('warnings', 'running', 'stdout', 'stderr')):
        if current_profile() in ["ubuntu", "debian"]:
            run("apt-get update")

        for package in packages:
            log_info("Installing: {0}".format(package))
            run("{mgr} {pkg}; true".format(
                mgr=config("package_manager"),
                pkg=package))
Esempio n. 4
0
def wait_for_vm():
    online = False
    with settings(hide('warnings', 'running', 'stdout', 'stderr'),
                  warn_only=True):
        while not online:
            try:
                run("echo")
                log_success("VM is up!")
                online = True
            except:
                log_info("Waiting for VM to boot...")
                sleep(4)
Esempio n. 5
0
def reset_local():
    try:
        log_info("Removing local configs")
        remove("tmp/swift.conf")
    except:
        pass

    try:
        log_info("Removing local rings")
        for f in glob("tmp/*.ring.gz"):
            remove(f)
    except:
        pass
Esempio n. 6
0
def swift_test(wait_for_prep=False):
    if tests_running.value == True:  # NOQA
        return

    tests_running.value = True

    if wait_for_prep:
        while not all([running_hosts.value >= len(env.hosts),
                       prep_auth_done.value == True]): # NOQA
            log_info("Waiting for all hosts to be available "
                     "before testing...")
            sleep(1)

    if not env.TEST_CONFIG:
        abort(red("Please set your SWIFT_TEST_CONFIG_FILE environment "
                  "variable to a valid config file location."))

    log_success("Running functional test suite...")
    local("cd tmp/swift && ./.functests")
Esempio n. 7
0
def platform_init():
    global PlatformManager
    global platform

    namespace, class_name = config('platform')
    try:
        log_info('Loading %s in %s' % (class_name, namespace))
        PlatformManager = platforms.load_manager(namespace, class_name)
    except Exception as e:
        log_error('Cannot load %s from %s: %s' % (class_name, namespace, e))
        sys.exit(1)

    helpers = {'log_success': log_success,
               'log_info': log_info,
               'log_warn': log_warn,
               'log_error': log_error,
               'execute_handler': execute_task_name,
               'run_handler': run,
               'host_broker_handler': host_broker_handler,
               'rexists': rexists}
    platform = PlatformManager(config('platform_options'), **helpers)
Esempio n. 8
0
def swift_deploy_from_local(limit_packages=None):
    src_dir = "/root/src"
    run("rm -rf {0} && mkdir -p {0}".format(src_dir))

    with cd(src_dir):
        for package in config("packages"):
            pkg, branch, url = package

            if limit_packages:
                if pkg not in limit_packages:
                    log_info("Skipping: %s" % pkg)
                    continue

            with settings(warn_only=True):
                run("pip uninstall %s -y" % pkg)

            put("tmp/%s.tar.gz" % pkg, src_dir)
            run("rm -rf %s" % pkg)
            run("tar xvf %s.tar.gz" % pkg)

            with(cd(pkg)):
                run("python setup.py build")
                run("python setup.py install")
Esempio n. 9
0
def swift_config_storage():
    if not current_role('storage'):
        return

    init_logfiles()
    format_drives()

    run("mkdir -p /etc/swift/{object,container,account}")
    run("mkdir -p /var/cache/swift")
    run("mkdir -p /var/lock")
    run("chmod o+x /var/cache")
    run("chown -R swift:swift /srv/node /etc/swift /var/cache/swift")

    # try and make /proc available in BSD
    if current_profile() == 'freebsd':
        run("mkdir -p /compat/linux/proc")
        run("rmdir /proc ; ln -s /compat/linux/proc /proc")
        append("/etc/fstab", "linprocfs /compat/linux/proc linprocfs rw 0 0",
               escape=False)
        append("/boot/loader.conf.local", "linprocfs_load=YES", escape=False)

    upload_storage_config()

    for svc in config("storage_services"):
        enable_service(svc)
        service(svc, action='restart')

    # While the ring files and conf don't exist, wait.
    while (not exists("tmp/swift.conf")
            or not exists("tmp/account.ring.gz")
            or not exists("tmp/container.ring.gz")
            or not exists("tmp/object.ring.gz")):
        log_info("Waiting for local config and ring files...")
        sleep(5)

    put("tmp/swift.conf", "/etc/swift")
    put("tmp/*.ring.gz", "/etc/swift")
Esempio n. 10
0
def python_base():
    packages = config("python_packages")
    with settings(hide('warnings', 'running', 'stdout', 'stderr')):
        for package in packages:
            log_info("Installing: {0}".format(package))
            run("pip install {0}; true".format(package))
Esempio n. 11
0
def service(service, action='start'):
    svc_cmd = config("service_manager")
    log_info("Attempting to %s %s" % (action, service))
    result = run(svc_cmd.format(service=service, action=action), pty=False)

    return result and result.succeeded
Esempio n. 12
0
def execute_task_name(task_name, *args):
    log_info('Executing task %s' % task_name)
    t = globals()[task_name]
    return execute(t, *args)