OLD | NEW |
1 from StringIO import StringIO | 1 from StringIO import StringIO |
2 import json | 2 import json |
3 import logging | 3 import logging |
4 import os | 4 import os |
5 import stat | 5 import stat |
6 import sys | 6 import sys |
7 import yaml | 7 import yaml |
8 | 8 |
9 from twisted.internet import defer | 9 from twisted.internet import defer |
10 from twisted.internet.process import Process | 10 from twisted.internet.process import Process |
(...skipping 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1430 | 1430 |
1431 log, log_units = yield self.get_service_and_units_by_charm_name( | 1431 log, log_units = yield self.get_service_and_units_by_charm_name( |
1432 "logging", | 1432 "logging", |
1433 containers=my_units) | 1433 containers=my_units) |
1434 self.assertTrue((yield log.is_subordinate())) | 1434 self.assertTrue((yield log.is_subordinate())) |
1435 for lu in log_units: | 1435 for lu in log_units: |
1436 self.assertTrue((yield lu.is_subordinate())) | 1436 self.assertTrue((yield lu.is_subordinate())) |
1437 | 1437 |
1438 mu1, mu2 = my_units | 1438 mu1, mu2 = my_units |
1439 lu1, lu2 = log_units | 1439 lu1, lu2 = log_units |
| 1440 self.mysql_units = my_units |
| 1441 self.log_units = log_units |
1440 | 1442 |
1441 mystate = pick_attr(service_states, relation_role="server") | 1443 mystate = pick_attr(service_states, relation_role="server") |
1442 logstate = pick_attr(service_states, relation_role="client") | 1444 logstate = pick_attr(service_states, relation_role="client") |
1443 | 1445 |
1444 yield mystate.add_unit_state(mu1) | 1446 yield mystate.add_unit_state(mu1) |
1445 self.relation = yield logstate.add_unit_state(lu1) | 1447 self.relation = yield logstate.add_unit_state(lu1) |
1446 # add the second container ( | 1448 # add the second container ( |
1447 yield mystate.add_unit_state(mu2) | 1449 yield mystate.add_unit_state(mu2) |
1448 self.relation2 = yield logstate.add_unit_state(lu2) | 1450 self.relation2 = yield logstate.add_unit_state(lu2) |
1449 | 1451 |
(...skipping 15 matching lines...) Expand all Loading... |
1465 self.log.seek(0) | 1467 self.log.seek(0) |
1466 exe = yield self.ua.get_invoker( | 1468 exe = yield self.ua.get_invoker( |
1467 "juju-info", "add", "mysql/1", self.relation2) | 1469 "juju-info", "add", "mysql/1", self.relation2) |
1468 result = yield exe(self.create_hook("relation-list", | 1470 result = yield exe(self.create_hook("relation-list", |
1469 "--format=smart")) | 1471 "--format=smart")) |
1470 self.assertEqual(result, 0) | 1472 self.assertEqual(result, 0) |
1471 # verify that we see the proper unit | 1473 # verify that we see the proper unit |
1472 self.assertIn("mysql/1", self.log.getvalue()) | 1474 self.assertIn("mysql/1", self.log.getvalue()) |
1473 # we don't see units in the other container | 1475 # we don't see units in the other container |
1474 self.assertNotIn("mysql/0", self.log.getvalue()) | 1476 self.assertNotIn("mysql/0", self.log.getvalue()) |
| 1477 |
| 1478 @defer.inlineCallbacks |
| 1479 def test_open_and_close_ports(self): |
| 1480 """Verify that port hook commands run and changes are immediate.""" |
| 1481 unit_state = self.log_units[0] |
| 1482 self.assertEqual((yield unit_state.get_open_ports()), []) |
| 1483 |
| 1484 exe = yield self.ua.get_invoker( |
| 1485 "database:42", "add", "logging/0", self.relation) |
| 1486 result = yield exe(self.create_hook("open-port", "80")) |
| 1487 self.assertEqual(result, 0) |
| 1488 self.assertEqual( |
| 1489 (yield unit_state.get_open_ports()), |
| 1490 [{"port": 80, "proto": "tcp"}]) |
| 1491 |
| 1492 result = yield exe(self.create_hook("open-port", "53/udp")) |
| 1493 self.assertEqual(result, 0) |
| 1494 self.assertEqual( |
| 1495 (yield unit_state.get_open_ports()), |
| 1496 [{"port": 80, "proto": "tcp"}, |
| 1497 {"port": 53, "proto": "udp"}]) |
| 1498 |
| 1499 result = yield exe(self.create_hook("open-port", "53/tcp")) |
| 1500 self.assertEqual(result, 0) |
| 1501 self.assertEqual( |
| 1502 (yield unit_state.get_open_ports()), |
| 1503 [{"port": 80, "proto": "tcp"}, |
| 1504 {"port": 53, "proto": "udp"}, |
| 1505 {"port": 53, "proto": "tcp"}]) |
| 1506 |
| 1507 result = yield exe(self.create_hook("open-port", "443/tcp")) |
| 1508 self.assertEqual(result, 0) |
| 1509 self.assertEqual( |
| 1510 (yield unit_state.get_open_ports()), |
| 1511 [{"port": 80, "proto": "tcp"}, |
| 1512 {"port": 53, "proto": "udp"}, |
| 1513 {"port": 53, "proto": "tcp"}, |
| 1514 {"port": 443, "proto": "tcp"}]) |
| 1515 |
| 1516 result = yield exe(self.create_hook("close-port", "80/tcp")) |
| 1517 self.assertEqual(result, 0) |
| 1518 self.assertEqual( |
| 1519 (yield unit_state.get_open_ports()), |
| 1520 [{"port": 53, "proto": "udp"}, |
| 1521 {"port": 53, "proto": "tcp"}, |
| 1522 {"port": 443, "proto": "tcp"}]) |
| 1523 |
| 1524 yield exe.ended |
| 1525 self.assertLogLines( |
| 1526 self.log.getvalue(), [ |
| 1527 "opened 80/tcp", |
| 1528 "opened 53/udp", |
| 1529 "opened 443/tcp", |
| 1530 "closed 80/tcp"]) |
OLD | NEW |