Repository: cekit/cekit

Issue:
When using the --verbose flag also set the debug flag for rhpkg command
**Describe the solution you'd like**
It is useful to debug rhpkg issues, sometimes the error message might not he enough to understand what is happening.

**Additional context**
We hit a issue recently that the rhpkg returns just "None"  in the error message, e.g.:

```
ERROR Command '['/usr/bin/rhpkg', '--user', ...
...
Returned non-zero exit status 1. Command stdout is 'None' with stderr 'None'
```


Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/cekit/cekit/pull/874?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit) Report
Attention: `3 lines` in your changes are missing coverage. Please review.
> Comparison is base [(`8ae5fbe`)](https://app.codecov.io/gh/cekit/cekit/commit/8ae5fbee849e3fd0a772238f0943fe8088258e86?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit) 90.34% compared to head [(`fd22e5f`)](https://app.codecov.io/gh/cekit/cekit/pull/874?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit) 90.27%.

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff             @@
##           develop     #874      +/-   ##
===========================================
- Coverage    90.34%   90.27%   -0.07%     
===========================================
  Files           41       41              
  Lines         3210     3219       +9     
===========================================
+ Hits          2900     2906       +6     
- Misses         310      313       +3     
```


| [Files](https://app.codecov.io/gh/cekit/cekit/pull/874?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit) | Coverage Δ | |
|---|---|---|
| [cekit/builders/podman.py](https://app.codecov.io/gh/cekit/cekit/pull/874?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit#diff-Y2VraXQvYnVpbGRlcnMvcG9kbWFuLnB5) | `97.50% <100.00%> (+0.13%)` | :arrow_up: |
| [cekit/cli.py](https://app.codecov.io/gh/cekit/cekit/pull/874?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit#diff-Y2VraXQvY2xpLnB5) | `89.83% <100.00%> (+0.05%)` | :arrow_up: |
| [cekit/builders/buildah.py](https://app.codecov.io/gh/cekit/cekit/pull/874?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit#diff-Y2VraXQvYnVpbGRlcnMvYnVpbGRhaC5weQ==) | `88.57% <50.00%> (-2.34%)` | :arrow_down: |
| [cekit/builders/osbs.py](https://app.codecov.io/gh/cekit/cekit/pull/874?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit#diff-Y2VraXQvYnVpbGRlcnMvb3Nicy5weQ==) | `83.16% <50.00%> (-0.45%)` | :arrow_down: |


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/cekit/cekit/pull/874?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cekit).


Patch:
diff --git a/cekit/builders/buildah.py b/cekit/builders/buildah.py
index d966a1a..d28b282 100644
--- a/cekit/builders/buildah.py
+++ b/cekit/builders/buildah.py
@@ -33,6 +33,9 @@ class BuildahBuilder(Builder):
         if not self.params.no_squash:
             cmd.append("--squash")
 
+        if self.params.trace:
+            cmd += ["--log-level", "debug"]
+
         if self.params.pull:
             cmd.append("--pull-always")
 
diff --git a/cekit/builders/osbs.py b/cekit/builders/osbs.py
index 3ae29c8..29f4e12 100644
--- a/cekit/builders/osbs.py
+++ b/cekit/builders/osbs.py
@@ -260,6 +260,8 @@ class OSBSBuilder(Builder):
         cmd = [self._fedpkg]
         if self.params.user:
             cmd += ["--user", self.params.user]
+        if self.params.trace:
+            cmd += ["--debug"]
         cmd += ["new-sources"] + cache_artifacts
 
         with Chdir(self.dist_git_dir):
@@ -278,6 +280,9 @@ class OSBSBuilder(Builder):
         git_tag: str = ""
         cmd: List[str] = [self._koji]
 
+        if self.params.trace:
+            cmd += ["--debug"]
+
         if self.params.user:
             cmd += ["--user", self.params.user]
 
diff --git a/cekit/builders/podman.py b/cekit/builders/podman.py
index 979f16b..53c6fa0 100644
--- a/cekit/builders/podman.py
+++ b/cekit/builders/podman.py
@@ -36,6 +36,9 @@ class PodmanBuilder(Builder):
         if not tags:
             tags = self.generator.get_tags()
 
+        if self.params.trace:
+            cmd += ["--log-level", "debug"]
+
         if self.params.pull:
             cmd.append("--pull-always")
 
diff --git a/cekit/cli.py b/cekit/cli.py
index 0cd464c..06dc948 100644
--- a/cekit/cli.py
+++ b/cekit/cli.py
@@ -39,6 +39,7 @@ def verify_release_passed(ctx, param, value):
     show_default=True,
 )
 @click.option("-v", "--verbose", help="Enable verbose output.", is_flag=True)
+@click.option("--trace", help="Enable trace output.", is_flag=True)
 @click.option("--nocolor", help="Disable color output.", is_flag=True)
 @click.option(
     "--work-dir",
@@ -67,7 +68,7 @@ def verify_release_passed(ctx, param, value):
     show_default=True,
 )
 @click.version_option(message="%(version)s", version=__version__)
-def cli(descriptor, verbose, nocolor, work_dir, config, redhat, target):
+def cli(descriptor, verbose, nocolor, work_dir, config, redhat, target, trace):
     """
     ABOUT
 


Test patch:
diff --git a/tests/test_integ_podman.py b/tests/test_integ_podman.py
index 20f0b2e..e319c98 100644
--- a/tests/test_integ_podman.py
+++ b/tests/test_integ_podman.py
@@ -5,6 +5,7 @@ from __future__ import print_function
 import os
 import shutil
 
+from _pytest.capture import CaptureResult
 from click.testing import CliRunner
 
 from cekit.cli import cli
@@ -50,7 +51,7 @@ def test_podman_from_scratch(tmpdir):
     run_cekit(os.path.join(tmpdir, "scratch"), env={"BUILDAH_LAYERS": "false"})
 
 
-def test_podman_operator_metadata(tmpdir):
+def test_podman_operator_metadata(tmpdir, capfd):
     tmpdir = str(tmpdir)
 
     shutil.copytree(
@@ -62,6 +63,14 @@ def test_podman_operator_metadata(tmpdir):
     # See: https://bugzilla.redhat.com/show_bug.cgi?id=1746022
     run_cekit(
         os.path.join(tmpdir, "operator-metadata"),
-        args=["--redhat", "build", "podman"],
+        args=["--redhat", "--trace", "build", "podman"],
         env={"BUILDAH_LAYERS": "false"},
     )
+
+    output: CaptureResult = capfd.readouterr()
+    print(output.err)
+    assert 'level=debug msg="Called build.PersistentPreRunE' in output.err
+    assert (
+        "Successfully tagged localhost/amq7/amq-streams-rhel7-operator-metadata:latest"
+        in output.out
+    )
diff --git a/tests/test_unit_args.py b/tests/test_unit_args.py
index 349ec4e..1c6f24a 100644
--- a/tests/test_unit_args.py
+++ b/tests/test_unit_args.py
@@ -32,6 +32,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": True,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),
@@ -54,6 +55,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "custom-target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),
@@ -76,6 +78,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),
@@ -98,6 +101,7 @@ def _get_class_by_name(clazz):
                 "config": "custom-config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),
@@ -120,6 +124,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),
@@ -142,6 +147,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": ("foo", "bar"),
@@ -164,6 +170,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),
@@ -190,6 +197,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),
@@ -216,6 +224,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),
@@ -242,6 +251,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),
@@ -266,6 +276,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "overrides": (),
                 "image": "image:1.0",
                 "steps_url": "https://github.com/cekit/behave-test-steps.git",
@@ -287,6 +298,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),
@@ -308,6 +320,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),
@@ -333,6 +346,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),
@@ -354,6 +368,7 @@ def _get_class_by_name(clazz):
                 "config": "~/.cekit/config",
                 "redhat": False,
                 "target": "target",
+                "trace": False,
                 "validate": False,
                 "dry_run": False,
                 "overrides": (),