Example #1
0
    def build_instances(self, global_config, metadata=None):
        """
        Build a set of instances on Openstack using the given list of configurations.
        Each configuration is expected to contain the following keywords: DISTRIBUTION,
        INSTANCE_NAME, SECURITY_GROUP, FLAVOR, OS1_KEY, and CLOUD_CONFIG, al defined in config_utils.

        The configurations will have the 'user', 'host_string' and 'server' keys added, which will contain
        the user to SSH in as, the host string for Fabric, and the novaclient.v1_1.server.Server created.

        :param global_config:   The structure dictionary produced by the configuration parser
        :type  global_config:   dict
        :param metadata:        The metadata to attach to the instances. Limit to 5 keys, 255 character values
        :type  metadata:        dict
        """
        for instance in config_utils.config_generator(global_config):
            # Build the base instance
            image = self.get_distribution_image(
                instance[config_utils.DISTRIBUTION])
            cloud_config = instance.get(config_utils.CLOUD_CONFIG)
            instance_name = instance[config_utils.INSTANCE_NAME]
            security_group = instance[config_utils.SECURITY_GROUP]
            flavor = instance[config_utils.FLAVOR]
            os1_key = instance[config_utils.OS1_KEY]

            server = self.create_instance(image.id, instance_name,
                                          security_group, flavor, os1_key,
                                          metadata, cloud_config)
            instance[config_utils.SYSTEM_USER] = image.metadata.get(
                config_utils.SYSTEM_USER, 'cloud-user').encode('ascii')
            instance[config_utils.NOVA_SERVER] = server.id

        # Wait until all the instances are active, then set necessary configs
        flattened_list = config_utils.flatten_structure(global_config)
        servers = [
            instance[config_utils.NOVA_SERVER] for instance in flattened_list
        ]
        self.wait_for_active_instances(servers)

        for instance_config in config_utils.config_generator(global_config):
            instance_ip = self.get_instance_floating_ip(
                instance_config[config_utils.NOVA_SERVER])
            user = global_config.get('username',
                                     instance_config[config_utils.SYSTEM_USER])
            instance_config[
                config_utils.HOST_STRING] = user + '@' + instance_ip
Example #2
0
    def build_instances(self, global_config, metadata=None):
        """
        Build a set of instances on Openstack using the given list of configurations.
        Each configuration is expected to contain the following keywords: DISTRIBUTION,
        INSTANCE_NAME, SECURITY_GROUP, FLAVOR, OS1_KEY, and CLOUD_CONFIG, al defined in config_utils.

        The configurations will have the 'user', 'host_string' and 'server' keys added, which will contain
        the user to SSH in as, the host string for Fabric, and the novaclient.v1_1.server.Server created.

        :param global_config:   The structure dictionary produced by the configuration parser
        :type  global_config:   dict
        :param metadata:        The metadata to attach to the instances. Limit to 5 keys, 255 character values
        :type  metadata:        dict
        """
        for instance in config_utils.config_generator(global_config):
            # Build the base instance
            image = self.get_distribution_image(instance[config_utils.DISTRIBUTION])
            cloud_config = instance.get(config_utils.CLOUD_CONFIG)
            instance_name = instance[config_utils.INSTANCE_NAME]
            security_group = instance[config_utils.SECURITY_GROUP]
            flavor = instance[config_utils.FLAVOR]
            os1_key = instance[config_utils.OS1_KEY]

            server = self.create_instance(image.id, instance_name, security_group, flavor, os1_key,
                                          metadata, cloud_config)
            instance[config_utils.SYSTEM_USER] = image.metadata.get(config_utils.SYSTEM_USER, 'cloud-user').encode('ascii')
            instance[config_utils.NOVA_SERVER] = server.id

        # Wait until all the instances are active, then set necessary configs
        flattened_list = config_utils.flatten_structure(global_config)
        servers = [instance[config_utils.NOVA_SERVER] for instance in flattened_list]
        self.wait_for_active_instances(servers)

        for instance_config in config_utils.config_generator(global_config):
            instance_ip = self.get_instance_floating_ip(instance_config[config_utils.NOVA_SERVER])
            user = global_config.get('username', instance_config[config_utils.SYSTEM_USER])
            instance_config[config_utils.HOST_STRING] = user + '@' + instance_ip
Example #3
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()
Example #4
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()