summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-05-06 13:03:09 +0300
committerLars Wirzenius <liw@liw.fi>2023-05-06 13:03:09 +0300
commitdbc62aebb37df18d1958e342afbc07c8beac3e98 (patch)
treec9085c3e11580cc5f587abadd2f3d9e94404da2d
parentc4a2d56fd712c29665043d7700c21a8bbadd934c (diff)
downloadvmdb2-dbc62aebb37df18d1958e342afbc07c8beac3e98.tar.gz
fix: --version option
Sponsored-by: author
-rw-r--r--vmdb/app.py8
-rw-r--r--vmdb2.md19
-rw-r--r--vmdb2.py38
-rw-r--r--vmdb2.subplot2
-rw-r--r--vmdb2.yaml9
5 files changed, 33 insertions, 43 deletions
diff --git a/vmdb/app.py b/vmdb/app.py
index 1fffe71..ef92548 100644
--- a/vmdb/app.py
+++ b/vmdb/app.py
@@ -34,9 +34,7 @@ class Vmdb2:
tvars = self.template_vars_from_args(args)
cmd = None
- if args.version:
- cmd = VersionCommand(self._version)
- elif args.image or args.output:
+ if args.image or args.output:
if args.image:
cmd = ReuseImageCommand(args.image, args.specfile, args.rootfs_tarball)
else:
@@ -59,7 +57,7 @@ class Vmdb2:
def parse_command_line(self):
p = argparse.ArgumentParser(
- description="build disk images with Debian installed"
+ prog="vmdb2", description="build disk images with Debian installed"
)
p.add_argument("--image", metavar="FILE")
@@ -67,7 +65,7 @@ class Vmdb2:
p.add_argument("--rootfs-tarball", metavar="FILE")
p.add_argument("-v", "--verbose", action="store_true")
p.add_argument("--log")
- p.add_argument("--version", action="store_true")
+ p.add_argument("--version", action="version", version=vmdb.__version__)
p.add_argument(
"--variable",
action="append",
diff --git a/vmdb2.md b/vmdb2.md
index 9c9a41c..4b2372d 100644
--- a/vmdb2.md
+++ b/vmdb2.md
@@ -258,6 +258,7 @@ kind of testing, and that the teardown field in the step is
implemented by the echo step. It's not a generic feature.
~~~scenario
+given an installed vmdb2
given file happy.vmdb
when I run vmdb2 -v happy.vmdb --output=happy.img
then exit code is 0
@@ -272,6 +273,18 @@ steps:
teardown: bar_teardown
~~~
+## Checking the version
+
+_Requirement: We can ask vmdb2 for its version._
+
+
+~~~scenario
+given an installed vmdb2
+when I run vmdb2 --version
+then exit code is 0
+then stdout matches regex ^\d+\.\d+$
+~~~
+
## Jinja2 templating in specification file values
@@ -283,6 +296,7 @@ outputs the image file name given by the user. A more realistic
specification file would instead do thing like create the file.
~~~scenario
+given an installed vmdb2
given file j2.vmdb
when I run vmdb2 -v j2.vmdb --output=foo.img
then exit code is 0
@@ -303,6 +317,7 @@ in the right order then? This scenario uses the "error" step provided
for testing this kind of thing.
~~~scenario
+given an installed vmdb2
given file unhappy.vmdb
when I try to run vmdb2 -v unhappy.vmdb --output=unhappy.img
then exit code is 1
@@ -310,7 +325,7 @@ then stdout contains "foo\nyikes\n"
then stdout contains "WAT?!\n"
then stdout contains "foo_teardown\n"
then stdout doesn't contain "bar_step"
-then stdout doesn't contain "bar_teardown"
+then stdout contains "bar_teardown"
~~~
~~~{.file #unhappy.vmdb .yaml .numberLines}
@@ -322,5 +337,3 @@ steps:
- echo: bar
teardown: bar_teardown
~~~
-
-
diff --git a/vmdb2.py b/vmdb2.py
index 78ecb62..719ca46 100644
--- a/vmdb2.py
+++ b/vmdb2.py
@@ -1,34 +1,4 @@
-import subprocess
-
-def _runcmd(ctx, argv):
- p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- stdout, stderr = p.communicate("")
- ctx['stdout'] = stdout
- ctx['stderr'] = stderr
- ctx['exit'] = p.returncode
-
-def _binary(basename):
- return os.path.join(srcdir, basename)
-
-def given_file(ctx, filename=None):
- with open(filename, 'wb') as f:
- f.write(get_file(filename))
-
-def run_vmdb2(ctx, filename=None, output=None):
- vmdb2 = _binary('vmdb2')
- _runcmd(ctx, [vmdb2, filename, '-v', '--output', output])
-
-def exit_code_is(ctx, exit_code=None):
- assert_eq(ctx['exit'], int(exit_code))
-
-def stdout_contains(ctx, pat1=None, pat2=None):
- stdout = ctx.get('stdout', b'').decode('utf-8')
- i = stdout.find(pat1)
- assert i >= 0, "pat1 not found"
- i = stdout[i:].find(pat2)
- assert i >= 0, "pat2 not found after pat1"
-
-def stdout_does_not_contain(ctx, pat1=None):
- stdout = ctx.get('stdout', b'').decode('utf-8')
- i = stdout.find(pat1)
- assert i == -1, "pattern found"
+def install_vmdb2(ctx):
+ srcdeir = globals()["srcdir"]
+ runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"]
+ runcmd_prepend_to_path(ctx, srcdir)
diff --git a/vmdb2.subplot b/vmdb2.subplot
index 909164c..2e23b85 100644
--- a/vmdb2.subplot
+++ b/vmdb2.subplot
@@ -4,9 +4,11 @@ authors:
markdowns:
- vmdb2.md
bindings:
+ - vmdb2.yaml
- lib/files.yaml
- lib/runcmd.yaml
impls:
python:
+ - vmdb2.py
- lib/files.py
- lib/runcmd.py
diff --git a/vmdb2.yaml b/vmdb2.yaml
index 7eab644..07915b3 100644
--- a/vmdb2.yaml
+++ b/vmdb2.yaml
@@ -1,3 +1,10 @@
+- given: an installed vmdb2
+ impl:
+ python:
+ function: install_vmdb2
+
- then: stdout contains "(?P<pat1>.+)" followed by "(?P<pat2>.+)"
regex: true
- function: stdout_contains
+ impl:
+ python:
+ function: stdout_contains