예제 #1
0
파일: machine_test.go 프로젝트: kapilt/juju
func (s *MachineSuite) TestMachineAgentRunsSafeNetworkerWhenNetworkManagementIsDisabled(c *gc.C) {
	attrs := coretesting.Attrs{"disable-network-management": true}
	err := s.BackingState.UpdateEnvironConfig(attrs, nil, nil)
	c.Assert(err, gc.IsNil)

	started := make(chan struct{}, 1)
	nonSafeStarted := make(chan struct{}, 1)
	s.agentSuite.PatchValue(&newSafeNetworker, func(st *apinetworker.State, conf agent.Config, confDir string) (*networker.Networker, error) {
		select {
		case started <- struct{}{}:
		default:
		}
		return networker.NewSafeNetworker(st, conf, confDir)
	})
	s.agentSuite.PatchValue(&newNetworker, func(st *apinetworker.State, conf agent.Config, confDir string) (*networker.Networker, error) {
		select {
		case nonSafeStarted <- struct{}{}:
		default:
		}
		return networker.NewNetworker(st, conf, confDir)
	})
	m, _, _ := s.primeAgent(c, version.Current, state.JobHostUnits)
	a := s.newAgent(c, m)
	defer a.Stop()
	go func() {
		c.Check(a.Run(nil), gc.IsNil)
	}()
	select {
	case <-started:
	case <-nonSafeStarted:
		c.Fatalf("expected to start safe networker, but started a normal one")
	case <-time.After(coretesting.LongWait):
		c.Fatalf("timed out waiting for the safe networker worker to be started")
	}
}
예제 #2
0
func (s *networkerSuite) newCustomNetworker(c *gc.C, facade *apinetworker.State, machineId string, canWriteConfig, initInterfaces bool) (*networker.Networker, string) {

	if initInterfaces {
		s.upInterfaces = set.NewStrings("lo", "eth0")
		s.interfacesWithAddress = set.NewStrings("lo", "eth0")
	}
	s.lastCommands = make(chan []string)
	s.vlanModuleLoaded = false
	configDir := c.MkDir()

	var nw *networker.Networker
	var err error
	if canWriteConfig {
		nw, err = networker.NewNetworker(facade, agentConfig(machineId), configDir)
	} else {
		nw, err = networker.NewSafeNetworker(facade, agentConfig(machineId), configDir)
	}
	c.Assert(err, gc.IsNil)
	c.Assert(nw, gc.NotNil)

	return nw, configDir
}