func (w *modelCommandWrapper) Init(args []string) error { store := w.ClientStore() if store == nil { store = jujuclient.NewFileClientStore() w.SetClientStore(store) } if !w.skipFlags { if w.modelName == "" && w.useDefaultModel { // Look for the default. defaultModel, err := GetCurrentModel(store) if err != nil { return err } w.modelName = defaultModel } if w.modelName == "" && !w.useDefaultModel { if w.allowEmptyEnv { return w.ModelCommand.Init(args) } else { return errors.Trace(ErrNoModelSpecified) } } } if w.modelName != "" { if err := w.SetModelName(w.modelName); err != nil { return errors.Annotate(err, "setting model name") } } return w.ModelCommand.Init(args) }
func (s *cmdLoginSuite) TestLoginCommand(c *gc.C) { s.createTestUser(c) // logout "admin" first; we'll need to give it // a non-random password before we can do so. s.changeUserPassword(c, "admin", "hunter2") s.run(c, nil, "logout") // TODO(axw) 2016-09-08 #1621375 // "juju logout" should clear the cookies for the controller. os.Remove(filepath.Join(utils.Home(), ".go-cookies")) context := s.run(c, strings.NewReader("hunter2\nhunter2\n"), "login", "test") c.Assert(testing.Stdout(context), gc.Equals, "") c.Assert(testing.Stderr(context), gc.Equals, ` please enter password for test@local on kontroll: You are now logged in to "kontroll" as "test@local". `[1:]) // We should have a macaroon, but no password, in the client store. store := jujuclient.NewFileClientStore() accountDetails, err := store.AccountDetails("kontroll") c.Assert(err, jc.ErrorIsNil) c.Assert(accountDetails.Password, gc.Equals, "") // We should be able to login with the macaroon. s.run(c, nil, "status") }
func (s *cmdLoginSuite) TestLoginCommand(c *gc.C) { s.createTestUser(c) // logout "admin" first; we'll need to give it // a non-random password before we can do so. s.changeUserPassword(c, "admin", "hunter2") s.run(c, nil, "logout") context := s.run(c, strings.NewReader("hunter2\nhunter2\n"), "login", "test") c.Assert(testing.Stdout(context), gc.Equals, "") c.Assert(testing.Stderr(context), gc.Equals, ` password: You are now logged in to "kontroll" as "test@local". `[1:]) // We should have a macaroon, but no password, in the client store. store := jujuclient.NewFileClientStore() accountDetails, err := store.AccountByName("kontroll", "test@local") c.Assert(err, jc.ErrorIsNil) c.Assert(accountDetails.Password, gc.Equals, "") c.Assert(accountDetails.Macaroon, gc.Not(gc.Equals), "") // We should be able to login with the macaroon. s.run(c, nil, "status") }
// NewRegisterCommand returns a command to allow the user to register a controller. func NewRegisterCommand() cmd.Command { c := ®isterCommand{} c.apiOpen = c.APIOpen c.listModelsFunc = c.listModels c.store = jujuclient.NewFileClientStore() return modelcmd.WrapBase(c) }
func (s *cmdControllerSuite) TestSystemKillCallsEnvironDestroyOnHostedEnviron(c *gc.C) { st := s.Factory.MakeModel(c, &factory.ModelParams{ Name: "foo", }) defer st.Close() st.SwitchBlockOn(state.DestroyBlock, "TestBlockDestroyModel") st.Close() opc := make(chan dummy.Operation, 200) dummy.Listen(opc) store := jujuclient.NewFileClientStore() _, err := store.ControllerByName("kontroll") c.Assert(err, jc.ErrorIsNil) s.run(c, "kill-controller", "kontroll", "-y") // Ensure that Destroy was called on the hosted environ ... // TODO(fwereade): how do we know it's the hosted environ? // what actual interactions made it ok to destroy any environ // here? (there used to be an undertaker that didn't work...) opRecvTimeout(c, st, opc, dummy.OpDestroy{}) // ... and that the details were removed removed from // the client store. _, err = store.ControllerByName("kontroll") c.Assert(err, jc.Satisfies, errors.IsNotFound) }
// Init implements Command.Init, then calls the wrapped command's Init. func (w *sysCommandWrapper) Init(args []string) error { store := w.ClientStore() if store == nil { store = jujuclient.NewFileClientStore() w.SetClientStore(store) } if w.setFlags { if w.controllerName == "" && w.useDefaultControllerName { name, err := w.getDefaultControllerName() if err != nil { return errors.Trace(err) } w.controllerName = name } if w.controllerName == "" && !w.useDefaultControllerName { return ErrNoControllerSpecified } } if w.controllerName != "" { if err := w.SetControllerName(w.controllerName); err != nil { return errors.Trace(err) } } return w.ControllerCommand.Init(args) }
// Create a home directory and Juju data home for user username. // This is used by setUpConn to create the 'ubuntu' user home, after RootDir, // and may be used again later for other users. func (s *JujuConnSuite) CreateUserHome(c *gc.C, params *UserHomeParams) { if s.RootDir == "" { c.Fatal("JujuConnSuite.setUpConn required first for RootDir") } c.Assert(params.Username, gc.Not(gc.Equals), "") home := filepath.Join(s.RootDir, "home", params.Username) err := os.MkdirAll(home, 0777) c.Assert(err, jc.ErrorIsNil) err = utils.SetHome(home) c.Assert(err, jc.ErrorIsNil) jujuHome := filepath.Join(home, ".local", "share") err = os.MkdirAll(filepath.Join(home, ".local", "share"), 0777) c.Assert(err, jc.ErrorIsNil) previousJujuXDGDataHome := osenv.SetJujuXDGDataHome(jujuHome) if params.SetOldHome { s.oldJujuXDGDataHome = previousJujuXDGDataHome } err = os.MkdirAll(s.DataDir(), 0777) c.Assert(err, jc.ErrorIsNil) jujuModelEnvKey := "JUJU_MODEL" if params.ModelEnvKey != "" { jujuModelEnvKey = params.ModelEnvKey } s.PatchEnvironment(osenv.JujuModelEnvKey, jujuModelEnvKey) s.ControllerStore = jujuclient.NewFileClientStore() }
// Init implements Command.Init, then calls the wrapped command's Init. func (w *sysCommandWrapper) Init(args []string) error { store := w.ClientStore() if store == nil { store = jujuclient.NewFileClientStore() } store = QualifyingClientStore{store} w.SetClientStore(store) if w.setControllerFlags { if w.controllerName == "" && w.useDefaultController { store := w.ClientStore() currentController, err := store.CurrentController() if err != nil { return translateControllerError(store, err) } w.controllerName = currentController } if w.controllerName == "" && !w.useDefaultController { return ErrNoControllersDefined } } if w.controllerName != "" { if err := w.SetControllerName(w.controllerName); err != nil { return translateControllerError(w.ClientStore(), err) } } return w.ControllerCommand.Init(args) }
func newSwitchCommand() cmd.Command { cmd := &switchCommand{ Store: jujuclient.NewFileClientStore(), } cmd.RefreshModels = cmd.JujuCommandBase.RefreshModels return modelcmd.WrapBase(cmd) }
func (w *modelCommandWrapper) Init(args []string) error { store := w.ClientStore() if store == nil { store = jujuclient.NewFileClientStore() } store = QualifyingClientStore{store} w.SetClientStore(store) if !w.skipModelFlags { if w.modelName == "" && w.useDefaultModel { // Look for the default. defaultModel, err := GetCurrentModel(store) if err != nil { return err } w.modelName = defaultModel } if w.modelName == "" && !w.useDefaultModel { return errors.Trace(ErrNoModelSpecified) } } if w.modelName != "" { if err := w.SetModelName(w.modelName); err != nil { return translateControllerError(store, err) } } return w.ModelCommand.Init(args) }
// NewRegisterCommand returns a command to allow the user to register a controller. func NewRegisterCommand() cmd.Command { cmd := ®isterCommand{} cmd.apiOpen = cmd.APIOpen cmd.refreshModels = cmd.RefreshModels cmd.store = jujuclient.NewFileClientStore() return modelcmd.WrapBase(cmd) }
func newSwitchCommand() cmd.Command { cmd := &switchCommand{ Store: jujuclient.NewFileClientStore(), ReadCurrentController: modelcmd.ReadCurrentController, WriteCurrentController: modelcmd.WriteCurrentController, } cmd.RefreshModels = cmd.JujuCommandBase.RefreshModels return modelcmd.WrapBase(cmd) }
func (s *ControllersFileSuite) TestReadEmptyFile(c *gc.C) { err := ioutil.WriteFile(osenv.JujuXDGDataHomePath("controllers.yaml"), []byte(""), 0600) c.Assert(err, jc.ErrorIsNil) controllerStore := jujuclient.NewFileClientStore() controllers, err := controllerStore.AllControllers() c.Assert(err, jc.ErrorIsNil) c.Assert(controllers, gc.IsNil) }
// Init implements Command.Init, then calls the wrapped command's Init. func (w *sysCommandWrapper) Init(args []string) error { store := w.ClientStore() if store == nil { store = jujuclient.NewFileClientStore() } store = QualifyingClientStore{store} w.SetClientStore(store) return w.ControllerCommand.Init(args) }
func (s *ControllersSuite) SetUpTest(c *gc.C) { s.FakeJujuXDGDataHomeSuite.SetUpTest(c) s.store = jujuclient.NewFileClientStore() s.controllerName = "test.controller" s.controller = jujuclient.ControllerDetails{ UnresolvedAPIEndpoints: []string{"test.server.hostname"}, ControllerUUID: "test.uuid", APIEndpoints: []string{"test.api.endpoint"}, CACert: "test.ca.cert", Cloud: "aws", CloudRegion: "southeastasia", } }
func (s *cmdControllerSuite) TestControllerKill(c *gc.C) { st := s.Factory.MakeModel(c, &factory.ModelParams{ Name: "foo", }) st.SwitchBlockOn(state.DestroyBlock, "TestBlockDestroyModel") st.Close() s.run(c, "kill-controller", "kontroll", "-y") store := jujuclient.NewFileClientStore() _, err := store.ControllerByName("kontroll") c.Assert(err, jc.Satisfies, errors.IsNotFound) }
func (s *ModelsSuite) TestRemoveControllerRemovesModels(c *gc.C) { store := jujuclient.NewFileClientStore() err := store.AddController("kontroll", jujuclient.ControllerDetails{ ControllerUUID: "abc", CACert: "woop", }) c.Assert(err, jc.ErrorIsNil) err = store.RemoveController("kontroll") c.Assert(err, jc.ErrorIsNil) models, err := jujuclient.ReadModelsFile(jujuclient.JujuModelsPath()) c.Assert(err, jc.ErrorIsNil) _, ok := models["admin/kontroll"] c.Assert(ok, jc.IsFalse) // kontroll models are removed }
func (s *AccountsSuite) TestRemoveControllerRemovesaccounts(c *gc.C) { store := jujuclient.NewFileClientStore() err := store.AddController("kontroll", jujuclient.ControllerDetails{ ControllerUUID: "abc", CACert: "woop", }) c.Assert(err, jc.ErrorIsNil) err = store.RemoveController("kontroll") c.Assert(err, jc.ErrorIsNil) accounts, err := jujuclient.ReadAccountsFile(jujuclient.JujuAccountsPath()) c.Assert(err, jc.ErrorIsNil) _, ok := accounts["kontroll"] c.Assert(ok, jc.IsFalse) // kontroll accounts are removed }
func (s *cmdControllerSuite) TestControllerDestroy(c *gc.C) { st := s.Factory.MakeModel(c, &factory.ModelParams{ Name: "just-a-controller", ConfigAttrs: testing.Attrs{"controller": true}, }) defer st.Close() factory.NewFactory(st).MakeService(c, nil) stop := make(chan struct{}) done := make(chan struct{}) // In order for the destroy controller command to complete we need to run // the code that the cleaner and undertaker workers would be running in // the agent in order to progress the lifecycle of the hosted model, // and cleanup the documents. go func() { defer close(done) a := testing.LongAttempt.Start() for a.Next() { err := s.State.Cleanup() c.Check(err, jc.ErrorIsNil) err = st.Cleanup() c.Check(err, jc.ErrorIsNil) err = st.ProcessDyingModel() if errors.Cause(err) != state.ErrModelNotDying { c.Check(err, jc.ErrorIsNil) if err == nil { // success! return } } select { case <-stop: return default: // retry } } }() s.run(c, "destroy-controller", "kontroll", "-y", "--destroy-all-models", "--debug") close(stop) <-done store := jujuclient.NewFileClientStore() _, err := store.ControllerByName("kontroll") c.Assert(err, jc.Satisfies, errors.IsNotFound) }
func (suite *PluginSuite) TestJujuEnvVars(c *gc.C) { // Plugins are run as model commands, and so require a current // account and model. err := modelcmd.WriteCurrentController("myctrl") c.Assert(err, jc.ErrorIsNil) store := jujuclient.NewFileClientStore() err = store.UpdateAccount("myctrl", "admin@local", jujuclient.AccountDetails{ User: "******", Password: "******", }) c.Assert(err, jc.ErrorIsNil) err = store.SetCurrentAccount("myctrl", "admin@local") c.Assert(err, jc.ErrorIsNil) suite.makeFullPlugin(PluginParams{Name: "foo"}) output := badrun(c, 0, "foo", "-m", "mymodel", "-p", "pluginarg") expectedDebug := "foo -m mymodel -p pluginarg\nmodel is: mymodel\n.*home is: .*\\.local/share/juju\n" c.Assert(output, gc.Matches, expectedDebug) }
func (suite *PluginSuite) TestJujuEnvVars(c *gc.C) { // Plugins are run as model commands, and so require a current // account and model. store := jujuclient.NewFileClientStore() err := store.AddController("myctrl", jujuclient.ControllerDetails{ ControllerUUID: testing.ControllerTag.Id(), CACert: "fake", }) c.Assert(err, jc.ErrorIsNil) err = store.SetCurrentController("myctrl") c.Assert(err, jc.ErrorIsNil) err = store.UpdateAccount("myctrl", jujuclient.AccountDetails{ User: "******", Password: "******", }) c.Assert(err, jc.ErrorIsNil) suite.makeFullPlugin(PluginParams{Name: "foo"}) output := badrun(c, 0, "foo", "-m", "mymodel", "-p", "pluginarg") expectedDebug := "foo -m mymodel -p pluginarg\nmodel is: mymodel\n" c.Assert(output, gc.Matches, expectedDebug) }
func NewContext() (*Context, error) { initialize() jar, err := cookiejar.New(nil) if err != nil { return nil, errors.Trace(err) } bclient := httpbakery.NewClient() bclient.Jar = jar bclient.VisitWebPage = httpbakery.OpenWebBrowser dialOpts := api.DefaultDialOpts() dialOpts.BakeryClient = bclient store := jujuclient.NewFileClientStore() cstore, err := newCacheStore(store) if err != nil { return nil, errors.Annotatef(err, "cannot make store cache") } return &Context{ store: cstore, jar: jar, dialOpts: dialOpts, }, nil }
func (s *JujuConnSuite) setUpConn(c *gc.C) { if s.RootDir != "" { c.Fatal("JujuConnSuite.setUpConn without teardown") } s.RootDir = c.MkDir() s.oldHome = utils.Home() home := filepath.Join(s.RootDir, "/home/ubuntu") err := os.MkdirAll(home, 0777) c.Assert(err, jc.ErrorIsNil) utils.SetHome(home) err = os.MkdirAll(filepath.Join(home, ".local", "share"), 0777) c.Assert(err, jc.ErrorIsNil) s.oldJujuXDGDataHome = osenv.SetJujuXDGDataHome(filepath.Join(home, ".local", "share", "juju")) err = os.MkdirAll(osenv.JujuXDGDataHome(), 0777) c.Assert(err, jc.ErrorIsNil) err = os.MkdirAll(s.DataDir(), 0777) c.Assert(err, jc.ErrorIsNil) s.PatchEnvironment(osenv.JujuModelEnvKey, "admin") cfg, err := config.New(config.UseDefaults, (map[string]interface{})(s.sampleConfig())) c.Assert(err, jc.ErrorIsNil) s.ControllerStore = jujuclient.NewFileClientStore() ctx := testing.Context(c) environ, err := environs.Prepare( modelcmd.BootstrapContext(ctx), s.ControllerStore, environs.PrepareParams{ BaseConfig: cfg.AllAttrs(), Credential: cloud.NewEmptyCredential(), ControllerName: ControllerName, CloudName: "dummy", }, ) c.Assert(err, jc.ErrorIsNil) // sanity check we've got the correct environment. c.Assert(environ.Config().Name(), gc.Equals, "admin") s.PatchValue(&dummy.DataDir, s.DataDir()) s.LogDir = c.MkDir() s.PatchValue(&dummy.LogDir, s.LogDir) versions := PreferredDefaultVersions(environ.Config(), version.Binary{ Number: jujuversion.Current, Arch: "amd64", Series: "precise", }) current := version.Binary{ Number: jujuversion.Current, Arch: arch.HostArch(), Series: series.HostSeries(), } versions = append(versions, current) // Upload tools for both preferred and fake default series s.DefaultToolsStorageDir = c.MkDir() s.PatchValue(&tools.DefaultBaseURL, s.DefaultToolsStorageDir) stor, err := filestorage.NewFileStorageWriter(s.DefaultToolsStorageDir) c.Assert(err, jc.ErrorIsNil) // Upload tools to both release and devel streams since config will dictate that we // end up looking in both places. envtesting.AssertUploadFakeToolsVersions(c, stor, "released", "released", versions...) envtesting.AssertUploadFakeToolsVersions(c, stor, "devel", "devel", versions...) s.DefaultToolsStorage = stor s.PatchValue(&juju.JujuPublicKey, sstesting.SignedMetadataPublicKey) err = bootstrap.Bootstrap(modelcmd.BootstrapContext(ctx), environ, bootstrap.BootstrapParams{}) c.Assert(err, jc.ErrorIsNil) s.BackingState = environ.(GetStater).GetStateInAPIServer() s.State, err = newState(environ, s.BackingState.MongoConnectionInfo()) c.Assert(err, jc.ErrorIsNil) apiInfo, err := environs.APIInfo(environ) c.Assert(err, jc.ErrorIsNil) apiInfo.Tag = s.AdminUserTag(c) apiInfo.Password = environ.Config().AdminSecret() s.APIState, err = api.Open(apiInfo, api.DialOpts{}) c.Assert(err, jc.ErrorIsNil) err = s.State.SetAPIHostPorts(s.APIState.APIHostPorts()) c.Assert(err, jc.ErrorIsNil) // Make sure the controller store has the controller api endpoint address set controller, err := s.ControllerStore.ControllerByName(ControllerName) c.Assert(err, jc.ErrorIsNil) controller.APIEndpoints = []string{s.APIState.APIHostPorts()[0][0].String()} err = s.ControllerStore.UpdateController(ControllerName, *controller) c.Assert(err, jc.ErrorIsNil) err = modelcmd.WriteCurrentController(ControllerName) c.Assert(err, jc.ErrorIsNil) s.Environ = environ // Insert expected values... servingInfo := state.StateServingInfo{ PrivateKey: testing.ServerKey, Cert: testing.ServerCert, CAPrivateKey: testing.CAKey, SharedSecret: "really, really secret", APIPort: 4321, StatePort: 1234, } s.State.SetStateServingInfo(servingInfo) }
func (s *ModelsSuite) SetUpTest(c *gc.C) { s.FakeJujuXDGDataHomeSuite.SetUpTest(c) s.store = jujuclient.NewFileClientStore() writeTestModelsFile(c) }
// NewShowControllerCommand returns a command to show details of the desired controllers. func NewShowControllerCommand() cmd.Command { cmd := &showControllerCommand{ store: jujuclient.NewFileClientStore(), } return modelcmd.WrapBase(cmd) }
// NewWhoAmICommand returns a command to print login details. func NewWhoAmICommand() cmd.Command { cmd := &whoAmICommand{ store: jujuclient.NewFileClientStore(), } return modelcmd.WrapBase(cmd) }
// registerCommands registers commands in the specified registry. func registerCommands(r commandRegistry, ctx *cmd.Context) { // Creation commands. r.Register(newBootstrapCommand()) r.Register(application.NewAddRelationCommand()) // Destruction commands. r.Register(application.NewRemoveRelationCommand()) r.Register(application.NewRemoveServiceCommand()) r.Register(application.NewRemoveUnitCommand()) // Reporting commands. r.Register(status.NewStatusCommand()) r.Register(newSwitchCommand()) r.Register(status.NewStatusHistoryCommand()) // Error resolution and debugging commands. r.Register(newRunCommand()) r.Register(newSCPCommand()) r.Register(newSSHCommand()) r.Register(newResolvedCommand()) r.Register(newDebugLogCommand()) r.Register(newDebugHooksCommand()) // Configuration commands. r.Register(model.NewModelGetConstraintsCommand()) r.Register(model.NewModelSetConstraintsCommand()) r.Register(newSyncToolsCommand()) r.Register(newUpgradeJujuCommand(nil)) r.Register(application.NewUpgradeCharmCommand()) // Charm tool commands. r.Register(newHelpToolCommand()) r.Register(charmcmd.NewSuperCommand()) // Manage backups. r.Register(backups.NewCreateCommand()) r.Register(backups.NewDownloadCommand()) r.Register(backups.NewShowCommand()) r.Register(backups.NewListCommand()) r.Register(backups.NewRemoveCommand()) r.Register(backups.NewRestoreCommand()) r.Register(backups.NewUploadCommand()) // Manage authorized ssh keys. r.Register(NewAddKeysCommand()) r.Register(NewRemoveKeysCommand()) r.Register(NewImportKeysCommand()) r.Register(NewListKeysCommand()) // Manage users and access r.Register(user.NewAddCommand()) r.Register(user.NewChangePasswordCommand()) r.Register(user.NewShowUserCommand()) r.Register(user.NewListCommand()) r.Register(user.NewEnableCommand()) r.Register(user.NewDisableCommand()) r.Register(user.NewLoginCommand()) r.Register(user.NewLogoutCommand()) r.Register(user.NewRemoveCommand()) r.Register(user.NewWhoAmICommand()) // Manage cached images r.Register(cachedimages.NewRemoveCommand()) r.Register(cachedimages.NewListCommand()) // Manage machines r.Register(machine.NewAddCommand()) r.Register(machine.NewRemoveCommand()) r.Register(machine.NewListMachinesCommand()) r.Register(machine.NewShowMachineCommand()) // Manage model r.Register(model.NewConfigCommand()) r.Register(model.NewDefaultsCommand()) r.Register(model.NewRetryProvisioningCommand()) r.Register(model.NewDestroyCommand()) r.Register(model.NewGrantCommand()) r.Register(model.NewRevokeCommand()) r.Register(model.NewShowCommand()) if featureflag.Enabled(feature.Migration) { r.Register(newMigrateCommand()) } if featureflag.Enabled(feature.DeveloperMode) { r.Register(model.NewDumpCommand()) r.Register(model.NewDumpDBCommand()) } // Manage and control actions r.Register(action.NewStatusCommand()) r.Register(action.NewRunCommand()) r.Register(action.NewShowOutputCommand()) r.Register(action.NewListCommand()) // Manage controller availability r.Register(newEnableHACommand()) // Manage and control services r.Register(application.NewAddUnitCommand()) r.Register(application.NewConfigCommand()) r.Register(application.NewDefaultDeployCommand()) r.Register(application.NewExposeCommand()) r.Register(application.NewUnexposeCommand()) r.Register(application.NewServiceGetConstraintsCommand()) r.Register(application.NewServiceSetConstraintsCommand()) // Operation protection commands r.Register(block.NewDisableCommand()) r.Register(block.NewListCommand()) r.Register(block.NewEnableCommand()) // Manage storage r.Register(storage.NewAddCommand()) r.Register(storage.NewListCommand()) r.Register(storage.NewPoolCreateCommand()) r.Register(storage.NewPoolListCommand()) r.Register(storage.NewShowCommand()) // Manage spaces r.Register(space.NewAddCommand()) r.Register(space.NewListCommand()) if featureflag.Enabled(feature.PostNetCLIMVP) { r.Register(space.NewRemoveCommand()) r.Register(space.NewUpdateCommand()) r.Register(space.NewRenameCommand()) } // Manage subnets r.Register(subnet.NewAddCommand()) r.Register(subnet.NewListCommand()) if featureflag.Enabled(feature.PostNetCLIMVP) { r.Register(subnet.NewCreateCommand()) r.Register(subnet.NewRemoveCommand()) } // Manage controllers r.Register(controller.NewAddModelCommand()) r.Register(controller.NewDestroyCommand()) r.Register(controller.NewListModelsCommand()) r.Register(controller.NewKillCommand()) r.Register(controller.NewListControllersCommand()) r.Register(controller.NewRegisterCommand()) r.Register(controller.NewUnregisterCommand(jujuclient.NewFileClientStore())) r.Register(controller.NewEnableDestroyControllerCommand()) r.Register(controller.NewShowControllerCommand()) r.Register(controller.NewGetConfigCommand()) // Debug Metrics r.Register(metricsdebug.New()) r.Register(metricsdebug.NewCollectMetricsCommand()) r.Register(setmeterstatus.New()) // Manage clouds and credentials r.Register(cloud.NewUpdateCloudsCommand()) r.Register(cloud.NewListCloudsCommand()) r.Register(cloud.NewListRegionsCommand()) r.Register(cloud.NewShowCloudCommand()) r.Register(cloud.NewAddCloudCommand()) r.Register(cloud.NewRemoveCloudCommand()) r.Register(cloud.NewListCredentialsCommand()) r.Register(cloud.NewDetectCredentialsCommand()) r.Register(cloud.NewSetDefaultRegionCommand()) r.Register(cloud.NewSetDefaultCredentialCommand()) r.Register(cloud.NewAddCredentialCommand()) r.Register(cloud.NewRemoveCredentialCommand()) r.Register(cloud.NewUpdateCredentialCommand()) // Juju GUI commands. r.Register(gui.NewGUICommand()) r.Register(gui.NewUpgradeGUICommand()) // Commands registered elsewhere. for _, newCommand := range registeredCommands { command := newCommand() r.Register(command) } for _, newCommand := range registeredEnvCommands { command := newCommand() r.Register(modelcmd.Wrap(command)) } rcmd.RegisterAll(r) }
func (s *BootstrapConfigSuite) SetUpTest(c *gc.C) { s.FakeJujuXDGDataHomeSuite.SetUpTest(c) s.store = jujuclient.NewFileClientStore() writeTestBootstrapConfigFile(c) }
// NewListControllersCommand returns a command to list registered controllers. func NewListControllersCommand() cmd.Command { cmd := &listControllersCommand{ store: jujuclient.NewFileClientStore(), } return modelcmd.WrapBase(cmd) }
func (s *cmdControllerSuite) testControllerDestroy(c *gc.C, forceAPI bool) { st := s.Factory.MakeModel(c, &factory.ModelParams{ Name: "just-a-controller", ConfigAttrs: testing.Attrs{"controller": true}, CloudRegion: "dummy-region", }) defer st.Close() factory.NewFactory(st).MakeApplication(c, nil) stop := make(chan struct{}) done := make(chan struct{}) // In order for the destroy controller command to complete we need to run // the code that the cleaner and undertaker workers would be running in // the agent in order to progress the lifecycle of the hosted model, // and cleanup the documents. go func() { defer close(done) a := testing.LongAttempt.Start() for a.Next() { err := s.State.Cleanup() c.Check(err, jc.ErrorIsNil) err = st.Cleanup() c.Check(err, jc.ErrorIsNil) err = st.ProcessDyingModel() if errors.Cause(err) != state.ErrModelNotDying { c.Check(err, jc.ErrorIsNil) if err == nil { // success! return } } select { case <-stop: return default: // retry } } }() if forceAPI { // Remove bootstrap config from the client store, // forcing the command to use the API. err := os.Remove(jujuclient.JujuBootstrapConfigPath()) c.Assert(err, jc.ErrorIsNil) } ops := make(chan dummy.Operation, 1) dummy.Listen(ops) s.run(c, "destroy-controller", "kontroll", "-y", "--destroy-all-models", "--debug") close(stop) <-done destroyOp := (<-ops).(dummy.OpDestroy) c.Assert(destroyOp.Env, gc.Equals, "controller") c.Assert(destroyOp.Cloud, gc.Equals, "dummy") c.Assert(destroyOp.CloudRegion, gc.Equals, "dummy-region") store := jujuclient.NewFileClientStore() _, err := store.ControllerByName("kontroll") c.Assert(err, jc.Satisfies, errors.IsNotFound) }