Revision 048eeb2b lib/storage.py
b/lib/storage.py | ||
---|---|---|
1 | 1 |
# |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2009, 2011 Google Inc. |
|
4 |
# Copyright (C) 2009, 2011, 2012 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
406 | 406 |
|
407 | 407 |
""" |
408 | 408 |
LIST_COMMAND = "vgs" |
409 |
VGREDUCE_COMMAND = "vgreduce" |
|
409 | 410 |
|
410 | 411 |
# Make sure to update constants.VALID_STORAGE_FIELDS when changing field |
411 | 412 |
# definitions. |
... | ... | |
418 | 419 |
(constants.SF_ALLOCATABLE, [], True), |
419 | 420 |
] |
420 | 421 |
|
421 |
def _RemoveMissing(self, name): |
|
422 |
def _RemoveMissing(self, name, _runcmd_fn=utils.RunCmd):
|
|
422 | 423 |
"""Runs "vgreduce --removemissing" on a volume group. |
423 | 424 |
|
424 | 425 |
@type name: string |
... | ... | |
428 | 429 |
# Ignoring vgreduce exit code. Older versions exit with an error even tough |
429 | 430 |
# the VG is already consistent. This was fixed in later versions, but we |
430 | 431 |
# cannot depend on it. |
431 |
result = utils.RunCmd(["vgreduce", "--removemissing", name])
|
|
432 |
result = _runcmd_fn([self.VGREDUCE_COMMAND, "--removemissing", name])
|
|
432 | 433 |
|
433 | 434 |
# Keep output in case something went wrong |
434 | 435 |
vgreduce_output = result.output |
435 | 436 |
|
436 |
result = utils.RunCmd(["vgs", "--noheadings", "--nosuffix", name]) |
|
437 |
if result.failed: |
|
437 |
# work around newer LVM version |
|
438 |
if ("Wrote out consistent volume group" not in vgreduce_output or |
|
439 |
"vgreduce --removemissing --force" in vgreduce_output): |
|
440 |
# we need to re-run with --force |
|
441 |
result = _runcmd_fn([self.VGREDUCE_COMMAND, "--removemissing", |
|
442 |
"--force", name]) |
|
443 |
vgreduce_output += "\n" + result.output |
|
444 |
|
|
445 |
result = _runcmd_fn([self.LIST_COMMAND, "--noheadings", |
|
446 |
"--nosuffix", name]) |
|
447 |
# we also need to check the output |
|
448 |
if result.failed or "Couldn't find device with uuid" in result.output: |
|
438 | 449 |
raise errors.StorageError(("Volume group '%s' still not consistent," |
439 | 450 |
" 'vgreduce' output: %r," |
440 | 451 |
" 'vgs' output: %r") % |
Also available in: Unified diff