Beispiel #1
0
func (s *syncToolsSuite) SetUpTest(c *C) {
	s.LoggingSuite.SetUpTest(c)
	s.origVersion = version.Current
	// It's important that this be v1 to match the test data.
	version.Current.Number = version.MustParse("1.2.3")

	// Create a target environments.yaml and make sure its environment is empty.
	s.home = testing.MakeFakeHome(c, `
environments:
    test-target:
        type: dummy
        state-server: false
        authorized-keys: "not-really-one"
`)
	var err error
	s.targetEnv, err = environs.NewFromName("test-target")
	c.Assert(err, IsNil)
	envtesting.RemoveAllTools(c, s.targetEnv)

	// Create a source storage.
	s.storage, err = envtesting.NewEC2HTTPTestStorage("127.0.0.1")
	c.Assert(err, IsNil)

	// Create a local tools directory.
	s.localStorage = c.MkDir()

	// Populate both with the public tools.
	for _, vers := range vAll {
		s.storage.PutBinary(vers)
		putBinary(c, s.localStorage, vers)
	}

	s.origLocation = defaultToolsLocation
	defaultToolsLocation = s.storage.Location()
}
Beispiel #2
0
// makeEmptyFakeHome creates a faked home without tools.
func makeEmptyFakeHome(c *gc.C) (environs.Environ, *coretesting.FakeHome) {
	fake := coretesting.MakeFakeHome(c, envConfig)
	dummy.Reset()
	env, err := environs.NewFromName("peckham")
	c.Assert(err, gc.IsNil)
	envtesting.RemoveAllTools(c, env)
	return env, fake
}
Beispiel #3
0
func (s *syncToolsSuite) SetUpTest(c *gc.C) {
	s.LoggingSuite.SetUpTest(c)

	// Create a target environments.yaml and make sure its environment is empty.
	s.home = coretesting.MakeFakeHome(c, `
environments:
    test-target:
        type: dummy
        state-server: false
        authorized-keys: "not-really-one"
`)
	var err error
	s.targetEnv, err = environs.NewFromName("test-target")
	c.Assert(err, gc.IsNil)
	envtesting.RemoveAllTools(c, s.targetEnv)
	s.origSyncTools = syncTools
}
Beispiel #4
0
func (s *ToolsSuite) Reset(c *C, attrs map[string]interface{}) {
	version.Current = s.origCurrentVersion
	dummy.Reset()
	final := map[string]interface{}{
		"name":            "test",
		"type":            "dummy",
		"state-server":    false,
		"authorized-keys": "i-am-a-key",
		"ca-cert":         testing.CACert,
		"ca-private-key":  "",
	}
	for k, v := range attrs {
		final[k] = v
	}
	env, err := environs.NewFromAttrs(final)
	c.Assert(err, IsNil)
	s.env = env
	envtesting.RemoveAllTools(c, s.env)
}
Beispiel #5
0
func (s *UpgraderSuite) TestUpgrader(c *C) {
	for i, test := range upgraderTests {
		c.Logf("\ntest %d: %s", i, test.about)
		// Note: primeTools sets version.Current...
		currentTools := s.primeTools(c, test.current)
		// ...but it also puts tools in storage we don't need, which is why we
		// don't clean up garbage from earlier runs first.
		envtesting.RemoveAllTools(c, s.Conn.Environ)
		uploaded := make(map[version.Binary]*state.Tools)
		for _, vers := range test.available {
			tools := s.uploadTools(c, vers)
			uploaded[vers] = tools
		}

		func() {
			u := s.startUpgrader(c, currentTools)
			defer u.Stop()
			s.proposeVersion(c, test.propose)
			s.State.StartSync()
			if test.upgrade.Number == version.Zero {
				assertNothingHappens(c, u)
				c.Assert(u.Stop(), IsNil)
				return
			}

			ug := waitDeath(c, u)
			tools := uploaded[test.upgrade]
			c.Check(ug.NewTools, DeepEquals, tools)
			c.Check(ug.OldTools.Binary, Equals, version.Current)
			c.Check(ug.DataDir, Equals, s.DataDir())
			c.Check(ug.AgentName, Equals, "testagent")

			// Check that the upgraded version was really downloaded.
			path := agent.SharedToolsDir(s.DataDir(), tools.Binary)
			data, err := ioutil.ReadFile(filepath.Join(path, "jujud"))
			c.Check(err, IsNil)
			c.Check(string(data), Equals, "jujud contents "+tools.Binary.String())
		}()
	}
}
Beispiel #6
0
func (s *UpgraderSuite) TestStillWorksAfterBadVersions(c *C) {
	currentTools := s.primeTools(c, t200p64)
	envtesting.RemoveAllTools(c, s.Conn.Environ)
	u := s.startUpgrader(c, currentTools)
	defer u.Stop()

	// Propose a missing version
	s.proposeVersion(c, v2144)
	s.State.StartSync()
	assertNothingHappens(c, u)

	// Propose an incompatible version
	s.proposeVersion(c, v300)
	s.State.StartSync()
	assertNothingHappens(c, u)

	// Propose a working version
	newTools := s.uploadTools(c, t2144p64)
	s.proposeVersion(c, v2144)
	s.State.StartSync()
	ug := waitDeath(c, u)
	c.Assert(ug.NewTools, DeepEquals, newTools)
}
func (test bootstrapTest) run(c *C) {
	defer testing.MakeFakeHome(c, envConfig).Restore()
	dummy.Reset()
	env, err := environs.NewFromName("peckham")
	c.Assert(err, IsNil)
	envtesting.RemoveAllTools(c, env)

	if test.version != "" {
		origVersion := version.Current
		version.Current = version.MustParseBinary(test.version)
		defer func() { version.Current = origVersion }()
	}
	uploadCount := len(test.uploads)
	if uploadCount == 0 {
		usefulVersion := version.Current
		usefulVersion.Series = env.Config().DefaultSeries()
		envtesting.UploadFakeToolsVersion(c, env.Storage(), usefulVersion)
	}

	// Run command and check for uploads.
	opc, errc := runCommand(new(BootstrapCommand), test.args...)
	if uploadCount > 0 {
		for i := 0; i < uploadCount; i++ {
			c.Check((<-opc).(dummy.OpPutFile).Env, Equals, "peckham")
		}
		list, err := environs.FindAvailableTools(env, version.Current.Major)
		c.Check(err, IsNil)
		c.Logf("found: " + list.String())
		urls := list.URLs()
		c.Check(urls, HasLen, len(test.uploads))
		for _, v := range test.uploads {
			c.Logf("seeking: " + v)
			vers := version.MustParseBinary(v)
			_, found := urls[vers]
			c.Check(found, Equals, true)
		}
	}

	// Check for remaining operations/errors.
	if test.err != "" {
		c.Check(<-errc, ErrorMatches, test.err)
		return
	}
	if !c.Check(<-errc, IsNil) {
		return
	}
	opPutBootstrapVerifyFile := (<-opc).(dummy.OpPutFile)
	c.Check(opPutBootstrapVerifyFile.Env, Equals, "peckham")
	c.Check(opPutBootstrapVerifyFile.FileName, Equals, "bootstrap-verify")

	opBootstrap := (<-opc).(dummy.OpBootstrap)
	c.Check(opBootstrap.Env, Equals, "peckham")
	c.Check(opBootstrap.Constraints, DeepEquals, test.constraints)

	// Check a CA cert/key was generated by reloading the environment.
	env, err = environs.NewFromName("peckham")
	c.Assert(err, IsNil)
	_, hasCert := env.Config().CACert()
	c.Check(hasCert, Equals, true)
	_, hasKey := env.Config().CAPrivateKey()
	c.Check(hasKey, Equals, true)
}