本文整理汇总了Golang中launchpad/net/juju-core/environs/config.SetJujuHome函数的典型用法代码示例。如果您正苦于以下问题:Golang SetJujuHome函数的具体用法?Golang SetJujuHome怎么用?Golang SetJujuHome使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetJujuHome函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUserData
func (*CloudInitSuite) TestUserData(c *C) {
testJujuHome := c.MkDir()
defer config.SetJujuHome(config.SetJujuHome(testJujuHome))
tools := &tools.Tools{
URL: "http://foo.com/tools/juju1.2.3-linux-amd64.tgz",
Binary: version.MustParseBinary("1.2.3-linux-amd64"),
}
envConfig, err := config.New(map[string]interface{}{
"type": "maas",
"name": "foo",
"default-series": "series",
"authorized-keys": "keys",
"ca-cert": testing.CACert,
})
c.Assert(err, IsNil)
cfg := &cloudinit.MachineConfig{
MachineId: "10",
MachineNonce: "5432",
Tools: tools,
StateServerCert: []byte(testing.ServerCert),
StateServerKey: []byte(testing.ServerKey),
StateInfo: &state.Info{
Password: "pw1",
CACert: []byte("CA CERT\n" + testing.CACert),
},
APIInfo: &api.Info{
Password: "pw2",
CACert: []byte("CA CERT\n" + testing.CACert),
},
DataDir: environs.DataDir,
Config: envConfig,
StatePort: envConfig.StatePort(),
APIPort: envConfig.APIPort(),
StateServer: true,
ProviderType: "dummy",
}
script1 := "script1"
script2 := "script2"
scripts := []string{script1, script2}
result, err := environs.ComposeUserData(cfg, scripts...)
c.Assert(err, IsNil)
unzipped, err := utils.Gunzip(result)
c.Assert(err, IsNil)
config := make(map[interface{}]interface{})
err = goyaml.Unmarshal(unzipped, &config)
c.Assert(err, IsNil)
// Just check that the cloudinit config looks good.
c.Check(config["apt_upgrade"], Equals, true)
// The scripts given to userData where added as the first
// commands to be run.
runCmd := config["runcmd"].([]interface{})
c.Check(runCmd[0], Equals, script1)
c.Check(runCmd[1], Equals, script2)
}
示例2: SetUpTest
func (s *TestingEnvironSuite) SetUpTest(c *C) {
s.home = os.Getenv("HOME")
s.jujuHome = os.Getenv("JUJU_HOME")
os.Setenv("HOME", "/home/eric")
os.Setenv("JUJU_HOME", "/home/eric/juju")
config.SetJujuHome("/home/eric/juju")
}
示例3: TestHelpCommands
func (s *MetadataSuite) TestHelpCommands(c *gc.C) {
// Check that we have correctly registered all the commands
// by checking the help output.
defer config.SetJujuHome(config.SetJujuHome(c.MkDir()))
out := badrun(c, 0, "help", "commands")
lines := strings.Split(out, "\n")
var names []string
for _, line := range lines {
f := strings.Fields(line)
if len(f) == 0 {
continue
}
names = append(names, f[0])
}
// The names should be output in alphabetical order, so don't sort.
c.Assert(names, gc.DeepEquals, commandNames)
}
示例4: SetUpTest
func (s *ConfigSuite) SetUpTest(c *C) {
s.oldJujuHome = config.SetJujuHome(c.MkDir())
s.savedVars = make(map[string]string)
for v, val := range envVars {
s.savedVars[v] = os.Getenv(v)
os.Setenv(v, val)
}
}
示例5: TestOpenReturnsNilInterfaceUponFailure
func (suite *EnvironProviderSuite) TestOpenReturnsNilInterfaceUponFailure(c *gc.C) {
testJujuHome := c.MkDir()
defer config.SetJujuHome(config.SetJujuHome(testJujuHome))
const oauth = "wrongly-formatted-oauth-string"
attrs := map[string]interface{}{
"maas-oauth": oauth,
"maas-server": "http://maas.testing.invalid/maas/",
"name": "wheee",
"type": "maas",
"authorized-keys": "I-am-not-a-real-key",
}
config, err := config.New(attrs)
c.Assert(err, gc.IsNil)
env, err := suite.environ.Provider().Open(config)
// When Open() fails (i.e. returns a non-nil error), it returns an
// environs.Environ interface object with a nil value and a nil
// type.
c.Check(env, gc.Equals, nil)
c.Check(err, gc.ErrorMatches, ".*malformed maas-oauth.*")
}
示例6: TestSecretAttrsReturnsSensitiveMAASAttributes
func (suite *EnvironProviderSuite) TestSecretAttrsReturnsSensitiveMAASAttributes(c *gc.C) {
testJujuHome := c.MkDir()
defer config.SetJujuHome(config.SetJujuHome(testJujuHome))
const oauth = "aa:bb:cc"
attrs := map[string]interface{}{
"maas-oauth": oauth,
"maas-server": "http://maas.testing.invalid/maas/",
"name": "wheee",
"type": "maas",
"authorized-keys": "I-am-not-a-real-key",
}
config, err := config.New(attrs)
c.Assert(err, gc.IsNil)
secretAttrs, err := suite.environ.Provider().SecretAttrs(config)
c.Assert(err, gc.IsNil)
expectedAttrs := map[string]interface{}{"maas-oauth": oauth}
c.Check(secretAttrs, gc.DeepEquals, expectedAttrs)
}
示例7: InitJujuHome
// InitJujuHome initializes the charm and environs/config packages to use
// default paths based on the $JUJU_HOME or $HOME environment variables.
// This function should be called before calling NewConn or Conn.Deploy.
func InitJujuHome() error {
jujuHome := os.Getenv("JUJU_HOME")
if jujuHome == "" {
home := os.Getenv("HOME")
if home == "" {
return stderrors.New("cannot determine juju home, neither $JUJU_HOME nor $HOME are set")
}
jujuHome = filepath.Join(home, ".juju")
}
config.SetJujuHome(jujuHome)
charm.CacheDir = filepath.Join(jujuHome, "charmcache")
return nil
}
示例8: TestHelpGlobalOptions
func (s *MetadataSuite) TestHelpGlobalOptions(c *gc.C) {
// Check that we have correctly registered all the topics
// by checking the help output.
defer config.SetJujuHome(config.SetJujuHome(c.MkDir()))
out := badrun(c, 0, "help", "global-options")
c.Assert(out, gc.Matches, `Global Options
These options may be used with any command, and may appear in front of any
command\.(.|\n)*`)
lines := strings.Split(out, "\n")
var flags []string
for _, line := range lines {
f := strings.Fields(line)
if len(f) == 0 || line[0] != '-' {
continue
}
flags = append(flags, line)
}
c.Assert(len(flags), gc.Equals, len(globalFlags))
for i, line := range flags {
c.Assert(line, gc.Matches, globalFlags[i])
}
}
示例9: MakeEmptyFakeHomeWithoutJuju
func MakeEmptyFakeHomeWithoutJuju(c *C) *FakeHome {
oldHomeEnv := os.Getenv("HOME")
oldJujuHomeEnv := os.Getenv("JUJU_HOME")
oldJujuEnv := os.Getenv("JUJU_ENV")
fakeHome := c.MkDir()
os.Setenv("HOME", fakeHome)
os.Setenv("JUJU_HOME", "")
os.Setenv("JUJU_ENV", "")
jujuHome := filepath.Join(fakeHome, ".juju")
oldJujuHome := config.SetJujuHome(jujuHome)
return &FakeHome{
oldHomeEnv: oldHomeEnv,
oldJujuEnv: oldJujuEnv,
oldJujuHomeEnv: oldJujuHomeEnv,
oldJujuHome: oldJujuHome,
files: []TestFile{},
}
}
示例10: TestWriteCertAndKey
func (*EnvironsCertSuite) TestWriteCertAndKey(c *C) {
defer testing.MakeEmptyFakeHome(c).Restore()
// Ensure that the juju home path is different
// from $HOME/.juju to check that WriteCertAndKey
// isn't just using $HOME.
config.SetJujuHome(c.MkDir())
cert, key := []byte("a cert"), []byte("a key")
err := environs.WriteCertAndKey("foo", cert, key)
c.Assert(err, IsNil)
// Check that the generated CA key has been written correctly.
caCertPEM, err := ioutil.ReadFile(config.JujuHomePath("foo-cert.pem"))
c.Assert(err, IsNil)
c.Assert(caCertPEM, DeepEquals, cert)
caKeyPEM, err := ioutil.ReadFile(config.JujuHomePath("foo-private-key.pem"))
c.Assert(err, IsNil)
c.Assert(caKeyPEM, DeepEquals, key)
}
示例11: TearDownTest
func (s *JujuConnSuite) TearDownTest(c *C) {
s.tearDownConn(c)
s.MgoSuite.TearDownTest(c)
s.LoggingSuite.TearDownTest(c)
config.SetJujuHome(s.oldJujuHome)
}
示例12: SetUpTest
func (s *JujuConnSuite) SetUpTest(c *C) {
s.oldJujuHome = config.SetJujuHome(c.MkDir())
s.LoggingSuite.SetUpTest(c)
s.MgoSuite.SetUpTest(c)
s.setUpConn(c)
}
示例13: TestHomePath
func (s *JujuHomeSuite) TestHomePath(c *C) {
testJujuHome := c.MkDir()
defer config.SetJujuHome(config.SetJujuHome(testJujuHome))
envPath := config.JujuHomePath("environments.yaml")
c.Assert(envPath, Equals, filepath.Join(testJujuHome, "environments.yaml"))
}
示例14: TestStandardHome
func (s *JujuHomeSuite) TestStandardHome(c *C) {
testJujuHome := c.MkDir()
defer config.SetJujuHome(config.SetJujuHome(testJujuHome))
c.Assert(config.JujuHome(), Equals, testJujuHome)
}
示例15: TearDownTest
func (s *ConfigSuite) TearDownTest(c *C) {
for k, v := range s.savedVars {
os.Setenv(k, v)
}
config.SetJujuHome(s.oldJujuHome)
}