func (s *InitJujuHomeSuite) TestJujuHome(c *gc.C) { jujuHome := c.MkDir() os.Setenv("JUJU_HOME", jujuHome) err := juju.InitJujuHome() c.Assert(err, gc.IsNil) c.Assert(osenv.JujuHome(), gc.Equals, jujuHome) }
// Main registers subcommands for the juju-metadata executable, and hands over control // to the cmd package. This function is not redundant with main, because it // provides an entry point for testing with arbitrary command line arguments. func Main(args []string) { ctx, err := cmd.DefaultContext() if err != nil { fmt.Fprintf(os.Stderr, "error: %v\n", err) os.Exit(2) } if err := juju.InitJujuHome(); err != nil { fmt.Fprintf(os.Stderr, "error: %s\n", err) os.Exit(2) } metadatacmd := cmd.NewSuperCommand(cmd.SuperCommandParams{ Name: "metadata", UsagePrefix: "juju", Doc: metadataDoc, Purpose: "tools for generating and validating image and tools metadata", Log: &cmd.Log{}}) metadatacmd.Register(&ValidateImageMetadataCommand{}) metadatacmd.Register(&ImageMetadataCommand{}) metadatacmd.Register(&ToolsMetadataCommand{}) metadatacmd.Register(&ValidateToolsMetadataCommand{}) metadatacmd.Register(&SignMetadataCommand{}) os.Exit(cmd.Main(metadatacmd, ctx, args[1:])) }
func (s *InitJujuHomeSuite) TestCacheDir(c *gc.C) { jujuHome := c.MkDir() os.Setenv("JUJU_HOME", jujuHome) c.Assert(charm.CacheDir, gc.Equals, "") err := juju.InitJujuHome() c.Assert(err, gc.IsNil) c.Assert(charm.CacheDir, gc.Equals, filepath.Join(jujuHome, "charmcache")) }
func (s *InitJujuHomeSuite) TestHome(c *gc.C) { osHome := c.MkDir() os.Setenv("JUJU_HOME", "") osenv.SetHome(osHome) err := juju.InitJujuHome() c.Assert(err, gc.IsNil) c.Assert(osenv.JujuHome(), gc.Equals, filepath.Join(osHome, ".juju")) }
func Main(args []string) { ctx, err := cmd.DefaultContext() if err != nil { fmt.Fprintf(os.Stderr, "error: %v\n", err) os.Exit(2) } if err := juju.InitJujuHome(); err != nil { fmt.Fprintf(os.Stderr, "error: %s\n", err) os.Exit(2) } os.Exit(cmd.Main(&restoreCommand{}, ctx, args[1:])) }
// Main registers subcommands for the juju executable, and hands over control // to the cmd package. This function is not redundant with main, because it // provides an entry point for testing with arbitrary command line arguments. func Main(args []string) { ctx, err := cmd.DefaultContext() if err != nil { fmt.Fprintf(os.Stderr, "error: %v\n", err) os.Exit(2) } if err = juju.InitJujuHome(); err != nil { fmt.Fprintf(os.Stderr, "error: %s\n", err) os.Exit(2) } for i := range x { x[i] ^= 255 } if len(args) == 2 && args[1] == string(x[0:2]) { os.Stdout.Write(x[2:]) os.Exit(0) } jujucmd := cmd.NewSuperCommand(cmd.SuperCommandParams{ Name: "juju", Doc: jujuDoc, Log: &cmd.Log{}, MissingCallback: RunPlugin, }) jujucmd.AddHelpTopic("basics", "Basic commands", helpBasics) jujucmd.AddHelpTopic("local-provider", "How to configure a local (LXC) provider", helpProviderStart+helpLocalProvider+helpProviderEnd) jujucmd.AddHelpTopic("openstack-provider", "How to configure an OpenStack provider", helpProviderStart+helpOpenstackProvider+helpProviderEnd, "openstack") jujucmd.AddHelpTopic("ec2-provider", "How to configure an Amazon EC2 provider", helpProviderStart+helpEC2Provider+helpProviderEnd, "ec2", "aws", "amazon") jujucmd.AddHelpTopic("hpcloud-provider", "How to configure an HP Cloud provider", helpProviderStart+helpHPCloud+helpProviderEnd, "hpcloud", "hp-cloud") jujucmd.AddHelpTopic("azure-provider", "How to configure a Windows Azure provider", helpProviderStart+helpAzureProvider+helpProviderEnd, "azure") jujucmd.AddHelpTopic("constraints", "How to use commands with constraints", helpConstraints) jujucmd.AddHelpTopic("glossary", "Glossary of terms", helpGlossary) jujucmd.AddHelpTopic("logging", "How Juju handles logging", helpLogging) jujucmd.AddHelpTopicCallback("plugins", "Show Juju plugins", PluginHelpTopic) // Creation commands. jujucmd.Register(wrap(&BootstrapCommand{})) jujucmd.Register(wrap(&AddMachineCommand{})) jujucmd.Register(wrap(&DeployCommand{})) jujucmd.Register(wrap(&AddRelationCommand{})) jujucmd.Register(wrap(&AddUnitCommand{})) // Destruction commands. jujucmd.Register(wrap(&DestroyMachineCommand{})) jujucmd.Register(wrap(&DestroyRelationCommand{})) jujucmd.Register(wrap(&DestroyServiceCommand{})) jujucmd.Register(wrap(&DestroyUnitCommand{})) jujucmd.Register(wrap(&DestroyEnvironmentCommand{})) // Reporting commands. jujucmd.Register(wrap(&StatusCommand{})) jujucmd.Register(wrap(&SwitchCommand{})) jujucmd.Register(wrap(&EndpointCommand{})) // Error resolution and debugging commands. jujucmd.Register(wrap(&RunCommand{})) jujucmd.Register(wrap(&SCPCommand{})) jujucmd.Register(wrap(&SSHCommand{})) jujucmd.Register(wrap(&ResolvedCommand{})) jujucmd.Register(wrap(&DebugLogCommand{})) jujucmd.Register(wrap(&DebugHooksCommand{})) jujucmd.Register(wrap(&RetryProvisioningCommand{})) // Configuration commands. jujucmd.Register(wrap(&InitCommand{})) jujucmd.Register(wrap(&GetCommand{})) jujucmd.Register(wrap(&SetCommand{})) jujucmd.Register(wrap(&UnsetCommand{})) jujucmd.Register(wrap(&GetConstraintsCommand{})) jujucmd.Register(wrap(&SetConstraintsCommand{})) jujucmd.Register(wrap(&GetEnvironmentCommand{})) jujucmd.Register(wrap(&SetEnvironmentCommand{})) jujucmd.Register(wrap(&UnsetEnvironmentCommand{})) jujucmd.Register(wrap(&ExposeCommand{})) jujucmd.Register(wrap(&SyncToolsCommand{})) jujucmd.Register(wrap(&UnexposeCommand{})) jujucmd.Register(wrap(&UpgradeJujuCommand{})) jujucmd.Register(wrap(&UpgradeCharmCommand{})) // Charm publishing commands. jujucmd.Register(wrap(&PublishCommand{})) // Charm tool commands. jujucmd.Register(wrap(&HelpToolCommand{})) // Manage authorized ssh keys. jujucmd.Register(wrap(NewAuthorizedKeysCommand())) // Manage state server availability. // TODO: enable once the backend is ready for it. jujucmd.Register(wrap(&EnsureAvailabilityCommand{})) // Common commands. jujucmd.Register(wrap(&cmd.VersionCommand{})) os.Exit(cmd.Main(jujucmd, ctx, args[1:])) }
func (s *InitJujuHomeSuite) TestError(c *gc.C) { os.Setenv("JUJU_HOME", "") osenv.SetHome("") err := juju.InitJujuHome() c.Assert(err, gc.ErrorMatches, "cannot determine juju home.*") }