Esempio n. 1
0
    def test_validation_option(self, mock_config, mock_validate):
        mock_config.return_value = INIConfig()

        # test
        read_config(validate=False)

        # validation
        self.assertFalse(mock_validate.called)
Esempio n. 2
0
    def test_validation_option(self, mock_config, mock_validate):
        mock_config.return_value = INIConfig()

        # test
        read_config(validate=False)

        # validation
        self.assertFalse(mock_validate.called)
Esempio n. 3
0
    def test_default_paths(self, mock_config, mock_validate, mock_open, *unused):
        mock_config.return_value = INIConfig()

        mock_fp = Mock()
        mock_fp.__enter__ = Mock(return_value=mock_fp)
        mock_fp.__exit__ = Mock()
        mock_open.return_value = mock_fp

        # test
        read_config(validate=False)

        # validation
        paths = ["/etc/pulp/consumer/consumer.conf", os.path.expanduser("~/.pulp/consumer.conf")]
        mock_open.assert_any(paths[0])
        mock_open.assert_any(paths[1])
        self.assertFalse(mock_validate.called)
Esempio n. 4
0
    def test_explicit_paths(self, mock_config, mock_validate, mock_open):
        mock_config.return_value = INIConfig()

        mock_fp = Mock()
        mock_fp.__enter__ = Mock(return_value=mock_fp)
        mock_fp.__exit__ = Mock()
        mock_open.return_value = mock_fp

        paths = ['/tmp/a.conf', '/tmp/b.conf']

        # test
        read_config(paths, validate=False)

        # validation

        mock_open.assert_any(paths[0])
        mock_open.assert_any(paths[1])
        self.assertFalse(mock_validate.called)
Esempio n. 5
0
    def test_explicit_paths(self, mock_config, mock_validate, mock_open):
        mock_config.return_value = INIConfig()

        mock_fp = Mock()
        mock_fp.__enter__ = Mock(return_value=mock_fp)
        mock_fp.__exit__ = Mock()
        mock_open.return_value = mock_fp

        paths = ["/tmp/a.conf", "/tmp/b.conf"]

        # test
        read_config(paths, validate=False)

        # validation

        mock_open.assert_any(paths[0])
        mock_open.assert_any(paths[1])
        self.assertFalse(mock_validate.called)
Esempio n. 6
0
    def test_valid(self, mock_config):
        mock_config.return_value = INIConfig(fp=StringIO(VALID))

        # test
        cfg = read_config()

        # validation
        self.assertTrue(isinstance(cfg, Config))
        self.assertEqual(len(cfg), len(SCHEMA))
        self.assertEqual(sorted(cfg.keys()), sorted([s[0] for s in SCHEMA]))
Esempio n. 7
0
    def test_read_no_validation(self, fake_config):
        paths = ['path_A', 'path_B']

        # test
        cfg = read_config(paths=paths, validate=False)

        # validation
        fake_config.assert_called_with(*paths)
        self.assertFalse(fake_config().validate.called)
        self.assertEqual(cfg, fake_config())
Esempio n. 8
0
    def test_read_paths(self, fake_config):
        paths = ['path_A', 'path_B']

        # test
        cfg = read_config(paths=paths)

        # validation
        fake_config.assert_called_with(*paths)
        fake_config().validate.assert_called_with(SCHEMA)
        self.assertEqual(cfg, fake_config())
Esempio n. 9
0
    def test_valid(self, mock_config):
        mock_config.return_value = INIConfig(fp=StringIO(VALID))

        # test
        cfg = read_config()

        # validation
        self.assertTrue(isinstance(cfg, Config))
        self.assertEqual(len(cfg), len(SCHEMA))
        self.assertEqual(sorted(cfg.keys()), sorted([s[0] for s in SCHEMA]))
Esempio n. 10
0
    def test_read_paths(self, fake_config):
        paths = ['path_A', 'path_B']

        # test
        cfg = read_config(paths=paths)

        # validation
        fake_config.assert_called_with(*paths)
        fake_config().validate.assert_called_with(SCHEMA)
        self.assertEqual(cfg, fake_config())
Esempio n. 11
0
    def test_read_no_validation(self, fake_config):
        paths = ['path_A', 'path_B']

        # test
        cfg = read_config(paths=paths, validate=False)

        # validation
        fake_config.assert_called_with(*paths)
        self.assertFalse(fake_config().validate.called)
        self.assertEqual(cfg, fake_config())
Esempio n. 12
0
    def test_default_paths(self, mock_config, mock_validate, mock_open, *unused):
        mock_config.return_value = INIConfig()

        mock_fp = Mock()
        mock_fp.__enter__ = Mock(return_value=mock_fp)
        mock_fp.__exit__ = Mock()
        mock_open.return_value = mock_fp

        # test
        read_config(validate=False)

        # validation
        paths = [
            '/etc/pulp/consumer/consumer.conf',
            os.path.expanduser('~/.pulp/consumer.conf')
        ]
        mock_open.assert_any(paths[0])
        mock_open.assert_any(paths[1])
        self.assertFalse(mock_validate.called)
Esempio n. 13
0
def update_settings():
    """
    Update the plugin settings using the consumer configuration.
    """
    pulp_conf.update(read_config())
    scheme = cfg.messaging.scheme
    host = cfg.messaging.host or cfg.server.host
    port = cfg.messaging.port
    adapter = cfg.messaging.transport
    plugin.cfg.messaging.url = '%s+%s://%s:%s' % (adapter, scheme, host, port)
    plugin.cfg.messaging.uuid = get_agent_id()
    plugin.cfg.messaging.cacert = cfg.messaging.cacert
    plugin.cfg.messaging.clientcert = cfg.messaging.clientcert or \
        os.path.join(cfg.filesystem.id_cert_dir, cfg.filesystem.id_cert_filename)
    plugin.authenticator = Authenticator()
    log.info(_('plugin configuration updated'))
Esempio n. 14
0
def update_settings():
    """
    Update the plugin settings using the consumer configuration.
    """
    pulp_conf.update(read_config())
    scheme = cfg.messaging.scheme
    host = cfg.messaging.host or cfg.server.host
    port = cfg.messaging.port
    adapter = cfg.messaging.transport
    plugin.cfg.messaging.url = '%s+%s://%s:%s' % (adapter, scheme, host, port)
    plugin.cfg.messaging.uuid = get_agent_id()
    plugin.cfg.messaging.cacert = cfg.messaging.cacert
    plugin.cfg.messaging.clientcert = cfg.messaging.clientcert or \
        os.path.join(cfg.filesystem.id_cert_dir, cfg.filesystem.id_cert_filename)
    plugin.authenticator = Authenticator()
    log.info(_('plugin configuration updated'))
Esempio n. 15
0
    def test_read(self, fake_config, fake_expanduser, fake_listdir):
        fake_listdir.return_value = ['A', 'B', 'C']
        fake_expanduser.return_value = '/home/pulp/.pulp/consumer.conf'

        # test
        cfg = read_config()

        # validation
        paths = [
            '/etc/pulp/consumer/consumer.conf',
            '/etc/pulp/consumer/conf.d/A',
            '/etc/pulp/consumer/conf.d/B',
            '/etc/pulp/consumer/conf.d/C',
        ]

        fake_config.assert_called_with(*paths)
        fake_config().validate.assert_called_with(SCHEMA)
        self.assertEqual(cfg, fake_config())
Esempio n. 16
0
    def test_read_with_override(self, fake_config, fake_expanduser,
                                fake_listdir):
        fake_listdir.return_value = ['A', 'B', 'C']
        fake_expanduser.return_value = '/home/pulp/.pulp/consumer.conf'

        # test
        cfg = read_config()

        # validation
        paths = [
            '/etc/pulp/consumer/consumer.conf', '/etc/pulp/consumer/conf.d/A',
            '/etc/pulp/consumer/conf.d/B', '/etc/pulp/consumer/conf.d/C',
            '/home/pulp/.pulp/consumer.conf'
        ]

        fake_config.assert_called_with(*paths)
        fake_config().validate.assert_called_with(SCHEMA)
        self.assertEqual(cfg, fake_config())
Esempio n. 17
0
def setup_plugin():
    """
    Plugin setup.
    Update the plugin configuration using the consumer configuration.
    """
    pulp_conf.update(read_config())
    scheme = cfg.messaging.scheme
    host = cfg.messaging.host or cfg.server.host
    port = cfg.messaging.port
    url = '%s://%s:%s' % (scheme, host, port)
    plugin_conf = plugin.cfg()
    plugin_conf.messaging.url = url
    plugin_conf.messaging.uuid = get_agent_id()
    plugin_conf.messaging.cacert = cfg.messaging.cacert
    plugin_conf.messaging.clientcert = cfg.messaging.clientcert or \
        os.path.join(cfg.filesystem.id_cert_dir, cfg.filesystem.id_cert_filename)
    plugin_conf.messaging.transport = cfg.messaging.transport
    plugin.authenticator = Authenticator()
    log.info('plugin configuration updated')
Esempio n. 18
0
def main():
    exit_code = launcher.main(read_config(),
                              exception_handler_class=ConsumerExceptionHandler)
    sys.exit(exit_code)
Esempio n. 19
0
import os

from yum.plugins import TYPE_CORE
from rhsm.profile import get_profile
from pulp.bindings.server import PulpConnection
from pulp.bindings.bindings import Bindings
from pulp.common.bundle import Bundle as BundleImpl
from pulp.client.consumer.config import read_config


requires_api_version = '2.5'
plugin_type = (TYPE_CORE,)
cfg = read_config()

#
# Pulp Integration
#

class Bundle(BundleImpl):
    """
    Consumer certificate (bundle)
    """

    def __init__(self):
        path = os.path.join(
            cfg['filesystem']['id_cert_dir'],
            cfg['filesystem']['id_cert_filename'])
        BundleImpl.__init__(self, path)


class PulpBindings(Bindings):
Esempio n. 20
0
import os

from yum.plugins import TYPE_CORE
from rhsm.profile import get_profile
from pulp.bindings.server import PulpConnection
from pulp.bindings.bindings import Bindings
from pulp.common.bundle import Bundle as BundleImpl
from pulp.client.consumer.config import read_config


requires_api_version = '2.5'
plugin_type = (TYPE_CORE,)
cfg = read_config()

#
# Pulp Integration
#


class Bundle(BundleImpl):
    """
    Consumer certificate (bundle)
    """

    def __init__(self):
        path = os.path.join(
            cfg['filesystem']['id_cert_dir'],
            cfg['filesystem']['id_cert_filename'])
        BundleImpl.__init__(self, path)

Esempio n. 21
0
from pulp.common.bundle import Bundle
from pulp.common.config import parse_bool
from pulp.agent.lib.dispatcher import Dispatcher
from pulp.agent.lib.conduit import Conduit as HandlerConduit
from pulp.bindings.server import PulpConnection
from pulp.bindings.bindings import Bindings
from pulp.bindings.exceptions import NotFoundException
from pulp.client.consumer.config import read_config

log = getLogger(__name__)

# pulp consumer configuration
# the graph (cfg) is provided for syntactic convenience

pulp_conf = read_config()
cfg = pulp_conf.graph()

# monitor file paths
path_monitor = PathMonitor()

# this plugin object
plugin = Plugin.find(__name__)

# registration status
registered = False


class ValidateRegistrationFailed(Exception):
    """
    The REST call to the server to validate registration failed.
Esempio n. 22
0
def main():
    exit_code = launcher.main(read_config(), exception_handler_class=ConsumerExceptionHandler)
    sys.exit(exit_code)
Esempio n. 23
0
from pulp.common.bundle import Bundle
from pulp.common.config import parse_bool
from pulp.agent.lib.dispatcher import Dispatcher
from pulp.agent.lib.conduit import Conduit as HandlerConduit
from pulp.bindings.server import PulpConnection
from pulp.bindings.bindings import Bindings
from pulp.bindings.exceptions import NotFoundException
from pulp.client.consumer.config import read_config


log = getLogger(__name__)

# pulp consumer configuration
# the graph (cfg) is provided for syntactic convenience

pulp_conf = read_config()
cfg = pulp_conf.graph()

# monitor file paths
path_monitor = PathMonitor()

# this plugin object
plugin = Plugin.find(__name__)

# registration status
registered = False


class ValidateRegistrationFailed(Exception):
    """
    The REST call to the server to validate registration failed.