Exemple #1
0
func waitChange(chg *state.Change) error {
	select {
	case <-chg.Ready():
	}
	// TODO case <-daemon.Dying():
	st := chg.State()
	st.Lock()
	defer st.Unlock()
	return chg.Err()
}
Exemple #2
0
func installSnap(chg *state.Change, name, channel string, userID int, flags snappy.InstallFlags) error {
	st := chg.State()
	ts, err := snapstateInstall(st, name, channel, userID, flags)
	if err != nil {
		return err
	}

	// ensure that each of our task runs after the existing tasks
	chgts := state.NewTaskSet(chg.Tasks()...)
	for _, t := range ts.Tasks() {
		t.WaitAll(chgts)
	}
	chg.AddAll(ts)

	return nil
}
Exemple #3
0
func ensureUbuntuCore(chg *state.Change, userID int) error {
	var ss snapstate.SnapState

	ubuntuCore := "ubuntu-core"
	err := snapstateGet(chg.State(), ubuntuCore, &ss)
	if err != state.ErrNoState {
		return err
	}

	// FIXME: workaround because we are not fully state based yet
	installed, err := (&snappy.Overlord{}).Installed()
	snaps := snappy.FindSnapsByName(ubuntuCore, installed)
	if len(snaps) > 0 {
		return nil
	}

	return installSnap(chg, ubuntuCore, "stable", userID, 0)
}
Exemple #4
0
func ensureChange(c *C, r *state.TaskRunner, sb *stateBackend, chg *state.Change) {
	for i := 0; i < 10; i++ {
		sb.ensureBefore = time.Hour
		r.Ensure()
		r.Wait()
		chg.State().Lock()
		s := chg.Status()
		chg.State().Unlock()
		if s.Ready() {
			return
		}
		if sb.ensureBefore > 0 {
			break
		}
	}
	var statuses []string
	chg.State().Lock()
	for _, t := range chg.Tasks() {
		statuses = append(statuses, t.Summary()+":"+t.Status().String())
	}
	chg.State().Unlock()
	c.Fatalf("Change didn't reach final state without blocking: %s", strings.Join(statuses, " "))
}