Strip invalid characters from autoamtically made VG/LV names (#483571).
We make names from mount points and host names, both of which can contain
characters that are invalid to LVM. The dash is the most promiment case here.
Checks get run when the user enters these bad characters, but not when anaconda
made up the names automatically. So strip dashes out of the generated names
before feeding them to LVM.
---
autopart.py | 8 ++------
lvm.py | 11 +++++++++++
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/autopart.py b/autopart.py
index b1c7644..a3ed44d 100644
--- a/autopart.py
+++ b/autopart.py
@@ -24,6 +24,7 @@ import parted
import copy
import string, sys
import fsset
+import re
import lvm
import logging
from anaconda_log import logger, logFile
@@ -1672,12 +1673,7 @@ def autoCreateLVMPartitionRequests(autoreq):
if mntpt == '/':
lvtemplate = 'lv_root'
else:
- tmp = string.strip(mntpt)
- tmp = tmp.replace('/', '_')
-
- while tmp.startswith('_'):
- tmp = tmp[1:]
-
+ tmp = lvm.safeLvmName(mntpt)
lvtemplate = "lv_%s" % (tmp,)
else:
if ptype == fsset.fileSystemTypeGet("swap"):
diff --git a/lvm.py b/lvm.py
index 0e07a1f..520619f 100644
--- a/lvm.py
+++ b/lvm.py
@@ -24,6 +24,7 @@ import os,sys
import string
import math
import isys
+import re
from flags import flags
@@ -528,6 +529,14 @@ def getMaxLVSize(pe):
else:
return (16*1024*1024) #Max is 16TiB
+def safeLvmName(str):
+ tmp = string.strip(str)
+ tmp = tmp.replace("/", "_")
+ tmp = re.sub("[^0-9a-zA-Z._]", "", str)
+ tmp = tmp.lstrip("_")
+
+ return tmp
+
def createSuggestedVGName(partitions, network):
"""Given list of partition requests, come up with a reasonable VG name
@@ -540,8 +549,10 @@ def createSuggestedVGName(partitions, network):
if hn == 'localhost' or hn == 'localhost.localdomain':
vgtemplate = "VolGroup"
elif hn.find('.') != -1:
+ hn = safeLvmName(hn)
vgtemplate = "vg_%s" % (hn.split('.')[0].lower(),)
else:
+ hn = safeLvmName(hn)
vgtemplate = "vg_%s" % (hn.lower(),)
else:
vgtemplate = "VolGroup"
--
1.6.0.3
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
|