diff --git a/ops/model.py b/ops/model.py index 6b665c96f..4798b2804 100644 --- a/ops/model.py +++ b/ops/model.py @@ -618,12 +618,7 @@ def open_port(self, protocol: typing.Literal['tcp', 'udp', 'icmp'], or ``port`` is not provided when ``protocol`` is 'tcp' or 'udp'. """ - normalised_protocol : str = protocol.lower() - if normalised_protocol == 'icmp' and port is not None: - raise ModelError("icmp cannot have a port number specified") - elif normalised_protocol in ('tcp', 'udp') and port is None: - raise ModelError(f"{normalised_protocol} must have a port number specified") - self._backend.open_port(normalised_protocol, port) + self._backend.open_port(protocol.lower(), port) def close_port(self, protocol: typing.Literal['tcp', 'udp', 'icmp'], port: Optional[int] = None) -> None: @@ -651,12 +646,7 @@ def close_port(self, protocol: typing.Literal['tcp', 'udp', 'icmp'], or ``port`` is not provided when ``protocol`` is 'tcp' or 'udp'. """ - normalised_protocol : str = protocol.lower() - if normalised_protocol == 'icmp' and port is not None: - raise ModelError("icmp cannot have a port number specified") - elif normalised_protocol in ('tcp', 'udp') and port is None: - raise ModelError(f"{normalised_protocol} must have a port number specified") - self._backend.close_port(normalised_protocol, port) + self._backend.close_port(protocol.lower(), port) def opened_ports(self) -> Set['Port']: """Return a list of opened ports for this unit.""" diff --git a/test/test_model.py b/test/test_model.py index e8157c623..fb3236560 100755 --- a/test/test_model.py +++ b/test/test_model.py @@ -3337,11 +3337,6 @@ def test_open_port_error(self): ['open-port', '8080/ftp'], ]) - with self.assertRaises(ops.ModelError) as cm: - self.unit.open_port('icmp', 8000) - with self.assertRaises(ops.ModelError) as cm: - self.unit.open_port('udp') - def test_close_port(self): fake_script(self, 'close-port', 'exit 0') @@ -3366,11 +3361,6 @@ def test_close_port_error(self): ['close-port', '8080/ftp'], ]) - with self.assertRaises(ops.ModelError) as cm: - self.unit.close_port('icmp', 8000) - with self.assertRaises(ops.ModelError) as cm: - self.unit.close_port('udp') - def test_opened_ports(self): fake_script(self, 'opened-ports', """echo 8080/tcp; echo icmp""")