Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(87)

Unified Diff: juju/state/tests/test_service.py

Issue 6256054: Destroying a subordinate shouldn't result in tracebacks
Patch Set: Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: juju/state/tests/test_service.py
=== modified file 'juju/state/tests/test_service.py'
--- juju/state/tests/test_service.py 2012-04-11 19:38:41 +0000
+++ juju/state/tests/test_service.py 2012-05-22 05:53:31 +0000
@@ -159,6 +159,43 @@
unit_state = yield service_state.add_unit_state()
returnValue(unit_state)
+ @inlineCallbacks
+ def setup_subordinate_defaults(self):
+ mysql_ep = RelationEndpoint("mysql", "juju-info", "juju-info",
+ "server", "global")
+ logging_ep = RelationEndpoint("logging", "juju-info", "juju-info",
+ "client", "container")
+
+ logging_charm_state = yield self.get_subordinate_charm()
+ self.assertTrue(logging_charm_state.is_subordinate())
+ log_state = yield self.service_state_manager.add_service_state(
+ "logging", logging_charm_state, dummy_constraints)
+ mysql_state = yield self.service_state_manager.add_service_state(
+ "mysql", self.charm_state, dummy_constraints)
+
+ m1 = yield self.machine_state_manager.add_machine_state(
+ series_constraints)
+ m2 = yield self.machine_state_manager.add_machine_state(
+ series_constraints)
+
+ relation_state, service_states = (yield
+ self.relation_state_manager.add_relation_state(
+ mysql_ep, logging_ep))
+
+ unit_state1 = yield mysql_state.add_unit_state()
+ yield unit_state1.assign_to_machine(m1)
+ unit_state0 = yield log_state.add_unit_state(
+ container=unit_state1)
+
+ unit_state3 = yield mysql_state.add_unit_state()
+ yield unit_state3.assign_to_machine(m2)
+ unit_state2 = yield log_state.add_unit_state(
+ container=unit_state3)
+
+ returnValue([service_states, relation_state,
+ [(unit_state0, unit_state1),
+ (unit_state2, unit_state3)]])
+
class ServiceStateManagerTest(ServiceStateManagerTestBase):
@@ -455,27 +492,9 @@
"""
Validate adding units with containers specified and recovering that.
"""
- mysql_ep = RelationEndpoint("mysql", "juju-info", "juju-info",
- "server", "global")
- logging_ep = RelationEndpoint("logging", "juju-info", "juju-info",
- "client", "container")
-
- logging_charm_state = yield self.get_subordinate_charm()
- self.assertTrue(logging_charm_state.is_subordinate())
- log_state = yield self.service_state_manager.add_service_state(
- "logging", logging_charm_state, dummy_constraints)
- mysql_state = yield self.service_state_manager.add_service_state(
- "mysql", self.charm_state, dummy_constraints)
-
- relation_state, service_states = (yield
- self.relation_state_manager.add_relation_state(
- mysql_ep, logging_ep))
-
- unit_state1 = yield mysql_state.add_unit_state()
- unit_state0 = yield log_state.add_unit_state(container=unit_state1)
-
- unit_state3 = yield mysql_state.add_unit_state()
- unit_state2 = yield log_state.add_unit_state(container=unit_state3)
+ service_states, relation_state, unit_states = (
+ yield self.setup_subordinate_defaults())
+ (unit_state0, unit_state1), (unit_state2, unit_state3) = unit_states
self.assertEquals((yield unit_state1.get_container()), None)
self.assertEquals((yield unit_state0.get_container()), unit_state1)
@@ -498,7 +517,7 @@
@inlineCallbacks
def verify_container(relation_state, service_relation_state,
- unit_state, container):
+ unit_state, container):
presence_path = self.get_presence_path(
relation_state,
service_relation_state.relation_role,
@@ -533,6 +552,11 @@
# we verify the content elsewhere
self.assertTrue(settings_info["private-address"])
+ mid = yield unit_state.get_assigned_machine_id()
+ cmid = yield container.get_assigned_machine_id()
+ if container:
+ self.assertEqual(mid, cmid)
+
# verify all the units are constructed as expected
# first the client roles with another container
yield verify_container(relation_state, logstate,
@@ -2540,6 +2564,38 @@
self.assertEqual(exposed_flag, False)
@inlineCallbacks
+ def test_set_and_clear_exposed_flag_subordinate(self):
+ """An exposed flag can be set on a subordinate service."""
+ service_states, relation_state, unit_states = (
+ yield self.setup_subordinate_defaults())
+ (u0, u1), (u2, u3) = unit_states
+ service_state = yield u1.get_service_state()
+
+ # Defaults to false
+ exposed_flag = yield service_state.get_exposed_flag()
+ self.assertEqual(exposed_flag, False)
+
+ # Can be set
+ yield service_state.set_exposed_flag()
+ exposed_flag = yield service_state.get_exposed_flag()
+ self.assertEqual(exposed_flag, True)
+
+ # Can be set multiple times
+ yield service_state.set_exposed_flag()
+ exposed_flag = yield service_state.get_exposed_flag()
+ self.assertEqual(exposed_flag, True)
+
+ # Can be cleared
+ yield service_state.clear_exposed_flag()
+ exposed_flag = yield service_state.get_exposed_flag()
+ self.assertEqual(exposed_flag, False)
+
+ # Can be cleared multiple times
+ yield service_state.clear_exposed_flag()
+ exposed_flag = yield service_state.get_exposed_flag()
+ self.assertEqual(exposed_flag, False)
+
+ @inlineCallbacks
def test_watch_exposed_flag(self):
"""An exposed watch is setup on a permanent basis."""
service_state = yield self.add_service("wordpress")
@@ -2731,6 +2787,52 @@
{"port": 443, "proto": "tcp"}])
@inlineCallbacks
+ def test_get_open_ports_subordiate(self):
+ """Verify introspection and that the ports changes are immediate."""
+ service_states, relation_state, unit_states = (
+ yield self.setup_subordinate_defaults())
+ (u0, u1), (u2, u3) = unit_states
+ service_state = yield u1.get_service_state()
+ unit_state = u1
+
+ # verify no open ports before activity
+ self.assertEqual((yield unit_state.get_open_ports()), [])
+
+ # then open_port, close_port
+ yield unit_state.open_port(80, "tcp")
+ self.assertEqual(
+ (yield unit_state.get_open_ports()),
+ [{"port": 80, "proto": "tcp"}])
+
+ yield unit_state.open_port(53, "udp")
+ self.assertEqual(
+ (yield unit_state.get_open_ports()),
+ [{"port": 80, "proto": "tcp"},
+ {"port": 53, "proto": "udp"}])
+
+ yield unit_state.open_port(53, "tcp")
+ self.assertEqual(
+ (yield unit_state.get_open_ports()),
+ [{"port": 80, "proto": "tcp"},
+ {"port": 53, "proto": "udp"},
+ {"port": 53, "proto": "tcp"}])
+
+ yield unit_state.open_port(443, "tcp")
+ self.assertEqual(
+ (yield unit_state.get_open_ports()),
+ [{"port": 80, "proto": "tcp"},
+ {"port": 53, "proto": "udp"},
+ {"port": 53, "proto": "tcp"},
+ {"port": 443, "proto": "tcp"}])
+
+ yield unit_state.close_port(80, "tcp")
+ self.assertEqual(
+ (yield unit_state.get_open_ports()),
+ [{"port": 53, "proto": "udp"},
+ {"port": 53, "proto": "tcp"},
+ {"port": 443, "proto": "tcp"}])
+
+ @inlineCallbacks
def test_close_open_port(self):
"""Verify closing an unopened port, then actually opening it, works."""
service_state = yield self.add_service("wordpress")

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b