Example #1
0
// Manifold returns a dependency manifold that runs a logger
// worker, using the resource names defined in the supplied config.
func Manifold(config ManifoldConfig) dependency.Manifold {

	newWorker := func(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
		return New(config.LogSource, logsender.NewAPI(apiCaller)), nil
	}

	return util.PostUpgradeManifold(config.PostUpgradeManifoldConfig, newWorker)
}
Example #2
0
func (s *PostUpgradeManifoldSuite) SetUpTest(c *gc.C) {
	s.IsolationSuite.SetUpTest(c)
	s.Stub = testing.Stub{}
	s.worker = &dummyWorker{}
	s.manifold = util.PostUpgradeManifold(util.PostUpgradeManifoldConfig{
		AgentName:         "agent-name",
		APICallerName:     "api-caller-name",
		UpgradeWaiterName: "upgradewaiter-name",
	}, s.newWorker)
}
Example #3
0
// Manifold returns a dependency manifold that runs a deployer worker,
// using the resource names defined in the supplied config.
func Manifold(config ManifoldConfig) dependency.Manifold {

	// newWorker trivially wraps NewDeployer for use in a util.PostUpgradeManifold.
	//
	// It's not tested at the moment, because the scaffolding
	// necessary is too unwieldy/distracting to introduce at this point.
	newWorker := func(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
		cfg := a.CurrentConfig()
		// Grab the tag and ensure that it's for a machine.
		tag, ok := cfg.Tag().(names.MachineTag)
		if !ok {
			return nil, errors.New("agent's tag is not a machine tag")
		}

		// Get the machine agent's jobs.
		// TODO(fwereade): this functionality should be on the
		// deployer facade instead.
		agentFacade := apiagent.NewState(apiCaller)
		entity, err := agentFacade.Entity(tag)
		if err != nil {
			return nil, err
		}

		var isUnitHoster bool
		for _, job := range entity.Jobs() {
			if job == multiwatcher.JobHostUnits {
				isUnitHoster = true
				break
			}
		}

		if !isUnitHoster {
			return nil, dependency.ErrUninstall
		}

		deployerFacade := apideployer.NewState(apiCaller)
		context := config.NewDeployContext(deployerFacade, cfg)
		w, err := NewDeployer(deployerFacade, context)
		if err != nil {
			return nil, errors.Annotate(err, "cannot start unit agent deployer worker")
		}
		return w, nil
	}

	return util.PostUpgradeManifold(config.PostUpgradeManifoldConfig, newWorker)
}
Example #4
0
// Manifold returns a dependency manifold that runs a machiner worker, using
// the resource names defined in the supplied config.
func Manifold(config ManifoldConfig) dependency.Manifold {

	// TODO(waigani) This function is currently covered by functional tests
	// under the machine agent. Add unit tests once infrastructure to do so is
	// in place.

	// newWorker non-trivially wraps NewMachiner to specialise a PostUpgradeManifold.
	var newWorker = func(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
		currentConfig := a.CurrentConfig()

		// TODO(fwereade): this functionality should be on the
		// deployer facade instead.
		agentFacade := apiagent.NewState(apiCaller)
		envConfig, err := agentFacade.ModelConfig()
		if err != nil {
			return nil, errors.Errorf("cannot read environment config: %v", err)
		}

		ignoreMachineAddresses, _ := envConfig.IgnoreMachineAddresses()
		// Containers only have machine addresses, so we can't ignore them.
		tag := currentConfig.Tag()
		if names.IsContainerMachine(tag.Id()) {
			ignoreMachineAddresses = false
		}
		if ignoreMachineAddresses {
			logger.Infof("machine addresses not used, only addresses from provider")
		}
		accessor := APIMachineAccessor{apimachiner.NewState(apiCaller)}
		w, err := NewMachiner(Config{
			MachineAccessor: accessor,
			Tag:             tag.(names.MachineTag),
			ClearMachineAddressesOnStart: ignoreMachineAddresses,
			NotifyMachineDead: func() error {
				return agent.SetCanUninstall(a)
			},
		})
		if err != nil {
			return nil, errors.Annotate(err, "cannot start machiner worker")
		}
		return w, err
	}

	return util.PostUpgradeManifold(config.PostUpgradeManifoldConfig, newWorker)
}
Example #5
0
func (s *PostUpgradeManifoldSuite) TestUpgradeWaitNotRequired(c *gc.C) {
	manifold := util.PostUpgradeManifold(util.PostUpgradeManifoldConfig{
		AgentName:         "agent-name",
		APICallerName:     "api-caller-name",
		UpgradeWaiterName: util.UpgradeWaitNotRequired,
	}, s.newWorker)

	c.Check(manifold.Inputs, jc.DeepEquals, []string{"agent-name", "api-caller-name"})

	expectAgent := &dummyAgent{}
	expectApiCaller := &dummyApiCaller{}
	getResource := dt.StubGetResource(dt.StubResources{
		"agent-name":      dt.StubResource{Output: expectAgent},
		"api-caller-name": dt.StubResource{Output: expectApiCaller},
	})
	worker, err := manifold.Start(getResource)
	c.Check(err, jc.ErrorIsNil)
	c.Check(worker, gc.Equals, s.worker)
	s.CheckCalls(c, []testing.StubCall{{
		FuncName: "newWorker",
		Args:     []interface{}{expectAgent, expectApiCaller},
	}})
}
Example #6
0
// MachineManifold returns a dependency.Manifold that runs a storage provisioner.
func MachineManifold(config MachineManifoldConfig) dependency.Manifold {
	newWorker := func(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
		if config.Clock == nil {
			return nil, dependency.ErrMissing
		}

		cfg := a.CurrentConfig()
		api, err := storageprovisioner.NewState(apiCaller, cfg.Tag())
		if err != nil {
			return nil, errors.Trace(err)
		}

		tag, ok := cfg.Tag().(names.MachineTag)
		if !ok {
			return nil, errors.Errorf("this manifold may only be used inside a machine agent")
		}

		storageDir := filepath.Join(cfg.DataDir(), "storage")
		w, err := NewStorageProvisioner(Config{
			Scope:       tag,
			StorageDir:  storageDir,
			Volumes:     api,
			Filesystems: api,
			Life:        api,
			Environ:     api,
			Machines:    api,
			Status:      api,
			Clock:       config.Clock,
		})
		if err != nil {
			return nil, errors.Trace(err)
		}
		return w, nil
	}

	return util.PostUpgradeManifold(config.PostUpgradeManifoldConfig, newWorker)
}
Example #7
0
// Manifold returns a dependency manifold that runs a logger
// worker, using the resource names defined in the supplied config.
func Manifold(config ManifoldConfig) dependency.Manifold {
	return util.PostUpgradeManifold(util.PostUpgradeManifoldConfig(config), newWorker)
}