def test_not_found_in_ironic(self, cli, pop_mock, process_mock): cli.node.get.side_effect = exceptions.NotFound() self.assertRaisesRegexp(utils.Error, 'not found', process.process, self.data) cli.node.get.assert_called_once_with(self.uuid) self.assertFalse(process_mock.called)
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)
def test_not_found_in_ironic(self): self.cli.node.get.side_effect = exceptions.NotFound() self.assertRaisesRegex(utils.Error, 'Node %s was not found' % self.uuid, process.process, self.data) self.cli.node.get.assert_called_once_with(self.uuid) self.assertFalse(self.process_mock.called) self.node_info.finished.assert_called_once_with(error=mock.ANY)
def test_failed_to_get_node(self, client_mock, add_mock, filters_mock): cli = client_mock.return_value cli.node.get.side_effect = exceptions.NotFound() self.assertRaisesRegexp(utils.Error, 'Cannot find node', introspect.introspect, self.uuid) cli.node.get.side_effect = exceptions.BadRequest() self.assertRaisesRegexp(utils.Error, 'Cannot get node', introspect.introspect, self.uuid) self.assertEqual(0, cli.node.list_ports.call_count) self.assertEqual(0, filters_mock.call_count) self.assertEqual(0, cli.node.set_power_state.call_count) self.assertEqual(0, cli.node.update.call_count) self.assertFalse(add_mock.called)
def test_failed_to_get_node(self, client_mock, start_mock): cli = client_mock.return_value cli.node.get.side_effect = exceptions.NotFound() self.assertRaisesRegex(utils.Error, 'Node %s was not found' % self.uuid, introspect.introspect, self.uuid) cli.node.get.side_effect = exceptions.BadRequest() self.assertRaisesRegex(utils.Error, '%s: Bad Request' % self.uuid, introspect.introspect, self.uuid) self.assertEqual(0, self.node_info.ports.call_count) self.assertEqual(0, self.sync_filter_mock.call_count) self.assertEqual(0, cli.node.set_power_state.call_count) self.assertFalse(start_mock.called) self.assertFalse(self.node_info.acquire_lock.called)
def test(self, client_mock, filters_mock): cli = client_mock.return_value cli.node.get.side_effect = [ exceptions.NotFound(), self.node1, exceptions.Conflict(), self.node2, ] cli.node.list_ports.return_value = [Mock(address='1'), Mock(address='2')] discoverd.discover(['uuid%d' % i for i in range(4)]) self.assertEqual(4, cli.node.get.call_count) cli.node.list_ports.assert_called_once_with('uuid1', limit=0) filters_mock.assert_called_once_with(cli) self.assertEqual(set(['1', '2']), discoverd.Firewall.MACS_DISCOVERY) self.assertEqual(2, cli.node.set_power_state.call_count) cli.node.set_power_state.assert_called_with(ANY, 'on') patch = [{'op': 'add', 'path': '/extra/on_discovery', 'value': 'true'}] cli.node.update.assert_any_call('uuid1', patch) cli.node.update.assert_any_call('uuid3', patch) self.assertEqual(2, cli.node.update.call_count)
def test_macs(self, client_mock, filters_mock): discoverd.ALLOW_SEARCH_BY_MAC = True cli = client_mock.return_value cli.port.get_by_address.side_effect = [ exceptions.NotFound(), Mock(node_uuid=self.node.uuid)] cli.port.create.side_effect = [None, exceptions.Conflict()] cli.node.get.return_value = self.node discoverd.process(self.data) self.assertFalse(cli.node.list.called) cli.port.get_by_address.assert_any_call('11:22:33:44:55:66') cli.port.get_by_address.assert_any_call('66:55:44:33:22:11') cli.node.get.assert_called_once_with(self.node.uuid) cli.node.update.assert_called_once_with(self.node.uuid, self.patch) cli.port.create.assert_any_call(node_uuid=self.node.uuid, address='11:22:33:44:55:66') cli.port.create.assert_any_call(node_uuid=self.node.uuid, address='66:55:44:33:22:11') self.assertEqual(2, cli.port.create.call_count) filters_mock.assert_called_once_with(cli) self.assertEqual(set(), discoverd.Firewall.MACS_DISCOVERY) cli.node.set_power_state.assert_called_once_with(self.node.uuid, 'off')
def test_store_find_node_error(self, hook_mock): self.cli.node.get.side_effect = exceptions.NotFound('boom') self.assertRaises(utils.Error, process.process, self.data) self._check_contents()
def test_validate_fail(self): self.mock_node_get.side_effect = ic_exc.NotFound() self.assertFalse(self.constraint.validate("bad_node", self.ctx))
def test_remove_not_found(self, mock_cli): mock_cli.return_value.node.remove_trait.side_effect = ( exceptions.NotFound('trait not found')) self.act.apply(self.node_info, self.params) mock_cli.return_value.node.remove_trait.assert_called_once_with( self.uuid, 'CUSTOM_FOO')