From 6322e2f9aa680574ff64ad7e62db9142267809ce Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Mon, 8 Apr 2024 14:42:22 +0200 Subject: [PATCH] Propagate exit code from the run() and do_() commandline methods --- .github/workflows/tests.yaml | 3 ++- behave/README.md | 6 ++++++ behave/features/service.feature | 11 +++++++++++ behave/fixtures/pac/_service-set_version-invalid | 5 +++++ osc/commandline.py | 9 +++++---- 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 behave/features/service.feature create mode 100644 behave/fixtures/pac/_service-set_version-invalid diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 685ed3a9..5b7a51c6 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -103,8 +103,9 @@ jobs: steps: - name: "Install packages" run: | + sudo sh -c '. /etc/os-release; echo "deb [trusted=yes] http://download.opensuse.org/repositories/openSUSE:Tools/xUbuntu_${VERSION_ID} ./" > /etc/apt/sources.list.d/openSUSE-Tools.list' 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 + sudo apt-get -y --no-install-recommends install python3-behave diffstat diffutils python3 python3-cryptography python3-pip python3-rpm python3-setuptools python3-urllib3 obs-build obs-service-set-version - name: "Checkout sources" uses: actions/checkout@v3 diff --git a/behave/README.md b/behave/README.md index 5cc4bc43..07deafaa 100644 --- a/behave/README.md +++ b/behave/README.md @@ -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 build obs-service-set_version +``` + Run tests --------- diff --git a/behave/features/service.feature b/behave/features/service.feature new file mode 100644 index 00000000..a7ae2cf7 --- /dev/null +++ b/behave/features/service.feature @@ -0,0 +1,11 @@ +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-set_version-invalid" to "{context.osc.temp}/test:factory/test-pkgA/_service" + When I execute osc with args "service manualrun" + Then stdout contains "Aborting: service call failed" + And the exit code is 255 diff --git a/behave/fixtures/pac/_service-set_version-invalid b/behave/fixtures/pac/_service-set_version-invalid new file mode 100644 index 00000000..d39afa05 --- /dev/null +++ b/behave/fixtures/pac/_service-set_version-invalid @@ -0,0 +1,5 @@ + + + invalid + + diff --git a/osc/commandline.py b/osc/commandline.py index 8d5f4501..845b7df1 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -245,7 +245,7 @@ class MainCommand(Command): 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__}" @@ -502,10 +502,10 @@ class OscMainCommand(MainCommand): # 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 @@ -561,7 +561,8 @@ class OscMainCommand(MainCommand): 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