Esempio n. 1
0
func (*ManifoldSuite) TestNewWorkerError(c *gc.C) {
	expectFacade := struct{ lifeflag.Facade }{}
	expectEntity := names.NewMachineTag("33")
	context := dt.StubContext(nil, map[string]interface{}{
		"api-caller": struct{ base.APICaller }{},
	})
	manifold := lifeflag.Manifold(lifeflag.ManifoldConfig{
		APICallerName: "api-caller",
		Entity:        expectEntity,
		Result:        life.IsNotAlive,
		NewFacade: func(_ base.APICaller) (lifeflag.Facade, error) {
			return expectFacade, nil
		},
		NewWorker: func(config lifeflag.Config) (worker.Worker, error) {
			c.Check(config.Facade, gc.Equals, expectFacade)
			c.Check(config.Entity, gc.Equals, expectEntity)
			c.Check(config.Result, gc.NotNil) // uncomparable
			return nil, errors.New("boof")
		},
	})

	worker, err := manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "boof")
}
Esempio n. 2
0
func (s *ManifoldSuite) TestStartNewWorkerError(c *gc.C) {
	expectFacade := &fakeFacade{}
	manifold := singular.Manifold(singular.ManifoldConfig{
		ClockName:     "clock",
		APICallerName: "api-caller",
		AgentName:     "agent",
		Duration:      time.Minute,
		NewFacade: func(_ base.APICaller, _ names.MachineTag) (singular.Facade, error) {
			return expectFacade, nil
		},
		NewWorker: func(config singular.FlagConfig) (worker.Worker, error) {
			c.Check(config.Facade, gc.Equals, expectFacade)
			err := config.Validate()
			c.Check(err, jc.ErrorIsNil)
			return nil, errors.New("blomp tik")
		},
	})
	context := dt.StubContext(nil, map[string]interface{}{
		"clock":      &fakeClock{},
		"api-caller": &fakeAPICaller{},
		"agent":      &mockAgent{},
	})

	worker, err := manifold.Start(context)
	c.Check(err, gc.ErrorMatches, "blomp tik")
	c.Check(worker, gc.IsNil)
}
Esempio n. 3
0
func (s *ServingInfoSetterSuite) startManifold(c *gc.C, a coreagent.Agent, mockAPIPort int) {
	apiCaller := basetesting.APICallerFunc(
		func(objType string, version int, id, request string, args, response interface{}) error {
			c.Assert(objType, gc.Equals, "Agent")
			switch request {
			case "GetEntities":
				c.Assert(args.(params.Entities).Entities, gc.HasLen, 1)
				result := response.(*params.AgentGetEntitiesResults)
				result.Entities = []params.AgentGetEntitiesResult{{
					Jobs: []multiwatcher.MachineJob{multiwatcher.JobManageModel},
				}}
			case "StateServingInfo":
				result := response.(*params.StateServingInfo)
				*result = params.StateServingInfo{
					Cert:       "cert",
					PrivateKey: "key",
					APIPort:    mockAPIPort,
				}
			default:
				c.Fatalf("not sure how to handle: %q", request)
			}
			return nil
		},
	)
	context := dt.StubContext(nil, map[string]interface{}{
		"agent":      a,
		"api-caller": apiCaller,
	})
	w, err := s.manifold.Start(context)
	c.Assert(w, gc.IsNil)
	c.Assert(err, gc.Equals, dependency.ErrUninstall)
}
Esempio n. 4
0
func (s *ManifoldSuite) SetUpSuite(c *gc.C) {
	s.IsolationSuite.SetUpSuite(c)
	s.fakeAgent = &fakeAgent{tag: fakeTag}
	s.fakeCaller = &fakeCaller{}

	s.context = dt.StubContext(nil, map[string]interface{}{
		"wut":     s.fakeAgent,
		"exactly": s.fakeCaller,
	})

	s.newFacade = func(facade machineactions.Facade) func(base.APICaller) machineactions.Facade {
		s.fakeFacade = facade
		return func(apiCaller base.APICaller) machineactions.Facade {
			c.Assert(apiCaller, gc.Equals, s.fakeCaller)
			return facade
		}
	}
	s.newWorker = func(w worker.Worker, err error) func(machineactions.WorkerConfig) (worker.Worker, error) {
		s.fakeWorker = w
		return func(wc machineactions.WorkerConfig) (worker.Worker, error) {
			c.Assert(wc.Facade, gc.Equals, s.fakeFacade)
			c.Assert(wc.MachineTag, gc.Equals, fakeTag)
			c.Assert(wc.HandleAction, gc.Equals, fakeHandleAction)
			return w, err
		}
	}
}
Esempio n. 5
0
func (s *ServingInfoSetterSuite) checkNotController(c *gc.C, job multiwatcher.MachineJob) {
	a := &mockAgent{}
	apiCaller := basetesting.APICallerFunc(
		func(objType string, version int, id, request string, args, response interface{}) error {
			c.Assert(objType, gc.Equals, "Agent")
			switch request {
			case "GetEntities":
				c.Assert(args.(params.Entities).Entities, gc.HasLen, 1)
				result := response.(*params.AgentGetEntitiesResults)
				result.Entities = []params.AgentGetEntitiesResult{{
					Jobs: []multiwatcher.MachineJob{job},
				}}
			default:
				c.Fatalf("not sure how to handle: %q", request)
			}
			return nil
		},
	)
	w, err := s.manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"agent":      a,
		"api-caller": apiCaller,
	}))
	c.Assert(w, gc.IsNil)
	c.Assert(err, gc.Equals, dependency.ErrUninstall)

	// State serving info shouldn't have been set for this job type.
	c.Assert(a.conf.ssiSet, jc.IsFalse)
}
Esempio n. 6
0
func (s *ManifoldSuite) TestWorkerFuncMissing(c *gc.C) {
	s.config.WorkerFunc = nil
	context := dt.StubContext(nil, nil)
	worker, err := s.manifold().Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "missing WorkerFunc not valid")
}
Esempio n. 7
0
func (*ManifoldSuite) TestAgentEntity_Error(c *gc.C) {
	manifold := resumer.Manifold(resumer.ManifoldConfig{
		AgentName:     "agent",
		APICallerName: "api-caller",
	})

	stub := &testing.Stub{}
	stub.SetErrors(errors.New("zap"))
	apiCaller := &fakeAPICaller{stub: stub}
	worker, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"agent":      &fakeAgent{},
		"api-caller": apiCaller,
	}))
	workertest.CheckNilOrKill(c, worker)
	c.Check(err, gc.ErrorMatches, "zap")

	stub.CheckCalls(c, []testing.StubCall{{
		FuncName: "Agent.GetEntities",
		Args: []interface{}{params.Entities{
			Entities: []params.Entity{{
				Tag: "machine-123",
			}},
		}},
	}})
}
Esempio n. 8
0
// checkManifoldNotValid checks that the supplied ManifoldConfig creates
// a manifold that cannot be started.
func checkManifoldNotValid(c *gc.C, config migrationflag.ManifoldConfig, expect string) {
	manifold := migrationflag.Manifold(config)
	worker, err := manifold.Start(dt.StubContext(nil, nil))
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, expect)
	c.Check(err, jc.Satisfies, errors.IsNotValid)
}
Esempio n. 9
0
func (s *ManifoldSuite) TestNoAgent(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"agent": dependency.ErrMissing,
	})
	_, err := s.manifold.Start(context)
	c.Assert(err, gc.Equals, dependency.ErrMissing)
}
Esempio n. 10
0
func (s *APIWorkersSuite) TestStartNoStartAPIWorkers(c *gc.C) {
	manifold := machine.APIWorkersManifold(machine.APIWorkersConfig{})
	worker, err := manifold.Start(dt.StubContext(nil, nil))
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "StartAPIWorkers not specified")
	c.Check(s.startCalled, jc.IsFalse)
}
Esempio n. 11
0
func (*HousingSuite) TestOccupyLocked(c *gc.C) {
	manifold := util.Housing{
		Occupy: "fortress",
	}.Decorate(dependency.Manifold{})
	abort := make(chan struct{})
	context := dt.StubContext(abort, map[string]interface{}{
		"fortress": newGuest(false),
	})

	// start the start func
	started := make(chan struct{})
	go func() {
		defer close(started)
		worker, err := manifold.Start(context)
		c.Check(worker, gc.IsNil)
		c.Check(errors.Cause(err), gc.Equals, fortress.ErrAborted)
	}()

	// check it's blocked...
	select {
	case <-time.After(coretesting.ShortWait):
	case <-started:
		c.Errorf("Start finished early")
	}

	// ...until the context is aborted.
	close(abort)
	select {
	case <-started:
	case <-time.After(coretesting.LongWait):
		c.Fatalf("timed out")
	}
}
Esempio n. 12
0
func (s *ManifoldSuite) TestNewWorkerError(c *gc.C) {
	fakeClock := &fakeClock{}
	fakeFacade := &fakeFacade{}
	fakeAPICaller := &fakeAPICaller{}

	stub := testing.Stub{}
	manifold := charmrevisionmanifold.Manifold(charmrevisionmanifold.ManifoldConfig{
		APICallerName: "api-caller",
		ClockName:     "clock",
		NewFacade: func(apiCaller base.APICaller) (charmrevisionmanifold.Facade, error) {
			stub.AddCall("NewFacade", apiCaller)
			return fakeFacade, nil
		},
		NewWorker: func(config charmrevision.Config) (worker.Worker, error) {
			stub.AddCall("NewWorker", config)
			return nil, errors.New("snrght")
		},
	})

	_, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"api-caller": fakeAPICaller,
		"clock":      fakeClock,
	}))
	c.Check(err, gc.ErrorMatches, "cannot create worker: snrght")
	stub.CheckCalls(c, []testing.StubCall{{
		"NewFacade", []interface{}{fakeAPICaller},
	}, {
		"NewWorker", []interface{}{charmrevision.Config{
			RevisionUpdater: fakeFacade,
			Clock:           fakeClock,
		}},
	}})
}
Esempio n. 13
0
func (s *ManifoldSuite) SetUpSuite(c *gc.C) {
	s.IsolationSuite.SetUpSuite(c)
	s.fakeAgent = &fakeAgent{}
	s.fakeCaller = &fakeCaller{}
	s.context = dt.StubContext(nil, map[string]interface{}{
		"agent":      s.fakeAgent,
		"api-caller": s.fakeCaller,
	})
	s.newFacade = func(facade retrystrategy.Facade) func(base.APICaller) retrystrategy.Facade {
		s.fakeFacade = facade
		return func(apiCaller base.APICaller) retrystrategy.Facade {
			c.Assert(apiCaller, gc.Equals, s.fakeCaller)
			return facade
		}
	}
	s.newWorker = func(w worker.Worker, err error) func(retrystrategy.WorkerConfig) (worker.Worker, error) {
		s.fakeWorker = w
		return func(wc retrystrategy.WorkerConfig) (worker.Worker, error) {
			c.Assert(wc.Facade, gc.Equals, s.fakeFacade)
			c.Assert(wc.AgentTag, gc.Equals, fakeTag)
			c.Assert(wc.RetryStrategy, gc.Equals, fakeStrategy)
			return w, err
		}
	}
}
Esempio n. 14
0
func (s *ManifoldSuite) TestNewWorker_Error(c *gc.C) {
	clock := &fakeClock{}
	facade := &fakeFacade{}
	manifold := resumer.Manifold(resumer.ManifoldConfig{
		AgentName:     "agent",
		APICallerName: "api-caller",
		Clock:         clock,
		Interval:      time.Hour,
		NewFacade: func(base.APICaller) (resumer.Facade, error) {
			return facade, nil
		},
		NewWorker: func(actual resumer.Config) (worker.Worker, error) {
			c.Check(actual, jc.DeepEquals, resumer.Config{
				Facade:   facade,
				Clock:    clock,
				Interval: time.Hour,
			})
			return nil, errors.New("blam")
		},
	})

	worker, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"agent":      &fakeAgent{},
		"api-caller": newFakeAPICaller(multiwatcher.JobManageModel),
	}))
	workertest.CheckNilOrKill(c, worker)
	c.Check(err, gc.ErrorMatches, "blam")
}
Esempio n. 15
0
func (s *ServingInfoSetterSuite) TestEntityLookupFailure(c *gc.C) {
	// Set up a fake Agent and APICaller
	a := &mockAgent{}
	apiCaller := basetesting.APICallerFunc(
		func(objType string, version int, id, request string, args, response interface{}) error {
			c.Assert(objType, gc.Equals, "Agent")
			switch request {
			case "GetEntities":
				c.Assert(args.(params.Entities).Entities, gc.HasLen, 1)
				result := response.(*params.AgentGetEntitiesResults)
				result.Entities = []params.AgentGetEntitiesResult{{
					Error: &params.Error{Message: "boom"},
				}}
			default:
				c.Fatalf("not sure how to handle: %q", request)
			}
			return nil
		},
	)
	// Call the manifold's start func with a fake resource getter that
	// returns the fake Agent and APICaller
	context := dt.StubContext(nil, map[string]interface{}{
		"agent":      a,
		"api-caller": apiCaller,
	})
	w, err := s.manifold.Start(context)
	c.Assert(w, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, "checking controller status: boom")
}
Esempio n. 16
0
func (s *ManifoldSuite) TestStartMissingAgent(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"agent-name": dependency.ErrMissing,
	})
	worker, err := s.manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.Equals, dependency.ErrMissing)
}
Esempio n. 17
0
func (s *ManifoldSuite) TestStartClockMissing(c *gc.C) {
	manifold := leadership.Manifold(leadership.ManifoldConfig{})
	context := dt.StubContext(nil, nil)
	worker, err := manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err.Error(), gc.Equals, "missing Clock not valid")
	c.Check(err, jc.Satisfies, errors.IsNotValid)
}
Esempio n. 18
0
func (*manifoldSuite) TestWorkerError(c *gc.C) {
	manifold := makeManifold(nil, errors.New("boglodite"))
	result, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"the-caller":  apitesting.APICallerFunc(nil),
		"the-environ": &fakeEnviron{},
	}))
	c.Assert(result, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, "boglodite")
}
Esempio n. 19
0
func (*manifoldSuite) TestAPIError(c *gc.C) {
	manifold := makeManifold(nil, nil)
	result, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"the-caller":  &fakeAPICaller{},
		"the-environ": &fakeEnviron{},
	}))
	c.Assert(result, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, "machine undertaker client requires a model API connection")
}
Esempio n. 20
0
func (*manifoldSuite) TestMissingEnviron(c *gc.C) {
	manifold := makeManifold(nil, nil)
	result, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"the-caller":  &fakeAPICaller{},
		"the-environ": dependency.ErrMissing,
	}))
	c.Assert(result, gc.IsNil)
	c.Assert(errors.Cause(err), gc.Equals, dependency.ErrMissing)
}
Esempio n. 21
0
func (s *APIWorkersSuite) TestStartSuccess(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"api-caller": new(mockAPIConn),
	})
	worker, err := s.manifold.Start(context)
	c.Check(worker, gc.Not(gc.IsNil))
	c.Check(err, jc.ErrorIsNil)
	c.Check(s.startCalled, jc.IsTrue)
}
Esempio n. 22
0
func (s *ServingInfoSetterSuite) TestStartAPICallerMissing(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"agent":      &mockAgent{},
		"api-caller": dependency.ErrMissing,
	})
	worker, err := s.manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.Equals, dependency.ErrMissing)
}
Esempio n. 23
0
func (s *APIWorkersSuite) TestStartAPIMissing(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"api-caller": dependency.ErrMissing,
	})
	worker, err := s.manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.Equals, dependency.ErrMissing)
	c.Check(s.startCalled, jc.IsFalse)
}
Esempio n. 24
0
func (s *ManifoldSuite) TestStartMissingAPICaller(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"api-caller":   dependency.ErrMissing,
		"metric-spool": s.factory,
	})
	worker, err := s.manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, dependency.ErrMissing.Error())
}
Esempio n. 25
0
func (s *ManifoldSuite) TestStartAPICallerMissing(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"agent-name":      &dummyAgent{},
		"api-caller-name": dependency.ErrMissing,
	})

	worker, err := s.manifold().Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
}
Esempio n. 26
0
func (s *ManifoldSuite) TestMissingEnviron(c *gc.C) {
	manifold := s.makeManifold()
	w, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"agent":      struct{ agent.Agent }{},
		"api-caller": struct{ base.APICaller }{},
		"environ":    dependency.ErrMissing,
	}))
	c.Check(w, gc.IsNil)
	c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
}
Esempio n. 27
0
func (*manifoldSuite) TestSuccess(c *gc.C) {
	w := fakeWorker{name: "Boris"}
	manifold := makeManifold(&w, nil)
	result, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"the-caller":  apitesting.APICallerFunc(nil),
		"the-environ": &fakeEnviron{},
	}))
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, gc.DeepEquals, &w)
}
Esempio n. 28
0
func (*ManifoldSuite) TestStartMissingAPICaller(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"api-caller": dependency.ErrMissing,
	})
	manifold := migrationflag.Manifold(validManifoldConfig())

	worker, err := manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
}
Esempio n. 29
0
func (s *ManifoldSuite) TestStartError(c *gc.C) {
	s.startErr = errors.New("boom")
	context := dt.StubContext(nil, map[string]interface{}{
		"agent-name":      &dummyAgent{},
		"api-caller-name": &dummyApiCaller{},
	})

	worker, err := s.manifold().Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "boom")
}
Esempio n. 30
0
func (*FlagSuite) TestManifoldStartGateMissing(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"some-gate": dependency.ErrMissing,
	})
	manifold := gate.FlagManifold(gate.FlagManifoldConfig{
		GateName: "some-gate",
	})
	worker, err := manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
}