Skip to content

Commit

Permalink
pybridge: Implement cockpit-bridge --version
Browse files Browse the repository at this point in the history
It was defined in argparse, but entirely ignored, so that it started the
protocol. Also add it to the manpage.

This also unbreaks the regular cockpit/ws container builds, as they use
--version to define the tag.

Add an integration test which exercises all non-protocol options.

Fixes #19233
  • Loading branch information
martinpitt committed Aug 24, 2023
1 parent 2b25f83 commit 09f5d87
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/man/cockpit-bridge.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
available to the user running this command.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--version</option></term>
<listitem>
<para>Show Cockpit version information.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

Expand Down
4 changes: 4 additions & 0 deletions src/cockpit/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from cockpit._vendor.systemd_ctypes import bus, run_async

from . import polyfills
from ._version import __version__
from .channel import ChannelRoutingRule
from .channels import CHANNEL_TYPES
from .config import Config, Environment
Expand Down Expand Up @@ -270,6 +271,9 @@ def main(*, beipack: bool = False) -> None:
if args.packages:
Packages().show()
return
elif args.version:
print(f'Version: {__version__}\nProtocol: 1')
return
elif args.bridges:
print(json.dumps(Packages().get_bridge_configs(), indent=2))
return
Expand Down
16 changes: 16 additions & 0 deletions test/verify/check-connection
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,22 @@ UnixPath=/run/cockpit/session
b.wait_visible("#nav-system li:contains(Hackices)")
self.assertFalse(b.is_present("#nav-system li:contains(Services)"))

def testBridgeCLI(self):
m = self.machine

out = m.execute("cockpit-bridge --help")
# this needs to work with both the C and Python bridges
self.assertRegex(out, r"[uU]sage:")
self.assertIn("--packages", out)

version = m.execute("cockpit-bridge --version")
self.assertIn("Protocol: 1", version)
self.assertRegex(version, r"Version: \d{3,}")

packages = m.execute("cockpit-bridge --packages")
self.assertRegex(packages, r"(^|\n)base1\s+.*/usr/share/cockpit/base1")
self.assertRegex(packages, r"(^|\n)system\s+.*/usr/share/cockpit/systemd")


@testlib.skipDistroPackage()
class TestReverseProxy(testlib.MachineCase):
Expand Down

0 comments on commit 09f5d87

Please sign in to comment.