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)
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)
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)
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)
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]))
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())
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())
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)
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'))
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())
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())
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')
def main(): exit_code = launcher.main(read_config(), exception_handler_class=ConsumerExceptionHandler) sys.exit(exit_code)
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):
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)
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.