Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Feb 23, 2024
1 parent ba6df17 commit eb8489e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
8 changes: 1 addition & 7 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import json
import pwd
import subprocess
from charms.mongodb.v1.helpers import copy_licenses_to_unit, KEY_FILE
from charms.operator_libs_linux.v1 import snap
from pathlib import Path
Expand Down Expand Up @@ -364,12 +363,7 @@ def _generate_relation_departed_key(rel_id: int) -> str:

def open_mongos_port(self) -> None:
"""Opens the mongos port for TCP connections."""
try:
logger.debug("opening tcp port")
subprocess.check_call(["open-port", "{}/TCP".format(Config.MONGOS_PORT)])
except subprocess.CalledProcessError as e:
logger.exception("failed opening port: %s", str(e))
raise
self.unit.open_port("tcp", Config.MONGOS_PORT)

# END: helper functions

Expand Down
20 changes: 1 addition & 19 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ops.model import BlockedStatus, WaitingStatus
from ops.testing import Harness

from charm import MongosOperatorCharm, subprocess
from charm import MongosOperatorCharm

from .helpers import patch_network_get

Expand Down Expand Up @@ -158,21 +158,3 @@ def test_mongos_host(self):
self.harness.charm.app_peer_data["external-connectivity"] = json.dumps(True)
mongos_host = self.harness.charm.get_mongos_host()
self.assertEqual(mongos_host, "1.1.1.1")

@patch("subprocess.check_call")
def test_set_port(self, _call):
"""Test verifies operation of set port."""
self.harness.charm.open_mongos_port()

# Make sure the port is opened and the service is started
self.assertEqual(_call.call_args_list, [mock.call(["open-port", "27018/TCP"])])

@patch("subprocess.check_call")
def test_set_port_failure(self, _call):
"""Test verifies that we raise the correct errors when we fail to open a port."""
_call.side_effect = subprocess.CalledProcessError(
cmd="open-port 27018/TCP", returncode=1
)

with self.assertRaises(subprocess.CalledProcessError):
self.harness.charm.open_mongos_port()

0 comments on commit eb8489e

Please sign in to comment.