def api_introspection(node_id): utils.check_auth(flask.request) if flask.request.method == 'POST': new_ipmi_password = flask.request.args.get('new_ipmi_password', type=str, default=None) if new_ipmi_password: new_ipmi_username = flask.request.args.get('new_ipmi_username', type=str, default=None) new_ipmi_credentials = (new_ipmi_username, new_ipmi_password) else: new_ipmi_credentials = None if new_ipmi_credentials and _get_version() >= (1, 9): return _('Setting IPMI credentials is deprecated and not allowed ' 'starting with API version 1.9'), 400 introspect.introspect(node_id, new_ipmi_credentials=new_ipmi_credentials, token=flask.request.headers.get('X-Auth-Token')) return '', 202 else: node_info = node_cache.get_node(node_id) return flask.json.jsonify(generate_introspection_status(node_info))
def test_with_maintenance(self, client_mock, add_mock, filters_mock): cli = client_mock.return_value cli.node.get.return_value = self.node_compat cli.node.validate.return_value = mock.Mock(power={'result': True}) add_mock.return_value = mock.Mock(uuid=self.node_compat.uuid, options={}, **{'node.return_value': self.node}) add_mock.return_value.ports.return_value = collections.OrderedDict( (p.address, p) for p in self.ports) introspect.introspect(self.node_compat.uuid) cli.node.get.assert_called_once_with(self.node_compat.uuid) cli.node.validate.assert_called_once_with(self.node_compat.uuid) add_mock.return_value.ports.assert_called_once_with() add_mock.assert_called_once_with(self.node_compat.uuid, bmc_address=None, ironic=cli) add_mock.return_value.add_attribute.assert_called_once_with('mac', self.macs) filters_mock.assert_called_with(cli) cli.node.set_boot_device.assert_called_once_with(self.node_compat.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.node_compat.uuid, 'reboot')
def test_forced_persistent_boot_compat(self, client_mock, start_mock): self.node.driver_info['force_persistent_boot_device'] = 'true' cli = self._prepare(client_mock) start_mock.return_value = self.node_info introspect.introspect(self.node.uuid) cli.get_node.assert_called_once_with(self.uuid) cli.validate_node.assert_called_once_with(self.uuid, required='power') start_mock.assert_called_once_with(self.uuid, bmc_address=[self.bmc_address], manage_boot=True, ironic=cli) self.node_info.ports.assert_called_once_with() self.node_info.add_attribute.assert_called_once_with('mac', self.macs) self.sync_filter_mock.assert_called_with(cli) cli.set_node_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=True) cli.set_node_power_state.assert_called_once_with(self.uuid, 'rebooting') self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def test_resolved_bmc_address(self, ipmi_mock, client_mock, start_mock): self.node.driver_info['ipmi_address'] = 'example.com' addresses = ['93.184.216.34', '2606:2800:220:1:248:1893:25c8:1946'] ipmi_mock.return_value = ('example.com',) + tuple(addresses) cli = self._prepare(client_mock) start_mock.return_value = self.node_info introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) cli.node.validate.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, bmc_address=addresses, manage_boot=True, ironic=cli) self.node_info.ports.assert_called_once_with() self.node_info.add_attribute.assert_called_once_with('mac', self.macs) self.sync_filter_mock.assert_called_with(cli) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot') self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def api_introspection(uuid): utils.check_auth(flask.request) if not uuidutils.is_uuid_like(uuid): raise utils.Error(_('Invalid UUID value'), code=400) if flask.request.method == 'POST': new_ipmi_password = flask.request.args.get('new_ipmi_password', type=str, default=None) if new_ipmi_password: new_ipmi_username = flask.request.args.get('new_ipmi_username', type=str, default=None) new_ipmi_credentials = (new_ipmi_username, new_ipmi_password) else: new_ipmi_credentials = None introspect.introspect(uuid, new_ipmi_credentials=new_ipmi_credentials, token=flask.request.headers.get('X-Auth-Token')) return '', 202 else: node_info = node_cache.get_node(uuid) return flask.json.jsonify(finished=bool(node_info.finished_at), error=node_info.error or None)
def test_loopback_bmc_address(self, client_mock, start_mock, filters_mock): self.node.driver_info['ipmi_address'] = '127.0.0.1' cli = self._prepare(client_mock) start_mock.return_value = self.node_info introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) cli.node.validate.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, bmc_address=None, ironic=cli) self.node_info.ports.assert_called_once_with() self.node_info.add_attribute.assert_called_once_with('mac', self.macs) filters_mock.assert_called_with(cli) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot') self.node_info.set_option.assert_called_once_with( 'new_ipmi_credentials', None) self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def api_introspection(node_id): if flask.request.method == 'POST': introspect.introspect(node_id, token=flask.request.headers.get('X-Auth-Token')) return '', 202 else: node_info = node_cache.get_node(node_id) return flask.json.jsonify(generate_introspection_status(node_info))
def test_inspect_wait_state_allowed(self, client_mock, start_mock): self.node.provision_state = 'inspect wait' cli = client_mock.return_value cli.node.get.return_value = self.node cli.node.validate.return_value = mock.Mock(power={'result': True}) introspect.introspect(self.uuid) self.assertTrue(start_mock.called)
def test_ok_ilo_and_drac(self, client_mock, add_mock, filters_mock): cli = self._prepare(client_mock) add_mock.return_value = self.node_info for name in ("ilo_address", "drac_host"): self.node.driver_info = {name: self.bmc_address} introspect.introspect(self.node.uuid) add_mock.assert_called_with(self.uuid, bmc_address=self.bmc_address, ironic=cli)
def test_ok_ilo_and_drac(self, client_mock, start_mock, filters_mock): cli = self._prepare(client_mock) start_mock.return_value = self.node_info for name in ('ilo_address', 'drac_host'): self.node.driver_info = {name: self.bmc_address} introspect.introspect(self.node.uuid) start_mock.assert_called_with(self.uuid, bmc_address=self.bmc_address, ironic=cli)
def test_no_lookup_attrs(self, client_mock, add_mock, filters_mock): cli = self._prepare(client_mock) self.node_info.ports.return_value = [] add_mock.return_value = self.node_info self.node_info.attributes = {} introspect.introspect(self.uuid) self.node_info.ports.assert_called_once_with() self.node_info.finished.assert_called_once_with(error=mock.ANY) self.assertEqual(0, filters_mock.call_count) self.assertEqual(0, cli.node.set_power_state.call_count)
def test_ok(self, client_mock, add_mock, filters_mock): cli = self._prepare(client_mock) add_mock.return_value = self.node_info introspect.introspect(self.uuid, new_ipmi_credentials=self.new_creds) add_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) filters_mock.assert_called_with(cli) self.assertFalse(cli.node.validate.called) self.assertFalse(cli.node.set_boot_device.called) self.assertFalse(cli.node.set_power_state.called) add_mock.return_value.set_option.assert_called_once_with("new_ipmi_credentials", self.new_creds)
def test_ok_ilo_and_drac(self, client_mock, start_mock): cli = self._prepare(client_mock) start_mock.return_value = self.node_info for name in ('ilo_address', 'drac_host'): self.node.driver_info = {name: self.bmc_address} introspect.introspect(self.node.uuid) start_mock.assert_called_with(self.uuid, bmc_address=[self.bmc_address], manage_boot=True, ironic=cli)
def test_no_lookup_attrs_with_node_not_found_hook(self, client_mock, add_mock, filters_mock): CONF.set_override("node_not_found_hook", "example", "processing") cli = self._prepare(client_mock) self.node_info.ports.return_value = [] add_mock.return_value = self.node_info self.node_info.attributes = {} introspect.introspect(self.uuid) self.node_info.ports.assert_called_once_with() self.assertFalse(self.node_info.finished.called) cli.node.set_boot_device.assert_called_once_with(self.uuid, "pxe", persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, "reboot")
def test_unexpected_error(self, client_mock, add_mock, filters_mock): cli = self._prepare(client_mock) add_mock.return_value = self.node_info filters_mock.side_effect = RuntimeError() introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) add_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) self.assertFalse(cli.node.set_boot_device.called) add_mock.return_value.finished.assert_called_once_with(error=mock.ANY) self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def test_no_macs(self, client_mock, add_mock, filters_mock): cli = self._prepare(client_mock) self.node_info.ports.return_value = [] add_mock.return_value = self.node_info introspect.introspect(self.node.uuid) self.node_info.ports.assert_called_once_with() add_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) self.assertFalse(self.node_info.add_attribute.called) self.assertFalse(filters_mock.called) cli.node.set_boot_device.assert_called_once_with(self.uuid, "pxe", persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, "reboot")
def test_no_lookup_attrs(self, client_mock, start_mock): cli = self._prepare(client_mock) self.node_info.ports.return_value = [] start_mock.return_value = self.node_info self.node_info.attributes = {} introspect.introspect(self.uuid) self.node_info.ports.assert_called_once_with() self.node_info.finished.assert_called_once_with( introspect.istate.Events.error, error=mock.ANY) self.assertEqual(0, self.sync_filter_mock.call_count) self.assertEqual(0, cli.node.set_power_state.call_count) self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def test_ok(self, client_mock, start_mock, filters_mock): cli = self._prepare(client_mock) start_mock.return_value = self.node_info introspect.introspect(self.uuid, new_ipmi_credentials=self.new_creds) start_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) filters_mock.assert_called_with(cli) self.assertFalse(cli.node.validate.called) self.assertFalse(cli.node.set_boot_device.called) self.assertFalse(cli.node.set_power_state.called) start_mock.return_value.set_option.assert_called_once_with( 'new_ipmi_credentials', self.new_creds)
def test_unexpected_error(self, client_mock, add_mock, filters_mock): cli = self._prepare(client_mock) add_mock.return_value = self.node_info filters_mock.side_effect = RuntimeError() introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) add_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) self.assertFalse(cli.node.set_boot_device.called) add_mock.return_value.finished.assert_called_once_with( error=mock.ANY)
def test_no_lookup_attrs_with_node_not_found_hook(self, client_mock, start_mock): CONF.set_override('node_not_found_hook', 'example', 'processing') cli = self._prepare(client_mock) self.node_info.ports.return_value = [] start_mock.return_value = self.node_info self.node_info.attributes = {} introspect.introspect(self.uuid) self.node_info.ports.assert_called_once_with() self.assertFalse(self.node_info.finished.called) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot')
def test_sleep_no_pxe_ssh(self, time_mock, sleep_mock, client_mock, add_mock, filters_mock): self.node.driver = "pxe_ipmitool" time_mock.return_value = 42 introspect._LAST_INTROSPECTION_TIME = 40 CONF.set_override("introspection_delay", 10) cli = self._prepare(client_mock) add_mock.return_value = self.node_info introspect.introspect(self.uuid) self.assertFalse(sleep_mock.called) cli.node.set_boot_device.assert_called_once_with(self.uuid, "pxe", persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, "reboot") # not changed self.assertEqual(40, introspect._LAST_INTROSPECTION_TIME)
def test_power_failure(self, client_mock, add_mock, filters_mock): cli = self._prepare(client_mock) cli.node.set_boot_device.side_effect = exceptions.BadRequest() cli.node.set_power_state.side_effect = exceptions.BadRequest() add_mock.return_value = self.node_info introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) add_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) cli.node.set_boot_device.assert_called_once_with(self.uuid, "pxe", persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, "reboot") add_mock.return_value.finished.assert_called_once_with(error=mock.ANY) self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def test_sleep_not_needed_with_pxe_ssh(self, time_mock, sleep_mock, client_mock, add_mock, filters_mock): self.node.driver = "agent_ssh" time_mock.return_value = 100 introspect._LAST_INTROSPECTION_TIME = 40 CONF.set_override("introspection_delay", 10) cli = self._prepare(client_mock) add_mock.return_value = self.node_info introspect.introspect(self.uuid) self.assertFalse(sleep_mock.called) cli.node.set_boot_device.assert_called_once_with(self.uuid, "pxe", persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, "reboot") # updated to the current time.time() self.assertEqual(100, introspect._LAST_INTROSPECTION_TIME)
def test_introspection_no_delay_without_manage_boot(self, time_mock, client_mock, start_mock): time_mock.return_value = 42 introspect._LAST_INTROSPECTION_TIME = 40 CONF.set_override('introspection_delay', 10) self._prepare(client_mock) start_mock.return_value = self.node_info self.node_info.manage_boot = False introspect.introspect(self.uuid, manage_boot=False) self.assertFalse(self.sleep_fixture.mock.called) # not updated self.assertEqual(40, introspect._LAST_INTROSPECTION_TIME)
def test_sleep_with_custom_driver(self, time_mock, sleep_mock, client_mock, add_mock, filters_mock): self.node.driver = "foobar" time_mock.return_value = 42 introspect._LAST_INTROSPECTION_TIME = 40 CONF.set_override("introspection_delay", 10) CONF.set_override("introspection_delay_drivers", "fo{1,2}b.r") cli = self._prepare(client_mock) add_mock.return_value = self.node_info introspect.introspect(self.uuid) sleep_mock.assert_called_once_with(8) cli.node.set_boot_device.assert_called_once_with(self.uuid, "pxe", persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, "reboot") # updated to the current time.time() self.assertEqual(42, introspect._LAST_INTROSPECTION_TIME)
def test_introspection_delay(self, time_mock, client_mock, start_mock): time_mock.return_value = 42 introspect._LAST_INTROSPECTION_TIME = 40 CONF.set_override('introspection_delay', 10) cli = self._prepare(client_mock) start_mock.return_value = self.node_info introspect.introspect(self.uuid) self.sleep_fixture.mock.assert_called_once_with(8) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot') # updated to the current time.time() self.assertEqual(42, introspect._LAST_INTROSPECTION_TIME)
def test_default_username(self, client_mock, add_mock, filters_mock): cli = self._prepare(client_mock) add_mock.return_value = self.node_info self.node.driver_info['ipmi_username'] = self.new_creds[0] introspect.introspect(self.uuid, new_ipmi_credentials=(None, self.new_creds[1])) add_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) filters_mock.assert_called_with(cli) self.assertFalse(cli.node.validate.called) self.assertFalse(cli.node.set_boot_device.called) self.assertFalse(cli.node.set_power_state.called) add_mock.return_value.set_option.assert_called_once_with( 'new_ipmi_credentials', self.new_creds)
def test_unexpected_error(self, client_mock, start_mock): cli = self._prepare(client_mock) start_mock.return_value = self.node_info self.sync_filter_mock.side_effect = RuntimeError() introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) self.assertFalse(cli.node.set_boot_device.called) start_mock.return_value.finished.assert_called_once_with( introspect.istate.Events.error, error=mock.ANY) self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def test_default_username(self, client_mock, start_mock, filters_mock): cli = self._prepare(client_mock) start_mock.return_value = self.node_info self.node.driver_info['ipmi_username'] = self.new_creds[0] introspect.introspect(self.uuid, new_ipmi_credentials=(None, self.new_creds[1])) start_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) filters_mock.assert_called_with(cli) self.assertFalse(cli.node.validate.called) self.assertFalse(cli.node.set_boot_device.called) self.assertFalse(cli.node.set_power_state.called) start_mock.return_value.set_option.assert_called_once_with( 'new_ipmi_credentials', self.new_creds)
def test_ok(self, client_mock, add_mock, filters_mock): cli = self._prepare(client_mock) add_mock.return_value = self.node_info introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) cli.node.validate.assert_called_once_with(self.uuid) add_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) self.node_info.ports.assert_called_once_with() self.node_info.add_attribute.assert_called_once_with("mac", self.macs) filters_mock.assert_called_with(cli) cli.node.set_boot_device.assert_called_once_with(self.uuid, "pxe", persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, "reboot") self.node_info.set_option.assert_called_once_with("new_ipmi_credentials", None) self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def test_no_macs(self, client_mock, start_mock): cli = self._prepare(client_mock) self.node_info.ports.return_value = [] start_mock.return_value = self.node_info introspect.introspect(self.node.uuid) self.node_info.ports.assert_called_once_with() start_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) self.assertFalse(self.node_info.add_attribute.called) self.assertFalse(self.sync_filter_mock.called) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot')
def test_unexpected_error(self, client_mock, start_mock): cli = self._prepare(client_mock) start_mock.return_value = self.node_info self.sync_filter_mock.side_effect = RuntimeError() introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, bmc_address=[self.bmc_address], manage_boot=True, ironic=cli) self.assertFalse(cli.node.set_boot_device.called) start_mock.return_value.finished.assert_called_once_with( introspect.istate.Events.error, error=mock.ANY) self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def test_any_state_with_maintenance(self, client_mock, add_mock, filters_mock): self.node.provision_state = 'manageable' self.node.maintenance = True cli = self._prepare(client_mock) add_mock.return_value = self.node_info introspect.introspect(self.uuid, new_ipmi_credentials=self.new_creds) add_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) filters_mock.assert_called_with(cli) self.assertFalse(cli.node.validate.called) self.assertFalse(cli.node.set_boot_device.called) self.assertFalse(cli.node.set_power_state.called) add_mock.return_value.set_option.assert_called_once_with( 'new_ipmi_credentials', self.new_creds)
def test_sleep_no_pxe_ssh(self, time_mock, sleep_mock, client_mock, add_mock, filters_mock): self.node.driver = 'pxe_ipmitool' time_mock.return_value = 42 introspect._LAST_INTROSPECTION_TIME = 40 CONF.set_override('introspection_delay', 10) cli = self._prepare(client_mock) add_mock.return_value = self.node_info introspect.introspect(self.uuid) self.assertFalse(sleep_mock.called) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot') # not changed self.assertEqual(40, introspect._LAST_INTROSPECTION_TIME)
def test_no_manage_boot(self, client_mock, add_mock): cli = self._prepare(client_mock) self.node_info.manage_boot = False add_mock.return_value = self.node_info introspect.introspect(self.node.uuid, manage_boot=False) cli.node.get.assert_called_once_with(self.uuid) add_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, manage_boot=False, ironic=cli) self.node_info.ports.assert_called_once_with() self.node_info.add_attribute.assert_called_once_with('mac', self.macs) self.sync_filter_mock.assert_called_with(cli) self.assertFalse(cli.node.validate.called) self.assertFalse(cli.node.set_boot_device.called) self.assertFalse(cli.node.set_power_state.called)
def test_sleep_not_needed_with_pxe_ssh(self, time_mock, sleep_mock, client_mock, add_mock, filters_mock): self.node.driver = 'agent_ssh' time_mock.return_value = 100 introspect._LAST_INTROSPECTION_TIME = 40 CONF.set_override('introspection_delay', 10) cli = self._prepare(client_mock) add_mock.return_value = self.node_info introspect.introspect(self.uuid) self.assertFalse(sleep_mock.called) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot') # updated to the current time.time() self.assertEqual(100, introspect._LAST_INTROSPECTION_TIME)
def test_no_macs(self, client_mock, start_mock): cli = self._prepare(client_mock) self.node_info.ports.return_value = [] start_mock.return_value = self.node_info introspect.introspect(self.node.uuid) self.node_info.ports.assert_called_once_with() start_mock.assert_called_once_with(self.uuid, bmc_address=[self.bmc_address], manage_boot=True, ironic=cli) self.assertFalse(self.node_info.add_attribute.called) self.assertFalse(self.sync_filter_mock.called) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot')
def test_sleep_with_custom_driver(self, time_mock, sleep_mock, client_mock, add_mock, filters_mock): self.node.driver = 'foobar' time_mock.return_value = 42 introspect._LAST_INTROSPECTION_TIME = 40 CONF.set_override('introspection_delay', 10) CONF.set_override('introspection_delay_drivers', 'fo{1,2}b.r') cli = self._prepare(client_mock) add_mock.return_value = self.node_info introspect.introspect(self.uuid) sleep_mock.assert_called_once_with(8) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot') # updated to the current time.time() self.assertEqual(42, introspect._LAST_INTROSPECTION_TIME)
def test_no_manage_boot(self, client_mock, add_mock): cli = self._prepare(client_mock) self.node_info.manage_boot = False add_mock.return_value = self.node_info introspect.introspect(self.node.uuid, manage_boot=False) cli.node.get.assert_called_once_with(self.uuid) add_mock.assert_called_once_with(self.uuid, bmc_address=[self.bmc_address], manage_boot=False, ironic=cli) self.node_info.ports.assert_called_once_with() self.node_info.add_attribute.assert_called_once_with('mac', self.macs) self.sync_filter_mock.assert_called_with(cli) self.assertFalse(cli.node.validate.called) self.assertFalse(cli.node.set_boot_device.called) self.assertFalse(cli.node.set_power_state.called)
def test_power_failure(self, client_mock, add_mock, filters_mock): cli = self._prepare(client_mock) cli.node.set_boot_device.side_effect = exceptions.BadRequest() cli.node.set_power_state.side_effect = exceptions.BadRequest() add_mock.return_value = self.node_info introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) add_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot') add_mock.return_value.finished.assert_called_once_with( error=mock.ANY)
def test_set_boot_device_failure(self, client_mock, start_mock): cli = self._prepare(client_mock) cli.node.set_boot_device.side_effect = exceptions.BadRequest() start_mock.return_value = self.node_info introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, bmc_address=[self.bmc_address], manage_boot=True, ironic=cli) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_not_called() start_mock.return_value.finished.assert_called_once_with( introspect.istate.Events.error, error=mock.ANY) self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def test_ok(self, client_mock, start_mock): cli = self._prepare(client_mock) start_mock.return_value = self.node_info introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) cli.node.validate.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) self.node_info.ports.assert_called_once_with() self.node_info.add_attribute.assert_called_once_with('mac', self.macs) self.sync_filter_mock.assert_called_with(cli) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot') self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def api_introspection(node_id): utils.check_auth(flask.request) if flask.request.method == 'POST': new_ipmi_password = flask.request.args.get('new_ipmi_password', type=str, default=None) if new_ipmi_password: new_ipmi_username = flask.request.args.get('new_ipmi_username', type=str, default=None) new_ipmi_credentials = (new_ipmi_username, new_ipmi_password) else: new_ipmi_credentials = None introspect.introspect(node_id, new_ipmi_credentials=new_ipmi_credentials, token=flask.request.headers.get('X-Auth-Token')) return '', 202 else: node_info = node_cache.get_node(node_id) return flask.json.jsonify(generate_introspection_status(node_info))
def test_ok(self, client_mock, add_mock, filters_mock): cli = self._prepare(client_mock) add_mock.return_value = self.node_info introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) cli.node.validate.assert_called_once_with(self.uuid) add_mock.assert_called_once_with(self.uuid, bmc_address=self.bmc_address, ironic=cli) self.node_info.ports.assert_called_once_with() self.node_info.add_attribute.assert_called_once_with('mac', self.macs) filters_mock.assert_called_with(cli) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot') add_mock.return_value.set_option.assert_called_once_with( 'new_ipmi_credentials', None)
def test_power_failure(self, client_mock, start_mock): cli = self._prepare(client_mock) cli.set_node_power_state.side_effect = os_exc.BadRequestException() start_mock.return_value = self.node_info self.async_exc = (utils.Error, 'Failed to power on') introspect.introspect(self.node.uuid) cli.get_node.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, bmc_address=[self.bmc_address], manage_boot=True, ironic=cli) cli.set_node_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.set_node_power_state.assert_called_once_with(self.uuid, 'rebooting') start_mock.return_value.finished.assert_called_once_with( introspect.istate.Events.error, error=mock.ANY) self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def test_ok(self, client_mock, start_mock): cli = self._prepare(client_mock) start_mock.return_value = self.node_info introspect.introspect(self.node.uuid) cli.node.get.assert_called_once_with(self.uuid) cli.node.validate.assert_called_once_with(self.uuid) start_mock.assert_called_once_with(self.uuid, bmc_address=[self.bmc_address], manage_boot=True, ironic=cli) self.node_info.ports.assert_called_once_with() self.node_info.add_attribute.assert_called_once_with('mac', self.macs) self.sync_filter_mock.assert_called_with(cli) cli.node.set_boot_device.assert_called_once_with(self.uuid, 'pxe', persistent=False) cli.node.set_power_state.assert_called_once_with(self.uuid, 'reboot') self.node_info.acquire_lock.assert_called_once_with() self.node_info.release_lock.assert_called_once_with()
def do_introspection(self, context, node_id, token=None, manage_boot=True): introspect.introspect(node_id, token=token, manage_boot=manage_boot)