[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH] adt-run: add --upgrade-to option for upgrade tests



---
 lib/adt_run_args.py |  3 +++
 runner/adt-run      | 43 ++++++++++++++++++++++++++++++++++---------
 runner/adt-run.1    | 21 +++++++++++++++++++++
 3 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/lib/adt_run_args.py b/lib/adt_run_args.py
index 90cba16..2505a97 100644
--- a/lib/adt_run_args.py
+++ b/lib/adt_run_args.py
@@ -254,6 +254,9 @@ details.'''
                          action='append', default=[],
                          help='Copy file or dir from host into testbed after '
                          'opening')
+    g_setup.add_argument('--upgrade-to', dest='upgrade_to', metavar='SUITE',
+                         default=None,
+                         help='Upgrades to SUITE after installing test dependencies.')
 
     # privileges
     g_priv = parser.add_argument_group('user/privilege handling options')
diff --git a/runner/adt-run b/runner/adt-run
index a97d1e0..83323ec 100755
--- a/runner/adt-run
+++ b/runner/adt-run
@@ -416,6 +416,26 @@ class Testbed:
 
         self.reset(deps_new)
         self.install_deps(deps_new, recommends)
+        if opts.upgrade_to:
+            self.upgrade_to(opts.upgrade_to)
+
+    def upgrade_to(self, suite):
+        adtlog.info('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ upgrade to %s' % suite)
+
+        install_lsb_release = '''apt-get install -y lsb-release'''
+        self.check_exec(['sh', '-c', install_lsb_release], kind='install')
+
+        orig_suite = self.check_exec(['sh', '-c', 'lsb_release -sc'], stdout=True).strip()
+        self.upgrade_from = orig_suite
+
+        add_sources = '''awk '/^deb / { if ($3 == "%s") { $3 = "%s"; print; } }' ''' \
+            '''/etc/apt/sources.list > /etc/apt/sources.list.d/%s.list''' % (orig_suite, suite, suite)
+        self.check_exec(['sh', '-ec', add_sources])
+
+        upgrade = '((apt-get update || (sleep 15; apt-get update)) && apt-get dist-upgrade -y -o Dpkg::Options::="--force-confnew") 2>&1'
+        self.check_exec(['sh', '-ec', upgrade], kind='install')
+
+        self.needs_reset()
 
     def needs_reset(self):
         # show what caused a reset
@@ -831,15 +851,20 @@ fi
 
         # create script to run test
         test_artifacts = '%s/%s-artifacts' % (self.scratch, test.name)
-        script = 'set -e; ' \
-                 'buildtree="%(t)s"; ' \
-                 'rm -rf "%(a)s"; mkdir -m 1777 -- "%(a)s"; ' \
-                 'export ADT_ARTIFACTS="%(a)s"; ' \
-                 'export ADTTMP=$(mktemp -d --tmpdir adttmp.XXXXXX); ' \
-                 'trap "rm -rf $ADTTMP" EXIT INT QUIT PIPE; '\
-                 'chmod 755 $ADTTMP; '\
-                 'cd "$buildtree"; '\
-                 % {'t': tree.tb, 'a': test_artifacts}
+        steps = [
+            'set -e; ',
+            'buildtree="%(t)s"; '
+            'rm -rf "%(a)s"; mkdir -m 1777 -- "%(a)s"; ',
+            'export ADT_ARTIFACTS="%(a)s"; ',
+            'export ADTTMP=$(mktemp -d --tmpdir adttmp.XXXXXX); ',
+            opts.upgrade_to and 'export ADT_UPGRADE_TO="%s"; ' % opts.upgrade_to or None,
+            opts.upgrade_to and 'export ADT_UPGRADE_FROM="%s"; ' % self.upgrade_from or None,
+            'trap "rm -rf $ADTTMP" EXIT INT QUIT PIPE; ',
+            'chmod 755 $ADTTMP; ',
+            'cd "$buildtree"; ',
+        ]
+        steps = [step for step in steps if step is not None]
+        script = ''.join(steps) % {'t': tree.tb, 'a': test_artifacts}
 
         if opts.user and 'rw-build-tree' in test.restrictions:
             script += 'chown -R %s "$buildtree"; ' % opts.user
diff --git a/runner/adt-run.1 b/runner/adt-run.1
index 4d8f5c9..e1edaef 100644
--- a/runner/adt-run.1
+++ b/runner/adt-run.1
@@ -236,6 +236,27 @@ before
 .B \-\-setup-commands
 thus you can use these files in the setup commands.
 
+.TP
+.BI \-\-upgrade\-to= SUITE
+Upgrades to
+.I SUITE
+.B after installing test dependencies, but before running tests.
+This is useful for doing upgrade tests, since your tests will run on the
+upgraded system. The testbed will be reset after each test. When the
+tests are executed, two environment variables will be set to describe
+the upgrade scenario:
+
+.B ADT_UPGRADE_FROM
+will contain the
+.I codename
+of the original distribution of the testbed, as reported by
+`lsb_release\ -sc`;
+
+.B ADT_UPGRADE_TO
+will contain
+.I SUITE
+(i.e. the distribution name that was passed in the command line).
+
 
 .SH USER/PRIVILEGE HANDLING OPTIONS
 
-- 
2.0.1




Reply to: