Skip to content

Commit c9aae8b

Browse files
authored
Use juju provided ip instead of resolved one (#558)
1 parent 90d679a commit c9aae8b

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/hostname_resolution.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,7 @@ def _update_host_details_in_databag(self, _) -> None:
5050
hostname = socket.gethostname()
5151
fqdn = socket.getfqdn()
5252

53-
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
54-
s.settimeout(0)
55-
try:
56-
s.connect(("10.10.10.10", 1))
57-
ip = s.getsockname()[0]
58-
except Exception:
59-
logger.exception("Unable to get local IP address")
60-
ip = "127.0.0.1"
53+
ip = str(self.model.get_binding(PEER).network.bind_address)
6154

6255
host_details = {"names": [hostname, fqdn], "address": ip}
6356

tests/unit/test_config.py

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ops.testing import Harness
1111

1212
from charm import MySQLOperatorCharm
13+
from constants import PEER
1314

1415
CONFIG = str(yaml.safe_load(Path("./config.yaml").read_text()))
1516
ACTIONS = str(yaml.safe_load(Path("./actions.yaml").read_text()))
@@ -22,6 +23,7 @@
2223
def harness():
2324
harness = Harness(MySQLOperatorCharm, meta=METADATA, config=CONFIG, actions=ACTIONS)
2425
harness.add_relation("restart", "mysql")
26+
harness.add_relation(PEER, "mysql")
2527
harness.begin()
2628
return harness
2729

0 commit comments

Comments
 (0)