Exemplo n.º 1
0
    def test_retries(self, client_mock, add_mock, filters_mock):
        cli = client_mock.return_value
        cli.node.get.return_value = self.node
        cli.node.validate.side_effect = [exceptions.Conflict,
                                         mock.Mock(power={'result': True})]
        cli.node.list_ports.return_value = self.ports
        cli.node.update.side_effect = [exceptions.Conflict,
                                       exceptions.Conflict,
                                       None]
        cli.node.set_boot_device.side_effect = [exceptions.Conflict,
                                                None]
        cli.node.set_power_state.side_effect = [exceptions.Conflict,
                                                None]
        add_mock.return_value = self.cached_node

        introspect.introspect(self.node.uuid)

        cli.node.get.assert_called_once_with(self.uuid)
        cli.node.validate.assert_called_with(self.uuid)
        cli.node.list_ports.assert_called_once_with(self.uuid, limit=0)

        cli.node.update.assert_called_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address,
                                         mac=self.macs)
        filters_mock.assert_called_with(cli)
        cli.node.set_boot_device.assert_called_with(self.uuid,
                                                    'pxe',
                                                    persistent=False)
        cli.node.set_power_state.assert_called_with(self.uuid,
                                                    'reboot')
Exemplo n.º 2
0
    def test_ok(self, client_mock, add_mock, filters_mock):
        cli = client_mock.return_value
        cli.node.get.return_value = self.node
        cli.node.validate.return_value = mock.Mock(power={'result': True})
        cli.node.list_ports.return_value = self.ports
        add_mock.return_value = self.cached_node

        introspect.introspect(self.node.uuid)

        cli.node.get.assert_called_once_with(self.uuid)
        cli.node.validate.assert_called_once_with(self.uuid)
        cli.node.list_ports.assert_called_once_with(self.uuid, limit=0)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address,
                                         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(
            'setup_ipmi_credentials', False)
Exemplo n.º 3
0
    def test_juno_compat(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})
        cli.node.list_ports.return_value = self.ports
        add_mock.return_value = mock.Mock(uuid=self.node_compat.uuid)

        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)
        cli.node.list_ports.assert_called_once_with(self.node_compat.uuid,
                                                    limit=0)

        cli.node.update.assert_called_once_with(self.node_compat.uuid,
                                                self.patch)
        add_mock.assert_called_once_with(self.node_compat.uuid,
                                         bmc_address=None,
                                         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')
Exemplo n.º 4
0
    def test_retries(self, client_mock, add_mock, filters_mock):
        cli = client_mock.return_value
        cli.node.get.return_value = self.node
        cli.node.validate.side_effect = [
            exceptions.Conflict,
            mock.Mock(power={'result': True})
        ]
        cli.node.list_ports.return_value = self.ports
        cli.node.update.side_effect = [
            exceptions.Conflict, exceptions.Conflict, None
        ]
        cli.node.set_boot_device.side_effect = [exceptions.Conflict, None]
        cli.node.set_power_state.side_effect = [exceptions.Conflict, None]
        add_mock.return_value = self.cached_node

        introspect.introspect(self.node.uuid)

        cli.node.get.assert_called_once_with(self.uuid)
        cli.node.validate.assert_called_with(self.uuid)
        cli.node.list_ports.assert_called_once_with(self.uuid, limit=0)

        cli.node.update.assert_called_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address,
                                         mac=self.macs)
        filters_mock.assert_called_with(cli)
        cli.node.set_boot_device.assert_called_with(self.uuid,
                                                    'pxe',
                                                    persistent=False)
        cli.node.set_power_state.assert_called_with(self.uuid, 'reboot')
Exemplo n.º 5
0
    def test_juno_compat(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})
        cli.node.list_ports.return_value = self.ports
        add_mock.return_value = mock.Mock(uuid=self.node_compat.uuid)

        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)
        cli.node.list_ports.assert_called_once_with(self.node_compat.uuid,
                                                    limit=0)

        cli.node.update.assert_called_once_with(self.node_compat.uuid,
                                                self.patch)
        add_mock.assert_called_once_with(self.node_compat.uuid,
                                         bmc_address=None,
                                         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')
Exemplo n.º 6
0
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)
        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)
Exemplo n.º 7
0
def api_discover():
    check_auth()
    data = flask.request.get_json(force=True)
    LOG.debug("/v1/discover got JSON %s", data)

    for uuid in data:
        introspect.introspect(uuid)
    return "", 202
Exemplo n.º 8
0
def api_discover():
    utils.check_auth(flask.request)

    data = flask.request.get_json(force=True)
    LOG.debug("/v1/discover got JSON %s", data)

    for uuid in data:
        introspect.introspect(uuid)
    return "", 202
Exemplo n.º 9
0
    def test_ok_ilo_and_drac(self, client_mock, add_mock, filters_mock):
        self._prepare(client_mock)
        add_mock.return_value = self.cached_node

        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)
Exemplo n.º 10
0
def api_discover():
    utils.check_auth(flask.request)

    data = flask.request.get_json(force=True)
    LOG.debug("/v1/discover got JSON %s", data)

    for uuid in data:
        if not uuidutils.is_uuid_like(uuid):
            raise utils.Error(_('Invalid UUID value'), code=400)

    for uuid in data:
        introspect.introspect(uuid)
    return "", 202
Exemplo n.º 11
0
def api_introspection(uuid):
    check_auth()

    if flask.request.method == 'POST':
        setup_ipmi_credentials = flask.request.args.get(
            'setup_ipmi_credentials', type=bool, default=False)
        introspect.introspect(uuid,
                              setup_ipmi_credentials=setup_ipmi_credentials)
        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)
Exemplo n.º 12
0
    def test_ok_ilo_and_drac(self, client_mock, add_mock, filters_mock):
        cli = client_mock.return_value
        cli.node.get.return_value = self.node
        cli.node.validate.return_value = mock.Mock(power={'result': True})
        cli.node.list_ports.return_value = self.ports
        add_mock.return_value = self.cached_node

        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,
                                    mac=self.macs)
Exemplo n.º 13
0
def api_introspection(uuid):
    utils.check_auth(flask.request)

    if flask.request.method == 'POST':
        setup_ipmi_credentials = flask.request.args.get(
            'setup_ipmi_credentials',
            type=bool,
            default=False)
        introspect.introspect(uuid,
                              setup_ipmi_credentials=setup_ipmi_credentials)
        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)
Exemplo n.º 14
0
    def test_unexpected_error(self, client_mock, add_mock, filters_mock):
        cli = self._prepare(client_mock)
        add_mock.return_value = self.cached_node
        filters_mock.side_effect = RuntimeError()

        introspect.introspect(self.node.uuid)

        cli.node.get.assert_called_once_with(self.uuid)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address)
        self.assertFalse(cli.node.set_boot_device.called)
        add_mock.return_value.finished.assert_called_once_with(
            error=mock.ANY)
Exemplo n.º 15
0
    def test_ok(self, client_mock, add_mock, filters_mock):
        cli = self._prepare(client_mock)
        add_mock.return_value = self.cached_node

        introspect.introspect(self.uuid, new_ipmi_credentials=self.new_creds)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address)
        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)
Exemplo n.º 16
0
    def test_setup_ipmi_credentials(self, client_mock, add_mock, filters_mock):
        conf.CONF.set('discoverd', 'enable_setting_ipmi_credentials', 'true')

        cli = client_mock.return_value
        cli.node.get.return_value = self.node
        cli.node.list_ports.return_value = self.ports
        cli.node.validate.side_effect = Exception()

        introspect.introspect(self.uuid, setup_ipmi_credentials=True)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address,
                                         mac=self.macs)
        filters_mock.assert_called_with(cli)
        self.assertFalse(cli.node.set_boot_device.called)
        self.assertFalse(cli.node.set_power_state.called)
Exemplo n.º 17
0
    def test_setup_ipmi_credentials(self, client_mock, add_mock, filters_mock):
        conf.CONF.set('discoverd', 'enable_setting_ipmi_credentials', 'true')

        cli = client_mock.return_value
        cli.node.get.return_value = self.node
        cli.node.list_ports.return_value = self.ports
        cli.node.validate.side_effect = Exception()

        introspect.introspect(self.uuid, setup_ipmi_credentials=True)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address,
                                         mac=self.macs)
        filters_mock.assert_called_with(cli)
        self.assertFalse(cli.node.set_boot_device.called)
        self.assertFalse(cli.node.set_power_state.called)
Exemplo n.º 18
0
    def test_unexpected_error(self, client_mock, add_mock, filters_mock):
        cli = client_mock.return_value
        cli.node.get.return_value = self.node
        cli.node.validate.return_value = mock.Mock(power={'result': True})
        cli.node.list_ports.return_value = self.ports
        add_mock.return_value = self.cached_node
        filters_mock.side_effect = RuntimeError()

        introspect.introspect(self.node.uuid)

        cli.node.get.assert_called_once_with(self.uuid)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address,
                                         mac=self.macs)
        self.assertFalse(cli.node.set_boot_device.called)
        add_mock.return_value.finished.assert_called_once_with(error=mock.ANY)
Exemplo n.º 19
0
    def test_no_macs(self, client_mock, add_mock, filters_mock):
        cli = client_mock.return_value
        cli.node.get.return_value = self.node
        cli.node.list_ports.return_value = []
        add_mock.return_value = self.cached_node

        introspect.introspect(self.node.uuid)

        cli.node.list_ports.assert_called_once_with(self.uuid, limit=0)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address,
                                         mac=[])
        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')
Exemplo n.º 20
0
    def test_no_macs(self, client_mock, add_mock, filters_mock):
        cli = self._prepare(client_mock)
        cli.node.list_ports.return_value = []
        add_mock.return_value = self.cached_node

        introspect.introspect(self.node.uuid)

        cli.node.list_ports.assert_called_once_with(self.uuid, limit=0)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address)
        self.assertFalse(self.cached_node.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')
Exemplo n.º 21
0
    def test_unexpected_error(self, client_mock, add_mock, filters_mock):
        cli = client_mock.return_value
        cli.node.get.return_value = self.node
        cli.node.validate.return_value = mock.Mock(power={'result': True})
        cli.node.list_ports.return_value = self.ports
        add_mock.return_value = self.cached_node
        filters_mock.side_effect = RuntimeError()

        introspect.introspect(self.node.uuid)

        cli.node.get.assert_called_once_with(self.uuid)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address,
                                         mac=self.macs)
        self.assertFalse(cli.node.set_boot_device.called)
        add_mock.return_value.finished.assert_called_once_with(
            error=mock.ANY)
Exemplo n.º 22
0
    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.cached_node

        introspect.introspect(self.node.uuid)

        cli.node.get.assert_called_once_with(self.uuid)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address)
        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)
Exemplo n.º 23
0
    def test_power_failure(self, client_mock, add_mock, filters_mock):
        cli = client_mock.return_value
        cli.node.get.return_value = self.node
        cli.node.validate.return_value = mock.Mock(power={'result': True})
        cli.node.list_ports.return_value = self.ports
        cli.node.set_boot_device.side_effect = exceptions.BadRequest()
        cli.node.set_power_state.side_effect = exceptions.BadRequest()
        add_mock.return_value = self.cached_node

        introspect.introspect(self.node.uuid)

        cli.node.get.assert_called_once_with(self.uuid)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address,
                                         mac=self.macs)
        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)
Exemplo n.º 24
0
    def test_ok(self, client_mock, add_mock, filters_mock):
        cli = self._prepare(client_mock)
        add_mock.return_value = self.cached_node

        introspect.introspect(self.node.uuid)

        cli.node.get.assert_called_once_with(self.uuid)
        cli.node.validate.assert_called_once_with(self.uuid)
        cli.node.list_ports.assert_called_once_with(self.uuid, limit=0)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address)
        self.cached_node.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)
Exemplo n.º 25
0
    def test_ok(self, client_mock, add_mock, filters_mock):
        cli = client_mock.return_value
        cli.node.get.return_value = self.node
        cli.node.validate.return_value = mock.Mock(power={'result': True})
        cli.node.list_ports.return_value = self.ports
        add_mock.return_value = self.cached_node

        introspect.introspect(self.node.uuid)

        cli.node.get.assert_called_once_with(self.uuid)
        cli.node.validate.assert_called_once_with(self.uuid)
        cli.node.list_ports.assert_called_once_with(self.uuid, limit=0)

        cli.node.update.assert_called_once_with(self.uuid, self.patch)
        add_mock.assert_called_once_with(self.uuid,
                                         bmc_address=self.bmc_address,
                                         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(
            'setup_ipmi_credentials', False)