@@ -214,3 +214,33 @@ async def test_resolve_local(event_loop):
214214 # Errored units won't get cleaned up unless we force them.
215215 await asyncio .gather (* (machine .destroy (force = True )
216216 for machine in model .machines .values ()))
217+
218+
219+ @base .bootstrapped
220+ @pytest .mark .asyncio
221+ async def test_subordinate_units (event_loop ):
222+ async with base .CleanModel () as model :
223+ u_app = await model .deploy ('ubuntu' )
224+ n_app = await model .deploy ('ntp' )
225+ await model .relate ('ubuntu' , 'ntp' )
226+ await model .wait_for_idle ()
227+
228+ # model subordinates
229+ model_subs = model .subordinate_units
230+ assert len (model_subs ) == 1
231+ assert 'ntp/0' in model_subs
232+ assert 'ubuntu/0' not in model_subs
233+
234+ n_unit = model_subs ['ntp/0' ]
235+ u_unit = u_app .units [0 ]
236+
237+ # application subordinates
238+ app_sub_names = [u .name for u in n_app .subordinate_units ]
239+ assert n_unit .name in app_sub_names
240+ assert u_unit .name not in app_sub_names
241+
242+ assert n_unit .is_subordinate
243+ assert not u_unit .is_subordinate
244+ assert n_unit .principal_unit == 'ubuntu/0'
245+ assert u_unit .principal_unit == ''
246+ assert [u .name for u in u_unit .get_subordinates ()] == [n_unit .name ]
0 commit comments