parent
3e5fb84772
commit
e562fd06a1
340
PR116.patch
340
PR116.patch
@ -1,154 +1,23 @@
|
|||||||
From 0f31c4c4b2cc5c475c26cc768f6d2c0812a7e3eb Mon Sep 17 00:00:00 2001
|
From 2a4952da6c5b9739a56201662d05841185420484 Mon Sep 17 00:00:00 2001
|
||||||
From: Colin Walters <walters@verbum.org>
|
From: rpm-build <rpm-build>
|
||||||
Date: Tue, 26 May 2015 22:28:29 -0400
|
Date: Sat, 30 May 2015 11:19:53 -0400
|
||||||
Subject: [PATCH 1/2] tests: Add a test script to cross-check loader config vs
|
Subject: [PATCH] Rebase PR116
|
||||||
GRUB2
|
|
||||||
|
|
||||||
One can run this on a machine to validate things. I'd like to
|
|
||||||
get this plugged into the actual OSTree tests as soon as we can
|
|
||||||
figure out how to sanely run grub2-generate as non-root in
|
|
||||||
our test suite.
|
|
||||||
|
|
||||||
Alternatively, this script can easily be run on a real install.
|
|
||||||
---
|
|
||||||
tests/grub2-entries-crosscheck.py | 105 ++++++++++++++++++++++++++++++++++++++
|
|
||||||
1 file changed, 105 insertions(+)
|
|
||||||
create mode 100644 tests/grub2-entries-crosscheck.py
|
|
||||||
|
|
||||||
diff --git a/tests/grub2-entries-crosscheck.py b/tests/grub2-entries-crosscheck.py
|
|
||||||
new file mode 100644
|
|
||||||
index 0000000..d68394d
|
|
||||||
--- /dev/null
|
|
||||||
+++ b/tests/grub2-entries-crosscheck.py
|
|
||||||
@@ -0,0 +1,105 @@
|
|
||||||
+#!/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:
|
|
||||||
+ loaderpath = '/boot/loader/entries'
|
|
||||||
+ grub2path = '/boot/grub2/grub.cfg'
|
|
||||||
+else:
|
|
||||||
+ loaderpath = sys.argv[1]
|
|
||||||
+ grub2path = sys.argv[2]
|
|
||||||
+
|
|
||||||
+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 = []
|
|
||||||
+grub2_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 GRUB2 config
|
|
||||||
+with open(grub2path) as f:
|
|
||||||
+ in_ostree_config = False
|
|
||||||
+ grub2_entry = None
|
|
||||||
+ for line in f:
|
|
||||||
+ if line.startswith('### BEGIN /etc/grub.d/15_ostree ###'):
|
|
||||||
+ in_ostree_config = True
|
|
||||||
+ elif line.startswith('### END /etc/grub.d/15_ostree ###'):
|
|
||||||
+ in_ostree_config = False
|
|
||||||
+ if grub2_entry is not None:
|
|
||||||
+ grub2_entries.append(grub2_entry)
|
|
||||||
+ elif in_ostree_config:
|
|
||||||
+ if line.startswith('menuentry '):
|
|
||||||
+ if grub2_entry is not None:
|
|
||||||
+ grub2_entries.append(grub2_entry)
|
|
||||||
+ grub2_entry = {}
|
|
||||||
+ elif line.startswith('linux'):
|
|
||||||
+ parts = line.split()
|
|
||||||
+ grub2_entry['linux'] = parts[1]
|
|
||||||
+ grub2_entry['options'] = ' '.join(parts[2:])
|
|
||||||
+ elif line.startswith('initrd'):
|
|
||||||
+ grub2_entry['initrd'] = line.split()[1]
|
|
||||||
+
|
|
||||||
+if len(entries) != len(grub2_entries):
|
|
||||||
+ fatal("Found {0} loader entries, but {1} GRUB2 entries\n".format(len(entries), len(grub2_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,grub2entry) in enumerate(zip(entries, grub2_entries)):
|
|
||||||
+ assert_matches_key(entry, grub2entry, 'linux')
|
|
||||||
+ assert_matches_key(entry, grub2entry, 'initrd')
|
|
||||||
+ entry_ostree = get_ostree_option(entry['options'])
|
|
||||||
+ grub2_ostree = get_ostree_option(grub2entry['options'])
|
|
||||||
+ if entry_ostree != grub2_ostree:
|
|
||||||
+ fatal("Mismatch on ostree option: {0} != {1}".format(entry_ostree, grub2_ostree))
|
|
||||||
+
|
|
||||||
+sys.stdout.write('GRUB2 configuration validated\n')
|
|
||||||
+sys.exit(0)
|
|
||||||
--
|
|
||||||
1.8.3.1
|
|
||||||
|
|
||||||
|
|
||||||
From 20bf7692a9a1a4777ebf9bc423945afcd9b2bae5 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Colin Walters <walters@verbum.org>
|
|
||||||
Date: Wed, 27 May 2015 20:08:44 -0400
|
|
||||||
Subject: [PATCH 2/2] tests: Add a crosscheck for syslinux bootloader config
|
|
||||||
generation
|
|
||||||
|
|
||||||
And actually wire this one up in admin-test.sh.
|
|
||||||
---
|
---
|
||||||
Makefile-tests.am | 4 ++
|
Makefile-tests.am | 4 ++
|
||||||
|
src/libostree/ostree-sysroot.c | 47 ++++++++++-----
|
||||||
tests/admin-test.sh | 24 ++++++--
|
tests/admin-test.sh | 24 ++++++--
|
||||||
|
tests/grub2-entries-crosscheck.py | 105 ++++++++++++++++++++++++++++++++++
|
||||||
tests/syslinux-entries-crosscheck.py | 107 +++++++++++++++++++++++++++++++++++
|
tests/syslinux-entries-crosscheck.py | 107 +++++++++++++++++++++++++++++++++++
|
||||||
3 files changed, 130 insertions(+), 5 deletions(-)
|
5 files changed, 269 insertions(+), 18 deletions(-)
|
||||||
create mode 100755 tests/syslinux-entries-crosscheck.py
|
create mode 100644 tests/grub2-entries-crosscheck.py
|
||||||
|
create mode 100644 tests/syslinux-entries-crosscheck.py
|
||||||
|
|
||||||
diff --git a/Makefile-tests.am b/Makefile-tests.am
|
diff --git a/Makefile-tests.am b/Makefile-tests.am
|
||||||
index 7f4437c..955cef1 100644
|
index 46bf499..06db55b 100644
|
||||||
--- a/Makefile-tests.am
|
--- a/Makefile-tests.am
|
||||||
+++ b/Makefile-tests.am
|
+++ b/Makefile-tests.am
|
||||||
@@ -75,6 +75,10 @@ insttest_DATA = tests/archive-test.sh \
|
@@ -72,6 +72,10 @@ insttest_DATA = tests/archive-test.sh \
|
||||||
tests/corrupt-repo-ref.js \
|
tests/corrupt-repo-ref.js \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
@ -158,7 +27,79 @@ index 7f4437c..955cef1 100644
|
|||||||
+
|
+
|
||||||
gpginsttestdir = $(pkglibexecdir)/installed-tests/gpghome
|
gpginsttestdir = $(pkglibexecdir)/installed-tests/gpghome
|
||||||
gpginsttest_DATA = tests/gpghome/secring.gpg \
|
gpginsttest_DATA = tests/gpghome/secring.gpg \
|
||||||
tests/gpghome/trustdb.gpg \
|
tests/gpghome/trustdb.gpg
|
||||||
|
diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c
|
||||||
|
index 6255803..b15ddf5 100644
|
||||||
|
--- a/src/libostree/ostree-sysroot.c
|
||||||
|
+++ b/src/libostree/ostree-sysroot.c
|
||||||
|
@@ -355,6 +355,35 @@ _ostree_sysroot_read_current_subbootversion (OstreeSysroot *self,
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
+static gint
|
||||||
|
+compare_boot_loader_configs (OstreeBootconfigParser *a,
|
||||||
|
+ OstreeBootconfigParser *b)
|
||||||
|
+{
|
||||||
|
+ const char *a_version = ostree_bootconfig_parser_get (a, "version");
|
||||||
|
+ const char *b_version = ostree_bootconfig_parser_get (b, "version");
|
||||||
|
+
|
||||||
|
+ if (a_version && b_version)
|
||||||
|
+ {
|
||||||
|
+ int r = strverscmp (a_version, b_version);
|
||||||
|
+ /* Reverse */
|
||||||
|
+ return -r;
|
||||||
|
+ }
|
||||||
|
+ else if (a_version)
|
||||||
|
+ return -1;
|
||||||
|
+ else
|
||||||
|
+ return 1;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static int
|
||||||
|
+compare_loader_configs_for_sorting (gconstpointer a_pp,
|
||||||
|
+ gconstpointer b_pp)
|
||||||
|
+{
|
||||||
|
+ OstreeBootconfigParser *a = *((OstreeBootconfigParser**)a_pp);
|
||||||
|
+ OstreeBootconfigParser *b = *((OstreeBootconfigParser**)b_pp);
|
||||||
|
+
|
||||||
|
+ return compare_boot_loader_configs (a, b);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
gboolean
|
||||||
|
_ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self,
|
||||||
|
int bootversion,
|
||||||
|
@@ -421,6 +450,9 @@ _ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+ /* Callers expect us to give them a sorted array */
|
||||||
|
+ g_ptr_array_sort (ret_loader_configs, compare_loader_configs_for_sorting);
|
||||||
|
+
|
||||||
|
done:
|
||||||
|
gs_transfer_out_value (out_loader_configs, &ret_loader_configs);
|
||||||
|
ret = TRUE;
|
||||||
|
@@ -700,19 +732,8 @@ compare_deployments_by_boot_loader_version_reversed (gconstpointer a_pp,
|
||||||
|
OstreeDeployment *b = *((OstreeDeployment**)b_pp);
|
||||||
|
OstreeBootconfigParser *a_bootconfig = ostree_deployment_get_bootconfig (a);
|
||||||
|
OstreeBootconfigParser *b_bootconfig = ostree_deployment_get_bootconfig (b);
|
||||||
|
- const char *a_version = ostree_bootconfig_parser_get (a_bootconfig, "version");
|
||||||
|
- const char *b_version = ostree_bootconfig_parser_get (b_bootconfig, "version");
|
||||||
|
-
|
||||||
|
- if (a_version && b_version)
|
||||||
|
- {
|
||||||
|
- int r = strverscmp (a_version, b_version);
|
||||||
|
- /* Reverse */
|
||||||
|
- return -r;
|
||||||
|
- }
|
||||||
|
- else if (a_version)
|
||||||
|
- return -1;
|
||||||
|
- else
|
||||||
|
- return 1;
|
||||||
|
+
|
||||||
|
+ return compare_boot_loader_configs (a_bootconfig, b_bootconfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
diff --git a/tests/admin-test.sh b/tests/admin-test.sh
|
diff --git a/tests/admin-test.sh b/tests/admin-test.sh
|
||||||
index 4278e01..f7fbb92 100755
|
index 4278e01..f7fbb92 100755
|
||||||
--- a/tests/admin-test.sh
|
--- a/tests/admin-test.sh
|
||||||
@ -276,8 +217,119 @@ index 4278e01..f7fbb92 100755
|
|||||||
+validate_bootloader
|
+validate_bootloader
|
||||||
|
|
||||||
echo "ok upgrade with multiple kernel args"
|
echo "ok upgrade with multiple kernel args"
|
||||||
|
diff --git a/tests/grub2-entries-crosscheck.py b/tests/grub2-entries-crosscheck.py
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..d68394d
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/tests/grub2-entries-crosscheck.py
|
||||||
|
@@ -0,0 +1,105 @@
|
||||||
|
+#!/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:
|
||||||
|
+ loaderpath = '/boot/loader/entries'
|
||||||
|
+ grub2path = '/boot/grub2/grub.cfg'
|
||||||
|
+else:
|
||||||
|
+ loaderpath = sys.argv[1]
|
||||||
|
+ grub2path = sys.argv[2]
|
||||||
|
+
|
||||||
|
+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 = []
|
||||||
|
+grub2_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 GRUB2 config
|
||||||
|
+with open(grub2path) as f:
|
||||||
|
+ in_ostree_config = False
|
||||||
|
+ grub2_entry = None
|
||||||
|
+ for line in f:
|
||||||
|
+ if line.startswith('### BEGIN /etc/grub.d/15_ostree ###'):
|
||||||
|
+ in_ostree_config = True
|
||||||
|
+ elif line.startswith('### END /etc/grub.d/15_ostree ###'):
|
||||||
|
+ in_ostree_config = False
|
||||||
|
+ if grub2_entry is not None:
|
||||||
|
+ grub2_entries.append(grub2_entry)
|
||||||
|
+ elif in_ostree_config:
|
||||||
|
+ if line.startswith('menuentry '):
|
||||||
|
+ if grub2_entry is not None:
|
||||||
|
+ grub2_entries.append(grub2_entry)
|
||||||
|
+ grub2_entry = {}
|
||||||
|
+ elif line.startswith('linux'):
|
||||||
|
+ parts = line.split()
|
||||||
|
+ grub2_entry['linux'] = parts[1]
|
||||||
|
+ grub2_entry['options'] = ' '.join(parts[2:])
|
||||||
|
+ elif line.startswith('initrd'):
|
||||||
|
+ grub2_entry['initrd'] = line.split()[1]
|
||||||
|
+
|
||||||
|
+if len(entries) != len(grub2_entries):
|
||||||
|
+ fatal("Found {0} loader entries, but {1} GRUB2 entries\n".format(len(entries), len(grub2_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,grub2entry) in enumerate(zip(entries, grub2_entries)):
|
||||||
|
+ assert_matches_key(entry, grub2entry, 'linux')
|
||||||
|
+ assert_matches_key(entry, grub2entry, 'initrd')
|
||||||
|
+ entry_ostree = get_ostree_option(entry['options'])
|
||||||
|
+ grub2_ostree = get_ostree_option(grub2entry['options'])
|
||||||
|
+ if entry_ostree != grub2_ostree:
|
||||||
|
+ fatal("Mismatch on ostree option: {0} != {1}".format(entry_ostree, grub2_ostree))
|
||||||
|
+
|
||||||
|
+sys.stdout.write('GRUB2 configuration validated\n')
|
||||||
|
+sys.exit(0)
|
||||||
diff --git a/tests/syslinux-entries-crosscheck.py b/tests/syslinux-entries-crosscheck.py
|
diff --git a/tests/syslinux-entries-crosscheck.py b/tests/syslinux-entries-crosscheck.py
|
||||||
new file mode 100755
|
new file mode 100644
|
||||||
index 0000000..8b58ed4
|
index 0000000..8b58ed4
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/tests/syslinux-entries-crosscheck.py
|
+++ b/tests/syslinux-entries-crosscheck.py
|
||||||
|
Loading…
Reference in New Issue
Block a user