tests: Add a crosscheck for syslinux bootloader config generation

And actually wire this one up in admin-test.sh.
This commit is contained in:
Colin Walters 2015-05-27 20:08:44 -04:00
parent 0f31c4c4b2
commit 20bf7692a9
3 changed files with 130 additions and 5 deletions

View File

@ -75,6 +75,10 @@ insttest_DATA = tests/archive-test.sh \
tests/corrupt-repo-ref.js \
$(NULL)
insttest_SCRIPTS += \
tests/syslinux-entries-crosscheck.py \
$(NULL)
gpginsttestdir = $(pkglibexecdir)/installed-tests/gpghome
gpginsttest_DATA = tests/gpghome/secring.gpg \
tests/gpghome/trustdb.gpg \

View File

@ -20,17 +20,20 @@ set -e
echo "1..10"
function validate_bootloader() {
(cd ${test_tmpdir};
if test -f sysroot/boot/syslinux/syslinux.cfg; then
$(dirname $0)/syslinux-entries-crosscheck.py sysroot
fi)
}
${CMD_PREFIX} ostree --repo=sysroot/ostree/repo pull-local --remote=testos testos-repo testos/buildmaster/x86_64-runtime
rev=$(${CMD_PREFIX} ostree --repo=sysroot/ostree/repo rev-parse testos/buildmaster/x86_64-runtime)
export rev
# This initial deployment gets kicked off with some kernel arguments
${CMD_PREFIX} ostree admin --sysroot=sysroot deploy --karg=root=LABEL=MOO --karg=quiet --os=testos testos:testos/buildmaster/x86_64-runtime
${CMD_PREFIX} ostree admin --sysroot=sysroot status | tee status.txt
assert_file_has_content status.txt 'Version: 1.0.10'
if test -f sysroot/boot/loader/syslinux.cfg; then
assert_file_has_content sysroot/boot/loader/syslinux.cfg 'TestOS 42 1.0.10'
fi
validate_bootloader
echo "ok deploy command"
@ -66,6 +69,7 @@ assert_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'option
assert_file_has_content sysroot/ostree/deploy/testos/deploy/${rev}.1/etc/os-release 'NAME=TestOS'
assert_file_has_content sysroot/ostree/boot.0/testos/${bootcsum}/0/etc/os-release 'NAME=TestOS'
${CMD_PREFIX} ostree admin --sysroot=sysroot status
validate_bootloader
echo "ok second deploy"
@ -77,6 +81,7 @@ assert_not_has_dir sysroot/boot/loader.1
assert_has_dir sysroot/ostree/boot.0.0
assert_not_has_dir sysroot/ostree/boot.0.1
${CMD_PREFIX} ostree admin --sysroot=sysroot status
validate_bootloader
echo "ok third deploy (swap)"
@ -90,6 +95,7 @@ assert_has_file sysroot/boot/loader/entries/ostree-otheros-0.conf
assert_file_has_content sysroot/ostree/deploy/testos/deploy/${rev}.1/etc/os-release 'NAME=TestOS'
assert_file_has_content sysroot/ostree/deploy/otheros/deploy/${rev}.0/etc/os-release 'NAME=TestOS'
${CMD_PREFIX} ostree admin --sysroot=sysroot status
validate_bootloader
echo "ok independent deploy"
@ -101,6 +107,7 @@ assert_file_has_content sysroot/ostree/deploy/testos/deploy/${rev}.2/etc/os-rele
assert_has_file sysroot/boot/loader/entries/ostree-testos-2.conf
assert_file_has_content sysroot/ostree/deploy/testos/deploy/${rev}.3/etc/os-release 'NAME=TestOS'
${CMD_PREFIX} ostree admin --sysroot=sysroot status
validate_bootloader
echo "ok fourth deploy (retain)"
@ -116,6 +123,7 @@ assert_file_has_content sysroot/ostree/deploy/testos/deploy/${rev}.4/etc/os-rele
assert_file_has_content sysroot/ostree/deploy/testos/deploy/${rev}.4/etc/a-new-config-file 'a new local config file'
assert_not_has_file sysroot/ostree/deploy/testos/deploy/${rev}.4/etc/aconfigfile
${CMD_PREFIX} ostree admin --sysroot=sysroot status
validate_bootloader
echo "ok deploy with modified /etc"
@ -133,6 +141,7 @@ assert_file_has_content sysroot/ostree/deploy/testos/deploy/${newrev}.0/etc/new-
# And persist /etc changes from before
assert_not_has_file sysroot/ostree/deploy/testos/deploy/${rev}.3/etc/aconfigfile
${CMD_PREFIX} ostree admin --sysroot=sysroot status
validate_bootloader
echo "ok upgrade bare"
@ -145,6 +154,7 @@ newrev=$(${CMD_PREFIX} ostree --repo=sysroot/ostree/repo rev-parse testos/buildm
assert_not_streq ${rev} ${newrev}
assert_file_has_content sysroot/ostree/deploy/testos/deploy/${newrev}.0/etc/os-release 'NAME=TestOS'
${CMD_PREFIX} ostree admin --sysroot=sysroot status
validate_bootloader
echo "ok upgrade"
@ -155,6 +165,7 @@ assert_file_has_content "${originfile}" "bacon:testos/buildmaster/x86_64-runtime
${CMD_PREFIX} ostree --repo=sysroot/ostree/repo remote list -u > remotes.txt
assert_file_has_content remotes.txt 'bacon.*http://tasty.com'
cp saved-origin ${originfile}
validate_bootloader
echo "ok set-origin"
@ -167,6 +178,7 @@ assert_not_has_dir sysroot/ostree/deploy/testos/deploy/${rev}.0
${CMD_PREFIX} ostree admin --sysroot=sysroot undeploy 0
assert_not_has_dir sysroot/ostree/deploy/testos/deploy/${newrev}.0
${CMD_PREFIX} ostree admin --sysroot=sysroot status
validate_bootloader
echo "ok undeploy"
@ -178,6 +190,7 @@ echo "ok deploy with unknown OS"
${CMD_PREFIX} ostree admin --sysroot=sysroot deploy --os=testos --karg-append=console=/dev/foo --karg-append=console=/dev/bar testos:testos/buildmaster/x86_64-runtime
${CMD_PREFIX} ostree admin --sysroot=sysroot deploy --os=testos testos:testos/buildmaster/x86_64-runtime
assert_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'console=/dev/foo.*console=/dev/bar'
validate_bootloader
echo "ok deploy with multiple kernel args"
@ -187,5 +200,6 @@ ${CMD_PREFIX} ostree admin --sysroot=sysroot upgrade --os=testos
newrev=$(${CMD_PREFIX} ostree --repo=sysroot/ostree/repo rev-parse testos/buildmaster/x86_64-runtime)
assert_not_streq ${origrev} ${newrev}
assert_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'console=/dev/foo.*console=/dev/bar'
validate_bootloader
echo "ok upgrade with multiple kernel args"

View File

@ -0,0 +1,107 @@
#!/usr/bin/python
#
# Copyright (C) 2015 Red Hat
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
import os
import sys
if len(sys.argv) == 1:
sysroot = ''
else:
sysroot = sys.argv[1]
loaderpath = sysroot + '/boot/loader/entries'
syslinuxpath = sysroot + '/boot/syslinux/syslinux.cfg'
def fatal(msg):
sys.stderr.write(msg)
sys.stderr.write('\n')
sys.exit(1)
def compare_entries_descending(a, b):
return int(b['version']) - int(a['version'])
def get_ostree_option(optionstring):
for o in optionstring.split():
if o.startswith('ostree='):
return o[8:]
raise ValueError('ostree= not found')
entries = []
syslinux_entries = []
# Parse loader configs
for fname in os.listdir(loaderpath):
path = os.path.join(loaderpath, fname)
with open(path) as f:
entry = {}
for line in f:
line = line.strip()
if (line == '' or line.startswith('#')):
continue
s = line.find(' ')
assert s > 0
k = line[0:s]
v = line[s+1:]
entry[k] = v
entries.append(entry)
entries.sort(compare_entries_descending)
# Parse SYSLINUX config
with open(syslinuxpath) as f:
in_ostree_config = False
syslinux_entry = None
syslinux_default = None
for line in f:
line = line.strip()
if line.startswith('DEFAULT '):
if syslinux_entry is not None:
syslinux_default = line.split(' ', 1)[1]
elif line.startswith('LABEL '):
if syslinux_entry is not None:
syslinux_entries.append(syslinux_entry)
syslinux_entry = {}
syslinux_entry['title'] = line.split(' ', 1)[1]
elif line.startswith('KERNEL '):
syslinux_entry['linux'] = line.split(' ', 1)[1]
elif line.startswith('INITRD '):
syslinux_entry['initrd'] = line.split(' ', 1)[1]
elif line.startswith('APPEND '):
syslinux_entry['options'] = line.split(' ', 1)[1]
if syslinux_entry is not None:
syslinux_entries.append(syslinux_entry)
if len(entries) != len(syslinux_entries):
fatal("Found {0} loader entries, but {1} SYSLINUX entries\n".format(len(entries), len(syslinux_entries)))
def assert_matches_key(a, b, key):
aval = a[key]
bval = b[key]
if aval != bval:
fatal("Mismatch on {0}: {1} != {2}".format(key, aval, bval))
for i,(entry,syslinuxentry) in enumerate(zip(entries, syslinux_entries)):
assert_matches_key(entry, syslinuxentry, 'linux')
assert_matches_key(entry, syslinuxentry, 'initrd')
entry_ostree = get_ostree_option(entry['options'])
syslinux_ostree = get_ostree_option(syslinuxentry['options'])
if entry_ostree != syslinux_ostree:
fatal("Mismatch on ostree option: {0} != {1}".format(entry_ostree, syslinux_ostree))
sys.stdout.write('SYSLINUX configuration validated\n')
sys.exit(0)