Example #1
0
    def test_no_manage_boot(self, finished_mock):
        self.node_info._manage_boot = False
        process._process_node(self.node_info, self.node, self.data)

        self.assertFalse(self.cli.node.set_power_state.called)
        finished_mock.assert_called_once_with(
            self.node_info, istate.Events.finish)
Example #2
0
    def test_no_power_off(self, finished_mock):
        CONF.set_override('power_off', False, 'processing')
        process._process_node(self.node_info, self.node, self.data)

        self.assertFalse(self.cli.node.set_power_state.called)
        finished_mock.assert_called_once_with(self.node_info,
                                              istate.Events.finish)
    def test_no_power_off(self, finished_mock):
        CONF.set_override('power_off', False, 'processing')
        process._process_node(self.node_info, self.node, self.data)

        self.assertFalse(self.cli.node.set_power_state.called)
        finished_mock.assert_called_once_with(
            self.node_info, istate.Events.finish)
    def test_store_data_with_database(self, store_mock):
        CONF.set_override('store_data', 'database', 'processing')

        process._process_node(self.node_info, self.node, self.data)

        data = intros_data_plugin._filter_data_excluded_keys(self.data)
        store_mock.assert_called_once_with(self.node_info.uuid, data, True)
        self.assertEqual(data, store_mock.call_args[0][1])
Example #5
0
    def test_store_data_with_database(self, store_mock):
        CONF.set_override('store_data', 'database', 'processing')

        process._process_node(self.node_info, self.node, self.data)

        data = intros_data_plugin._filter_data_excluded_keys(self.data)
        store_mock.assert_called_once_with(self.node_info.uuid, data, True)
        self.assertEqual(data, store_mock.call_args[0][1])
    def test_power_off_enroll_state(self, finished_mock, post_hook_mock):
        self.node.provision_state = 'enroll'
        self.node_info.node = mock.Mock(return_value=self.node)

        process._process_node(self.node_info, self.node, self.data)

        self.assertTrue(post_hook_mock.called)
        self.assertTrue(self.cli.node.set_power_state.called)
        finished_mock.assert_called_once_with(self.node_info)
    def test_power_off_enroll_state(self, finished_mock, post_hook_mock):
        self.node.provision_state = 'enroll'
        self.node_info.node = mock.Mock(return_value=self.node)

        process._process_node(self.node_info, self.node, self.data)

        self.assertTrue(post_hook_mock.called)
        self.assertTrue(self.cli.node.set_power_state.called)
        finished_mock.assert_called_once_with(self.node_info)
    def test_port_failed(self):
        self.cli.port.create.side_effect = (
            [exceptions.Conflict()] + self.ports[1:])

        process._process_node(self.node_info, self.node, self.data)

        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[0])
        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[1])
    def test_set_ipmi_credentials(self):
        self.node_info.set_option('new_ipmi_credentials', self.new_creds)

        process._process_node(self.node_info, self.node, self.data)

        self.cli.node.update.assert_any_call(self.uuid, self.patch_credentials)
        self.cli.node.set_power_state.assert_called_once_with(self.uuid, 'off')
        self.cli.node.get_boot_device.assert_called_with(self.uuid)
        self.assertEqual(self.validate_attempts + 1,
                         self.cli.node.get_boot_device.call_count)
Example #10
0
    def test_power_off_failed(self, finished_mock):
        self.cli.node.set_power_state.side_effect = RuntimeError('boom')

        process._process_node(self.node, self.data, self.node_info)

        self.cli.node.set_power_state.assert_called_once_with(self.uuid, 'off')
        finished_mock.assert_called_once_with(
            mock.ANY,
            error='Failed to power off node %s, check its power '
            'management configuration: boom' % self.uuid)
Example #11
0
    def test_port_failed(self):
        self.cli.port.create.side_effect = ([exceptions.Conflict()] +
                                            self.ports[1:])

        process._process_node(self.node, self.data, self.node_info)

        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[0])
        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[1])
    def test_set_ipmi_credentials(self):
        self.node_info.set_option('new_ipmi_credentials', self.new_creds)

        process._process_node(self.node_info, self.node, self.data)

        self.cli.node.update.assert_any_call(self.uuid, self.patch_credentials)
        self.cli.node.set_power_state.assert_called_once_with(self.uuid, 'off')
        self.cli.node.get_boot_device.assert_called_with(self.uuid)
        self.assertEqual(self.validate_attempts + 1,
                         self.cli.node.get_boot_device.call_count)
    def test_store_data(self, swift_mock):
        CONF.set_override('store_data', 'swift', 'processing')
        swift_conn = swift_mock.return_value
        name = 'inspector_data-%s' % self.uuid
        expected = self.data

        process._process_node(self.node_info, self.node, self.data)

        swift_conn.create_object.assert_called_once_with(name, mock.ANY)
        self.assertEqual(expected,
                         json.loads(swift_conn.create_object.call_args[0][1]))
    def test_store_data_no_logs(self, swift_mock):
        CONF.set_override('store_data', 'swift', 'processing')
        swift_conn = swift_mock.return_value
        name = 'inspector_data-%s' % self.uuid
        self.data['logs'] = 'something'

        process._process_node(self.node_info, self.node, self.data)

        swift_conn.create_object.assert_called_once_with(name, mock.ANY)
        self.assertNotIn('logs',
                         json.loads(swift_conn.create_object.call_args[0][1]))
Example #15
0
    def test_store_data(self, swift_mock):
        CONF.set_override('store_data', 'swift', 'processing')
        swift_conn = swift_mock.return_value
        name = 'inspector_data-%s' % self.uuid
        expected = self.data

        process._process_node(self.node_info, self.node, self.data)

        swift_conn.create_object.assert_called_once_with(name, mock.ANY)
        self.assertEqual(expected,
                         json.loads(swift_conn.create_object.call_args[0][1]))
Example #16
0
    def test_store_data_no_logs(self, swift_mock):
        CONF.set_override('store_data', 'swift', 'processing')
        swift_conn = swift_mock.return_value
        name = 'inspector_data-%s' % self.uuid
        self.data['logs'] = 'something'

        process._process_node(self.node_info, self.node, self.data)

        swift_conn.create_object.assert_called_once_with(name, mock.ANY)
        self.assertNotIn('logs',
                         json.loads(swift_conn.create_object.call_args[0][1]))
    def test_power_off_failed(self, finished_mock):
        self.cli.node.set_power_state.side_effect = RuntimeError('boom')

        process._process_node(self.node_info, self.node, self.data)

        self.cli.node.set_power_state.assert_called_once_with(self.uuid, 'off')
        finished_mock.assert_called_once_with(
            mock.ANY,
            error='Failed to power off node %s, check its power '
                  'management configuration: boom' % self.uuid
        )
    def test_port_failed(self):
        self.cli.port.create.side_effect = (
            [exceptions.Conflict()] + self.ports[1:])

        process._process_node(self.node_info, self.node, self.data)

        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[0],
                                             extra={}, pxe_enabled=True)
        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[1],
                                             extra={}, pxe_enabled=False)
Example #19
0
    def test_ok(self, finished_mock, post_hook_mock):
        process._process_node(self.node, self.data, self.node_info)

        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[0])
        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[1])
        self.cli.node.set_power_state.assert_called_once_with(self.uuid, 'off')
        self.assertFalse(self.cli.node.validate.called)

        post_hook_mock.assert_called_once_with(self.data, self.node_info)
        finished_mock.assert_called_once_with(mock.ANY)
    def test_ok(self, finished_mock, post_hook_mock):
        process._process_node(self.node_info, self.node, self.data)

        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[0])
        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[1])
        self.cli.node.set_power_state.assert_called_once_with(self.uuid, 'off')
        self.assertFalse(self.cli.node.validate.called)

        post_hook_mock.assert_called_once_with(self.data, self.node_info)
        finished_mock.assert_called_once_with(mock.ANY)
    def test_set_ipmi_credentials_no_address(self):
        self.node_info.set_option('new_ipmi_credentials', self.new_creds)
        del self.node.driver_info['ipmi_address']
        self.patch_credentials.append({'op': 'add',
                                       'path': '/driver_info/ipmi_address',
                                       'value': self.bmc_address})

        process._process_node(self.node_info, self.node, self.data)

        self.cli.node.update.assert_any_call(self.uuid, self.patch_credentials)
        self.cli.node.set_power_state.assert_called_once_with(self.uuid, 'off')
        self.cli.node.get_boot_device.assert_called_with(self.uuid)
        self.assertEqual(self.validate_attempts + 1,
                         self.cli.node.get_boot_device.call_count)
    def test_set_ipmi_credentials_no_address(self):
        self.node_info.set_option('new_ipmi_credentials', self.new_creds)
        del self.node.driver_info['ipmi_address']
        self.patch_credentials.append({'op': 'add',
                                       'path': '/driver_info/ipmi_address',
                                       'value': self.bmc_address})

        process._process_node(self.node_info, self.node, self.data)

        self.cli.node.update.assert_any_call(self.uuid, self.patch_credentials)
        self.cli.node.set_power_state.assert_called_once_with(self.uuid, 'off')
        self.cli.node.get_boot_device.assert_called_with(self.uuid)
        self.assertEqual(self.validate_attempts + 1,
                         self.cli.node.get_boot_device.call_count)
    def test_set_ipmi_credentials_timeout(self, finished_mock):
        self.node_info.set_option('new_ipmi_credentials', self.new_creds)
        self.cli.node.get_boot_device.side_effect = RuntimeError('boom')

        process._process_node(self.node_info, self.node, self.data)

        self.cli.node.update.assert_any_call(self.uuid, self.patch_credentials)
        self.assertEqual(2, self.cli.node.update.call_count)
        self.assertEqual(process._CREDENTIALS_WAIT_RETRIES,
                         self.cli.node.get_boot_device.call_count)
        self.assertFalse(self.cli.node.set_power_state.called)
        finished_mock.assert_called_once_with(
            mock.ANY,
            error='Failed to validate updated IPMI credentials for node %s, '
            'node might require maintenance' % self.uuid)
    def test_set_ipmi_credentials_timeout(self, finished_mock):
        self.node_info.set_option('new_ipmi_credentials', self.new_creds)
        self.cli.node.get_boot_device.side_effect = RuntimeError('boom')

        process._process_node(self.node_info, self.node, self.data)

        self.cli.node.update.assert_any_call(self.uuid, self.patch_credentials)
        self.assertEqual(2, self.cli.node.update.call_count)
        self.assertEqual(process._CREDENTIALS_WAIT_RETRIES,
                         self.cli.node.get_boot_device.call_count)
        self.assertFalse(self.cli.node.set_power_state.called)
        finished_mock.assert_called_once_with(
            mock.ANY,
            error='Failed to validate updated IPMI credentials for node %s, '
            'node might require maintenance' % self.uuid)
    def test_store_data_location(self, swift_mock):
        CONF.set_override('store_data', 'swift', 'processing')
        CONF.set_override('store_data_location', 'inspector_data_object',
                          'processing')
        swift_conn = swift_mock.return_value
        name = 'inspector_data-%s' % self.uuid
        patch = [{'path': '/extra/inspector_data_object',
                  'value': name, 'op': 'add'}]
        expected = self.data

        process._process_node(self.node_info, self.node, self.data)

        swift_conn.create_object.assert_called_once_with(name, mock.ANY)
        self.assertEqual(expected,
                         json.loads(swift_conn.create_object.call_args[0][1]))
        self.cli.node.update.assert_any_call(self.uuid, patch)
Example #26
0
    def test_ok(self, finished_mock, post_hook_mock):
        process._process_node(self.node_info, self.node, self.data)

        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[0],
                                             extra={},
                                             pxe_enabled=True)
        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[1],
                                             extra={},
                                             pxe_enabled=False)
        self.cli.node.set_power_state.assert_called_once_with(self.uuid, 'off')
        self.assertFalse(self.cli.node.validate.called)

        post_hook_mock.assert_called_once_with(self.data, self.node_info)
        finished_mock.assert_called_once_with(mock.ANY, istate.Events.finish)
    def test_store_data_location_with_swift(self, swift_mock):
        CONF.set_override('store_data', 'swift', 'processing')
        CONF.set_override('store_data_location', 'inspector_data_object',
                          'processing')
        swift_conn = swift_mock.return_value
        name = 'inspector_data-%s' % self.uuid
        patch = [{'path': '/extra/inspector_data_object',
                  'value': name, 'op': 'add'}]
        expected = self.data

        process._process_node(self.node_info, self.node, self.data)

        swift_conn.create_object.assert_called_once_with(name, mock.ANY)
        self.assertEqual(expected,
                         json.loads(swift_conn.create_object.call_args[0][1]))
        self.cli.node.update.assert_any_call(self.uuid, patch)
Example #28
0
    def test_ok_node_active(self, finished_mock, post_hook_mock):
        self.node.provision_state = 'active'
        CONF.set_override('permit_active_introspection', True, 'processing')
        process._process_node(self.node_info, self.node, self.data)

        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[0],
                                             extra={},
                                             pxe_enabled=True)
        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[1],
                                             extra={},
                                             pxe_enabled=False)

        self.cli.node.set_power_state.assert_not_called()
        self.assertFalse(self.cli.node.validate.called)

        post_hook_mock.assert_called_once_with(mock.ANY, self.data,
                                               self.node_info)
        finished_mock.assert_called_once_with(mock.ANY, istate.Events.finish)
Example #29
0
 def call(self, mock_cli):
     mock_cli.return_value = self.cli
     return process._process_node(self.node, self.data, self.node_info)
 def test_return_includes_uuid_with_ipmi_creds(self):
     self.node_info.set_option('new_ipmi_credentials', self.new_creds)
     ret_val = process._process_node(self.node_info, self.node, self.data)
     self.assertEqual(self.uuid, ret_val.get('uuid'))
     self.assertTrue(ret_val.get('ipmi_setup_credentials'))
 def test_return_includes_uuid_with_ipmi_creds(self):
     self.node_info.set_option('new_ipmi_credentials', self.new_creds)
     ret_val = process._process_node(self.node_info, self.node, self.data)
     self.assertEqual(self.uuid, ret_val.get('uuid'))
     self.assertTrue(ret_val.get('ipmi_setup_credentials'))
Example #32
0
 def test_return_includes_uuid(self):
     ret_val = process._process_node(self.node_info, self.node, self.data)
     self.assertEqual(self.uuid, ret_val.get('uuid'))
 def call(self, mock_cli):
     mock_cli.return_value = self.cli
     return process._process_node(self.node, self.data, self.node_info)
 def test_return_includes_uuid(self):
     ret_val = process._process_node(self.node_info, self.node, self.data)
     self.assertEqual(self.uuid, ret_val.get('uuid'))