func (s *CreateSuite) TestRunAPIConnectFails(c *gc.C) { // TODO(dimitern): Change this once API is implemented. s.command = subnet.NewCreateCommand(nil) s.AssertRunFails(c, "cannot connect to the API server: no environment specified", "10.10.0.0/24", "space", "zone1", ) // No API calls recoreded. s.api.CheckCallNames(c) }
func (s *CreateSuite) TestInit(c *gc.C) { for i, test := range []struct { about string args []string expectCIDR string expectSpace string expectZones []string expectPublic bool expectPrivate bool expectErr string }{{ about: "no arguments", expectErr: "CIDR is required", expectPrivate: true, }, { about: "only a subnet argument (invalid)", args: s.Strings("foo"), expectPrivate: true, expectErr: "space name is required", }, { about: "no zone arguments (both CIDR and space are invalid)", args: s.Strings("foo", "%invalid"), expectPrivate: true, expectErr: "at least one zone is required", }, { about: "invalid CIDR", args: s.Strings("foo", "space", "zone"), expectPrivate: true, expectErr: `"foo" is not a valid CIDR`, }, { about: "incorrectly specified CIDR", args: s.Strings("5.4.3.2/10", "space", "zone"), expectPrivate: true, expectErr: `"5.4.3.2/10" is not correctly specified, expected "5.0.0.0/10"`, }, { about: "invalid space name", args: s.Strings("10.10.0.0/24", "%inv$alid", "zone"), expectCIDR: "10.10.0.0/24", expectPrivate: true, expectErr: `"%inv\$alid" is not a valid space name`, }, { about: "duplicate zones specified", args: s.Strings("10.10.0.0/24", "myspace", "zone1", "zone2", "zone1"), expectCIDR: "10.10.0.0/24", expectSpace: "myspace", expectZones: s.Strings("zone1", "zone2"), expectPrivate: true, expectErr: `duplicate zone "zone1" specified`, }, { about: "both --public and --private specified", args: s.Strings("10.1.0.0/16", "new-space", "zone", "--public", "--private"), expectCIDR: "10.1.0.0/16", expectSpace: "new-space", expectZones: s.Strings("zone"), expectErr: `cannot specify both --public and --private`, expectPublic: true, expectPrivate: true, }, { about: "--public specified", args: s.Strings("10.1.0.0/16", "new-space", "zone", "--public"), expectCIDR: "10.1.0.0/16", expectSpace: "new-space", expectZones: s.Strings("zone"), expectPublic: true, expectPrivate: false, expectErr: "", }, { about: "--private explicitly specified", args: s.Strings("10.1.0.0/16", "new-space", "zone", "--private"), expectCIDR: "10.1.0.0/16", expectSpace: "new-space", expectZones: s.Strings("zone"), expectPublic: false, expectPrivate: true, expectErr: "", }, { about: "--private specified out of order", args: s.Strings("2001:db8::/32", "--private", "space", "zone"), expectCIDR: "2001:db8::/32", expectSpace: "space", expectZones: s.Strings("zone"), expectPublic: false, expectPrivate: true, expectErr: "", }, { about: "--public specified twice", args: s.Strings("--public", "2001:db8::/32", "--public", "space", "zone"), expectCIDR: "2001:db8::/32", expectSpace: "space", expectZones: s.Strings("zone"), expectPublic: true, expectPrivate: false, expectErr: "", }} { c.Logf("test #%d: %s", i, test.about) // Create a new instance of the subcommand for each test, but // since we're not running the command no need to use // modelcmd.Wrap(). wrappedCommand, command := subnet.NewCreateCommand(s.api) err := coretesting.InitCommand(wrappedCommand, test.args) if test.expectErr != "" { c.Check(err, gc.ErrorMatches, test.expectErr) } else { c.Check(err, jc.ErrorIsNil) c.Check(command.CIDR.Id(), gc.Equals, test.expectCIDR) c.Check(command.Space.Id(), gc.Equals, test.expectSpace) c.Check(command.Zones.SortedValues(), jc.DeepEquals, test.expectZones) c.Check(command.IsPublic, gc.Equals, test.expectPublic) c.Check(command.IsPrivate, gc.Equals, test.expectPrivate) } // No API calls should be recorded at this stage. s.api.CheckCallNames(c) } }
func (s *CreateSuite) SetUpTest(c *gc.C) { s.BaseSuite.SetFeatureFlags(feature.PostNetCLIMVP) s.BaseSubnetSuite.SetUpTest(c) s.command, _ = subnet.NewCreateCommand(s.api) c.Assert(s.command, gc.NotNil) }
// 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) }