6
6
from juju.state.errors import (
7
7
JujuError, StateError, StateChanged, CharmStateNotFound,
8
8
ServiceStateNotFound, ServiceUnitStateNotFound,
9
MachineStateNotFound, MachineStateInUse, NoUnusedMachines,
9
MachineStateNotFound, MachineStateInUse, NoUnusedMachines,
10
10
ServiceUnitStateMachineAlreadyAssigned, ServiceStateNameInUse,
11
11
BadServiceStateName, EnvironmentStateNotFound,
12
12
RelationAlreadyExists, RelationStateNotFound, UnitRelationStateNotFound,
14
14
BadDescriptor, DuplicateEndpoints, IncompatibleEndpoints,
15
15
NoMatchingEndpoints, AmbiguousRelation,
16
16
ServiceUnitStateMachineNotAssigned, ServiceUnitDebugAlreadyEnabled,
17
ServiceUnitResolvedAlreadyEnabled,
17
ServiceUnitResolvedAlreadyEnabled, ServiceUnitUpgradeAlreadyEnabled,
18
18
ServiceUnitRelationResolvedAlreadyEnabled, PrincipalNotFound,
19
RelationBrokenContextError)
19
RelationBrokenContextError, PrincipalServiceUnitRequired,
20
NotSubordinateCharm, UnitMissingContainer, SubordinateUsedAsContainer,
21
InvalidRelationIdentity, UnsupportedSubordinateServiceRemoval,
22
IllegalSubordinateMachineAssignment)
22
25
class StateErrorsTest(TestCase):
101
104
"Service unit 'wordpress/0' is already in debug mode.")
106
def test_unit_already_marked_for_upgrade(self):
107
error = ServiceUnitUpgradeAlreadyEnabled("wordpress/0")
108
self.assertIsStateError(error)
109
self.assertEquals(error.unit_name, "wordpress/0")
112
"Service unit 'wordpress/0' is already marked for upgrade.")
103
114
def test_unit_already_in_resolved_mode(self):
104
115
error = ServiceUnitResolvedAlreadyEnabled("wordpress/0")
105
116
self.assertIsStateError(error)
220
231
error = RelationBrokenContextError("+++ OUT OF CHEESE ERROR +++")
221
232
self.assertIsStateError(error)
222
233
self.assertEquals(str(error), "+++ OUT OF CHEESE ERROR +++")
235
def test_unit_missing_container(self):
236
error = UnitMissingContainer("blubber/0")
237
self.assertIsStateError(error)
238
self.assertEquals(str(error),
239
"The unit blubber/0 expected a principal "
240
"container but none was assigned.")
242
def test_principal_service_unit_required(self):
243
error = PrincipalServiceUnitRequired("lard", 1)
244
self.assertIsStateError(error)
245
self.assertEquals(str(error),
246
"Expected principal service unit as container for "
247
"lard instance, got 1")
249
def test_subordinate_used_as_container(self):
250
error = SubordinateUsedAsContainer("lard", "blubber/0")
251
self.assertIsStateError(error)
252
self.assertEquals(str(error),
253
"Attempted to assign unit of lard "
254
"to subordinate blubber/0")
256
def test_not_subordinate_charm(self):
257
error = NotSubordinateCharm("lard", "blubber/0")
258
self.assertIsStateError(error)
259
self.assertEquals(str(error),
260
"lard cannot be used as subordinate to blubber/0")
262
def test_unsupported_subordinate_service_removal(self):
263
error = UnsupportedSubordinateServiceRemoval("lard", "blubber")
264
self.assertIsStateError(error)
265
self.assertEquals(str(error),
266
"Unsupported attempt to destroy subordinate "
267
"service 'lard' while principal service "
268
"'blubber' is related.")
270
def test_invalid_relation_ident(self):
271
error = InvalidRelationIdentity("invalid-id$forty-two")
272
self.assertTrue(isinstance(error, JujuError))
273
self.assertTrue(isinstance(error, ValueError))
276
"Not a valid relation id: 'invalid-id$forty-two'")
278
def test_illegal_subordinate_machine_assignment(self):
279
error = IllegalSubordinateMachineAssignment("blubber/1")
280
self.assertTrue(isinstance(error, JujuError))
283
"Unable to assign subordinate blubber/1 to machine.")