Beispiel #1
0
func (s *filesSuite) TestWriteControllerAddsNewline(c *gc.C) {
	err := envcmd.WriteCurrentController("fubar")
	c.Assert(err, jc.ErrorIsNil)
	current, err := ioutil.ReadFile(envcmd.GetCurrentControllerFilePath())
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(string(current), gc.Equals, "fubar\n")
}
func (s *EnvironmentCommandSuite) TestEnvironCommandInitControllerFile(c *gc.C) {
	// If there is a current-controller file, error raised.
	err := envcmd.WriteCurrentController("fubar")
	c.Assert(err, jc.ErrorIsNil)
	_, err = initTestCommand(c)
	c.Assert(err, gc.ErrorMatches, `not operating on an environment, using controller "fubar"`)
}
Beispiel #3
0
func (s *EnvironmentsSuite) SetUpTest(c *gc.C) {
	s.FakeJujuHomeSuite.SetUpTest(c)

	err := envcmd.WriteCurrentController("fake")
	c.Assert(err, jc.ErrorIsNil)

	last1 := time.Date(2015, 3, 20, 0, 0, 0, 0, time.UTC)
	last2 := time.Date(2015, 3, 1, 0, 0, 0, 0, time.UTC)

	envs := []base.UserEnvironment{
		{
			Name:           "test-env1",
			Owner:          "user-admin@local",
			UUID:           "test-env1-UUID",
			LastConnection: &last1,
		}, {
			Name:           "test-env2",
			Owner:          "user-admin@local",
			UUID:           "test-env2-UUID",
			LastConnection: &last2,
		}, {
			Name:  "test-env3",
			Owner: "user-admin@local",
			UUID:  "test-env3-UUID",
		},
	}
	s.api = &fakeEnvMgrAPIClient{envs: envs}
	s.creds = &configstore.APICredentials{User: "******", Password: "******"}
}
Beispiel #4
0
func (s *SwitchSimpleSuite) TestCurrentControllerHasPrecedence(c *gc.C) {
	testing.WriteEnvironments(c, testing.MultipleEnvConfig)
	envcmd.WriteCurrentController("fubar")
	context, err := testing.RunCommand(c, newSwitchCommand())
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(testing.Stdout(context), gc.Equals, "fubar (controller)\n")
}
Beispiel #5
0
func (s *filesSuite) TestWriteControllerRemovesEnvironmentFile(c *gc.C) {
	err := envcmd.WriteCurrentEnvironment("fubar")
	c.Assert(err, jc.ErrorIsNil)
	err = envcmd.WriteCurrentController("baz")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(envcmd.GetCurrentEnvironmentFilePath(), jc.DoesNotExist)
}
Beispiel #6
0
func (s *BaseSuite) SetUpTest(c *gc.C) {
	s.FakeJujuHomeSuite.SetUpTest(c)
	memstore := configstore.NewMem()
	s.PatchValue(&configstore.Default, func() (configstore.Storage, error) {
		return memstore, nil
	})
	os.Setenv(osenv.JujuEnvEnvKey, "testing")
	info := memstore.CreateInfo("testing")
	info.SetBootstrapConfig(map[string]interface{}{"random": "extra data"})
	info.SetAPIEndpoint(configstore.APIEndpoint{
		Addresses:   []string{"127.0.0.1:12345"},
		Hostnames:   []string{"localhost:12345"},
		CACert:      testing.CACert,
		EnvironUUID: "env-uuid",
	})
	info.SetAPICredentials(configstore.APICredentials{
		User:     "******",
		Password: "******",
	})
	err := info.Write()
	c.Assert(err, jc.ErrorIsNil)
	s.PatchValue(user.ReadPassword, func() (string, error) {
		return "sekrit", nil
	})
	err = envcmd.WriteCurrentController("testing")
	c.Assert(err, jc.ErrorIsNil)
}
Beispiel #7
0
func (*filesSuite) TestCurrentCommenctionNameController(c *gc.C) {
	err := envcmd.WriteCurrentController("baz")
	c.Assert(err, jc.ErrorIsNil)
	name, isController, err := envcmd.CurrentConnectionName()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(isController, jc.IsTrue)
	c.Assert(name, gc.Equals, "baz")
}
Beispiel #8
0
func (s *ControllerCommandSuite) TestControllerCommandInitExplicit(c *gc.C) {
	// Take controller name from command line arg, and it trumps the current-
	// controller file.
	err := envcmd.WriteCurrentController("fubar")
	c.Assert(err, jc.ErrorIsNil)
	testEnsureControllerName(c, "explicit", "-c", "explicit")
	testEnsureControllerName(c, "explicit", "--controller", "explicit")
}
Beispiel #9
0
func (s *removeBlocksSuite) SetUpTest(c *gc.C) {
	s.FakeJujuHomeSuite.SetUpTest(c)

	err := envcmd.WriteCurrentController("fake")
	c.Assert(err, jc.ErrorIsNil)

	s.api = &fakeRemoveBlocksAPI{}
}
Beispiel #10
0
func (s *filesSuite) TestSetCurrentControllerExistingController(c *gc.C) {
	err := envcmd.WriteCurrentController("fubar")
	c.Assert(err, jc.ErrorIsNil)
	ctx := testing.Context(c)
	err = envcmd.SetCurrentController(ctx, "new-sys")
	c.Assert(err, jc.ErrorIsNil)
	s.assertCurrentController(c, "new-sys")
	c.Assert(testing.Stderr(ctx), gc.Equals, "fubar (controller) -> new-sys (controller)\n")
}
func (s *cmdControllerSuite) TestControllerEnvironmentsCommand(c *gc.C) {
	c.Assert(envcmd.WriteCurrentController("dummyenv"), jc.ErrorIsNil)
	s.createEnv(c, "new-env", false)
	context := s.run(c, "list-environments")
	c.Assert(testing.Stdout(context), gc.Equals, ""+
		"NAME      OWNER              LAST CONNECTION\n"+
		"dummyenv  dummy-admin@local  just now\n"+
		"new-env   dummy-admin@local  never connected\n"+
		"\n")
}
func (s *cmdControllerSuite) TestRemoveBlocks(c *gc.C) {
	c.Assert(envcmd.WriteCurrentController("dummyenv"), jc.ErrorIsNil)
	s.State.SwitchBlockOn(state.DestroyBlock, "TestBlockDestroyEnvironment")
	s.State.SwitchBlockOn(state.ChangeBlock, "TestChangeBlock")

	s.run(c, "remove-all-blocks")

	blocks, err := s.State.AllBlocksForController()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(blocks, gc.HasLen, 0)
}
func (s *cmdControllerSuite) TestListBlocks(c *gc.C) {
	c.Assert(envcmd.WriteCurrentController("dummyenv"), jc.ErrorIsNil)
	s.State.SwitchBlockOn(state.DestroyBlock, "TestBlockDestroyEnvironment")
	s.State.SwitchBlockOn(state.ChangeBlock, "TestChangeBlock")

	ctx := s.run(c, "list-all-blocks", "--format", "json")
	expected := fmt.Sprintf(`[{"name":"dummyenv","env-uuid":"%s","owner-tag":"%s","blocks":["BlockDestroy","BlockChange"]}]`,
		s.State.EnvironUUID(), s.AdminUserTag(c).String())

	strippedOut := strings.Replace(testing.Stdout(ctx), "\n", "", -1)
	c.Check(strippedOut, gc.Equals, expected)
}
func (s *cmdControllerSuite) TestCreateEnvironment(c *gc.C) {
	c.Assert(envcmd.WriteCurrentController("dummyenv"), jc.ErrorIsNil)
	// The JujuConnSuite doesn't set up an ssh key in the fake home dir,
	// so fake one on the command line.  The dummy provider also expects
	// a config value for 'state-server'.
	context := s.run(c, "create-environment", "new-env", "authorized-keys=fake-key", "state-server=false")
	c.Check(testing.Stdout(context), gc.Equals, "")
	c.Check(testing.Stderr(context), gc.Equals, `
created environment "new-env"
dummyenv (controller) -> new-env
`[1:])

	// Make sure that the saved server details are sufficient to connect
	// to the api server.
	api, err := juju.NewAPIFromName("new-env", nil)
	c.Assert(err, jc.ErrorIsNil)
	api.Close()
}
Beispiel #15
0
func (s *UseEnvironmentSuite) SetUpTest(c *gc.C) {
	s.FakeJujuHomeSuite.SetUpTest(c)

	err := envcmd.WriteCurrentController("fake")
	c.Assert(err, jc.ErrorIsNil)

	envs := []base.UserEnvironment{{
		Name:  "unique",
		Owner: "tester@local",
		UUID:  "some-uuid",
	}, {
		Name:  "test",
		Owner: "tester@local",
		UUID:  env1UUID,
	}, {
		Name:  "test",
		Owner: "bob@local",
		UUID:  env2UUID,
	}, {
		Name:  "other",
		Owner: "bob@local",
		UUID:  env3UUID,
	}, {
		Name:  "other",
		Owner: "bob@remote",
		UUID:  env4UUID,
	}}
	s.api = &fakeEnvMgrAPIClient{envs: envs}
	s.creds = configstore.APICredentials{User: "******", Password: "******"}
	s.endpoint = configstore.APIEndpoint{
		Addresses:  []string{"127.0.0.1:12345"},
		Hostnames:  []string{"localhost:12345"},
		CACert:     testing.CACert,
		ServerUUID: serverUUID,
	}
}
Beispiel #16
0
func (*filesSuite) TestErrorWritingCurrentController(c *gc.C) {
	// Can't write a file over a directory.
	os.MkdirAll(envcmd.GetCurrentControllerFilePath(), 0777)
	err := envcmd.WriteCurrentController("fubar")
	c.Assert(err, gc.ErrorMatches, "unable to write to the controller file: .*")
}
Beispiel #17
0
func (s *ControllerCommandSuite) TestControllerCommandInitSystemFile(c *gc.C) {
	// If there is a current-controller file, use that.
	err := envcmd.WriteCurrentController("fubar")
	c.Assert(err, jc.ErrorIsNil)
	testEnsureControllerName(c, "fubar")
}
Beispiel #18
0
func (s *filesSuite) TestReadCurrentControllerSet(c *gc.C) {
	err := envcmd.WriteCurrentController("fubar")
	c.Assert(err, jc.ErrorIsNil)
	s.assertCurrentController(c, "fubar")
}