Skip to content

Commit

Permalink
Propagate exit code from the run() and do_() commandline methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dmach committed Apr 8, 2024
1 parent dabefbb commit a97b95d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@ jobs:
# to save resources, run only after unit tests have passed
needs: unit
runs-on: "ubuntu-latest"
container:
image: 'registry.opensuse.org/opensuse/leap:15.5'

steps:
- name: "Install packages"
run: |
sudo apt-get -y update
sudo apt-get -y --no-install-recommends install python3-behave diffstat diffutils python3 python3-cryptography python3-pip python3-rpm python3-setuptools python3-urllib3
zypper -n modifyrepo --disable repo-openh264 || :
zypper -n --gpg-auto-import-keys refresh
zypper -n install git-lfs
zypper -n install python3-behave diffstat diffutils obs-service-replace_using_env python3 python3-cryptography python3-pip python3-rpm python3-setuptools python3-urllib3
- name: "Checkout sources"
uses: actions/checkout@v3
Expand Down
6 changes: 6 additions & 0 deletions behave/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ $ podman stop|kill obs-server
$ podman rmi obs-server
```

Install test dependencies
-------------------------
```
$ zypper install python3-behave diffstat diffutils obs-service-replace_using_env python3 python3-cryptography python3-pip python3-rpm python3-setuptools python3-urllib3
```

Run tests
---------

Expand Down
10 changes: 10 additions & 0 deletions behave/features/service.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: `osc service` command


Scenario: Run `osc service manualrun`
Given I set working directory to "{context.osc.temp}"
And I execute osc with args "checkout test:factory test-pkgA"
And I set working directory to "{context.osc.temp}/test:factory/test-pkgA"
And I copy file "{context.fixtures}/pac/_service-manual-exit-2" to "{context.osc.temp}/test:factory/test-pkgA/_service"
When I execute osc with args "service manualrun"
Then the exit code is 2
9 changes: 9 additions & 0 deletions behave/fixtures/pac/_service-manual-exit-2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<services>
<service name="replace_using_env" mode="manual">
<param name="eval">
echo Forcing error
exit 2
</param>
<param name="file">filename</param>
</service>
</services>
9 changes: 5 additions & 4 deletions osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def run(self, args):
if not cmd:
self.parser.error("Please specify a command")
self.post_parse_args(args)
cmd.run(args)
return cmd.run(args)

def load_command(self, cls, module_prefix):
mod_cls_name = f"{module_prefix}.{cls.__name__}"
Expand Down Expand Up @@ -502,10 +502,10 @@ def run(self, args):
# handler doesn't take positional args via *args
if args.positional_args:
self.parser.error(f"unrecognized arguments: " + " ".join(args.positional_args))
self.func(args.command, args)
return self.func(args.command, args)
else:
# handler takes positional args via *args
self.func(args.command, args, *args.positional_args)
return self.func(args.command, args, *args.positional_args)

return LegacyCommandWrapper

Expand Down Expand Up @@ -561,7 +561,8 @@ def main(cls, argv=None, run=True):
cmd.load_legacy_commands()
if run:
args = cmd.parse_args(args=argv)
cmd.run(args)
exit_code = cmd.run(args)
sys.exit(exit_code)
else:
args = None
return cmd, args
Expand Down

0 comments on commit a97b95d

Please sign in to comment.