summaryrefslogtreecommitdiff
path: root/ironic/drivers/modules/ilo/raid.py
blob: 07d6951331a7c029a2698e9098ae813a023bef49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# Copyright 2018 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

"""
iLO5 RAID specific methods
"""

from ironic_lib import metrics_utils
from oslo_log import log as logging
from oslo_utils import importutils

from ironic.common import exception
from ironic.common.i18n import _
from ironic.common import raid
from ironic.common import states
from ironic.conductor import utils as manager_utils
from ironic import conf
from ironic.drivers import base
from ironic.drivers.modules import deploy_utils
from ironic.drivers.modules.ilo import common as ilo_common


LOG = logging.getLogger(__name__)
CONF = conf.CONF
METRICS = metrics_utils.get_metrics_logger(__name__)

ilo_error = importutils.try_import('proliantutils.exception')


class Ilo5RAID(base.RAIDInterface):
    """Implementation of OOB RAIDInterface for iLO5."""

    def get_properties(self):
        """Return the properties of the interface."""
        return ilo_common.REQUIRED_PROPERTIES

    def _set_clean_failed(self, task, msg, exc):
        LOG.error("RAID configuration job failed for node %(node)s. "
                  "Message: '%(message)s'.",
                  {'node': task.node.uuid, 'message': msg})
        task.node.last_error = msg
        task.process_event('fail')

    def _set_driver_internal_true_value(self, task, *keys):
        driver_internal_info = task.node.driver_internal_info
        for key in keys:
            driver_internal_info[key] = True
        task.node.driver_internal_info = driver_internal_info
        task.node.save()

    def _set_driver_internal_false_value(self, task, *keys):
        driver_internal_info = task.node.driver_internal_info
        for key in keys:
            driver_internal_info[key] = False
        task.node.driver_internal_info = driver_internal_info
        task.node.save()

    def _pop_driver_internal_values(self, task, *keys):
        driver_internal_info = task.node.driver_internal_info
        for key in keys:
            driver_internal_info.pop(key, None)
        task.node.driver_internal_info = driver_internal_info
        task.node.save()

    def _prepare_for_read_raid(self, task, raid_step):
        deploy_opts = deploy_utils.build_agent_options(task.node)
        task.driver.boot.prepare_ramdisk(task, deploy_opts)
        manager_utils.node_power_action(task, states.REBOOT)
        if raid_step == 'create_raid':
            self._set_driver_internal_true_value(
                task, 'ilo_raid_create_in_progress')
        else:
            self._set_driver_internal_true_value(
                task, 'ilo_raid_delete_in_progress')
        self._set_driver_internal_true_value(task, 'cleaning_reboot')
        self._set_driver_internal_false_value(task, 'skip_current_clean_step')

    @METRICS.timer('Ilo5RAID.create_configuration')
    @base.clean_step(priority=0, abortable=False, argsinfo={
        'create_root_volume': {
            'description': (
                'This specifies whether to create the root volume. '
                'Defaults to `True`.'
            ),
            'required': False
        },
        'create_nonroot_volumes': {
            'description': (
                'This specifies whether to create the non-root volumes. '
                'Defaults to `True`.'
            ),
            'required': False
        }
    })
    def create_configuration(self, task, create_root_volume=True,
                             create_nonroot_volumes=True):
        """Create a RAID configuration on a bare metal using agent ramdisk.

        This method creates a RAID configuration on the given node.

        :param task: a TaskManager instance.
        :param create_root_volume: If True, a root volume is created
            during RAID configuration. Otherwise, no root volume is
            created. Default is True.
        :param create_nonroot_volumes: If True, non-root volumes are
            created. If False, no non-root volumes are created. Default
            is True.
        :raises: MissingParameterValue, if node.target_raid_config is missing
            or was found to be empty after skipping root volume and/or non-root
            volumes.
        :raises: NodeCleaningFailure, on failure to execute step.
        """
        node = task.node
        target_raid_config = raid.filter_target_raid_config(
            node, create_root_volume=create_root_volume,
            create_nonroot_volumes=create_nonroot_volumes)
        driver_internal_info = node.driver_internal_info
        driver_internal_info['target_raid_config'] = target_raid_config
        LOG.debug("Calling OOB RAID create_configuration for node %(node)s "
                  "with the following target RAID configuration: %(target)s",
                  {'node': node.uuid, 'target': target_raid_config})
        ilo_object = ilo_common.get_ilo_object(node)

        try:
            # Raid configuration in progress, checking status
            if not driver_internal_info.get('ilo_raid_create_in_progress'):
                ilo_object.create_raid_configuration(target_raid_config)
                self._prepare_for_read_raid(task, 'create_raid')
                return states.CLEANWAIT
            else:
                # Raid configuration is done, updating raid_config
                raid_conf = (
                    ilo_object.read_raid_configuration(
                        raid_config=target_raid_config))
                if len(raid_conf['logical_disks']):
                    raid.update_raid_info(node, raid_conf)
                    LOG.debug("Node %(uuid)s raid create clean step is done.",
                              {'uuid': node.uuid})
                    self._pop_driver_internal_values(
                        task, 'ilo_raid_create_in_progress',
                        'cleaning_reboot', 'skip_current_clean_step')
                    node.driver_internal_info = driver_internal_info
                    node.save()
                else:
                    # Raid configuration failed
                    msg = "Unable to create raid"
                    self._pop_driver_internal_values(
                        task, 'ilo_raid_create_in_progress',
                        'cleaning_reboot', 'skip_current_clean_step')
                    node.driver_internal_info = driver_internal_info
                    node.save()
                    raise exception.NodeCleaningFailure(
                        "Clean step create_configuration failed "
                        "on node %(node)s with error: %(err)s" %
                        {'node': node.uuid, 'err': msg})
        except ilo_error.IloError as ilo_exception:
            operation = (_("Failed to create raid configuration on node %s")
                         % node.uuid)
            self._pop_driver_internal_values(task,
                                             'ilo_raid_create_in_progress',
                                             'cleaning_reboot',
                                             'skip_current_clean_step')
            node.driver_internal_info = driver_internal_info
            node.save()
            self._set_clean_failed(task, operation, ilo_exception)

    @METRICS.timer('Ilo5RAID.delete_configuration')
    @base.clean_step(priority=0, abortable=False)
    def delete_configuration(self, task):
        """Delete the RAID configuration.

        :param task: a TaskManager instance  containing the node to act on.
        :raises: NodeCleaningFailure, on failure to execute step.
        """
        node = task.node
        LOG.debug("OOB RAID delete_configuration invoked for node %s.",
                  node.uuid)
        driver_internal_info = node.driver_internal_info
        ilo_object = ilo_common.get_ilo_object(node)

        try:
            # Raid configuration in progress, checking status
            if not driver_internal_info.get('ilo_raid_delete_in_progress'):
                ilo_object.delete_raid_configuration()
                self._prepare_for_read_raid(task, 'delete_raid')
                return states.CLEANWAIT
            else:
                # Raid configuration is done, updating raid_config
                raid_conf = ilo_object.read_raid_configuration()
                if not len(raid_conf['logical_disks']):
                    node.raid_config = {}
                    LOG.debug("Node %(uuid)s raid delete clean step is done.",
                              {'uuid': node.uuid})
                    self._pop_driver_internal_values(
                        task, 'ilo_raid_delete_in_progress',
                        'cleaning_reboot', 'skip_current_clean_step')
                    node.driver_internal_info = driver_internal_info
                    node.save()
                else:
                    # Raid configuration failed
                    msg = ("Unable to delete this logical disks: %s" %
                           raid_conf['logical_disks'])
                    self._pop_driver_internal_values(
                        task, 'ilo_raid_delete_in_progress',
                        'cleaning_reboot', 'skip_current_clean_step')
                    node.driver_internal_info = driver_internal_info
                    node.save()
                    raise exception.NodeCleaningFailure(
                        "Clean step delete_configuration failed "
                        "on node %(node)s with error: %(err)s" %
                        {'node': node.uuid, 'err': msg})
        except ilo_error.IloLogicalDriveNotFoundError:
            LOG.info("No logical drive found to delete on node %(node)s",
                     {'node': node.uuid})
        except ilo_error.IloError as ilo_exception:
            operation = (_("Failed to delete raid configuration on node %s")
                         % node.uuid)
            self._pop_driver_internal_values(task,
                                             'ilo_raid_delete_in_progress',
                                             'cleaning_reboot',
                                             'skip_current_clean_step')
            node.driver_internal_info = driver_internal_info
            node.save()
            self._set_clean_failed(task, operation, ilo_exception)