def test_save_unprocessed_data(self, store_mock):
        CONF.set_override('store_data', 'swift', 'processing')
        expected = copy.deepcopy(self.data)

        process.process(self.data)

        store_mock.assert_called_once_with(mock.ANY, expected)
 def test_failure_to_write(self, log_mock, hook_mock):
     CONF.set_override('always_store_ramdisk_logs', True, 'processing')
     CONF.set_override('ramdisk_logs_dir', '/I/cannot/write/here',
                       'processing')
     process.process(self.data)
     self.assertEqual([], os.listdir(self.tempdir))
     self.assertTrue(log_mock.called)
示例#3
0
    def test_save_unprocessed_data(self, store_mock):
        CONF.set_override('store_data', 'swift', 'processing')
        expected = copy.deepcopy(self.data)

        process.process(self.data)

        store_mock.assert_called_once_with(mock.ANY, expected)
 def test_failure_to_write(self, log_mock, hook_mock):
     CONF.set_override('always_store_ramdisk_logs', True, 'processing')
     CONF.set_override('ramdisk_logs_dir', '/I/cannot/write/here',
                       'processing')
     process.process(self.data)
     self.assertEqual([], os.listdir(self.tempdir))
     self.assertTrue(log_mock.called)
示例#5
0
    def test_no_ipmi(self, cli, pop_mock, process_mock):
        del self.data['ipmi_address']
        process.process(self.data)

        pop_mock.assert_called_once_with(bmc_address=None,
                                         mac=self.data['macs'])
        cli.node.get.assert_called_once_with(self.uuid)
        process_mock.assert_called_once_with(cli.node.get.return_value,
                                             self.data, pop_mock.return_value)
示例#6
0
    def test_save_unprocessed_data(self, cli, pop_mock, process_mock):
        CONF.set_override('store_data', 'swift', 'processing')
        expected = copy.deepcopy(self.data)

        with mock.patch.object(process, '_store_unprocessed_data',
                               autospec=True) as store_mock:
            process.process(self.data)

        store_mock.assert_called_once_with(mock.ANY, expected)
    def test_no_ipmi(self, cli, pop_mock, process_mock):
        del self.data['ipmi_address']
        process.process(self.data)

        pop_mock.assert_called_once_with(bmc_address=None,
                                         mac=self.data['macs'])
        cli.node.get.assert_called_once_with(self.uuid)
        process_mock.assert_called_once_with(cli.node.get.return_value,
                                             self.data, pop_mock.return_value)
示例#8
0
    def test_no_ipmi(self):
        del self.inventory['bmc_address']
        process.process(self.data)

        self.find_mock.assert_called_once_with(bmc_address=None, mac=mock.ANY)
        actual_macs = self.find_mock.call_args[1]['mac']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        self.cli.node.get.assert_called_once_with(self.uuid)
        self.process_mock.assert_called_once_with(self.node_info, self.node,
                                                  self.data)
示例#9
0
    def test_no_ipmi(self, cli, pop_mock, process_mock):
        del self.data['ipmi_address']
        process.process(self.data)

        pop_mock.assert_called_once_with(bmc_address=None, mac=mock.ANY)
        actual_macs = pop_mock.call_args[1]['mac']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        cli.node.get.assert_called_once_with(self.uuid)
        process_mock.assert_called_once_with(cli.node.get.return_value,
                                             self.data, pop_mock.return_value)
示例#10
0
    def test_save_unprocessed_data(self, cli, pop_mock, process_mock):
        CONF.set_override('store_data', 'swift', 'processing')
        expected = copy.deepcopy(self.data)

        with mock.patch.object(process,
                               '_store_unprocessed_data',
                               autospec=True) as store_mock:
            process.process(self.data)

        store_mock.assert_called_once_with(mock.ANY, expected)
示例#11
0
    def test_no_ipmi(self, cli, pop_mock, process_mock):
        del self.data['ipmi_address']
        process.process(self.data)

        pop_mock.assert_called_once_with(bmc_address=None, mac=mock.ANY)
        actual_macs = pop_mock.call_args[1]['mac']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        cli.node.get.assert_called_once_with(self.uuid)
        process_mock.assert_called_once_with(cli.node.get.return_value,
                                             self.data, pop_mock.return_value)
示例#12
0
    def test_unexpected_exception(self):
        self.process_mock.side_effect = RuntimeError('boom')

        with self.assertRaisesRegex(utils.Error,
                                    'Unexpected exception') as ctx:
            process.process(self.data)

        self.assertEqual(500, ctx.exception.http_code)
        self.node_info.finished.assert_called_once_with(
            error='Unexpected exception RuntimeError during processing: boom')
示例#13
0
    def test_unexpected_exception(self):
        self.process_mock.side_effect = RuntimeError('boom')

        with self.assertRaisesRegex(utils.Error,
                                    'Unexpected exception') as ctx:
            process.process(self.data)

        self.assertEqual(500, ctx.exception.http_code)
        self.node_info.finished.assert_called_once_with(
            error='Unexpected exception RuntimeError during processing: boom')
示例#14
0
    def test_no_ipmi(self):
        del self.inventory['bmc_address']
        process.process(self.data)

        self.find_mock.assert_called_once_with(bmc_address=None, mac=mock.ANY)
        actual_macs = self.find_mock.call_args[1]['mac']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        self.cli.node.get.assert_called_once_with(self.uuid)
        self.process_mock.assert_called_once_with(self.node_info, self.node,
                                                  self.data)
示例#15
0
    def test_ipmi_not_detected_with_old_field(self):
        self.inventory['bmc_address'] = '0.0.0.0'
        self.data['ipmi_address'] = '0.0.0.0'
        process.process(self.data)

        self.find_mock.assert_called_once_with(bmc_address=None, mac=mock.ANY)
        actual_macs = self.find_mock.call_args[1]['mac']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        self.cli.node.get.assert_called_once_with(self.uuid)
        self.process_mock.assert_called_once_with(self.node_info, self.node,
                                                  self.data)
示例#16
0
    def test_ipmi_not_detected_with_old_field(self):
        self.inventory['bmc_address'] = '0.0.0.0'
        self.data['ipmi_address'] = '0.0.0.0'
        process.process(self.data)

        self.find_mock.assert_called_once_with(bmc_address=None, mac=mock.ANY)
        actual_macs = self.find_mock.call_args[1]['mac']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        self.cli.node.get.assert_called_once_with(self.uuid)
        self.process_mock.assert_called_once_with(self.node_info, self.node,
                                                  self.data)
示例#17
0
 def test_failure_to_write(self, log_mock, makedirs_mock, hook_mock):
     tempdir = tempfile.mkdtemp()
     logs_dir = os.path.join(tempdir, 'I/never/exist')
     CONF.set_override('always_store_ramdisk_logs', True, 'processing')
     CONF.set_override('ramdisk_logs_dir', logs_dir, 'processing')
     makedirs_mock.side_effect = OSError()
     process.process(self.data)
     os.rmdir(tempdir)
     self.assertEqual([], os.listdir(self.tempdir))
     self.assertTrue(makedirs_mock.called)
     self.assertTrue(log_mock.called)
示例#18
0
 def test_failure_to_write(self, log_mock, makedirs_mock, hook_mock):
     tempdir = tempfile.mkdtemp()
     logs_dir = os.path.join(tempdir, 'I/never/exist')
     CONF.set_override('always_store_ramdisk_logs', True, 'processing')
     CONF.set_override('ramdisk_logs_dir', logs_dir, 'processing')
     makedirs_mock.side_effect = OSError()
     process.process(self.data)
     os.rmdir(tempdir)
     self.assertEqual([], os.listdir(self.tempdir))
     self.assertTrue(makedirs_mock.called)
     self.assertTrue(log_mock.called)
示例#19
0
    def test_save_unprocessed_data_failure(self):
        CONF.set_override('store_data', 'swift', 'processing')

        res = process.process(self.data)

        # assert store failure doesn't break processing
        self.assertEqual(self.fake_result_json, res)
示例#20
0
    def test_save_unprocessed_data_failure(self):
        CONF.set_override('store_data', 'swift', 'processing')

        res = process.process(self.data)

        # assert store failure doesn't break processing
        self.assertEqual(self.fake_result_json, res)
示例#21
0
    def test_not_found_in_cache_active_introspection(self, mock_record):
        CONF.set_override('permit_active_introspection', True, 'processing')
        self.find_mock.side_effect = utils.NotFoundInCacheError('not found')
        self.cli.node.get.side_effect = exceptions.NotFound('boom')
        self.cache_fixture.mock.acquire_lock = mock.Mock()
        self.cache_fixture.mock.uuid = '1111'
        self.cache_fixture.mock.finished_at = None
        self.cache_fixture.mock.node = mock.Mock()
        mock_record.return_value = self.cache_fixture.mock
        res = process.process(self.data)

        self.assertEqual(self.fake_result_json, res)
        self.find_mock.assert_called_once_with(
            bmc_address=[self.bmc_address, self.bmc_v6address],
            mac=mock.ANY)
        actual_macs = self.find_mock.call_args[1]['mac']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        mock_record.assert_called_once_with(
            bmc_addresses=['1.2.3.4',
                           '2001:1234:1234:1234:1234:1234:1234:1234/64'],
            macs=mock.ANY)
        actual_macs = mock_record.call_args[1]['macs']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        self.cli.node.get.assert_not_called()
        self.process_mock.assert_called_once_with(
            mock.ANY, mock.ANY, self.data)
示例#22
0
 def test_node_not_found_hook_run_ok(self, hook_mock):
     CONF.set_override('node_not_found_hook', 'example', 'processing')
     self.find_mock.side_effect = utils.NotFoundInCacheError('BOOM')
     hook_mock.return_value = node_cache.NodeInfo(
         uuid=self.node.uuid, started_at=self.started_at)
     res = process.process(self.data)
     self.assertEqual(self.fake_result_json, res)
     hook_mock.assert_called_once_with(self.data)
示例#23
0
 def test_node_not_found_hook_run_ok(self, hook_mock):
     CONF.set_override('node_not_found_hook', 'example', 'processing')
     self.find_mock.side_effect = utils.NotFoundInCacheError('BOOM')
     hook_mock.return_value = node_cache.NodeInfo(
         uuid=self.node.uuid,
         started_at=self.started_at)
     res = process.process(self.data)
     self.assertEqual(self.fake_result_json, res)
     hook_mock.assert_called_once_with(self.data)
 def test_node_not_found_hook_run_ok(self, cli, pop_mock, process_mock):
     CONF.set_override('node_not_found_hook', 'example', 'processing')
     plugins_base._NOT_FOUND_HOOK_MGR = None
     pop_mock.side_effect = iter([utils.NotFoundInCacheError('BOOM')])
     with mock.patch.object(example_plugin,
                            'example_not_found_hook') as hook_mock:
         hook_mock.return_value = node_cache.NodeInfo(
             uuid=self.node.uuid, started_at=self.started_at)
         res = process.process(self.data)
         self.assertEqual(self.fake_result_json, res)
         hook_mock.assert_called_once_with(self.data)
示例#25
0
def api_continue():
    data = flask.request.get_json(force=True)
    if not isinstance(data, dict):
        raise utils.Error(_('Invalid data: expected a JSON object, got %s') %
                          data.__class__.__name__)

    logged_data = {k: (v if k not in _LOGGING_EXCLUDED_KEYS else '<hidden>')
                   for k, v in data.items()}
    LOG.debug("Received data from the ramdisk: %s", logged_data)

    return flask.jsonify(process.process(data))
示例#26
0
def api_continue():
    data = flask.request.get_json(force=True)
    if not isinstance(data, dict):
        raise utils.Error(_('Invalid data: expected a JSON object, got %s') %
                          data.__class__.__name__)

    logged_data = {k: (v if k not in _LOGGING_EXCLUDED_KEYS else '<hidden>')
                   for k, v in data.items()}
    LOG.debug("Received data from the ramdisk: %s", logged_data,
              data=data)

    return flask.jsonify(process.process(data))
示例#27
0
 def test_node_not_found_hook_run_ok(self, cli, pop_mock, process_mock):
     CONF.set_override('node_not_found_hook', 'example', 'processing')
     plugins_base._NOT_FOUND_HOOK_MGR = None
     pop_mock.side_effect = iter([utils.NotFoundInCacheError('BOOM')])
     with mock.patch.object(example_plugin,
                            'example_not_found_hook') as hook_mock:
         hook_mock.return_value = node_cache.NodeInfo(
             uuid=self.node.uuid,
             started_at=self.started_at)
         res = process.process(self.data)
         self.assertEqual(self.fake_result_json, res)
         hook_mock.assert_called_once_with(self.data)
示例#28
0
    def test_ok(self):
        res = process.process(self.data)

        self.assertEqual(self.fake_result_json, res)

        self.find_mock.assert_called_once_with(bmc_address=self.bmc_address,
                                               mac=mock.ANY)
        actual_macs = self.find_mock.call_args[1]['mac']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        self.cli.node.get.assert_called_once_with(self.uuid)
        self.process_mock.assert_called_once_with(self.node_info, self.node,
                                                  self.data)
示例#29
0
    def test_ok(self):
        res = process.process(self.data)

        self.assertEqual(self.fake_result_json, res)

        self.find_mock.assert_called_once_with(bmc_address=self.bmc_address,
                                               mac=mock.ANY)
        actual_macs = self.find_mock.call_args[1]['mac']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        self.cli.node.get.assert_called_once_with(self.uuid)
        self.process_mock.assert_called_once_with(
            self.node_info, self.node, self.data)
示例#30
0
    def test_save_unprocessed_data_failure(self, swift_mock):
        CONF.set_override('store_data', 'swift', 'processing')
        name = 'inspector_data-%s-%s' % (
            self.uuid, process._UNPROCESSED_DATA_STORE_SUFFIX)

        swift_conn = swift_mock.return_value
        swift_conn.create_object.side_effect = utils.Error('Oops')

        res = process.process(self.data)

        # assert store failure doesn't break processing
        self.assertEqual(self.fake_result_json, res)
        swift_conn.create_object.assert_called_once_with(name, mock.ANY)
示例#31
0
    def test_ok(self, cli, pop_mock, process_mock):
        res = process.process(self.data)

        self.assertEqual(self.fake_result_json, res)

        # Only boot interface is added by default
        self.assertEqual(['em2'], sorted(self.data['interfaces']))
        self.assertEqual([self.pxe_mac], self.data['macs'])

        pop_mock.assert_called_once_with(bmc_address=self.bmc_address,
                                         mac=self.data['macs'])
        cli.node.get.assert_called_once_with(self.uuid)
        process_mock.assert_called_once_with(cli.node.get.return_value,
                                             self.data, pop_mock.return_value)
    def test_ok(self, cli, pop_mock, process_mock):
        res = process.process(self.data)

        self.assertEqual(self.fake_result_json, res)

        # Only boot interface is added by default
        self.assertEqual(['em2'], sorted(self.data['interfaces']))
        self.assertEqual([self.pxe_mac], self.data['macs'])

        pop_mock.assert_called_once_with(bmc_address=self.bmc_address,
                                         mac=self.data['macs'])
        cli.node.get.assert_called_once_with(self.uuid)
        process_mock.assert_called_once_with(cli.node.get.return_value,
                                             self.data, pop_mock.return_value)
示例#33
0
    def test_save_unprocessed_data_failure(self, swift_mock):
        CONF.set_override('store_data', 'swift', 'processing')
        name = 'inspector_data-%s-%s' % (
            self.uuid,
            process._UNPROCESSED_DATA_STORE_SUFFIX
        )

        swift_conn = swift_mock.return_value
        swift_conn.create_object.side_effect = utils.Error('Oops')

        res = process.process(self.data)

        # assert store failure doesn't break processing
        self.assertEqual(self.fake_result_json, res)
        swift_conn.create_object.assert_called_once_with(name, mock.ANY)
示例#34
0
    def test_found_in_cache_active_introspection(self):
        CONF.set_override('permit_active_introspection', True, 'processing')
        self.node.provision_state = 'active'
        self.cache_fixture.mock.acquire_lock = mock.Mock()
        self.cache_fixture.mock.uuid = '1111'
        self.cache_fixture.mock.finished_at = None
        self.cache_fixture.mock.node = mock.Mock()
        res = process.process(self.data)

        self.assertEqual(self.fake_result_json, res)
        self.find_mock.assert_called_once_with(
            bmc_address=[self.bmc_address, self.bmc_v6address], mac=mock.ANY)
        actual_macs = self.find_mock.call_args[1]['mac']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        self.cli.node.get.assert_called_once_with(self.uuid)
        self.process_mock.assert_called_once_with(mock.ANY, mock.ANY,
                                                  self.data)
示例#35
0
 def do_continue(self, context, data):
     return process.process(data)
示例#36
0
def api_continue():
    data = flask.request.get_json(force=True)
    LOG.debug("/v1/continue got JSON %s", data)

    return flask.jsonify(process.process(data))
示例#37
0
 def test_always_store_logs(self, hook_mock):
     CONF.set_override('always_store_ramdisk_logs', True, 'processing')
     process.process(self.data)
     self._check_contents()
示例#38
0
 def test_no_error_no_logs(self, hook_mock):
     process.process(self.data)
     self.assertEqual([], os.listdir(self.tempdir))
示例#39
0
 def test_no_error_no_logs(self, hook_mock):
     process.process(self.data)
     self.assertEqual([], os.listdir(self.tempdir))
示例#40
0
 def test_always_store_logs(self, hook_mock):
     CONF.set_override('always_store_ramdisk_logs', True, 'processing')
     process.process(self.data)
     self._check_contents()
示例#41
0
def api_continue():
    data = flask.request.get_json(force=True)
    LOG.debug("/v1/continue got JSON %s", data)

    return flask.jsonify(process.process(data))