Exemple #1
0
def get_broker(server_config):
    """Build an object for managing the target system's AMQP broker.

    Talk to the host named by ``server_config`` and use simple heuristics to
    determine which AMQP broker is installed. If Qpid or RabbitMQ appear to be
    installed, return a :class:`pulp_smash.cli.Service` object for managing
    those services respectively. Otherwise, raise an exception.

    :param pulp_smash.config.ServerConfig server_config: Information about the
        system on which an AMQP broker exists.
    :rtype: pulp_smash.cli.Service
    :raises pulp_smash.exceptions.NoKnownBrokerError: If unable to find any
        AMQP brokers on the target system.
    """
    # On Fedora 23, /usr/sbin and /usr/local/sbin are only added to the $PATH
    # for login shells. (See pathmunge() in /etc/profile.) As a result, logging
    # into a system and executing `which qpidd` and remotely executing `ssh
    # pulp.example.com which qpidd` may return different results.
    client = cli.Client(server_config, cli.echo_handler)
    executables = ('qpidd', 'rabbitmq')  # ordering indicates preference
    for executable in executables:
        command = ('test', '-e', '/usr/sbin/' + executable)
        if client.run(command).returncode == 0:
            return cli.Service(server_config, executable)
    raise exceptions.NoKnownBrokerError(
        'Unable to determine the AMQP broker used by {}. It does not appear '
        'to be any of {}.'.format(server_config.base_url, executables))
def reset_pulp(server_config):
    """Stop Pulp, reset its database, remove certain files, and start it.

    :param pulp_smash.config.ServerConfig server_config: Information about the
        Pulp server being targeted.
    :returns: Nothing.
    """
    services = tuple((
        cli.Service(server_config, service) for service in PULP_SERVICES
    ))
    for service in services:
        service.stop()

    # Reset the database and nuke accumulated files.
    #
    # Why use `runuser` instead of `sudo`? Because some systems are configured
    # to refuse to execute `sudo` unless a tty is present (The author has
    # encountered this on at least one RHEL 7.2 system.)
    #
    # Why not use runuser's `-u` flag? Because RHEL 6 ships an old version of
    # runuser that doesn't support the flag, and RHEL 6 is a supported Pulp
    # platform.
    client = cli.Client(server_config)
    prefix = '' if is_root(server_config) else 'sudo '
    client.run('mongo pulp_database --eval db.dropDatabase()'.split())
    client.run((
        prefix + 'runuser --shell /bin/sh apache --command pulp-manage-db'
    ).split())
    client.run((prefix + 'rm -rf /var/lib/pulp/content').split())
    client.run((prefix + 'rm -rf /var/lib/pulp/published').split())

    for service in services:
        service.start()
 def setUp(self):
     """Provide a server config and Pulp services to stop and start."""
     self.cfg = config.get_config()
     if check_issue_2277(self.cfg):
         self.skipTest('https://pulp.plan.io/issues/2277')
     self.broker = utils.get_broker(self.cfg)
     self.services = tuple(
         (cli.Service(self.cfg, service) for service in PULP_SERVICES))
Exemple #4
0
    def setUpClass(cls):
        """Instantiate and save :class:`pulp_smash.cli.Service` objects.

        Give each object a different service manager (systemd, sysv, etc).
        """
        cls.services = []
        with mock.patch.object(cli.Service, '_get_prefix', return_value=()):
            with mock.patch.object(cli, 'Client'):
                for service_manager in ('systemd', 'sysv'):
                    with mock.patch.object(
                            cli.Service,
                            '_get_service_manager',
                            return_value=service_manager,
                    ):
                        service = cli.Service(mock.Mock(), mock.Mock())
                        cls.services.append(service)
Exemple #5
0
def reset_squid(server_config):
    """Stop Squid, reset its cache directory, and restart it.

    :param pulp_smash.config.ServerConfig server_config: Information about the
        Pulp server being targeted.
    :returns: Nothing.
    """
    squid_service = cli.Service(server_config, 'squid')
    squid_service.stop()

    # Clean out the cache directory and reinitialize it.
    client = cli.Client(server_config)
    prefix = '' if client.run(('id', '-u')).stdout.strip() == '0' else 'sudo '
    client.run((prefix + 'rm -rf /var/spool/squid').split())
    client.run((prefix + 'mkdir --context=system_u:object_r:squid_cache_t:s0' +
                ' --mode=750 /var/spool/squid').split())
    client.run((prefix + 'chown squid:squid /var/spool/squid').split())
    client.run((prefix + 'squid -z').split())

    squid_service.start()
Exemple #6
0
def reset_pulp(server_config):
    """Stop Pulp, reset its database, remove certain files, and start it.

    :param pulp_smash.config.ServerConfig server_config: Information about the
        Pulp server being targeted.
    :returns: Nothing.
    """
    services = tuple(
        (cli.Service(server_config, service) for service in PULP_SERVICES))
    for service in services:
        service.stop()

    # Reset the database and nuke accumulated files.
    client = cli.Client(server_config)
    prefix = '' if client.run(('id', '-u')).stdout.strip() == '0' else 'sudo '
    client.run('mongo pulp_database --eval db.dropDatabase()'.split())
    client.run('sudo -u apache pulp-manage-db'.split())
    client.run((prefix + 'rm -rf /var/lib/pulp/content/*').split())
    client.run((prefix + 'rm -rf /var/lib/pulp/published/*').split())

    for service in services:
        service.start()
Exemple #7
0
 def setUp(self):
     """Provide a server config and Pulp services to stop and start."""
     self.cfg = config.get_config()
     self.broker = utils.get_broker(self.cfg)
     self.services = tuple(
         (cli.Service(self.cfg, service) for service in PULP_SERVICES))