From e2df83dc44ad9ea356932409f2eb73ab9cc9f664 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 23 Jan 2007 15:38:01 +0000 Subject: [PATCH] Update documentation for actual implementation; implement new "reset" command; a few minor fixes --- doc/README.virtualisation-server | 34 +++++++++++++++++++++----------- runner/adt-run | 20 +++++++++---------- virt-subproc/VirtSubproc.py | 16 +++++---------- virt-subproc/adt-virt-chroot | 4 ---- virt-subproc/adt-virt-xenlvm | 29 +++++++++++++++------------ 5 files changed, 53 insertions(+), 50 deletions(-) diff --git a/doc/README.virtualisation-server b/doc/README.virtualisation-server index 25cfdfa..ed2002a 100644 --- a/doc/README.virtualisation-server +++ b/doc/README.virtualisation-server @@ -42,14 +42,26 @@ Protocol where the words after ok are features that not all regimes support. Valid in all states. - Currently defined features: + Currently defined capabilities: - + revert: the testbed will actually revert when it is closed. - If this feature is not mentioned then changes to the testbed - are persistent (so destructive tests should not be performed). + + revert + The testbed will actually revert when it is closed. If this + feature is not mentioned then changes to the testbed are + persistent (so destructive tests should not be performed). - + changed-files: the regime will provide a changed-files file - (see below). + + root-on-testbed + Commands specified by `execute' will be run as root on the + testbed, and copyup/copydown will have full access to the + filesystem. Unless this capability is advertised, root access + is not (or may not be) available. + + + suggested-normal-user= + The caller is advised that would be a good user to + use for running tests (and doing other operations) when root + is not required. The advertised account will exist on the + testbed already. Several suggested-normal-user= capabilities + (with distinct s) may be advertised in which case + more than one such user is available. * Command @@ -64,12 +76,12 @@ Protocol * Command - stop + reset - Stops the testbed. Replaces local-pathname (on the host) with a - directory containing a representation of the changes to the - testbed's filesystem; these changes are undone (if `revert' was - advertised). Then reverts the testbed. State: Open to Closed. + Restores the testbed, undoing all of the changes made so far. + State: Open, remains Open. Only available if the `revert' + capability is advertised. If possible, the testbed's set of running + processes will also be restored to the initial state. * Command diff --git a/runner/adt-run b/runner/adt-run index ad816b2..11ff607 100755 --- a/runner/adt-run +++ b/runner/adt-run @@ -412,29 +412,25 @@ def parse_args(): opts.actions.append(Action(kind, af, arghandling, what)) def finalise_options(): - global opts, testbed + global opts, tb - if opts.user is None and 'root-on-testbed' not in caps: + if opts.user is None and 'root-on-testbed' not in tb.caps: opts.user = '' if opts.user is None: su = 'suggested-normal-user=' ul = [ e[length(su):] - for e in caps + for e in tb.caps if e.startswith(su) ] - if len(ul) > 1: - print >>sys.stderr, "warning: virtualisation" - " system offers several suggested-normal-user" - " values: "+('/'.join(ul))+", using "+ul[0] if ul: opts.user = ul[0] else: opts.user = '' if opts.user: - if 'root-on-testbed' not in caps: + if 'root-on-testbed' not in tb.caps: print >>sys.stderr, "warning: virtualisation" " system does not offer root on testbed," " but --user option specified: failure likely" @@ -445,7 +441,7 @@ def finalise_options(): if opts.gainroot is None: opts.gainroot = '' if opts.user or - 'root-on-testbed' not in testbed.caps: + 'root-on-testbed' not in tb.caps: opts.gainroot = 'fakeroot' if opts.gnupghome.startswith('~/'): @@ -494,7 +490,7 @@ class Testbed: if tb.sp is None: return tb.command('close') def prepare(tb): - if tb.modified and 'reset' in caps: + if tb.modified and 'reset' in tb.caps: tb.command('reset') tb.blamed = [] tb.modified = False @@ -603,7 +599,7 @@ class Restriction: class Restriction_rw_tests_tree(Restriction): pass class Restriction_breaks_testbed(Restriction): - if 'reset' not in caps: + if 'reset' not in tb.caps: raise Unsupported(f.lno, 'Test breaks testbed but testbed cannot reset') @@ -1014,6 +1010,8 @@ def build_source(act): def process_actions(): global binaries + + tb.open() binaries = Binaries() b.reset() diff --git a/virt-subproc/VirtSubproc.py b/virt-subproc/VirtSubproc.py index 833cb5d..0fc61b5 100644 --- a/virt-subproc/VirtSubproc.py +++ b/virt-subproc/VirtSubproc.py @@ -96,18 +96,12 @@ def cmd_open(c, ce): downtmp = caller.hook_open() return [downtmp] -def cmd_close(c, ce): - global downtmp +def cmd_reset(c, ce): cmdnumargs(c, ce) - if not downtmp: bomb("`close' when not open") - cleanup() - -def cmd_stop(c, ce): - global downtmp - cmdnumargs(c, ce, 1) - if not downtmp: bomb("`stop' when not open") - caller.hook_stop() - cleanup() + if not downtmp: bomb("`reset' when not open") + if not 'revert' in caller.hook_capabilities(): + bomb("`reset' when `revert' not advertised") + caller.hook_reset() def down_python_script(gobody, functions=''): # Many things are made much harder by the inability of diff --git a/virt-subproc/adt-virt-chroot b/virt-subproc/adt-virt-chroot index ffcc39b..4ec079c 100755 --- a/virt-subproc/adt-virt-chroot +++ b/virt-subproc/adt-virt-chroot @@ -72,10 +72,6 @@ def hook_open(): downtmp = vsp.execute('mktemp -t -d', downp=True, outp=True) return downtmp -def hook_stop(): - vsp.execute('rm -rf --', c[1:2]) - os.mkdir(c[1]) - def hook_cleanup(): vsp.execute('rm -rf --', [downtmp], downp=True) diff --git a/virt-subproc/adt-virt-xenlvm b/virt-subproc/adt-virt-xenlvm index 870afb1..5cda2aa 100755 --- a/virt-subproc/adt-virt-xenlvm +++ b/virt-subproc/adt-virt-xenlvm @@ -35,6 +35,7 @@ sys.path.insert(1, our_base+'/python') import VirtSubproc as vsp witholder = None +downtmp = '/root/adt-downtmp' def parse_args(): global debuglevel, xlargs, gain_root @@ -54,8 +55,8 @@ def parse_args(): else: gain_root = opts.gain_root.split() vsp.down = gain_root + ['adt-xenlvm-on-testbed'] + xlargs + ['--'] -def hook_open(): - hook_cleanup() +def do_open(): + assert(withholder is None) withholder = subprocess.Popen( gain_root + ['adt-xenlvm-with-testbed'] + xlargs + ['--','sh','-ec','echo y; exec cat'], @@ -70,25 +71,27 @@ def hook_open(): if l != "y\n": bomb("with-testbed sh gave wrong output `%s', not `l'" % l.rstrip("\n")) - downtmp = '/root/adt-downtmp' - vsp.execute('mkdir %s' % downtmp, downp=True) - return downtmp + vsp.execute('mkdir %s' % downtmp, downp=True) -def hook_stop(): +def do_close(): withholder.stdin.close() withholder.stdout.close() rc = withholder.wait() withholder = None - if rc: bomb("with-testbed failed at shutdown, code %d" % rc) + if rc: bomb("with-testbed failed when closing/resetting, code %d" % rc) + +def hook_open(): + hook_cleanup() + do_open() + return downtmp + +def hook_reset(): + do_close() + do_open() def hook_cleanup(): if withholder is not None: - withholder.stdin.close() - withholder.stdout.close() - rc = withholder.wait() - withholder = None - if rc: print >>sys.stderr, ( - "with-testbed failed during cleanup, code %d" % rc) + do_close() def hook_capabilities(): return ('revert','root-on-testbed','suggest-normal-user=adtxenu') -- 2.30.2