~xnox/pyjuju/myjuju

« back to all changes in this revision

Viewing changes to juju/hooks/tests/test_invoker.py

  • Committer: Benjamin Saller
  • Date: 2012-07-03 07:35:54 UTC
  • mfrom: (539.1.11 subordinate-ports)
  • Revision ID: bcsaller@gmail.com-20120703073554-hudmij40dkpeghqz
Support for open/close ports on subordinates [r=kapil] [f=984484]

open-port/close-port now open the ports both on the container and the subordinate unit when called from a subordinate unit. This allows status reporting to include proper feedback to the user that the port is open on the subordinate even though its the principal units networking that is actually changed (as its the runtime container).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1477
1477
 
1478
1478
        mu1, mu2 = my_units
1479
1479
        lu1, lu2 = log_units
 
1480
        self.mysql_units = my_units
 
1481
        self.log_units = log_units
1480
1482
 
1481
1483
        mystate = pick_attr(service_states, relation_role="server")
1482
1484
        logstate = pick_attr(service_states, relation_role="client")
1483
1485
 
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)
1489
1491
 
1509
1511
                                            "--format=smart"))
1510
1512
        self.assertEqual(result, 0)
1511
1513
        # verify that we see the proper unit
 
1514
        yield exe.ended
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())
1515
1518
 
1516
1519
 
 
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]
 
1525
 
 
1526
        self.assertEqual((yield unit_state.get_open_ports()), [])
 
1527
 
 
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)
 
1532
        self.assertEqual(
 
1533
            (yield unit_state.get_open_ports()),
 
1534
            [{"port": 80, "proto": "tcp"}])
 
1535
        self.assertEqual(
 
1536
            (yield container_state.get_open_ports()),
 
1537
            [{"port": 80, "proto": "tcp"}])
 
1538
 
 
1539
        result = yield exe(self.create_hook("open-port", "53/udp"))
 
1540
        self.assertEqual(result, 0)
 
1541
        self.assertEqual(
 
1542
            (yield unit_state.get_open_ports()),
 
1543
            [{"port": 80, "proto": "tcp"},
 
1544
             {"port": 53, "proto": "udp"}])
 
1545
        self.assertEqual(
 
1546
            (yield container_state.get_open_ports()),
 
1547
            [{"port": 80, "proto": "tcp"},
 
1548
             {"port": 53, "proto": "udp"}])
 
1549
 
 
1550
 
 
1551
        result = yield exe(self.create_hook("close-port", "80/tcp"))
 
1552
        self.assertEqual(result, 0)
 
1553
        self.assertEqual(
 
1554
            (yield unit_state.get_open_ports()),
 
1555
            [{"port": 53, "proto": "udp"} ,])
 
1556
        self.assertEqual(
 
1557
            (yield container_state.get_open_ports()),
 
1558
            [{"port": 53, "proto": "udp"},])
 
1559
 
 
1560
        yield exe.ended
 
1561
        self.assertLogLines(
 
1562
            self.log.getvalue(), [
 
1563
                "opened 80/tcp",
 
1564
                "opened 53/udp",
 
1565
                "closed 80/tcp"])
 
1566
 
 
1567
 
1517
1568
def capture_separate_log(name, level):
1518
1569
    """Support the separate capture of logging at different log levels.
1519
1570