func (s *upgradeStateContextSuite) initializeContext(c *gc.C, utag names.UnitTag) { paths := uniter.NewPaths(s.datadir, utag) s.uniterStateFile = paths.State.OperationsFile s.statefile = operation.NewStateFile(s.uniterStateFile) c.Assert(os.MkdirAll(filepath.Dir(s.uniterStateFile), 0755), gc.IsNil) s.unitTag = utag }
func newExecutor(c *gc.C, st *operation.State) (operation.Executor, string) { path := filepath.Join(c.MkDir(), "state") err := operation.NewStateFile(path).Write(st) c.Assert(err, jc.ErrorIsNil) executor, err := operation.NewExecutor(path, failGetInstallCharm, failAcquireLock) c.Assert(err, jc.ErrorIsNil) return executor, path }
func performUpgrade(opsFile string, state *operation.State) error { statefile := operation.NewStateFile(opsFile) if state.Kind == operation.Continue && state.Hook != nil && state.Hook.Kind == hooks.Stop { state.Stopped = true state.Hook = nil return statefile.Write(state) } return nil }
func (s *ExecutorSuite) initLockTest(c *gc.C, lockFunc func() (mutex.Releaser, error)) operation.Executor { initialState := justInstalledState() statePath := filepath.Join(c.MkDir(), "state") err := operation.NewStateFile(statePath).Write(&initialState) c.Assert(err, jc.ErrorIsNil) executor, err := operation.NewExecutor(statePath, failGetInstallCharm, lockFunc) c.Assert(err, jc.ErrorIsNil) return executor }
func addInstalled(opsFile string, state *operation.State) error { statefile := operation.NewStateFile(opsFile) if state.Kind == operation.Install { return nil } if state.Kind == operation.RunHook && state.Hook.Kind == hooks.Install { return nil } if !state.Installed { state.Installed = true return statefile.Write(state) } return nil }
func (s *StateFileSuite) TestStates(c *gc.C) { for i, t := range stateTests { c.Logf("test %d", i) path := filepath.Join(c.MkDir(), "uniter") file := operation.NewStateFile(path) _, err := file.Read() c.Assert(err, gc.Equals, operation.ErrNoStateFile) err = file.Write(&t.st) if t.err == "" { c.Assert(err, jc.ErrorIsNil) } else { c.Assert(err, gc.ErrorMatches, "invalid operation state: "+t.err) err := utils.WriteYaml(path, &t.st) c.Assert(err, jc.ErrorIsNil) _, err = file.Read() c.Assert(err, gc.ErrorMatches, `cannot read ".*": invalid operation state: `+t.err) continue } st, err := file.Read() c.Assert(err, jc.ErrorIsNil) c.Assert(st, jc.DeepEquals, &t.st) } }
func assertWroteState(c *gc.C, path string, expect operation.State) { actual, err := operation.NewStateFile(path).Read() c.Assert(err, jc.ErrorIsNil) c.Assert(*actual, gc.DeepEquals, expect) }