Beispiel #1
0
def configure_pulp_server(instance_name, global_config):
    """
    Set up a Pulp server using Fabric and a puppet module. Fabric will apply the given
    host name, ensure puppet and any modules declared in PUPPET_MODULES are installed,
    and will then apply the puppet manifest.

    :raise RuntimeError: if the server could not be successfully configured. This could be
    for any number of reasons. Currently fabric is set to be quite verbose, so see its output
    """
    config = get_instance_config(instance_name, global_config)
    host_string = config[HOST_STRING]
    private_key = config[PRIVATE_KEY]

    with settings(host_string=host_string, key_file=private_key):
        # Confirm the server is available
        fabric_confirm_ssh_key(host_string, private_key)

        # Set the hostname
        run('sudo hostname ' + config[HOSTNAME])

        # Ensure the puppet modules are installed
        for module in PUPPET_MODULES:
            run(PUPPET_MODULE_INSTALL % module)

        # Add external facts to the server
        puppet_external_facts = {PULP_REPO_FACT: config[REPOSITORY_URL]}
        add_external_fact(host_string, private_key, puppet_external_facts)

        # Apply the manifest to the server
        apply_puppet(host_string, private_key, PULP_SERVER_MANIFEST)

        fabric_network.disconnect_all()
Beispiel #2
0
def configure_pulp_server(instance_name, global_config):
    """
    Set up a Pulp server using Fabric and a puppet module. Fabric will apply the given
    host name, ensure puppet and any modules declared in PUPPET_MODULES are installed,
    and will then apply the puppet manifest.

    :raise RuntimeError: if the server could not be successfully configured. This could be
    for any number of reasons. Currently fabric is set to be quite verbose, so see its output
    """
    config = get_instance_config(instance_name, global_config)
    host_string = config[HOST_STRING]
    private_key = config[PRIVATE_KEY]

    with settings(host_string=host_string, key_filename=private_key):
        # Confirm the server is available
        fabric_confirm_ssh_key(host_string, private_key)

        # Set the hostname
        run('sudo hostname ' + config[HOSTNAME])

        # Ensure the puppet modules are installed
        for module in PUPPET_MODULES:
            run(PUPPET_MODULE_INSTALL % module)

        # Add external facts to the server
        puppet_external_facts = {PULP_REPO_FACT: config[REPOSITORY_URL]}
        add_external_fact(host_string, private_key, puppet_external_facts)

        # Apply the manifest to the server
        apply_puppet(host_string, private_key, PULP_SERVER_MANIFEST)

        fabric_network.disconnect_all()
Beispiel #3
0
def configure_consumer(instance_name, global_config):
    """
    Set up a Pulp consumer using Fabric and a puppet module. Fabric will apply the given consumer
    hostname, ensure root can ssh into the consumer, ensure puppet and all modules in PUPPET_MODULES
    are installed, then apply the puppet manifest. Finally, it will write an /etc/hosts entry for the
    server

    :raise SystemExit: if the consumer could not be successfully configured. This could be
    for any number of reasons. Currently fabric is set to be quite verbose, so see its output
    """
    config = get_instance_config(instance_name, global_config)
    parent_config = get_parent_config(instance_name, global_config)

    with settings(host_string=config[HOST_STRING],
                  key_filename=config[PRIVATE_KEY]):
        fabric_confirm_ssh_key(config[HOST_STRING], config[PRIVATE_KEY])

        # Set the hostname
        run('sudo hostname ' + config[HOSTNAME])

        # Ensure puppet modules are installed
        for module in PUPPET_MODULES:
            run(PUPPET_MODULE_INSTALL % module)

        # Add external facts to the consumer so it can find the server
        puppet_external_facts = {
            PULP_SERVER_FACT: parent_config[HOSTNAME],
            PULP_REPO_FACT: config[REPOSITORY_URL],
        }
        add_external_fact(config[HOST_STRING], config[PRIVATE_KEY],
                          puppet_external_facts)

        apply_puppet(config[HOST_STRING], config[PRIVATE_KEY],
                     PULP_CONSUMER_MANIFEST)

        # Write /etc/hosts
        server_ip = parent_config[HOST_STRING].split('@')[1]
        run(HOSTS_TEMPLATE % {
            'ip': server_ip,
            'hostname': parent_config[HOSTNAME]
        })
        fabric_network.disconnect_all()
Beispiel #4
0
def configure_consumer(instance_name, global_config):
    """
    Set up a Pulp consumer using Fabric and a puppet module. Fabric will apply the given consumer
    hostname, ensure root can ssh into the consumer, ensure puppet and all modules in PUPPET_MODULES
    are installed, then apply the puppet manifest. Finally, it will write an /etc/hosts entry for the
    server

    :raise SystemExit: if the consumer could not be successfully configured. This could be
    for any number of reasons. Currently fabric is set to be quite verbose, so see its output
    """
    config = get_instance_config(instance_name, global_config)
    parent_config = get_parent_config(instance_name, global_config)

    with settings(host_string=config[HOST_STRING], key_file=config[PRIVATE_KEY]):
        fabric_confirm_ssh_key(config[HOST_STRING], config[PRIVATE_KEY])

        # Set the hostname
        run('sudo hostname ' + config[HOSTNAME])

        # Ensure puppet modules are installed
        for module in PUPPET_MODULES:
            run(PUPPET_MODULE_INSTALL % module)

        # Add external facts to the consumer so it can find the server
        puppet_external_facts = {
            PULP_SERVER_FACT: parent_config[HOSTNAME],
            PULP_REPO_FACT: config[REPOSITORY_URL],
        }
        add_external_fact(config[HOST_STRING], config[PRIVATE_KEY], puppet_external_facts)

        apply_puppet(config[HOST_STRING], config[PRIVATE_KEY], PULP_CONSUMER_MANIFEST)

        # Write /etc/hosts
        server_ip = parent_config[HOST_STRING].split('@')[1]
        run(HOSTS_TEMPLATE % {'ip': server_ip, 'hostname':  parent_config[HOSTNAME]})
        fabric_network.disconnect_all()
Beispiel #5
0
def configure_tester(instance_name, global_config):
    """
    Set up the server that runs the integration tests. The basic steps performed are to clone
    the pulp-automation repository, run setup.py, ensure there are entries in /etc/hosts,
    place the ssh key on the tester so it can SSH into the consumer, and write the .yml file
    for the tests.

    :raise RuntimeError: if the tester could not be successfully configured. This could be
    for any number of reasons. Currently fabric is set to be quite verbose, so see its output.
    """
    config = get_instance_config(instance_name, global_config)
    flattened_configs = flatten_structure(global_config)
    server_config = filter(lambda conf: conf[ROLE] == PULP_SERVER_ROLE, flattened_configs)[0]
    consumer_config = filter(lambda conf: conf[ROLE] == PULP_CONSUMER_ROLE, flattened_configs)[0]

    with settings(host_string=config[HOST_STRING], key_file=config[PRIVATE_KEY]):
        fabric_confirm_ssh_key(config[HOST_STRING], config[PRIVATE_KEY])

        run('sudo hostname ' + config[INSTANCE_NAME])

        # This is OS1 specific, but it's common for yum to not work without it
        run('echo "http_caching=packages" | sudo tee -a /etc/yum.conf')

        # Install necessary dependencies.
        print 'Installing necessary test dependencies... '
        with hide('stdout'):
            for dependency in PULP_AUTO_DEPS:
                run(YUM_INSTALL_TEMPLATE % dependency)

        # Install the test suite
        run(INSTALL_TEST_SUITE)

        # Write to /etc/hosts
        server_ip = server_config[HOST_STRING].split('@')[1]
        consumer_ip = consumer_config[HOST_STRING].split('@')[1]
        run(HOSTS_TEMPLATE % {'ip': server_ip, 'hostname': server_config[HOSTNAME]})
        run(HOSTS_TEMPLATE % {'ip': consumer_ip, 'hostname': consumer_config[HOSTNAME]})

        # Generate a key pair so the test machine can ssh as root to the consumer
        local('ssh-keygen -f consumer_temp_rsa -N ""')
        with settings(host_string=consumer_config[HOST_STRING], key_file=consumer_config[PRIVATE_KEY]):
            # Authorize the generated key for root access
            put('consumer_temp_rsa.pub', '~/authorized_keys')
            run('sudo cp ~/authorized_keys /root/.ssh/authorized_keys')

        # Put the private key on the test machine and clean up
        key_path = '/home/' + config[HOST_STRING].split('@')[0] + '/.ssh/id_rsa'
        key_path = key_path.encode('ascii')
        put('consumer_temp_rsa', key_path)
        run('chmod 0600 ' + key_path)
        local('rm consumer_temp_rsa consumer_temp_rsa.pub')

        # Write the YAML configuration file
        get('~/pulp-automation/tests/inventory.yml', 'template_inventory.yml')
        with open('template_inventory.yml', 'r') as template_config:
            config_yaml = yaml.load(template_config)

            # Write the server configuration
            server = {
                'url': 'https://' + server_config[HOSTNAME] + '/',
                'hostname': server_config[HOSTNAME]
            }
            server_yaml = dict(config_yaml[ROLES_KEY][SERVER_YAML_KEY].items() + server.items())
            config_yaml[ROLES_KEY][SERVER_YAML_KEY] = server_yaml

            # Write the qpid configuration
            config_yaml[ROLES_KEY]['qpid'] = {'url': server_config[HOSTNAME]}

            # Write the consumer configuration
            consumer = {
                'hostname': consumer_config[HOSTNAME],
                'ssh_key': key_path,
                'os': {'name': config['os_name'], 'version': config['os_version']},
                'pulp': server_yaml
            }
            consumer_yaml = dict(config_yaml[ROLES_KEY][CONSUMER_YAML_KEY][0].items() + consumer.items())
            config_yaml[ROLES_KEY][CONSUMER_YAML_KEY][0] = consumer_yaml

            with open('inventory.yml', 'w') as test_config:
                yaml.dump(config_yaml, test_config)

        # Place the config file on the server and clean up
        put('inventory.yml', '~/pulp-automation/inventory.yml')
        os.remove('inventory.yml')
        os.remove('template_inventory.yml')
        fabric_network.disconnect_all()
Beispiel #6
0
def configure_tester(instance_name, global_config):
    """
    Set up the server that runs the integration tests. The basic steps performed are to clone
    the pulp-automation repository, run setup.py, ensure there are entries in /etc/hosts,
    place the ssh key on the tester so it can SSH into the consumer, and write the .yml file
    for the tests.

    :raise RuntimeError: if the tester could not be successfully configured. This could be
    for any number of reasons. Currently fabric is set to be quite verbose, so see its output.
    """
    config = get_instance_config(instance_name, global_config)
    flattened_configs = flatten_structure(global_config)
    server_config = filter(lambda conf: conf[ROLE] == PULP_SERVER_ROLE,
                           flattened_configs)[0]
    consumer_config = filter(lambda conf: conf[ROLE] == PULP_CONSUMER_ROLE,
                             flattened_configs)[0]

    with settings(host_string=config[HOST_STRING],
                  key_filename=config[PRIVATE_KEY]):
        fabric_confirm_ssh_key(config[HOST_STRING], config[PRIVATE_KEY])

        run('sudo hostname ' + config[INSTANCE_NAME])

        # This is OS1 specific, but it's common for yum to not work without it
        run('echo "http_caching=packages" | sudo tee -a /etc/yum.conf')

        # Install necessary dependencies.
        print 'Installing necessary test dependencies... '
        with hide('stdout'):
            for dependency in PULP_AUTO_DEPS:
                run(YUM_INSTALL_TEMPLATE % dependency)

        # Install the test suite
        branch = config.get(TEST_SUITE_BRANCH, 'master')
        run(INSTALL_TEST_SUITE % branch)

        # Write to /etc/hosts
        server_ip = server_config[HOST_STRING].split('@')[1]
        consumer_ip = consumer_config[HOST_STRING].split('@')[1]
        run(HOSTS_TEMPLATE % {
            'ip': server_ip,
            'hostname': server_config[HOSTNAME]
        })
        run(HOSTS_TEMPLATE % {
            'ip': consumer_ip,
            'hostname': consumer_config[HOSTNAME]
        })

        # Generate a key pair so the test machine can ssh as root to the consumer
        local('ssh-keygen -f consumer_temp_rsa -N ""')
        with settings(host_string=consumer_config[HOST_STRING],
                      key_filename=consumer_config[PRIVATE_KEY]):
            # Authorize the generated key for root access
            put('consumer_temp_rsa.pub', '~/authorized_keys')
            run('sudo cp ~/authorized_keys /root/.ssh/authorized_keys')

        # Put the private key on the test machine and clean up
        key_path = '/home/' + config[HOST_STRING].split(
            '@')[0] + '/.ssh/id_rsa'
        key_path = key_path.encode('ascii')
        put('consumer_temp_rsa', key_path)
        run('chmod 0600 ' + key_path)
        local('rm consumer_temp_rsa consumer_temp_rsa.pub')

        # Write the YAML configuration file
        get('~/pulp-automation/tests/inventory.yml', 'template_inventory.yml')
        with open('template_inventory.yml', 'r') as template_config:
            config_yaml = yaml.load(template_config)

            # Write the server configuration
            server = {
                'url': 'https://' + server_config[HOSTNAME] + '/',
                'hostname': server_config[HOSTNAME],
                'verify_api_ssl': False,
            }
            server_yaml = dict(
                config_yaml[ROLES_KEY][SERVER_YAML_KEY].items() +
                server.items())
            config_yaml[ROLES_KEY][SERVER_YAML_KEY] = server_yaml

            # Write the qpid configuration
            config_yaml[ROLES_KEY]['qpid'] = {'url': server_config[HOSTNAME]}

            # Write the consumer configuration
            consumer = {
                'hostname': consumer_config[HOSTNAME],
                'ssh_key': key_path,
                'os': {
                    'name': config['os_name'],
                    'version': config['os_version']
                },
                'pulp': server_yaml,
                'verify': False
            }
            consumer_yaml = dict(
                config_yaml[ROLES_KEY][CONSUMER_YAML_KEY][0].items() +
                consumer.items())
            config_yaml[ROLES_KEY][CONSUMER_YAML_KEY][0] = consumer_yaml

            with open('inventory.yml', 'w') as test_config:
                yaml.dump(config_yaml, test_config)

        # Place the config file on the server and clean up
        put('inventory.yml', '~/pulp-automation/inventory.yml')
        os.remove('inventory.yml')
        os.remove('template_inventory.yml')
        fabric_network.disconnect_all()