virtinst: ignore comments in keymap conf files

On a host system with keyboard configured to en-US, it was noticed
that virt-install created install XML with keymap='de'. The host
system did not have /etc/vconsole.conf, so /etc/sysconfig/keyboard
was the next file to check, which contained the following

KEYTABLE=""

Currently the parsing code does not ignore comments and incorrectly
parsed a 'de' keymap. Fix by ignoring any lines that start with '#'
after trimming whitespace.
This commit is contained in:
Jim Fehlig 2017-10-11 15:13:26 -06:00 committed by Cole Robinson
parent 09a53eb2a3
commit 9a9f9ecd2c
2 changed files with 4 additions and 1 deletions

View File

@ -32,5 +32,5 @@ class TestHostkeymap(unittest.TestCase):
self.assertEquals(
hostkeymap._sysconfig_keyboard(_open("sysconfig-comments.txt")),
"de-latin1-nodeadkeys")
"")

View File

@ -71,6 +71,9 @@ def _sysconfig_keyboard(f):
s = f.readline()
if s == "":
break
s = s.strip()
if s.startswith("#"):
continue
if (re.search("KEYMAP", s) is not None or
re.search("KEYTABLE", s) is not None or
(re.search("KEYBOARD", s) is not None and