summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-11-02 16:20:08 +0200
committerLars Wirzenius <liw@liw.fi>2022-11-02 16:20:08 +0200
commit6e1f1350e73a57b2b4a6621227b66477d85a4850 (patch)
tree4d7c9af5664d825b90688e2504c6d6c353ded462
parentd286c58d728ec40e02bfb44ffd50ce7a92f777dc (diff)
downloaddebian-subplot-6e1f1350e73a57b2b4a6621227b66477d85a4850.tar.gz
feat: install and remove a package
Sponsored-by: author
-rw-r--r--debian.md23
-rw-r--r--debian.py14
-rw-r--r--debian.yaml5
3 files changed, 37 insertions, 5 deletions
diff --git a/debian.md b/debian.md
index 5f9d29e..ba35311 100644
--- a/debian.md
+++ b/debian.md
@@ -57,3 +57,26 @@ given a Debian system
when I run, as debian, sudo apt update
then command is successful
~~~
+
+## Can install and remove a package
+
+_Requirement: The system administrator can install and remove a
+package._
+
+Justification: Without this, it may be impossible to install a bug fix
+or security update.
+
+The scenario uses the `liwc` package, which is rarely used or
+installed by anyone. If your Debian system does have it, this will
+fail and you will need to edit the scenario to use a different
+package.
+
+~~~scenario
+given a Debian system
+when I try to run, as debian, dpkg -l liwc
+then command fails
+when I run, as debian, sudo apt update
+when I run, as debian, sudo apt install -y liwc
+when I run, as debian, sudo apt remove -y liwc
+then command is successful
+~~~
diff --git a/debian.py b/debian.py
index 7456d8a..ec14bd8 100644
--- a/debian.py
+++ b/debian.py
@@ -15,13 +15,17 @@ def debian_system(ctx, hostname=None):
def run_as_on_host(ctx, username=None, argv0=None, args=None):
- runcmd_run = globals()["runcmd_run"]
runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
+ try_to_run_as_on_host(ctx, username=username, argv0=argv0, args=args)
+ runcmd_exit_code_is_zero(ctx)
+
- logging.debug(f"run_as_on_host: username={username!r}")
- logging.debug(f"run_as_on_host: argv0={argv0!r}")
- logging.debug(f"run_as_on_host: args={args!r}")
+def try_to_run_as_on_host(ctx, username=None, argv0=None, args=None):
+ runcmd_run = globals()["runcmd_run"]
+
+ logging.debug(f"try_to_run_as_on_host: username={username!r}")
+ logging.debug(f"try_to_run_as_on_host: argv0={argv0!r}")
+ logging.debug(f"try_to_run_as_on_host: args={args!r}")
target = f"{username}@{ctx['hostname']}"
argv = ["ssh", target, "--", shlex.quote(argv0)] + shlex.split(args)
runcmd_run(ctx, argv)
- runcmd_exit_code_is_zero(ctx)
diff --git a/debian.yaml b/debian.yaml
index 45497ee..c488841 100644
--- a/debian.yaml
+++ b/debian.yaml
@@ -7,3 +7,8 @@
impl:
python:
function: run_as_on_host
+
+- when: I try to run, as {username}, {argv0}{args:text}
+ impl:
+ python:
+ function: try_to_run_as_on_host