Exemple #1
0
 def test_read_config_file(self):
     """Ensure Pulp Smash can read the config file."""
     open_ = mock.mock_open(read_data=PULP_SMASH_CONFIG)
     with mock.patch.object(builtins, 'open', open_):
         cfg = config.PulpSmashConfig()
         with mock.patch.object(cfg, 'get_config_file_path'):
             cfg = cfg.read()
     with self.subTest('check pulp_auth'):
         self.assertEqual(cfg.pulp_auth, ['username', 'password'])
     with self.subTest('check pulp_version'):
         self.assertEqual(cfg.pulp_version, config.Version('2.12.1'))
     with self.subTest('check systems'):
         self.assertEqual(
             sorted(cfg.systems),
             sorted([
                 config.PulpSystem(hostname='first.example.com',
                                   roles={
                                       'amqp broker': {
                                           'service': 'qpidd'
                                       },
                                       'api': {
                                           'port': 1234,
                                           'scheme': 'https',
                                           'verify': True,
                                       },
                                       'mongod': {},
                                       'pulp cli': {},
                                       'pulp celerybeat': {},
                                       'pulp resource manager': {},
                                       'pulp workers': {},
                                       'shell': {
                                           'transport': 'local'
                                       },
                                       'squid': {},
                                   }),
                 config.PulpSystem(hostname='second.example.com',
                                   roles={
                                       'api': {
                                           'port': 2345,
                                           'scheme': 'https',
                                           'verify': False,
                                       },
                                       'pulp celerybeat': {},
                                       'pulp resource manager': {},
                                       'pulp workers': {},
                                       'shell': {
                                           'transport': 'ssh'
                                       },
                                       'squid': {}
                                   }),
             ]))
Exemple #2
0
    def setUpClass(cls):
        """Assert methods delegate to :meth:`pulp_smash.api.Client.request`.

        All methods on :class:`pulp_smash.api.Client`, such as
        :meth:`pulp_smash.api.Client.delete`, should delegate to
        :meth:`pulp_smash.api.Client.request`. Mock out ``request`` and call
        the other methods.
        """
        methods = {'delete', 'get', 'head', 'options', 'patch', 'post', 'put'}
        cls.mocks = {}
        for method in methods:
            client = api.Client(config.PulpSmashConfig(
                pulp_auth=['admin', 'admin'],
                systems=[
                    config.PulpSystem(
                        hostname='example.com',
                        roles={'api': {
                            'scheme': 'http',
                        }}
                    )
                ]
            ))
            with mock.patch.object(client, 'request') as request:
                getattr(client, method)('')
            cls.mocks[method] = request
Exemple #3
0
def _gen_attrs():
    """Generate attributes for populating a ``PulpSmashConfig``.

    Example usage: ``PulpSmashConfig(**_gen_attrs())``.

    :returns: A dict. It populates all attributes in a ``PulpSmashConfig``.
    """
    return {
        'pulp_auth': [utils.uuid4() for _ in range(2)],
        'pulp_version':
        '.'.join(type('')(random.randint(1, 150)) for _ in range(4)),
        'systems': [
            config.PulpSystem(hostname='pulp.example.com',
                              roles={
                                  'amqp broker': {
                                      'service': 'qpidd'
                                  },
                                  'api': {
                                      'port': random.randint(1, 65535),
                                      'scheme': 'https',
                                      'verify': True
                                  },
                                  'mongod': {},
                                  'pulp cli': {},
                                  'pulp celerybeat': {},
                                  'pulp resource manager': {},
                                  'pulp workers': {},
                                  'shell': {
                                      'transport': 'local'
                                  },
                                  'squid': {}
                              })
        ],
    }
Exemple #4
0
 def test_read_old_config_file(self):
     """Ensure Pulp Smash can read old config file format."""
     open_ = mock.mock_open(read_data=OLD_CONFIG)
     with mock.patch.object(builtins, 'open', open_):
         cfg = config.PulpSmashConfig()
         with mock.patch.object(cfg, 'get_config_file_path'):
             with self.assertWarns(DeprecationWarning):
                 cfg = cfg.read()
     with self.subTest('check pulp_auth'):
         self.assertEqual(cfg.pulp_auth, ['username', 'password'])
     with self.subTest('check pulp_version'):
         self.assertEqual(cfg.pulp_version, config.Version('2.12'))
     with self.subTest('check systems'):
         self.assertEqual(cfg.systems, [
             config.PulpSystem(hostname='pulp.example.com',
                               roles={
                                   'amqp broker': {
                                       'service': 'qpidd'
                                   },
                                   'api': {
                                       'scheme': 'https',
                                       'verify': False,
                                   },
                                   'mongod': {},
                                   'pulp cli': {},
                                   'pulp celerybeat': {},
                                   'pulp resource manager': {},
                                   'pulp workers': {},
                                   'shell': {
                                       'transport': 'ssh'
                                   },
                                   'squid': {},
                               })
         ])
Exemple #5
0
 def test_implicit_local_transport(self):
     """Assert it is possible to implicitly ask for a "local" transport."""
     cfg = config.PulpSmashConfig(systems=[
         config.PulpSystem(
             hostname=socket.getfqdn(),
             roles={
                 'pulp cli': {},
             }
         )
     ])
     self.assertIsInstance(cli.Client(cfg).machine, LocalMachine)
Exemple #6
0
 def test_explicit_local_transport(self):
     """Assert it is possible to explicitly ask for a "local" transport."""
     cfg = config.PulpSmashConfig(systems=[
         config.PulpSystem(
             hostname=utils.uuid4(),
             roles={
                 'pulp cli': {},
                 'shell': {'transport': 'local'},
             }
         )
     ])
     self.assertIsInstance(cli.Client(cfg).machine, LocalMachine)
Exemple #7
0
 def test_default_response_handler(self):
     """Assert the default response handler checks return codes."""
     cfg = config.PulpSmashConfig(systems=[
         config.PulpSystem(
             hostname=utils.uuid4(),
             roles={
                 'pulp cli': {},
                 'shell': {'transport': 'local'},
             }
         )
     ])
     self.assertIs(cli.Client(cfg).response_handler, cli.code_handler)
Exemple #8
0
 def test_implicit_pulp_system(self):
     """Assert it is possible to implicitly target a pulp cli PulpSystem."""
     cfg = config.PulpSmashConfig(systems=[
         config.PulpSystem(
             hostname=utils.uuid4(),
             roles={
                 'pulp cli': {},
             }
         ),
         config.PulpSystem(
             hostname=utils.uuid4(),
             roles={
                 'pulp cli': {},
             }
         )
     ])
     with mock.patch('pulp_smash.cli.plumbum') as plumbum:
         machine = mock.Mock()
         plumbum.machines.SshMachine.return_value = machine
         self.assertEqual(cli.Client(cfg).machine, machine)
         plumbum.machines.SshMachine.assert_called_once_with(
             cfg.systems[0].hostname)
Exemple #9
0
 def test_explicit_response_handler(self):
     """Assert it is possible to explicitly set a response handler."""
     cfg = config.PulpSmashConfig(systems=[
         config.PulpSystem(
             hostname=utils.uuid4(),
             roles={
                 'pulp cli': {},
                 'shell': {'transport': 'local'},
             }
         )
     ])
     handler = mock.Mock()
     self.assertIs(cli.Client(cfg, handler).response_handler, handler)
Exemple #10
0
 def test_run(self):
     """Assert the function executes ``cli.Client.run``."""
     with mock.patch.object(cli, 'Client') as client:
         cfg = config.PulpSmashConfig(
             pulp_auth=['u', 'p'],
             systems=[
                 config.PulpSystem(
                     hostname='example.com',
                     roles={'pulp cli': {}}
                 )
             ]
         )
         response = utils.pulp_admin_login(cfg)
         self.assertIs(response, client.return_value.run.return_value)
Exemple #11
0
    def test_response_handler(self):
        """Assert ``__init__`` saves the ``response_handler`` argument.

        The argument should be saved as an instance attribute.
        """
        response_handler = mock.Mock()
        client = api.Client(config.PulpSmashConfig(
            pulp_auth=['admin', 'admin'],
            systems=[
                config.PulpSystem(
                    hostname='base url',
                    roles={'api': {'scheme': 'http'}},
                )
            ]
        ), response_handler)
        self.assertIs(client.response_handler, response_handler)
Exemple #12
0
 def test_json_arg(self):
     """Assert methods with a ``json`` argument pass on that argument."""
     json = mock.Mock()
     client = api.Client(config.PulpSmashConfig(
         pulp_auth=['admin', 'admin'],
         systems=[
             config.PulpSystem(
                 hostname='base url',
                 roles={'api': {'scheme': 'http'}},
             )
         ]
     ))
     for method in {'patch', 'post', 'put'}:
         with self.subTest(method=method):
             with mock.patch.object(client, 'request') as request:
                 getattr(client, method)('some url', json)
             self.assertEqual(
                 request.call_args[0], (method.upper(), 'some url'))
             self.assertIs(request.call_args[1]['json'], json)