Beispiel #1
0
def _process_node(node_info, node, introspection_data):
    # NOTE(dtantsur): repeat the check in case something changed
    keep_power_on = ir_utils.check_provision_state(node)

    _run_post_hooks(node_info, introspection_data)
    store_introspection_data(node_info.uuid, introspection_data)

    ironic = ir_utils.get_client()
    pxe_filter.driver().sync(ironic)

    node_info.invalidate_cache()
    rules.apply(node_info, introspection_data)

    resp = {'uuid': node.id}

    # determine how to handle power
    if keep_power_on or not node_info.manage_boot:
        power_action = False
    else:
        power_action = CONF.processing.power_off
    utils.executor().submit(_finish,
                            node_info,
                            ironic,
                            introspection_data,
                            power_off=power_action)

    return resp
Beispiel #2
0
def _process_node(node, introspection_data, node_info):
    # NOTE(dtantsur): repeat the check in case something changed
    ir_utils.check_provision_state(node)

    node_info.create_ports(introspection_data.get('macs') or ())

    _run_post_hooks(node_info, introspection_data)
    _store_data(node_info, introspection_data)

    ironic = ir_utils.get_client()
    firewall.update_filters(ironic)

    node_info.invalidate_cache()
    rules.apply(node_info, introspection_data)

    resp = {'uuid': node.uuid}

    if node_info.options.get('new_ipmi_credentials'):
        new_username, new_password = (
            node_info.options.get('new_ipmi_credentials'))
        utils.executor().submit(_finish_set_ipmi_credentials,
                                ironic, node, node_info, introspection_data,
                                new_username, new_password)
        resp['ipmi_setup_credentials'] = True
        resp['ipmi_username'] = new_username
        resp['ipmi_password'] = new_password
    else:
        utils.executor().submit(_finish, ironic, node_info, introspection_data)

    return resp
Beispiel #3
0
def _process_node(node_info, node, introspection_data):
    # NOTE(dtantsur): repeat the check in case something changed
    ir_utils.check_provision_state(node)
    interfaces = introspection_data.get('interfaces')
    node_info.create_ports(list(interfaces.values()))
    _run_post_hooks(node_info, introspection_data)
    _store_data(node_info, introspection_data)

    ironic = ir_utils.get_client()
    firewall.update_filters(ironic)

    node_info.invalidate_cache()
    rules.apply(node_info, introspection_data)

    resp = {'uuid': node.uuid}

    if node_info.options.get('new_ipmi_credentials'):
        new_username, new_password = (
            node_info.options.get('new_ipmi_credentials'))
        utils.executor().submit(_finish_set_ipmi_credentials,
                                node_info, ironic, node, introspection_data,
                                new_username, new_password)
        resp['ipmi_setup_credentials'] = True
        resp['ipmi_username'] = new_username
        resp['ipmi_password'] = new_password
    else:
        utils.executor().submit(_finish, node_info, ironic, introspection_data,
                                power_off=CONF.processing.power_off)

    return resp
 def test_node_scope_2(self, mock_get_all):
     mock_get_all.return_value = self.rules
     self.node_info.node().properties['inspection_scope'] = "scope_2"
     rules.apply(self.node_info, self.data)
     self.rules[0].apply_actions.assert_called_once()  # global
     self.rules[1].apply_actions.assert_not_called()  # scope_1
     self.rules[2].apply_actions.assert_called_once()  # scope_2
     self.rules[3].apply_actions.assert_not_called()  # scope_3
Beispiel #5
0
    def test_only_rollback(self, mock_get_all):
        mock_get_all.return_value = self.rules
        for rule in self.rules:
            rule.check_conditions.return_value = False

        rules.apply(self.node_info, self.data)

        for rule in self.rules:
            rule.check_conditions.assert_called_once_with(self.node_info,
                                                          self.data)
            rule.apply_actions.assert_called_once_with(
                self.node_info, rollback=True)
Beispiel #6
0
    def test_only_rollback(self, mock_get_all):
        mock_get_all.return_value = self.rules
        for rule in self.rules:
            rule.check_conditions.return_value = False

        rules.apply(self.node_info, self.data)

        for rule in self.rules:
            rule.check_conditions.assert_called_once_with(
                self.node_info, self.data)
            rule.apply_actions.assert_called_once_with(self.node_info,
                                                       rollback=True)
Beispiel #7
0
    def test_actions(self, mock_get_all):
        mock_get_all.return_value = self.rules
        for idx, rule in enumerate(self.rules):
            rule.check_conditions.return_value = not bool(idx)

        rules.apply(self.node_info, self.data)

        for idx, rule in enumerate(self.rules):
            rule.check_conditions.assert_called_once_with(
                self.node_info, self.data)
            rule.apply_actions.assert_called_once_with(self.node_info,
                                                       rollback=bool(idx))
Beispiel #8
0
def _reapply_with_data(node_info, introspection_data):
    failures = []
    _run_pre_hooks(introspection_data, failures)
    if failures:
        raise utils.Error(_('Pre-processing failures detected reapplying '
                            'introspection on stored data:\n%s') %
                          '\n'.join(failures), node_info=node_info)

    _run_post_hooks(node_info, introspection_data)
    store_introspection_data(node_info.uuid, introspection_data)
    node_info.invalidate_cache()
    rules.apply(node_info, introspection_data)
Beispiel #9
0
    def test_actions(self, mock_get_all):
        mock_get_all.return_value = self.rules
        for idx, rule in enumerate(self.rules):
            rule.check_conditions.return_value = not bool(idx)

        rules.apply(self.node_info, self.data)

        for idx, rule in enumerate(self.rules):
            rule.check_conditions.assert_called_once_with(self.node_info,
                                                          self.data)
            rule.apply_actions.assert_called_once_with(
                self.node_info, rollback=bool(idx))
Beispiel #10
0
def _reapply_with_data(node_info, introspection_data):
    failures = []
    _run_pre_hooks(introspection_data, failures)
    if failures:
        raise utils.Error(_('Pre-processing failures detected reapplying '
                            'introspection on stored data:\n%s') %
                          '\n'.join(failures), node_info=node_info)

    interfaces = introspection_data.get('interfaces')
    node_info.create_ports(list(interfaces.values()))
    _run_post_hooks(node_info, introspection_data)
    _store_data(node_info, introspection_data)
    node_info.invalidate_cache()
    rules.apply(node_info, introspection_data)
Beispiel #11
0
    def test_apply(self, mock_get_all):
        mock_get_all.return_value = self.rules
        for idx, rule in enumerate(self.rules):
            rule.check_conditions.return_value = not bool(idx)

        rules.apply(self.node_info, self.data)

        for idx, rule in enumerate(self.rules):
            rule.check_conditions.assert_called_once_with(
                self.node_info, self.data)
            if rule.check_conditions.return_value:
                rule.apply_actions.assert_called_once_with(self.node_info,
                                                           data=self.data)
            else:
                self.assertFalse(rule.apply_actions.called)
Beispiel #12
0
def _process_node(node, introspection_data, node_info):
    # NOTE(dtantsur): repeat the check in case something changed
    utils.check_provision_state(node)

    node_info.create_ports(introspection_data.get('macs') or ())

    _run_post_hooks(node_info, introspection_data)

    if CONF.processing.store_data == 'swift':
        swift_object_name = swift.store_introspection_data(
            introspection_data, node_info.uuid)
        LOG.info(
            _LI('Introspection data for node %(node)s was stored in '
                'Swift in object %(obj)s'), {
                    'node': node_info.uuid,
                    'obj': swift_object_name
                })
        if CONF.processing.store_data_location:
            node_info.patch([{
                'op': 'add',
                'path': '/extra/%s' % CONF.processing.store_data_location,
                'value': swift_object_name
            }])
    else:
        LOG.debug(
            'Swift support is disabled, introspection data for node %s '
            'won\'t be stored', node_info.uuid)

    ironic = utils.get_client()
    firewall.update_filters(ironic)

    node_info.invalidate_cache()
    rules.apply(node_info, introspection_data)

    resp = {'uuid': node.uuid}

    if node_info.options.get('new_ipmi_credentials'):
        new_username, new_password = (
            node_info.options.get('new_ipmi_credentials'))
        utils.spawn_n(_finish_set_ipmi_credentials, ironic, node, node_info,
                      introspection_data, new_username, new_password)
        resp['ipmi_setup_credentials'] = True
        resp['ipmi_username'] = new_username
        resp['ipmi_password'] = new_password
    else:
        utils.spawn_n(_finish, ironic, node_info)

    return resp
def _process_node(node, introspection_data, node_info):
    # NOTE(dtantsur): repeat the check in case something changed
    ir_utils.check_provision_state(node)

    node_info.create_ports(introspection_data.get('macs') or ())

    _run_post_hooks(node_info, introspection_data)

    if CONF.processing.store_data == 'swift':
        stored_data = {k: v for k, v in introspection_data.items()
                       if k not in _STORAGE_EXCLUDED_KEYS}
        swift_object_name = swift.store_introspection_data(stored_data,
                                                           node_info.uuid)
        LOG.info(_LI('Introspection data was stored in Swift in object %s'),
                 swift_object_name,
                 node_info=node_info, data=introspection_data)
        if CONF.processing.store_data_location:
            node_info.patch([{'op': 'add', 'path': '/extra/%s' %
                              CONF.processing.store_data_location,
                              'value': swift_object_name}])
    else:
        LOG.debug('Swift support is disabled, introspection data '
                  'won\'t be stored',
                  node_info=node_info, data=introspection_data)

    ironic = ir_utils.get_client()
    firewall.update_filters(ironic)

    node_info.invalidate_cache()
    rules.apply(node_info, introspection_data)

    resp = {'uuid': node.uuid}

    if node_info.options.get('new_ipmi_credentials'):
        new_username, new_password = (
            node_info.options.get('new_ipmi_credentials'))
        utils.executor().submit(_finish_set_ipmi_credentials,
                                ironic, node, node_info, introspection_data,
                                new_username, new_password)
        resp['ipmi_setup_credentials'] = True
        resp['ipmi_username'] = new_username
        resp['ipmi_password'] = new_password
    else:
        utils.executor().submit(_finish, ironic, node_info, introspection_data)

    return resp
Beispiel #14
0
def _reapply(node_info):
    # runs in background
    try:
        introspection_data = _get_unprocessed_data(node_info.uuid)
    except Exception as exc:
        LOG.exception(_LE('Encountered exception while fetching '
                          'stored introspection data'),
                      node_info=node_info)
        msg = (_('Unexpected exception %(exc_class)s while fetching '
                 'unprocessed introspection data from Swift: %(error)s') % {
                     'exc_class': exc.__class__.__name__,
                     'error': exc
                 })
        node_info.finished(error=msg)
        return

    failures = []
    _run_pre_hooks(introspection_data, failures)
    if failures:
        LOG.error(_LE('Pre-processing failures detected reapplying '
                      'introspection on stored data:\n%s'),
                  '\n'.join(failures),
                  node_info=node_info)
        node_info.finished(error='\n'.join(failures))
        return

    try:
        ironic = ir_utils.get_client()
        node_info.create_ports(introspection_data.get('macs') or ())
        _run_post_hooks(node_info, introspection_data)
        _store_data(node_info, introspection_data)
        node_info.invalidate_cache()
        rules.apply(node_info, introspection_data)
        _finish(ironic, node_info, introspection_data, power_off=False)
    except Exception as exc:
        LOG.exception(_LE('Encountered exception reapplying '
                          'introspection on stored data'),
                      node_info=node_info,
                      data=introspection_data)
        node_info.finished(error=str(exc))
    else:
        LOG.info(_LI('Successfully reapplied introspection on stored '
                     'data'),
                 node_info=node_info,
                 data=introspection_data)
Beispiel #15
0
def _process_node(node, introspection_data, node_info):
    # NOTE(dtantsur): repeat the check in case something changed
    utils.check_provision_state(node)

    node_info.create_ports(introspection_data.get('macs') or ())

    _run_post_hooks(node_info, introspection_data)

    if CONF.processing.store_data == 'swift':
        swift_object_name = swift.store_introspection_data(introspection_data,
                                                           node_info.uuid)
        LOG.info(_LI('Introspection data for node %(node)s was stored in '
                     'Swift in object %(obj)s'),
                 {'node': node_info.uuid, 'obj': swift_object_name})
        if CONF.processing.store_data_location:
            node_info.patch([{'op': 'add', 'path': '/extra/%s' %
                              CONF.processing.store_data_location,
                              'value': swift_object_name}])
    else:
        LOG.debug('Swift support is disabled, introspection data for node %s '
                  'won\'t be stored', node_info.uuid)

    ironic = utils.get_client()
    firewall.update_filters(ironic)

    node_info.invalidate_cache()
    rules.apply(node_info, introspection_data)

    resp = {'uuid': node.uuid}

    if node_info.options.get('new_ipmi_credentials'):
        new_username, new_password = (
            node_info.options.get('new_ipmi_credentials'))
        utils.spawn_n(_finish_set_ipmi_credentials,
                      ironic, node, node_info, introspection_data,
                      new_username, new_password)
        resp['ipmi_setup_credentials'] = True
        resp['ipmi_username'] = new_username
        resp['ipmi_password'] = new_password
    else:
        utils.spawn_n(_finish, ironic, node_info)

    return resp
Beispiel #16
0
def _process_node(node_info, node, introspection_data):
    # NOTE(dtantsur): repeat the check in case something changed
    ir_utils.check_provision_state(node)
    _run_post_hooks(node_info, introspection_data)
    _store_data(node_info.uuid, introspection_data)

    ironic = ir_utils.get_client()
    pxe_filter.driver().sync(ironic)

    node_info.invalidate_cache()
    rules.apply(node_info, introspection_data)

    resp = {'uuid': node.uuid}

    utils.executor().submit(_finish,
                            node_info,
                            ironic,
                            introspection_data,
                            power_off=CONF.processing.power_off)

    return resp
Beispiel #17
0
def _reapply(node_info):
    # runs in background
    try:
        introspection_data = _get_unprocessed_data(node_info.uuid)
    except Exception:
        LOG.exception(_LE('Encountered exception while fetching '
                          'stored introspection data'),
                      node_info=node_info)
        node_info.release_lock()
        return

    failures = []
    _run_pre_hooks(introspection_data, failures)
    if failures:
        LOG.error(_LE('Pre-processing failures detected reapplying '
                      'introspection on stored data:\n%s'),
                  '\n'.join(failures), node_info=node_info)
        node_info.finished(error='\n'.join(failures))
        return

    try:
        ironic = ir_utils.get_client()
        node_info.create_ports(introspection_data.get('macs') or ())
        _run_post_hooks(node_info, introspection_data)
        _store_data(node_info, introspection_data)
        node_info.invalidate_cache()
        rules.apply(node_info, introspection_data)
        _finish(ironic, node_info, introspection_data,
                power_off=False)
    except Exception as exc:
        LOG.exception(_LE('Encountered exception reapplying '
                          'introspection on stored data'),
                      node_info=node_info,
                      data=introspection_data)
        node_info.finished(error=str(exc))
    else:
        LOG.info(_LI('Successfully reapplied introspection on stored '
                     'data'), node_info=node_info, data=introspection_data)
Beispiel #18
0
    def test_no_rules(self, mock_get_all):
        mock_get_all.return_value = []

        rules.apply(self.node_info, self.data)
Beispiel #19
0
    def test_no_rules(self, mock_get_all):
        mock_get_all.return_value = []

        rules.apply(self.node_info, self.data)