Beispiel #1
0
def install_deps(config, messages):
    deps = ["puppet", "openssh-clients", "tar", "nc"]
    modules_pkg = 'openstack-puppet-modules'

    local = utils.ScriptRunner()
    local.append('rpm -q --requires %s | egrep -v "^(rpmlib|\/|perl)"' %
                 modules_pkg)

    # This can fail if there are no dependencies other than those
    # filtered out by the egrep expression.
    rc, modules_deps = local.execute(can_fail=False)

    # Modules package might not be installed if we are running from source.
    # In this case we assume user knows what (s)he's doing and we don't
    # install modules dependencies
    if ('%s is not installed' % modules_pkg) not in modules_deps:
        modules_deps = [i.strip() for i in modules_deps.split() if i.strip()]
        deps.extend(modules_deps)

    for hostname in filtered_hosts(config):
        server = utils.ScriptRunner(hostname)
        packages = ' '.join(deps)
        server.append("yum install -y %s" % packages)
        server.append("yum update -y %s" % packages)
        # yum does not fail if one of the packages is missing
        for package in deps:
            server.append("rpm -q --whatprovides %s" % (package))
        server.execute()
Beispiel #2
0
def dummy_interface(host):
    """Creates dummy interface on given hosts.

    Returns interface name.
    """
    # Only single dummy interface will be created, hence the name is hardcoded
    ifname = 'dummy'
    script = (
        'DEVICE={0}\n'
        'BOOTPROTO=none\n'
        'ONBOOT=yes\n'
        'TYPE=Ethernet\n'
        'NM_CONTROLLED=no\n'.format(ifname)
    )
    server = utils.ScriptRunner(host)
    server.append(
        'ip link show {ifname} || ('
        'modprobe dummy && '
        'ip link set name {ifname} dev dummy0 && '
        'ip link set dev dummy address 06:66:DE:AF:66:60'
        ')'.format(**locals())
    )
    server.append(
        'cat > /etc/sysconfig/network-scripts/ifcfg-{ifname} '
        '<<EOF\n{script}EOF'.format(**locals())
    )
    server.execute()
    return ifname
Beispiel #3
0
def disable_nm(config):
    """
    Sets NM_CONTROLLED="no" in existing network scripts on all nodes.
    """
    for hostname in filtered_hosts(config):
        server = utils.ScriptRunner(hostname)
        server.append('ip a | grep -e "^[0-9]\: [a-zA-Z0-9\-]*\:" | '
                      'sed -e "s/.*: \\(.*\\):.*/\\1/g"')
        rc, out = server.execute()
        devices = [i.strip() for i in out.split('\n') if i.strip()]

        devre = '\|'.join(devices)
        path = '/etc/sysconfig/network-scripts/'
        server.clear()
        server.append('ls -1 %(path)s | grep -e "ifcfg-\(%(devre)s\)"' %
                      locals())
        rc, out = server.execute()
        netscripts = [i.strip() for i in out.split('\n') if i.strip()]

        opt = 'NM_CONTROLLED'
        server.clear()
        for script in netscripts:
            server.append('sed -i \'s/^%(opt)s=.*/%(opt)s="no"/g\' '
                          '%(path)s%(script)s' % locals())
        server.execute()
Beispiel #4
0
def createmanifest(config):
    manifestfile = "%s_qpid.pp"%config['CONFIG_QPID_HOST']
    manifestdata = ""
    ssl_manifestdata = ""
    server = utils.ScriptRunner(config['CONFIG_QPID_HOST'])
    ports = set(["'5672'"])
    if config['CONFIG_QPID_ENABLE_SSL'] == 'y':
        ports.add("'%s'" % (config['CONFIG_QPID_SSL_PORT']))
        config['CONFIG_QPID_ENABLE_SSL'] = 'true'
        if config['CONFIG_QPID_SSL_SELF_SIGNED'] == 'y':
            server.append( "openssl req -batch -new -x509 -nodes -keyout %s -out %s -days 1095"
                % (config['CONFIG_QPID_SSL_KEY_FILE'], config['CONFIG_QPID_SSL_CERT_FILE']) )
            server.execute()
        ssl_manifestdata = getManifestTemplate('qpid_ssl.pp')
    else:
        #Set default values 
        config['CONFIG_QPID_SSL_PORT'] = "5671"
        config['CONFIG_QPID_SSL_CERT_FILE'] = ""
        config['CONFIG_QPID_SSL_KEY_FILE'] = ""
        config['CONFIG_QPID_NSS_CERTDB_PW'] = ""
        config['CONFIG_QPID_ENABLE_SSL'] = 'false'

    manifestdata = getManifestTemplate('qpid.pp')
    manifestdata += ssl_manifestdata

    #All hosts should be able to talk to qpid
    hosts = ["'%s'" % i for i in filtered_hosts(config, exclude=False)]
    config['FIREWALL_ALLOWED'] = ','.join(hosts)
    config['FIREWALL_SERVICE_NAME'] = "qpid"
    config['FIREWALL_PORTS'] = ','.join(ports)
    manifestdata += getManifestTemplate("firewall.pp")
    appendManifestFile(manifestfile, manifestdata, 'pre')
Beispiel #5
0
def deliver_ssl_file(content, path, host):
    server = utils.ScriptRunner(host)
    server.append("grep -- '{content}' {path} || "
                  "echo '{content}' > {path} ".format(
                      content=content,
                      path=path))
    server.execute()
Beispiel #6
0
def run_rhsm_reg(host, username, password):
    """
    Registers given host to Red Hat Repositories via subscription manager.
    """
    server = utils.ScriptRunner(host)

    # register host
    cmd = ('subscription-manager register --username=\"%s\" '
           '--password=\"%s\" --autosubscribe || true')
    server.append(cmd % (username, password.replace('"', '\\"')))

    # subscribe to required channel
    cmd = ('subscription-manager list --consumed | grep -i openstack || '
           'subscription-manager subscribe --pool %s')
    pool = ("$(subscription-manager list --available | "
            "grep -e 'Red Hat OpenStack' -m 1 -A 2 | grep 'Pool Id' | "
            "awk '{print $3}')")
    server.append(cmd % pool)
    server.append("subscription-manager repos "
                  "--enable rhel-6-server-optional-rpms")

    server.append("yum clean all")
    server.append("rpm -q --whatprovides yum-utils || "
                  "yum install -y yum-utils")
    server.append("yum clean metadata")
    server.execute(mask_list=[password])
Beispiel #7
0
def check_cinder_vg(config, messages):
    cinders_volume = config["CONFIG_CINDER_VOLUME_NAME"]

    # Do we have a cinder-volumes vg?
    have_cinders_volume = False
    server = utils.ScriptRunner(config['CONFIG_STORAGE_HOST'])
    server.append('vgdisplay %s' % cinders_volume)
    try:
        server.execute()
        have_cinders_volume = True
    except exceptions.ScriptRuntimeError:
        pass

    if config["CONFIG_CINDER_VOLUMES_CREATE"] == "n":
        if not have_cinders_volume:
            raise exceptions.MissingRequirements("The cinder server should "
                                                 "contain a volume group")
    match = re.match(r'^(?P<size>\d+)G$',
                     config['CONFIG_CINDER_VOLUMES_SIZE'].strip())
    if not match:
        msg = 'Invalid Cinder volumes VG size.'
        raise exceptions.ParamValidationError(msg)

    cinders_volume_size = int(match.group('size')) * 1024
    cinders_reserve = int(cinders_volume_size * 0.03)

    cinders_volume_size = cinders_volume_size + cinders_reserve
    config['CONFIG_CINDER_VOLUMES_SIZE'] = '%sM' % cinders_volume_size
Beispiel #8
0
def check_nm_status(config, messages):
    hosts_with_nm = []
    for host in filtered_hosts(config):
        server = utils.ScriptRunner(host)
        server.append("systemctl")
        rc, out = server.execute(can_fail=False)
        server.clear()

        if rc < 1:
            server.append("systemctl is-enabled NetworkManager")
            rc, is_enabled = server.execute(can_fail=False)
            is_enabled = is_enabled.strip("\n ")
            server.clear()

            server.append("systemctl is-active NetworkManager")
            rc, is_active = server.execute(can_fail=False)
            is_active = is_active.strip("\n ")

            if is_enabled == "enabled" or is_active == "active":
                hosts_with_nm.append(host)
        else:
            server.clear()
            server.append("service NetworkManager status")
            rc, out = server.execute(can_fail=False)

            if rc < 1:
                hosts_with_nm.append(host)

        server.clear()

    if hosts_with_nm:
        hosts_list = ', '.join("%s" % x for x in hosts_with_nm)
        msg = output_messages.WARN_NM_ENABLED
        messages.append(utils.color_text(msg % hosts_list, 'yellow'))
Beispiel #9
0
def manage_rdo(host, config):
    """
    Installs and enables RDO repo on host in case it is installed locally.
    """
    try:
        cmd = "rpm -q rdo-release --qf='%{version}-%{release}.%{arch}\n'"
        rc, out = utils.execute(cmd, use_shell=True)
    except exceptions.ExecuteRuntimeError:
        # RDO repo is not installed, so we don't need to continue
        return
    match = re.match(r'^(?P<version>\w+)\-(?P<release>\d+\.[\d\w]+)\n', out)
    version, release = match.group('version'), match.group('release')
    rdo_url = ("http://rdo.fedorapeople.org/openstack/openstack-%(version)s/"
               "rdo-release-%(version)s-%(release)s.rpm" % locals())

    server = utils.ScriptRunner(host)
    server.append("(rpm -q 'rdo-release-%(version)s' ||"
                  " yum install -y --nogpg %(rdo_url)s) || true" % locals())
    try:
        server.execute()
    except exceptions.ScriptRuntimeError as ex:
        msg = 'Failed to set RDO repo on host %s:\n%s' % (host, ex)
        raise exceptions.ScriptRuntimeError(msg)

    reponame = 'openstack-%s' % version
    server.clear()
    server.append('yum-config-manager --enable %(reponame)s' % locals())
    # yum-config-manager returns 0 always, but returns current setup if succeeds
    rc, out = server.execute()
    match = re.search('enabled\s*=\s*(1|True)', out)
    if not match:
        msg = ('Failed to set RDO repo on host %s:\nRPM file seems to be '
               'installed, but appropriate repo file is probably missing '
               'in /etc/yum.repos.d/' % host)
        raise exceptions.ScriptRuntimeError(msg)
def create_manifest(config, messages):
    client_host = config['CONFIG_CONTROLLER_HOST'].strip()
    manifestfile = "%s_osclient.pp" % client_host

    server = utils.ScriptRunner(client_host)
    server.append('echo $HOME')
    rc, root_home = server.execute()
    root_home = root_home.strip()

    homedir = os.path.expanduser('~')
    config['HOME_DIR'] = homedir

    uname, gname = utils.get_current_username()
    config['NO_ROOT_USER'], config['NO_ROOT_GROUP'] = uname, gname

    no_root_allinone = (client_host == utils.get_localhost_ip()
                        and root_home != homedir)
    config['NO_ROOT_USER_ALLINONE'] = no_root_allinone and True or False

    manifestdata = getManifestTemplate("openstack_client")
    appendManifestFile(manifestfile, manifestdata)

    msg = ("File %s/keystonerc_admin has been created on OpenStack client host"
           " %s. To use the command line tools you need to source the file.")
    messages.append(msg % (root_home, client_host))

    if no_root_allinone:
        msg = ("Copy of keystonerc_admin file has been created for non-root "
               "user in %s.")
        messages.append(msg % homedir)
Beispiel #11
0
def installdeps(config):
    for hostname in gethostlist(controller.CONF):
        server = utils.ScriptRunner(hostname)
        for package in ("puppet", "openssh-clients", "tar"):
            server.append("rpm -q %s || yum install -y %s" %
                          (package, package))
        server.execute()
Beispiel #12
0
def installdeps(config):
    for hostname in filtered_hosts(config):
        server = utils.ScriptRunner(hostname)
        for package in ("puppet", "openssh-clients", "tar", "nc"):
            server.append("rpm -q %s || yum install -y %s" %
                          (package, package))
        server.execute()
Beispiel #13
0
def manage_epel(host, config):
    """
    Installs and/or enables EPEL repo if it is required or disables it if it
    is not required.
    """
    if config['HOST_DETAILS'][host]['os'] in ('Fedora', 'Unknown'):
        return

    # yum's $releasever can be non numeric on RHEL, so interpolate here
    releasever = config['HOST_DETAILS'][host]['release'].split('.')[0]
    mirrors = ('https://mirrors.fedoraproject.org/metalink?repo=epel-%s&'
               'arch=$basearch' % releasever)
    server = utils.ScriptRunner(host)
    if config['CONFIG_USE_EPEL'] == 'y':
        server.append('REPOFILE=$(mktemp)')
        server.append('cat /etc/yum.conf > $REPOFILE')
        server.append("echo -e '[packstack-epel]\nname=packstack-epel\n"
                      "enabled=1\nmirrorlist=%(mirrors)s' >> $REPOFILE" %
                      locals())
        server.append('( rpm -q --whatprovides epel-release ||'
                      ' yum install -y --nogpg -c $REPOFILE epel-release ) '
                      '|| true')
        server.append('rm -rf $REPOFILE')
        try:
            server.execute()
        except exceptions.ScriptRuntimeError as ex:
            msg = 'Failed to set EPEL repo on host %s:\n%s' % (host, ex)
            raise exceptions.ScriptRuntimeError(msg)

    # if there's an epel repo explicitly enables or disables it
    # according to: CONFIG_USE_EPEL
    if config['CONFIG_USE_EPEL'] == 'y':
        cmd = 'enable'
        enabled = '(1|True)'
    else:
        cmd = 'disable'
        enabled = '(0|False)'

    server.clear()
    server.append('yum-config-manager --%(cmd)s epel' % locals())
    rc, out = server.execute()

    # yum-config-manager returns 0 always, but returns current setup
    # if succeeds
    match = re.search('enabled\s*\=\s*%(enabled)s' % locals(), out)
    if match:
        return
    msg = 'Failed to set EPEL repo on host %s:\n'
    if cmd == 'enable':
        # fail in case user wants to have EPEL enabled
        msg += ('RPM file seems to be installed, but appropriate repo file is '
                'probably missing in /etc/yum.repos.d/')
        raise exceptions.ScriptRuntimeError(msg % host)
    else:
        # just warn in case disabling failed which might happen when EPEL repo
        # is not installed at all
        msg += 'This is OK in case you don\'t want EPEL installed and enabled.'
        # TO-DO: fill logger name when logging will be refactored.
        logger = logging.getLogger()
        logger.warn(msg % host)
Beispiel #14
0
def run_tempest(config, messages):
    logfile = basedefs.DIR_LOG + "/run_tempest.log"
    print("Running Tempest on %s" % config['CONFIG_TEMPEST_HOST'])
    server = utils.ScriptRunner(config['CONFIG_TEMPEST_HOST'])
    server.append('/var/lib/tempest/run_tempest.sh -V %s > %s' %
                  (config['CONFIG_RUN_TEMPEST_TESTS'], logfile))
    server.execute()
Beispiel #15
0
def check_ifcfg(host, device):
    """
    Raises ScriptRuntimeError if given host does not have give device.
    """
    server = utils.ScriptRunner(host)
    cmd = "ip addr show dev %s || ( echo Device %s does not exist && exit 1 )"
    server.append(cmd % (device, device))
    server.execute()
Beispiel #16
0
def gather_host_keys(config, messages):
    global compute_hosts

    for host in compute_hosts:
        local = utils.ScriptRunner()
        local.append('ssh-keyscan %s' % host)
        retcode, hostkey = local.execute()
        config['HOST_KEYS_%s' % host] = hostkey
Beispiel #17
0
def run_tempest(config, messages):
    logfile = basedefs.DIR_LOG + "/tempest.log"
    print("Running Tempest on %s" % config['CONFIG_TEMPEST_HOST'])
    server = utils.ScriptRunner(config['CONFIG_TEMPEST_HOST'])
    server.append('pushd /var/lib/tempest')
    server.append('tox -eall -- --concurrency=2 %s > %s'
                  % (config['CONFIG_RUN_TEMPEST_TESTS'], logfile))
    server.append('popd')
    server.execute()
Beispiel #18
0
def wait_for_puppet(currently_running, messages):
    log_len = 0
    twirl = ["-", "\\", "|", "/"]
    while currently_running:
        for hostname, finished_logfile in currently_running:
            log_file = os.path.splitext(os.path.basename(finished_logfile))[0]
            space_len = basedefs.SPACE_LEN - len(log_file)
            if len(log_file) > log_len:
                log_len = len(log_file)
            if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
                twirl = twirl[-1:] + twirl[:-1]
                sys.stdout.write(("\rTesting if puppet apply is finished: %s"
                                 % log_file).ljust(40 + log_len))
                sys.stdout.write("[ %s ]" % twirl[0])
                sys.stdout.flush()
            try:
                # Once a remote puppet run has finished, we retrieve the log
                # file and check it for errors
                local_server = utils.ScriptRunner()
                log = os.path.join(basedefs.PUPPET_MANIFEST_DIR,
                                   os.path.basename(finished_logfile))
                log = log.replace(".finished", ".log")
                local_server.append('scp -o StrictHostKeyChecking=no '
                                    '-o UserKnownHostsFile=/dev/null '
                                    'root@[%s]:%s %s'
                                    % (hostname, finished_logfile, log))
                # To not pollute logs we turn of logging of command execution
                local_server.execute(log=False)

                # If we got to this point the puppet apply has finished
                currently_running.remove((hostname, finished_logfile))

                # clean off the last "testing apply" msg
                if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
                    sys.stdout.write(("\r").ljust(45 + log_len))

            except ScriptRuntimeError:
                # the test raises an exception if the file doesn't exist yet
                # TO-DO: We need to start testing 'e' for unexpected exceptions
                time.sleep(3)
                continue

            # check log file for relevant notices
            messages.extend(scan_logfile(log))

            # check the log file for errors
            sys.stdout.write('\r')
            try:
                validate_logfile(log)
                state = utils.state_message('%s:' % log_file, 'DONE', 'green')
                sys.stdout.write('%s\n' % state)
                sys.stdout.flush()
            except PuppetError:
                state = utils.state_message('%s:' % log_file, 'ERROR', 'red')
                sys.stdout.write('%s\n' % state)
                sys.stdout.flush()
                raise
Beispiel #19
0
def install_cinder_deps(config):
    server = utils.ScriptRunner(controller.CONF['CONFIG_CINDER_HOST'])
    pkgs = []
    if controller.CONF['CONFIG_CINDER_BACKEND'] == 'lvm':
        pkgs.append('lvm2')
    for p in pkgs:
        server.append("rpm -q %(package)s || yum install -y %(package)s" %
                      dict(package=p))
    server.execute()
Beispiel #20
0
def install_cinder_deps(config, messages):
    server = utils.ScriptRunner(config['CONFIG_CONTROLLER_HOST'])
    pkgs = []
    if config['CONFIG_CINDER_BACKEND'] == 'lvm':
        pkgs.append('lvm2')
    for p in pkgs:
        server.append("rpm -q --whatprovides %(package)s || "
                      "yum install -y %(package)s" % dict(package=p))
    server.execute()
Beispiel #21
0
def run_rhsm_reg(host,
                 username,
                 password,
                 optional=False,
                 proxy_server=None,
                 proxy_port=None,
                 proxy_user=None,
                 proxy_password=None):
    """
    Registers given host to Red Hat Repositories via subscription manager.
    """
    releasever = config['HOST_DETAILS'][host]['release'].split('.')[0]
    server = utils.ScriptRunner(host)

    # configure proxy if it is necessary
    if proxy_server:
        cmd = ('subscription-manager config '
               '--server.proxy_hostname=%(proxy_server)s '
               '--server.proxy_port=%(proxy_port)s')
        if proxy_user:
            cmd += (' --server.proxy_user=%(proxy_user)s '
                    '--server.proxy_password=%(proxy_password)s')
        server.append(cmd % locals())

    # register host
    cmd = ('subscription-manager register --username=\"%s\" '
           '--password=\"%s\" --autosubscribe || true')
    server.append(cmd % (username, password.replace('"', '\\"')))

    # subscribe to required channel
    cmd = ('subscription-manager list --consumed | grep -i openstack || '
           'subscription-manager subscribe --pool %s')
    pool = ("$(subscription-manager list --available"
            " | grep -m1 -A15 'Red Hat Enterprise Linux OpenStack Platform'"
            " | grep -i 'Pool ID:' | awk '{print $3}')")
    server.append(cmd % pool)

    if optional:
        server.append("subscription-manager repos "
                      "--enable rhel-%s-server-optional-rpms" % releasever)
    server.append("subscription-manager repos "
                  "--enable rhel-%s-server-openstack-5.0-rpms" % releasever)

    # mrg channel naming is a big mess
    if releasever == '7':
        mrg_prefix = 'rhel-x86_64-server-7'
    elif releasever == '6':
        mrg_prefix = 'rhel-6-server'
    server.append("subscription-manager repos "
                  "--enable %s-mrg-messaging-2-rpms" % mrg_prefix)

    server.append("yum clean all")
    server.append("rpm -q --whatprovides yum-utils || "
                  "yum install -y yum-utils")
    server.append("yum clean metadata")
    server.execute(mask_list=[password])
Beispiel #22
0
def run_tempest(config, messages):
    logfile = basedefs.DIR_LOG + "/tempest.log"
    print("Running Tempest on %s" % config['CONFIG_TEMPEST_HOST'])
    server = utils.ScriptRunner(config['CONFIG_TEMPEST_HOST'])
    server.append('pushd /var/lib/tempest')
    server.append('tempest run --regex \'(%s)\' --concurrency 2  > %s'
                  % (config['CONFIG_RUN_TEMPEST_TESTS'].replace(' ', '|'),
                     logfile))
    server.append('popd')
    server.execute()
Beispiel #23
0
def install_keys_on_host(hostname, sshkeydata):
    server = utils.ScriptRunner(hostname)
    # TODO replace all that with ssh-copy-id
    server.append("mkdir -p ~/.ssh")
    server.append("chmod 500 ~/.ssh")
    server.append("grep '%s' ~/.ssh/authorized_keys > /dev/null 2>&1 || "
                  "echo %s >> ~/.ssh/authorized_keys"
                  % (sshkeydata, sshkeydata))
    server.append("chmod 400 ~/.ssh/authorized_keys")
    server.append("restorecon -r ~/.ssh")
    server.execute()
Beispiel #24
0
def finalize(config, messages):
    for hostname in filtered_hosts(config):
        server = utils.ScriptRunner(hostname)
        server.append("installed=$(rpm -q kernel --last | head -n1 | "
                      "sed 's/kernel-\([a-z0-9\.\_\-]*\).*/\\1/g')")
        server.append("loaded=$(uname -r | head -n1)")
        server.append('[ "$loaded" == "$installed" ]')
        try:
            rc, out = server.execute()
        except ScriptRuntimeError:
            messages.append('Because of the kernel update the host %s '
                            'requires reboot.' % hostname)
Beispiel #25
0
def installKeys(config):
    with open(config["CONFIG_SSH_KEY"]) as fp:
        sshkeydata = fp.read().strip()
    for hostname in filtered_hosts(config):
        server = utils.ScriptRunner(hostname)
        # TODO replace all that with ssh-copy-id
        server.append("mkdir -p ~/.ssh")
        server.append("chmod 500 ~/.ssh")
        server.append("grep '%s' ~/.ssh/authorized_keys > /dev/null 2>&1 || echo %s >> ~/.ssh/authorized_keys" % (sshkeydata, sshkeydata))
        server.append("chmod 400 ~/.ssh/authorized_keys")
        server.append("restorecon -r ~/.ssh")
        server.execute()
Beispiel #26
0
def install_deps(config, messages):
    deps = ["puppet", "hiera", "openssh-clients", "tar", "nc"]
    modules_pkg = 'openstack-puppet-modules'

    local = utils.ScriptRunner()
    local.append('rpm -q --requires %s | egrep -v "^(rpmlib|\/|perl)"'
                 % modules_pkg)

    # This can fail if there are no dependencies other than those
    # filtered out by the egrep expression.
    rc, modules_deps = local.execute(can_fail=False)

    # Modules package might not be installed if we are running from source.
    # In this case we assume user knows what (s)he's doing and we don't
    # install modules dependencies
    if ('%s is not installed' % modules_pkg) not in modules_deps:
        modules_deps = [i.strip() for i in modules_deps.split() if i.strip()]
        deps.extend(modules_deps)

    for hostname in filtered_hosts(config):
        server = utils.ScriptRunner(hostname)
        packages = ' '.join(deps)
        server.append("yum install -y %s" % packages)
        server.append("yum update -y %s" % packages)
        # yum does not fail if one of the packages is missing
        for package in deps:
            server.append("rpm -q --whatprovides %s" % (package))

        # To avoid warning messages such as
        # "Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera
        # defaults". We create a symbolic link to /etc/hiera.yaml.
        server.append('[[ ! -L /etc/puppet/hiera.yaml ]] && '
                      'ln -s /etc/hiera.yaml /etc/puppet/hiera.yaml || '
                      'echo "hiera.yaml symlink already created"')

        server.append("sed -i 's;:datadir:.*;:datadir: "
                      "%s/hieradata;g' /etc/puppet/hiera.yaml"
                      % config['HOST_DETAILS'][hostname]['tmpdir'])

        server.execute()
Beispiel #27
0
def waitforpuppet(currently_running):
    global controller
    log_len = 0
    twirl = ["-", "\\", "|", "/"]
    while currently_running:
        for hostname, finished_logfile in currently_running:
            log_file = os.path.splitext(os.path.basename(finished_logfile))[0]
            space_len = basedefs.SPACE_LEN - len(log_file)
            if len(log_file) > log_len:
                log_len = len(log_file)
            if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
                twirl = twirl[-1:] + twirl[:-1]
                sys.stdout.write(
                    ("\rTesting if puppet apply is finished : %s" %
                     log_file).ljust(40 + log_len))
                sys.stdout.write("[ %s ]" % twirl[0])
                sys.stdout.flush()
            try:
                # Once a remote puppet run has finished, we retrieve the log
                # file and check it for errors
                local_server = utils.ScriptRunner()
                log = os.path.join(
                    basedefs.PUPPET_MANIFEST_DIR,
                    os.path.basename(finished_logfile).replace(
                        ".finished", ".log"))
                local_server.append(
                    'scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@%s:%s %s'
                    % (hostname, finished_logfile, log))
                # Errors are expected here if the puppet run isn't finished so we suppress logging them
                local_server.execute(logerrors=False)

                # If we got to this point the puppet apply has finished
                currently_running.remove((hostname, finished_logfile))

                # clean off the last "testing apply" msg
                if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
                    sys.stdout.write(("\r").ljust(45 + log_len))

            except ScriptRuntimeError:
                # the test raises an exception if the file doesn't exist yet
                # TO-DO: We need to start testing 'e' for unexpected exceptions
                time.sleep(3)
                continue

            # check log file for relevant notices
            controller.MESSAGES.extend(scan_puppet_logfile(log))

            # check the log file for errors
            validate_puppet_logfile(log)
            sys.stdout.write(("\r%s : " % log_file).ljust(space_len))
            print("[ " + utils.color_text(output_messages.INFO_DONE, 'green') +
                  " ]")
Beispiel #28
0
def install_deps(config, messages):
    deps = ["puppet", "openssh-clients", "tar", "nc"]
    modules_pkg = 'openstack-puppet-modules'

    local = utils.ScriptRunner()
    local.append('rpm -q --requires %s | egrep -v "^(rpmlib|\/|perl)"'
                 % modules_pkg)
    rc, modules_deps = local.execute()

    # Modules package might not be installed if we are running from source.
    # In this case we assume user knows what (s)he's doing and we don't
    # install modules dependencies
    if ('%s is not installed' % modules_pkg) not in modules_deps:
        modules_deps = [i.strip() for i in modules_deps.split() if i.strip()]
        deps.extend(modules_deps)

    for hostname in filtered_hosts(config):
        server = utils.ScriptRunner(hostname)
        for package in deps:
            server.append("rpm -q --whatprovides %s || yum install -y %s"
                          % (package, package))
        server.execute()
Beispiel #29
0
def createmanifest():
    client_host = controller.CONF['CONFIG_OSCLIENT_HOST'].strip()
    manifestfile = "%s_osclient.pp" % client_host
    manifestdata = getManifestTemplate("openstack_client.pp")
    appendManifestFile(manifestfile, manifestdata)

    server = utils.ScriptRunner(client_host)
    server.append('echo $HOME')
    rc, root_home = server.execute()

    msg = ("To use the command line tools you need to source the file "
           "%s/keystonerc_admin created on %s")
    controller.MESSAGES.append(msg % (root_home.strip(), client_host))
Beispiel #30
0
def copy_puppet_modules(config, messages):
    os_modules = ' '.join(('apache', 'ceilometer', 'certmonger', 'cinder',
                           'concat', 'firewall', 'glance', 'galera', 'heat',
                           'horizon', 'inifile', 'ironic', 'keystone',
                           'manila', 'memcached', 'mongodb', 'mysql',
                           'neutron', 'nova', 'nssdb', 'openstack',
                           'packstack', 'qpid', 'rabbitmq', 'redis', 'remote',
                           'rsync', 'sahara', 'ssh', 'stdlib', 'swift',
                           'sysctl', 'tempest', 'trove', 'vcsrepo', 'vlan',
                           'vswitch', 'xinetd', 'openstacklib'))

    # write puppet manifest to disk
    manifestfiles.writeManifests()
    # write hieradata file to disk
    generateHieraDataFile()

    server = utils.ScriptRunner()
    for hostname in filtered_hosts(config):
        host_dir = config['HOST_DETAILS'][hostname]['tmpdir']
        # copy hiera defaults.yaml file
        server.append("cd %s" % basedefs.HIERADATA_DIR)
        server.append("tar --dereference -cpzf - ../hieradata | "
                      "ssh -o StrictHostKeyChecking=no "
                      "-o UserKnownHostsFile=/dev/null "
                      "root@%s tar -C %s -xpzf -" % (hostname, host_dir))

        # copy Packstack manifests
        server.append("cd %s/puppet" % basedefs.DIR_PROJECT_DIR)
        server.append("cd %s" % basedefs.PUPPET_MANIFEST_DIR)
        server.append("tar --dereference -cpzf - ../manifests | "
                      "ssh -o StrictHostKeyChecking=no "
                      "-o UserKnownHostsFile=/dev/null "
                      "root@%s tar -C %s -xpzf -" % (hostname, host_dir))

        # copy resources
        resources = config.get('RESOURCES', {})
        for path, localname in resources.get(hostname, []):
            server.append("scp -o StrictHostKeyChecking=no "
                          "-o UserKnownHostsFile=/dev/null "
                          "%s root@[%s]:%s/resources/%s" %
                          (path, hostname, host_dir, localname))

        # copy Puppet modules required by Packstack
        server.append("cd %s" % MODULE_DIR)
        server.append("tar --dereference -cpzf - %s | "
                      "ssh -o StrictHostKeyChecking=no "
                      "-o UserKnownHostsFile=/dev/null "
                      "root@%s tar -C %s -xpzf -" %
                      (os_modules, hostname,
                       os.path.join(host_dir, 'modules')))
    server.execute()