Ubuntu Pastebin

Paste from TheMue at Mon, 17 Aug 2015 16:05:50 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
func (s *MachineSuite) TestMachineAgentDoesNotStartAddresser(c *gc.C) {
	// Patch addresser worker constructor.
	started := make(chan struct{})
	newTestAddresser := func(api *apiaddresser.API) (worker.Worker, error) {
		close(started)
		return worker.NewNoOpWorker(), nil
	}
	s.PatchValue(&newAddresser, newTestAddresser)

	// Patch environment to use mock.
	config := mockTestingEnvConfig(c)

	// Start the machine agent.
	m, _, _ := s.primeAgent(c, version.Current, state.JobHostUnits)
	a := s.newAgent(c, m)
	go func() { c.Check(a.Run(nil), jc.ErrorIsNil) }()
	defer func() { c.Check(a.Stop(), jc.ErrorIsNil) }()

	// Ensure the worker is not started.
	select {
	case <-started:
		c.Fatalf("addresser worker unexpectedly started")
	case <-time.After(coretesting.ShortWait):
	}
}

// mockTestingEnvConfig prepares an environment configuration using
// the mock provider which does not support networking.
func mockTestingEnvConfig(c *gc.C) *config.Config {
	environs.RegisterProvider("mock", mockEnvironProvider{})
	cfg, err := config.New(config.NoDefaults, mockConfig())
	c.Assert(err, jc.ErrorIsNil)
	env, err := environs.Prepare(cfg, envcmd.BootstrapContext(coretesting.Context(c)), configstore.NewMem())
	c.Assert(err, jc.ErrorIsNil)
	return env.Config()
}

// mockConfig returns a configuration for the usage of the
// mock provider below.
func mockConfig() coretesting.Attrs {
	return dummy.SampleConfig().Merge(coretesting.Attrs{
		"type": "mock",
	})
}

// mockEnviron is an environment without networking support.
type mockEnviron struct {
	environs.Environ
}

func (e mockEnviron) Config() *config.Config {
	cfg, err := config.New(config.NoDefaults, mockConfig())
	if err != nil {
		panic("invalid configuration for testing")
	}
	return cfg
}

// mockEnvironProvider is the smallest possible provider to
// test the addresses without networking support.
type mockEnvironProvider struct {
	environs.EnvironProvider
}

func (p mockEnvironProvider) PrepareForBootstrap(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) {
	return &mockEnviron{}, nil
}

func (p mockEnvironProvider) Open(*config.Config) (environs.Environ, error) {
	return &mockEnviron{}, nil
}
Download as text