예제 #1
0
func (s *cacheFileInterfaceSuite) TestMigrateJENV(c *gc.C) {
	modelUUID := testing.ModelTag.Id()
	info := s.writeEnv(c, "testing", modelUUID, "", "tester", "secret")
	envDir := filepath.Join(s.dir, "models")
	jenvFilename := configstore.JENVFilename(envDir, "testing")
	c.Assert(info.Location(), gc.Equals, fmt.Sprintf("file %q", jenvFilename))

	// Add server details and write again will migrate the info to the
	// cache file.
	endpoint := info.APIEndpoint()
	endpoint.ServerUUID = modelUUID
	info.SetAPIEndpoint(endpoint)
	err := info.Write()
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(jenvFilename, jc.DoesNotExist)
	cache := s.readCacheFile(c)

	envInfo, ok := cache.Environment["testing"]
	c.Assert(ok, jc.IsTrue)
	c.Assert(envInfo.User, gc.Equals, "tester")
	c.Assert(envInfo.ModelUUID, gc.Equals, modelUUID)
	c.Assert(envInfo.ServerUUID, gc.Equals, modelUUID)
	// Server entry also written.
	srvInfo, ok := cache.Server["testing"]
	c.Assert(ok, jc.IsTrue)
	c.Assert(srvInfo.User, gc.Equals, "tester")
	c.Assert(srvInfo.ServerUUID, gc.Equals, modelUUID)

	readInfo, err := s.store.ReadInfo("testing")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(readInfo.APIEndpoint(), jc.DeepEquals, info.APIEndpoint())
}
예제 #2
0
func (s *cacheFileInterfaceSuite) TestList(c *gc.C) {
	// List returns both JENV environments and the cache file environments.
	s.writeEnv(c, "jenv-1", "fake-uuid1", "", "tester", "secret")
	s.writeEnv(c, "jenv-2", "fake-uuid2", "", "tester", "secret")
	s.writeEnv(c, "cache-1", "fake-uuid3", "fake-server", "tester", "secret")
	s.writeEnv(c, "cache-2", "fake-uuid4", "fake-server", "tester", "secret")

	environments, err := s.store.List()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(environments, jc.SameContents, []string{"jenv-1", "jenv-2", "cache-1", "cache-2"})

	// Confirm that the sources are from where we'd expect.
	envDir := filepath.Join(s.dir, "models")
	c.Assert(configstore.JENVFilename(envDir, "jenv-1"), jc.IsNonEmptyFile)
	c.Assert(configstore.JENVFilename(envDir, "jenv-2"), jc.IsNonEmptyFile)
	cache := s.readCacheFile(c)
	names := make([]string, 0)
	for name := range cache.Environment {
		names = append(names, name)
	}
	c.Assert(names, jc.SameContents, []string{"cache-1", "cache-2"})
}
예제 #3
0
func (s *cacheFileInterfaceSuite) TestExistingJENVBlocksNew(c *gc.C) {
	modelUUID := testing.ModelTag.Id()
	info := s.writeEnv(c, "testing", modelUUID, "", "tester", "secret")
	envDir := filepath.Join(s.dir, "models")
	jenvFilename := configstore.JENVFilename(envDir, "testing")
	c.Assert(info.Location(), gc.Equals, fmt.Sprintf("file %q", jenvFilename))

	info = s.store.CreateInfo("testing")
	// In order to trigger the writing to the cache file, we need to store
	// a server uuid.
	info.SetAPIEndpoint(configstore.APIEndpoint{
		ModelUUID:  modelUUID,
		ServerUUID: modelUUID,
	})
	err := info.Write()
	c.Assert(err, gc.ErrorMatches, "model info already exists")
}