Пример #1
0
    def test_unbind(self, repolib_unbind, bind_report):
        options = {}
        conduit = MagicMock(autospec=Conduit)
        repo_id = 'animals'
        cfg = {
            'filesystem': {
                'repo_file': 'pulp.repo',
                'mirror_list_dir': '/tmp/mirror-list',
                'gpg_keys_dir': '/tmp/gpg',
                'cert_dir': '/tmp/certs',
            }
        }
        cfg = Config(cfg)
        conduit.get_consumer_config.return_value = cfg

        # test
        handler = bind.RepoHandler({})
        report = handler.unbind(conduit, repo_id, options)

        # validation
        cfg = cfg.graph()
        bind_report.assert_called_once_with(repo_id)
        repolib_unbind.assert_called_once_with(
            cfg.filesystem.repo_file,
            os.path.join(cfg.filesystem.mirror_list_dir, repo_id),
            cfg.filesystem.gpg_keys_dir, cfg.filesystem.cert_dir, repo_id)
        bind_report.return_value.set_succeeded.assert_called_once_with()
        self.assertEqual(bind_report.return_value, report)
Пример #2
0
    def test_unbind(self, repolib_unbind, bind_report):
        options = {}
        conduit = MagicMock(autospec=Conduit)
        repo_id = 'animals'
        cfg = {
            'filesystem': {
                'repo_file': 'pulp.repo',
                'mirror_list_dir': '/tmp/mirror-list',
                'gpg_keys_dir': '/tmp/gpg',
                'cert_dir': '/tmp/certs',
            }
        }
        cfg = Config(cfg)
        conduit.get_consumer_config.return_value = cfg

        # test
        handler = bind.RepoHandler({})
        report = handler.unbind(conduit, repo_id, options)

        # validation
        cfg = cfg.graph()
        bind_report.assert_called_once_with(repo_id)
        repolib_unbind.assert_called_once_with(
            cfg.filesystem.repo_file,
            os.path.join(cfg.filesystem.mirror_list_dir, repo_id),
            cfg.filesystem.gpg_keys_dir,
            cfg.filesystem.cert_dir,
            repo_id)
        bind_report.return_value.set_succeeded.assert_called_once_with()
        self.assertEqual(bind_report.return_value, report)
Пример #3
0
def node_configuration(path=NODE_CONFIGURATION_PATH):
    """
    Get the node configuration object.
    The node configuration is overridden using values from the pulp
    consumer.conf and defaulted using server.conf as appropriate.
    :param path: The optional path to the configuration.
    :return: The configuration object.
    :rtype: pulp.common.config.Graph
    """
    cfg = Config(path)
    cfg.validate(NODE_SCHEMA)
    return cfg.graph()
Пример #4
0
    def test_bind(self, repolib_bind, urls, bind_report):
        options = {}
        conduit = MagicMock(autospec=Conduit)
        repo_id = 'animals'
        repo_name = 'Animals'
        cfg = {
            'server': {
                'verify_ssl': 'true'
            },
            'filesystem': {
                'repo_file': 'pulp.repo',
                'mirror_list_dir': '/tmp/mirror-list',
                'gpg_keys_dir': '/tmp/gpg',
                'cert_dir': '/tmp/certs',
            }
        }
        cfg = Config(cfg)
        conduit.get_consumer_config.return_value = cfg
        details = {
            'repo_name': repo_name,
            'protocols': ['https'],
            'server_name': 'content-world',
            'relative_path': 'relative/path'
        }
        binding = {
            'type_id': 'dog',
            'repo_id': repo_id,
            'details': details
        }
        urls.return_value = ['https://content-world']

        # test
        handler = bind.RepoHandler({})
        report = handler.bind(conduit, binding, options)

        # validation
        cfg = cfg.graph()
        bind_report.assert_called_once_with(repo_id)
        repolib_bind.assert_called_once_with(
            cfg.filesystem.repo_file,
            os.path.join(cfg.filesystem.mirror_list_dir, repo_id),
            cfg.filesystem.gpg_keys_dir,
            cfg.filesystem.cert_dir,
            repo_id,
            repo_name,
            urls.return_value,
            details.get('gpg_keys', {}),
            details.get('client_cert'),
            len(urls.return_value) > 0,
            verify_ssl=True,
            ca_path=cfg.server.ca_path)
        bind_report.return_value.set_succeeded.assert_called_once_with()
        self.assertEqual(bind_report.return_value, report)
Пример #5
0
def node_configuration(path=NODE_CONFIGURATION_PATH):
    """
    Get the node configuration object.
    The node configuration is overridden using values from the pulp
    consumer.conf and defaulted using server.conf as appropriate.
    :param path: The optional path to the configuration.
    :return: The configuration object.
    :rtype: pulp.common.config.Graph
    """
    cfg = Config(path)
    cfg.validate(NODE_SCHEMA)
    return cfg.graph()
Пример #6
0
    def test_bind(self, repolib_bind, urls, bind_report):
        options = {}
        conduit = MagicMock(autospec=Conduit)
        repo_id = 'animals'
        repo_name = 'Animals'
        cfg = {
            'server': {
                'verify_ssl': 'true'
            },
            'filesystem': {
                'repo_file': 'pulp.repo',
                'mirror_list_dir': '/tmp/mirror-list',
                'gpg_keys_dir': '/tmp/gpg',
                'cert_dir': '/tmp/certs',
            }
        }
        cfg = Config(cfg)
        conduit.get_consumer_config.return_value = cfg
        details = {
            'repo_name': repo_name,
            'protocols': ['https'],
            'server_name': 'content-world',
            'relative_path': 'relative/path'
        }
        binding = {'type_id': 'dog', 'repo_id': repo_id, 'details': details}
        urls.return_value = ['https://content-world']

        # test
        handler = bind.RepoHandler({})
        report = handler.bind(conduit, binding, options)

        # validation
        cfg = cfg.graph()
        bind_report.assert_called_once_with(repo_id)
        repolib_bind.assert_called_once_with(
            cfg.filesystem.repo_file,
            os.path.join(cfg.filesystem.mirror_list_dir, repo_id),
            cfg.filesystem.gpg_keys_dir,
            cfg.filesystem.cert_dir,
            repo_id,
            repo_name,
            urls.return_value,
            details.get('gpg_keys', {}),
            details.get('client_cert'),
            len(urls.return_value) > 0,
            verify_ssl=True,
            ca_path=cfg.server.ca_path)
        bind_report.return_value.set_succeeded.assert_called_once_with()
        self.assertEqual(bind_report.return_value, report)
Пример #7
0
    def setUp(self):
        super(PulpClientTests, self).setUp()

        self.config = SafeConfigParser()
        config_filename = os.path.join(DATA_DIR, 'test-override-client.conf')
        self.config = Config(config_filename)

        self.server_mock = mock.Mock()
        self.pulp_connection = PulpConnection('',
                                              server_wrapper=self.server_mock)
        self.bindings = Bindings(self.pulp_connection)

        # Disabling color makes it easier to grep results since the character codes aren't there
        self.recorder = okaara.prompt.Recorder()
        self.prompt = PulpPrompt(enable_color=False,
                                 output=self.recorder,
                                 record_tags=True)

        self.logger = logging.getLogger('pulp')
        self.exception_handler = ExceptionHandler(self.prompt, self.config)

        self.context = ClientContext(self.bindings, self.config, self.logger,
                                     self.prompt, self.exception_handler)

        self.cli = PulpCli(self.context)
        self.context.cli = self.cli
Пример #8
0
        def get_consumer_config():
            class Config(object):
                def graph(self):
                    config = MagicMock()
                    config.server.verify_ssl = verify_ssl
                    return config

            return Config()
Пример #9
0
        def get_consumer_config():
            class Config(object):
                def graph(self):
                    config = MagicMock()
                    config.server.ca_path = ca_path
                    return config

            return Config()
Пример #10
0
 def __init__(self):
     """
     Read from file-system on construction.
     """
     cfg = Config(CONFIG_PATH)
     files = cfg['filesystem']
     path = os.path.join(files['id_cert_dir'], files['id_cert_filename'])
     Bundle.__init__(self, path)
Пример #11
0
def read_config(paths=None, validate=True):
    """
    Read and validate the admin configuration.
    :param validate: Validate the configuration.
    :param validate: bool
    :param paths: A list of paths to configuration files to read.
        Reads the standard locations when not specified.
    :param paths: list
    :return: A configuration object.
    :rtype: Config
    """
    if not paths:
        paths = ['/etc/pulp/admin/admin.conf']
        conf_d_dir = '/etc/pulp/admin/conf.d'
        paths += [
            os.path.join(conf_d_dir, i) for i in sorted(os.listdir(conf_d_dir))
        ]
        overrides = os.path.expanduser('~/.pulp/admin.conf')
        if os.path.exists(overrides):
            validate_overrides(overrides)
            paths.append(overrides)
    config = Config(DEFAULT)
    config.update(Config(*paths))
    if validate:
        config.validate(SCHEMA)
    return config
Пример #12
0
 def __init__(self):
     cfg = Config(CONFIG_PATH)
     server = cfg['server']
     host = server['host']
     port = int(server['port'])
     files = cfg['filesystem']
     cert = os.path.join(files['id_cert_dir'], files['id_cert_filename'])
     connection = PulpConnection(host, port, cert_filename=cert)
     PulpBindings.__init__(self, connection)
Пример #13
0
 def load_plugin(mock_read):
     mock_read.return_value = Config()
     plugin = __import__('pulp.agent.gofer.pulpplugin', {}, {}, ['pulpplugin'])
     reload(plugin)
     plugin.descriptor = Mock()
     plugin.plugin = Mock()
     plugin.path_monitor = Mock()
     plugin.registered = True
     return plugin
Пример #14
0
    def test_clean(self, delete, clean_report):
        conduit = MagicMock(autospec=Conduit)
        cfg = {
            'filesystem': {
                'repo_file': 'pulp.repo',
            }
        }
        cfg = Config(cfg)
        conduit.get_consumer_config.return_value = cfg

        # test
        handler = bind.RepoHandler({})
        report = handler.clean(conduit)

        # validation
        cfg = cfg.graph()
        clean_report.assert_called_once_with()
        delete.assert_called_once_with(cfg.filesystem.repo_file)
        clean_report.return_value.set_succeeded.assert_called_once_with()
        self.assertEqual(clean_report.return_value, report)
Пример #15
0
    def test_clean(self, delete, clean_report):
        conduit = MagicMock(autospec=Conduit)
        cfg = {
            'filesystem': {
                'repo_file': 'pulp.repo',
            }
        }
        cfg = Config(cfg)
        conduit.get_consumer_config.return_value = cfg

        # test
        handler = bind.RepoHandler({})
        report = handler.clean(conduit)

        # validation
        cfg = cfg.graph()
        clean_report.assert_called_once_with()
        delete.assert_called_once_with(cfg.filesystem.repo_file)
        clean_report.return_value.set_succeeded.assert_called_once_with()
        self.assertEqual(clean_report.return_value, report)
Пример #16
0
def read_config(paths=None, validate=True):
    """
    Read and validate the consumer configuration.
    :param validate: Validate the configuration.
    :param validate: bool
    :param paths: A list of paths to configuration files to read.
        Reads the standard locations when not specified.
    :param paths: list
    :return: A configuration object.
    :rtype: Config
    """
    if not paths:
        paths = ['/etc/pulp/consumer/consumer.conf']
        overrides = os.path.expanduser('~/.pulp/consumer.conf')
        if os.path.exists(overrides):
            paths.append(overrides)
    config = Config(*paths)
    if validate:
        config.validate(SCHEMA)
    return config
Пример #17
0
def read_config(paths=None, validate=True):
    """
    Read and validate the consumer configuration.
    :param validate: Validate the configuration.
    :param validate: bool
    :param paths: A list of paths to configuration files to read.
        Reads the standard locations when not specified.
    :param paths: list
    :return: A configuration object.
    :rtype: Config
    """
    if not paths:
        paths = ['/etc/pulp/consumer/consumer.conf']
        overrides = os.path.expanduser('~/.pulp/consumer.conf')
        if os.path.exists(overrides):
            paths.append(overrides)
    config = Config(*paths)
    if validate:
        config.validate(SCHEMA)
    return config
Пример #18
0
def _load_configuration(filenames):
    """
    @param filenames: list of filenames to load
    @type  filenames: list

    @return: configuration object
    @rtype:  ConfigParser
    """

    config = Config(*filenames)
    return config
Пример #19
0
 def load_plugin(mock_read):
     mock_read.return_value = Config()
     plugin = __import__('pulp.agent.gofer.pulpplugin', {}, {},
                         ['pulpplugin'])
     reload(plugin)
     plugin_cfg = Mock()
     plugin_cfg.messaging = Mock()
     plugin.plugin = Mock()
     plugin.plugin.cfg.return_value = plugin_cfg
     plugin.path_monitor = Mock()
     return plugin
Пример #20
0
def validate_overrides(path):
    """
    Raise RuntimeError if the file at 'path' provides a password and is not private to owner.

    :param path: Full path to the file to check. Assumed the file exists.
    :type path: basestring

    :raises: RuntimeError if file is not private and contains a password
    """
    valid_private_perms = [400, 600, 700]
    file_perm = int(oct(os.stat(path).st_mode & 0777))

    cfg = Config(path)
    if cfg.has_option("auth", "password"):
        if file_perm not in valid_private_perms:
            runtime_dict = {'path': path, 'file_perm': file_perm,
                            'valid_private_perms': valid_private_perms}
            raise RuntimeError(_(
                "File %(path)s contains a password and has incorrect permissions: %(file_perm)d, "
                "It should be one of %(valid_private_perms)s.") % runtime_dict)
Пример #21
0
    def test_override(self):
        # Setup
        valid_fp = StringIO(VALID)
        override_fp = StringIO(OVERRIDE_PROPERTIES)

        config = Config(valid_fp, override_fp)

        # Test
        value = config['server']['url']

        # Verify
        self.assertEqual(value, 'http://bar.com')
Пример #22
0
 def get_consumer_config(self):
     """
     Get the consumer configuration.
     :return: The consumer configuration object.
     :rtype: pulp.common.config.Config
     """
     paths = ['/etc/pulp/consumer/consumer.conf']
     overrides = os.path.expanduser('~/.pulp/consumer.conf')
     if os.path.exists(overrides):
         paths.append(overrides)
     cfg = Config(*paths)
     return cfg
Пример #23
0
 def __init__(self, name, path):
     """
     @param name: The handler name.
     @type name: str
     @param path: The absolute path to the descriptor.
     @type path: str
     """
     cfg = Config(path)
     validator = Validator(self.SCHEMA)
     validator.validate(cfg)
     self.name = name
     self.cfg = cfg
Пример #24
0
def read_config(path=NODE_CONFIGURATION_PATH, validate=True):
    """
    Get the node configuration object.
    The node configuration is overridden using values from the pulp
    consumer.conf and defaulted using server.conf as appropriate.
    :param path: The optional path to the configuration.
    :return: The configuration object.
    :rtype: pulp.common.config.Graph
    """
    config = Config(DEFAULT)
    config.update(Config(path))
    if validate:
        config.validate(SCHEMA)
    return config.graph()
Пример #25
0
    def test_bind(self, mock_lock):
        options = {}
        conduit = TestConduit(self.CONFIGURATION)
        bindings = [dict(self.BINDING)]

        report = self.dispatcher.bind(conduit, bindings, options)

        self.assertTrue(report.succeeded)
        self.assertTrue(os.path.isfile(self.REPO_FILE))
        repofile = Config(self.REPO_FILE)
        self.assertEqual(repofile[self.REPO_ID]['name'], self.REPO_NAME)
        self.assertEqual(repofile[self.REPO_ID]['enabled'], '1')
        self.assertEqual(repofile[self.REPO_ID]['sslverify'], '1')
Пример #26
0
def read_config(paths=None, validate=True):
    """
    Read and validate the admin configuration.
    :param validate: Validate the configuration.
    :param validate: bool
    :param paths: A list of paths to configuration files to read.
        Reads the standard locations when not specified.
    :param paths: list
    :return: A configuration object.
    :rtype: Config
    """
    if not paths:
        paths = ['/etc/pulp/admin/admin.conf']
        conf_d_dir = '/etc/pulp/admin/conf.d'
        paths += [os.path.join(conf_d_dir, i) for i in sorted(os.listdir(conf_d_dir))]
        overrides = os.path.expanduser('~/.pulp/admin.conf')
        if os.path.exists(overrides):
            paths.append(overrides)
    config = Config(DEFAULT)
    config.update(Config(*paths))
    if validate:
        config.validate(SCHEMA)
    return config
Пример #27
0
 def test_unbind(self, mock_lock):
     # Setup
     options = {}
     conduit = TestConduit(self.CONFIGURATION)
     bindings = [dict(self.BINDING)]
     self.dispatcher.bind(conduit, bindings, options)
     # Test
     options = {}
     conduit = TestConduit(self.CONFIGURATION)
     bindings = [self.UNBINDING]
     report = self.dispatcher.unbind(conduit, bindings, options)
     # Verify
     self.assertTrue(report.succeeded)
     self.assertTrue(os.path.isfile(self.REPO_FILE))
     repofile = Config(self.REPO_FILE)
     self.assertFalse(self.REPO_ID in repofile)
Пример #28
0
def is_valid(source_id, descriptor):
    """
    Get whether a content source descriptor is valid.
    :param source_id: A content source ID.
    :type source_id: str
    :param descriptor: A content source descriptor.
    :type descriptor: dict
    :return: True if valid.
    :rtype: bool
    """
    try:
        schema = list(SCHEMA)
        schema[0] = source_id
        validator = Validator((schema, ))
        cfg = Config({source_id: descriptor})
        validator.validate(cfg)
        return True
    except ValidationException, e:
        log.error(str(e))
Пример #29
0
def read_config(path=NODE_CONFIGURATION_PATH, validate=True):
    """
    Get the node configuration object.
    The node configuration is overridden using values from the pulp
    consumer.conf and defaulted using server.conf as appropriate.
    :param path: The optional path to the configuration.
    :return: The configuration object.
    :rtype: pulp.common.config.Graph
    """
    config = Config(DEFAULT)
    config.update(Config(path))
    if validate:
        config.validate(SCHEMA)
    return config.graph()
Пример #30
0
 def setUp(self):
     TestCase.setUp(self)
     self.config = SafeConfigParser()
     path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data',
                         'client.conf')
     self.config = Config(path)
     self.server_mock = mock.Mock()
     self.pulp_connection = \
         PulpConnection('', server_wrapper=self.server_mock)
     self.bindings = Bindings(self.pulp_connection)
     self.recorder = okaara.prompt.Recorder()
     self.prompt = PulpPrompt(enable_color=False,
                              output=self.recorder,
                              record_tags=True)
     self.logger = logging.getLogger('pulp')
     self.exception_handler = ExceptionHandler(self.prompt, self.config)
     self.context = ClientContext(self.bindings, self.config, self.logger,
                                  self.prompt, self.exception_handler)
     self.cli = PulpCli(self.context)
     self.context.cli = self.cli
Пример #31
0
 def __init__(self, cfg, section):
     """
     Construct the object and validate the configuration.
     @param cfg: The descriptor configuration.
     @type cfg: Config
     @param section: The typedef section name within the descriptor.
     @type section: str
     """
     schema = ((
         section,
         REQUIRED,
         (('class', REQUIRED, ANY), ),
     ), )
     cfg = Config(cfg, filter=[section])
     if cfg:
         validator = Validator(schema)
         validator.validate(cfg)
         self.cfg = cfg[section]
     else:
         raise SectionNotFound(section)
Пример #32
0
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#

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.common.config import Config

requires_api_version = '2.5'
plugin_type = (TYPE_CORE,)
cfg = Config('/etc/pulp/consumer/consumer.conf')
cfg = cfg.graph()

#
# 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)
Пример #33
0
 def get_consumer_config(self):
     cfg = Config(self.cfg)
     return cfg
Пример #34
0
 def node_configuration(self):
     path = os.path.join(self.parentfs, 'node.crt')
     with open(path, 'w+') as fp:
         fp.write(NODE_CERTIFICATE)
     node_conf = Config({'main': {constants.NODE_CERTIFICATE: path}})
     return node_conf.graph()
Пример #35
0
 def test_invalid(self):
     for s in (MISSING_ENABLED, MISSING_TYPE, MISSING_BASE_URL):
         fp = StringIO(s)
         config = Config(fp)
         for source_id, descriptor in config.items():
             self.assertFalse(is_valid(source_id, descriptor))
Пример #36
0
 def test_valid(self):
     fp = StringIO(VALID)
     config = Config(fp)
     for source_id, descriptor in config.items():
         self.assertTrue(is_valid(source_id, descriptor))
Пример #37
0
 def test_invalid(self):
     for s in (MISSING_ENABLED, MISSING_TYPE, MISSING_BASE_URL):
         fp = StringIO(s)
         config = Config(fp)
         for source_id, descriptor in config.items():
             self.assertFalse(is_valid(source_id, descriptor))
Пример #38
0
 def test_valid(self):
     fp = StringIO(VALID)
     config = Config(fp)
     for source_id, descriptor in config.items():
         self.assertTrue(is_valid(source_id, descriptor))
Пример #39
0
 def fn(s, filter):
     fp = StringIO(s)
     d = dict(Config(fp))
     return Config(d, filter=filter)
Пример #40
0
 def node_configuration(self):
     path = os.path.join(self.parentfs, 'node.crt')
     with open(path, 'w+') as fp:
         fp.write(NODE_CERTIFICATE)
     node_conf = Config({'main': {constants.NODE_CERTIFICATE: path}})
     return node_conf.graph()
Пример #41
0
 def read(self, s, filter=None):
     fp = StringIO(s)
     cfg = Config(fp, filter=filter)
     return cfg