Skip to content
Snippets Groups Projects
Commit 96c7a5b0 authored by Iustin Pop's avatar Iustin Pop
Browse files

Throw specific error when ':' exists in PV names


While ':' is not actually a supporte character in PV names (it has a
special meaning for commands like lvcreate), we should throw specific
errors for this case instead of generic “Can't create LV”.

This patch does two things:

- modifies the separator used when listing PVs to be '|' such that we
  can actually parse ':' as part of PV names
- check if any of the discovered PVs have ':' in their name when
  creating LVs, and if so throw a specific error

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 6bcb1446
No related branches found
No related tags found
No related merge requests found
......@@ -362,6 +362,9 @@ class LogicalVolume(BlockDev):
pvs_info.reverse()
pvlist = [ pv[1] for pv in pvs_info ]
if utils.any(pvlist, lambda v: ":" in v):
_ThrowError("Some of your PVs have invalid character ':'"
" in their name")
free_size = sum([ pv[0] for pv in pvs_info ])
current_pvs = len(pvlist)
stripes = min(current_pvs, constants.LVM_STRIPECOUNT)
......@@ -395,9 +398,10 @@ class LogicalVolume(BlockDev):
@return: list of tuples (free_space, name) with free_space in mebibytes
"""
sep = "|"
command = ["pvs", "--noheadings", "--nosuffix", "--units=m",
"-opv_name,vg_name,pv_free,pv_attr", "--unbuffered",
"--separator=:"]
"--separator=%s" % sep ]
result = utils.RunCmd(command)
if result.failed:
logging.error("Can't get the PV information: %s - %s",
......@@ -405,7 +409,7 @@ class LogicalVolume(BlockDev):
return None
data = []
for line in result.stdout.splitlines():
fields = line.strip().split(':')
fields = line.strip().split(sep)
if len(fields) != 4:
logging.error("Can't parse pvs output: line '%s'", line)
return None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment