diff --git a/ops/jujuversion.py b/ops/jujuversion.py index 8e25b3eba..ea27eb3e2 100644 --- a/ops/jujuversion.py +++ b/ops/jujuversion.py @@ -144,3 +144,13 @@ def supports_exec_service_context(self) -> bool: # releases have the change (3.2.1 tag was never released). return False return True + + @property + def supports_pebble_log_forwarding(self) -> bool: + """Report whether the Pebble bundled with this Juju version supports log forwarding.""" + # Log forwarding was available from Pebble 1.4, but labels were added in + # 1.6, and that's when this became really useful, so we use that as a + # cutoff. Juju 3.4.0 was the first to have Pebble 1.6 (actually 1.7). + # https://github.com/canonical/pebble/releases/tag/v1.6.0 + # https://github.com/juju/juju/blob/e1b7dcd7390348c37f8b860011e7436e6ed3f4cc/go.mod#L27 + return (self.major, self.minor, self.patch) >= (3, 4, 0) diff --git a/test/test_jujuversion.py b/test/test_jujuversion.py index 713248bfa..fe2e457c0 100644 --- a/test/test_jujuversion.py +++ b/test/test_jujuversion.py @@ -100,6 +100,20 @@ def test_supports_exec_service_context(): assert ops.JujuVersion('3.4.0').supports_exec_service_context +@pytest.mark.parametrize( + 'version,has_support', + [ + ('2.9.50', False), + ('3.3.6', False), + ('3.4.0', True), + ('3.4.1', True), + ('4.0.0', True), + ], +) +def test_supports_pebble_log_forwarding(version: str, has_support: bool): + assert ops.JujuVersion(version).supports_pebble_log_forwarding is has_support + + @pytest.mark.parametrize( 'invalid_version', [