func (s *MachineSuite) waitProvisioned(c *gc.C, unit *state.Unit) (*state.Machine, instance.Id) { c.Logf("waiting for unit %q to be provisioned", unit) machineId, err := unit.AssignedMachineId() c.Assert(err, gc.IsNil) m, err := s.State.Machine(machineId) c.Assert(err, gc.IsNil) w := m.Watch() defer w.Stop() timeout := time.After(coretesting.LongWait) for { select { case <-timeout: c.Fatalf("timed out waiting for provisioning") case _, ok := <-w.Changes(): c.Assert(ok, jc.IsTrue) err := m.Refresh() c.Assert(err, gc.IsNil) if instId, err := m.InstanceId(); err == nil { c.Logf("unit provisioned with instance %s", instId) return m, instId } else { c.Check(err, jc.Satisfies, state.IsNotProvisionedError) } } } panic("watcher died") }
func waitForUnitStarted(stateConn *state.State, unit *state.Unit, c *gc.C) { timeout := time.After(5 * time.Second) for { select { case <-timeout: c.Fatalf("no activity detected") case <-time.After(coretesting.ShortWait): err := unit.Refresh() c.Assert(err, gc.IsNil) st, info, data, err := unit.Status() c.Assert(err, gc.IsNil) switch st { case params.StatusPending, params.StatusInstalled: c.Logf("waiting...") continue case params.StatusStarted: c.Logf("started!") return case params.StatusDown: stateConn.StartSync() c.Logf("unit is still down") default: c.Fatalf("unexpected status %s %s %v", st, info, data) } } } }
func (s *UnitSuite) newAgent(c *gc.C, unit *state.Unit) *UnitAgent { a := &UnitAgent{} s.initAgent(c, a, "--unit-name", unit.Name()) err := a.ReadConfig(unit.Tag()) c.Assert(err, gc.IsNil) return a }
func (s *FilterSuite) APILogin(c *gc.C, unit *state.Unit) { password, err := utils.RandomPassword() c.Assert(err, gc.IsNil) err = unit.SetPassword(password) c.Assert(err, gc.IsNil) s.st = s.OpenAPIAs(c, unit.Tag(), password) s.uniter = s.st.Uniter() c.Assert(s.uniter, gc.NotNil) }
func newUnitToolWaiter(u *state.Unit) *toolsWaiter { w := u.Watch() waiter := &toolsWaiter{ changes: make(chan struct{}, 1), watcher: w, tooler: u, } go func() { for _ = range w.Changes() { waiter.changes <- struct{}{} } close(waiter.changes) }() return waiter }