Exemplo n.º 1
0
func (s *HookContextSuite) getHookContext(c *gc.C, uuid string, relid int,
	remote string, proxies proxy.Settings) *runner.HookContext {
	if relid != -1 {
		_, found := s.apiRelunits[relid]
		c.Assert(found, jc.IsTrue)
	}
	facade, err := s.st.Uniter()
	c.Assert(err, jc.ErrorIsNil)

	relctxs := map[int]*runner.ContextRelation{}
	for relId, relUnit := range s.apiRelunits {
		cache := runner.NewRelationCache(relUnit.ReadSettings, nil)
		relctxs[relId] = runner.NewContextRelation(relUnit, cache)
	}

	env, err := s.State.Environment()
	c.Assert(err, jc.ErrorIsNil)

	context, err := runner.NewHookContext(s.apiUnit, facade, "TestCtx", uuid,
		env.Name(), relid, remote, relctxs, apiAddrs,
		proxies, false, nil, nil, s.machine.Tag().(names.MachineTag),
		NewRealPaths(c))
	c.Assert(err, jc.ErrorIsNil)
	return context
}
Exemplo n.º 2
0
func (s *HookContextSuite) getMeteredHookContext(c *gc.C, uuid string, relid int,
	remote string, proxies proxy.Settings, canAddMetrics bool, metrics *charm.Metrics, paths RealPaths) *runner.HookContext {
	if relid != -1 {
		_, found := s.apiRelunits[relid]
		c.Assert(found, jc.IsTrue)
	}
	facade, err := s.st.Uniter()
	c.Assert(err, jc.ErrorIsNil)

	relctxs := map[int]*runner.ContextRelation{}
	for relId, relUnit := range s.apiRelunits {
		cache := runner.NewRelationCache(relUnit.ReadSettings, nil)
		relctxs[relId] = runner.NewContextRelation(relUnit, cache)
	}

	context, err := runner.NewHookContext(s.meteredApiUnit, facade, "TestCtx", uuid,
		"test-env-name", relid, remote, relctxs, apiAddrs, names.NewUserTag("owner"),
		proxies, canAddMetrics, metrics, nil, s.machine.Tag().(names.MachineTag), paths)
	c.Assert(err, jc.ErrorIsNil)
	return context
}