1478
1478
mu1, mu2 = my_units
1479
1479
lu1, lu2 = log_units
1480
self.mysql_units = my_units
1481
self.log_units = log_units
1481
1483
mystate = pick_attr(service_states, relation_role="server")
1482
1484
logstate = pick_attr(service_states, relation_role="client")
1484
1486
yield mystate.add_unit_state(mu1)
1485
1487
self.relation = yield logstate.add_unit_state(lu1)
1486
# add the second container (
1488
# add the second container
1487
1489
yield mystate.add_unit_state(mu2)
1488
1490
self.relation2 = yield logstate.add_unit_state(lu2)
1509
1511
"--format=smart"))
1510
1512
self.assertEqual(result, 0)
1511
1513
# verify that we see the proper unit
1512
1515
self.assertIn("mysql/1", self.log.getvalue())
1513
1516
# we don't see units in the other container
1514
1517
self.assertNotIn("mysql/0", self.log.getvalue())
1520
@defer.inlineCallbacks
1521
def test_open_and_close_ports(self):
1522
"""Verify that port hook commands run and changes are immediate."""
1523
unit_state = self.log_units[0]
1524
container_state = self.mysql_units[0]
1526
self.assertEqual((yield unit_state.get_open_ports()), [])
1528
exe = yield self.ua.get_invoker(
1529
"database:42", "add", "logging/0", self.relation)
1530
result = yield exe(self.create_hook("open-port", "80"))
1531
self.assertEqual(result, 0)
1533
(yield unit_state.get_open_ports()),
1534
[{"port": 80, "proto": "tcp"}])
1536
(yield container_state.get_open_ports()),
1537
[{"port": 80, "proto": "tcp"}])
1539
result = yield exe(self.create_hook("open-port", "53/udp"))
1540
self.assertEqual(result, 0)
1542
(yield unit_state.get_open_ports()),
1543
[{"port": 80, "proto": "tcp"},
1544
{"port": 53, "proto": "udp"}])
1546
(yield container_state.get_open_ports()),
1547
[{"port": 80, "proto": "tcp"},
1548
{"port": 53, "proto": "udp"}])
1551
result = yield exe(self.create_hook("close-port", "80/tcp"))
1552
self.assertEqual(result, 0)
1554
(yield unit_state.get_open_ports()),
1555
[{"port": 53, "proto": "udp"} ,])
1557
(yield container_state.get_open_ports()),
1558
[{"port": 53, "proto": "udp"},])
1561
self.assertLogLines(
1562
self.log.getvalue(), [
1517
1568
def capture_separate_log(name, level):
1518
1569
"""Support the separate capture of logging at different log levels.