func unitMatchExposure(u *state.Unit, patterns []string) (bool, bool, error) { s, err := u.Service() if err != nil { return false, false, err } return matchExposure(patterns, s) }
func (s *AssignSuite) assertAssignedUnit(c *gc.C, unit *state.Unit) string { // Get service networks. service, err := unit.Service() c.Assert(err, jc.ErrorIsNil) serviceNetworks, err := service.Networks() c.Assert(err, jc.ErrorIsNil) serviceCons, err := service.Constraints() c.Assert(err, jc.ErrorIsNil) // Check the machine on the unit is set. machineId, err := unit.AssignedMachineId() c.Assert(err, jc.ErrorIsNil) // Check that the principal is set on the machine. machine, err := s.State.Machine(machineId) c.Assert(err, jc.ErrorIsNil) machineCons, err := machine.Constraints() c.Assert(err, jc.ErrorIsNil) machineNetworks, err := machine.RequestedNetworks() c.Assert(err, jc.ErrorIsNil) c.Assert(machineNetworks, gc.DeepEquals, serviceNetworks) c.Assert(serviceCons.IncludeNetworks(), gc.DeepEquals, machineCons.IncludeNetworks()) c.Assert(serviceCons.ExcludeNetworks(), gc.DeepEquals, machineCons.ExcludeNetworks()) machineUnits, err := machine.Units() c.Assert(err, jc.ErrorIsNil) c.Assert(machineUnits, gc.HasLen, 1) // Make sure it is the right unit. c.Assert(machineUnits[0].Name(), gc.Equals, unit.Name()) return machineId }