~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/drivers/modules/ipmitool.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2015-04-17 09:28:31 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20150417092831-wu2awfbqomnzpeim
Tags: 2015.1~rc1-0ubuntu1
* New upstream milestone release:
  - d/control: Align with upstream dependencies
  - d/p/fix-requirements.patch: Dropped no longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
111
111
    'dual_bridge': ['ipmitool', '-m', '0', '-b', '0', '-t', '0',
112
112
                    '-B', '0', '-T', '0', '-h']}
113
113
 
 
114
# Note(TheJulia): This string is hardcoded in ipmitool's lanplus driver
 
115
# and is substituted in return for the error code received from the IPMI
 
116
# controller.  As of 1.8.15, no internationalization support appears to
 
117
# be in ipmitool which means the string should always be returned in this
 
118
# form regardless of locale.
 
119
IPMITOOL_RETRYABLE_FAILURES = ['insufficient resources for session']
 
120
 
114
121
 
115
122
def _check_option_support(options):
116
123
    """Checks if the specific ipmitool options are supported on host.
335
342
            args.append(driver_info[name])
336
343
 
337
344
    # specify retry timing more precisely, if supported
 
345
    num_tries = max(
 
346
        (CONF.ipmi.retry_timeout // CONF.ipmi.min_command_interval), 1)
 
347
 
338
348
    if _is_option_supported('timing'):
339
 
        num_tries = max(
340
 
            (CONF.ipmi.retry_timeout // CONF.ipmi.min_command_interval), 1)
341
349
        args.append('-R')
342
350
        args.append(str(num_tries))
343
351
 
344
352
        args.append('-N')
345
353
        args.append(str(CONF.ipmi.min_command_interval))
346
354
 
347
 
    # 'ipmitool' command will prompt password if there is no '-f' option,
348
 
    # we set it to '\0' to write a password file to support empty password
349
 
    with _make_password_file(driver_info['password'] or '\0') as pw_file:
350
 
        args.append('-f')
351
 
        args.append(pw_file)
352
 
        args.extend(command.split(" "))
 
355
    end_time = (time.time() + CONF.ipmi.retry_timeout)
 
356
 
 
357
    while True:
 
358
        num_tries = num_tries - 1
353
359
        # NOTE(deva): ensure that no communications are sent to a BMC more
354
360
        #             often than once every min_command_interval seconds.
355
361
        time_till_next_poll = CONF.ipmi.min_command_interval - (
356
362
                time.time() - LAST_CMD_TIME.get(driver_info['address'], 0))
357
363
        if time_till_next_poll > 0:
358
364
            time.sleep(time_till_next_poll)
359
 
        try:
360
 
            out, err = utils.execute(*args)
361
 
        finally:
362
 
            LAST_CMD_TIME[driver_info['address']] = time.time()
363
 
        return out, err
 
365
        # Resetting the list that will be utilized so the password arguments
 
366
        # from any previous execution are preserved.
 
367
        cmd_args = args[:]
 
368
        # 'ipmitool' command will prompt password if there is no '-f'
 
369
        # option, we set it to '\0' to write a password file to support
 
370
        # empty password
 
371
        with _make_password_file(
 
372
                    driver_info['password'] or '\0'
 
373
                ) as pw_file:
 
374
            cmd_args.append('-f')
 
375
            cmd_args.append(pw_file)
 
376
            cmd_args.extend(command.split(" "))
 
377
            try:
 
378
                out, err = utils.execute(*cmd_args)
 
379
                return out, err
 
380
            except processutils.ProcessExecutionError as e:
 
381
                with excutils.save_and_reraise_exception() as ctxt:
 
382
                    err_list = [x for x in IPMITOOL_RETRYABLE_FAILURES
 
383
                                if x in e.message]
 
384
                    if ((time.time() > end_time) or
 
385
                        (num_tries == 0) or
 
386
                        not err_list):
 
387
                        LOG.error(_LE('IPMI Error while attempting '
 
388
                                  '"%(cmd)s" for node %(node)s. '
 
389
                                  'Error: %(error)s'),
 
390
                                  {
 
391
                                      'node': driver_info['uuid'],
 
392
                                      'cmd': e.cmd,
 
393
                                      'error': e
 
394
                                  })
 
395
                    else:
 
396
                        ctxt.reraise = False
 
397
                        LOG.warning(_LW('IPMI Error encountered, retrying '
 
398
                                    '"%(cmd)s" for node %(node)s. '
 
399
                                    'Error: %(error)s'),
 
400
                                    {
 
401
                                        'node': driver_info['uuid'],
 
402
                                        'cmd': e.cmd,
 
403
                                        'error': e
 
404
                                    })
 
405
            finally:
 
406
                LAST_CMD_TIME[driver_info['address']] = time.time()
364
407
 
365
408
 
366
409
def _sleep_time(iter):