本文整理汇总了Golang中github.com/juju/utils.SetHome函数的典型用法代码示例。如果您正苦于以下问题:Golang SetHome函数的具体用法?Golang SetHome怎么用?Golang SetHome使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetHome函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestDetectCredentialsNovarc
func (s *credentialsSuite) TestDetectCredentialsNovarc(c *gc.C) {
if runtime.GOOS != "linux" {
c.Skip("not running linux")
}
home := utils.Home()
dir := c.MkDir()
utils.SetHome(dir)
s.AddCleanup(func(*gc.C) {
utils.SetHome(home)
})
content := `
# Some secrets
export OS_TENANT_NAME=gary
EXPORT OS_USERNAME=bob
export OS_PASSWORD = dobbs
OS_REGION_NAME=region
`[1:]
novarc := filepath.Join(dir, ".novarc")
err := ioutil.WriteFile(novarc, []byte(content), 0600)
credentials, err := s.provider.DetectCredentials()
c.Assert(err, jc.ErrorIsNil)
c.Assert(credentials.DefaultRegion, gc.Equals, "region")
expected := cloud.NewCredential(
cloud.UserPassAuthType, map[string]string{
"username": "bob",
"password": "dobbs",
"tenant-name": "gary",
"domain-name": "",
},
)
expected.Label = `openstack region "region" project "gary" user "bob"`
c.Assert(credentials.AuthCredentials["bob"], jc.DeepEquals, expected)
}
示例2: SetUpTest
func (s *AuthKeysSuite) SetUpTest(c *gc.C) {
s.BaseSuite.SetUpTest(c)
old := utils.Home()
newhome := c.MkDir()
utils.SetHome(newhome)
s.AddCleanup(func(*gc.C) { utils.SetHome(old) })
s.dotssh = filepath.Join(newhome, ".ssh")
err := os.Mkdir(s.dotssh, 0755)
c.Assert(err, gc.IsNil)
}
示例3: TestDetectCredentialsKnownLocationUnix
func (s *credentialsSuite) TestDetectCredentialsKnownLocationUnix(c *gc.C) {
if runtime.GOOS == "windows" {
c.Skip("skipping on Windows")
}
home := utils.Home()
dir := c.MkDir()
utils.SetHome(dir)
s.AddCleanup(func(*gc.C) {
utils.SetHome(home)
})
s.assertDetectCredentialsKnownLocation(c, dir)
}
示例4: SetUpTest
func (s *fakeHomeSuite) SetUpTest(c *gc.C) {
utils.SetHome(home)
os.Setenv("JUJU_DATA", jujuXDGDataHome)
osenv.SetJujuXDGDataHome(jujuXDGDataHome)
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
}
示例5: TearDownTest
func (s *JujuOSEnvSuite) TearDownTest(c *gc.C) {
for name, value := range s.oldEnvironment {
os.Setenv(name, value)
}
err := utils.SetHome(s.oldHomeEnv)
c.Assert(err, jc.ErrorIsNil)
}
示例6: SetUpTest
func (s *TestingBaseSuite) SetUpTest(c *gc.C) {
utils.SetHome(home)
os.Setenv("JUJU_HOME", jujuHome)
osenv.SetJujuHome(jujuHome)
s.BaseSuite.SetUpTest(c)
}
示例7: TearDownTest
func (s *ConfigSuite) TearDownTest(c *gc.C) {
utils.SetHome(s.savedHome)
os.Setenv("AWS_ACCESS_KEY_ID", s.savedAccessKey)
os.Setenv("AWS_SECRET_ACCESS_KEY", s.savedSecretKey)
delete(aws.Regions, "configtest")
s.BaseSuite.TearDownTest(c)
}
示例8: SetUpTest
func (s *fakeHomeSuite) SetUpTest(c *gc.C) {
utils.SetHome("/home/eric")
os.Setenv("JUJU_HOME", "/home/eric/juju")
osenv.SetJujuHome("/home/eric/juju")
s.FakeJujuHomeSuite.SetUpTest(c)
}
示例9: SetUpTest
func (s *JujuOSEnvSuite) SetUpTest(c *gc.C) {
s.oldEnvironment = make(map[string]string)
for _, name := range []string{
osenv.JujuXDGDataHomeEnvKey,
osenv.JujuModelEnvKey,
osenv.JujuLoggingConfigEnvKey,
osenv.JujuFeatureFlagEnvKey,
osenv.XDGDataHome,
} {
s.oldEnvironment[name] = os.Getenv(name)
os.Setenv(name, "")
}
s.oldHomeEnv = utils.Home()
s.oldJujuXDGDataHome = osenv.SetJujuXDGDataHome("")
utils.SetHome("")
// Update the feature flag set to be the requested initial set.
// This works for both windows and unix, even though normally
// the feature flags on windows are determined using the registry.
// For tests, setting with the environment variable isolates us
// from a single resource that was hitting contention during parallel
// test runs.
os.Setenv(osenv.JujuFeatureFlagEnvKey, s.initialFeatureFlags)
featureflag.SetFlagsFromEnvironment(osenv.JujuFeatureFlagEnvKey)
}
示例10: SetUpTest
func (s *TestingBaseSuite) SetUpTest(c *gc.C) {
utils.SetHome(home)
os.Setenv("JUJU_DATA", jujuXDGDataHome)
osenv.SetJujuXDGDataHome(jujuXDGDataHome)
s.BaseSuite.SetUpTest(c)
}
示例11: SetUpTest
func (s *fakeHomeSuite) SetUpTest(c *gc.C) {
utils.SetHome(home)
os.Setenv("JUJU_HOME", jujuHome)
osenv.SetJujuHome(jujuHome)
s.FakeJujuHomeSuite.SetUpTest(c)
}
示例12: TearDownTest
func (s *JujuOSEnvSuite) TearDownTest(c *gc.C) {
for name, value := range s.oldEnvironment {
os.Setenv(name, value)
}
utils.SetHome(s.oldHomeEnv)
osenv.SetJujuHome(s.oldJujuHome)
}
示例13: CreateUserHome
// 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()
}
示例14: tearDownConn
func (s *JujuConnSuite) tearDownConn(c *gc.C) {
serverAlive := gitjujutesting.MgoServer.Addr() != ""
// Bootstrap will set the admin password, and render non-authorized use
// impossible. s.State may still hold the right password, so try to reset
// the password so that the MgoSuite soft-resetting works. If that fails,
// it will still work, but it will take a while since it has to kill the
// whole database and start over.
if err := s.State.SetAdminMongoPassword(""); err != nil && serverAlive {
c.Logf("cannot reset admin password: %v", err)
}
for _, st := range s.apiStates {
err := st.Close()
if serverAlive {
c.Assert(err, gc.IsNil)
}
}
err := s.Conn.Close()
if serverAlive {
c.Assert(err, gc.IsNil)
}
err = s.APIConn.Close()
if serverAlive {
c.Assert(err, gc.IsNil)
}
dummy.Reset()
s.apiStates = nil
s.Conn = nil
s.State = nil
utils.SetHome(s.oldHome)
osenv.SetJujuHome(s.oldJujuHome)
s.oldHome = ""
s.RootDir = ""
}
示例15: setUpConn
func (s *JujuConnSuite) setUpConn(c *gc.C) {
if s.RootDir != "" {
panic("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, gc.IsNil)
utils.SetHome(home)
s.oldJujuHome = osenv.SetJujuHome(filepath.Join(home, ".juju"))
err = os.Mkdir(osenv.JujuHome(), 0777)
c.Assert(err, gc.IsNil)
err = os.MkdirAll(s.DataDir(), 0777)
c.Assert(err, gc.IsNil)
s.PatchEnvironment(osenv.JujuEnvEnvKey, "")
// TODO(rog) remove these files and add them only when
// the tests specifically need them (in cmd/juju for example)
s.writeSampleConfig(c, osenv.JujuHomePath("environments.yaml"))
err = ioutil.WriteFile(osenv.JujuHomePath("dummyenv-cert.pem"), []byte(testing.CACert), 0666)
c.Assert(err, gc.IsNil)
err = ioutil.WriteFile(osenv.JujuHomePath("dummyenv-private-key.pem"), []byte(testing.CAKey), 0600)
c.Assert(err, gc.IsNil)
store, err := configstore.Default()
c.Assert(err, gc.IsNil)
s.ConfigStore = store
ctx := testing.Context(c)
environ, err := environs.PrepareFromName("dummyenv", ctx, s.ConfigStore)
c.Assert(err, gc.IsNil)
// sanity check we've got the correct environment.
c.Assert(environ.Config().Name(), gc.Equals, "dummyenv")
s.PatchValue(&dummy.DataDir, s.DataDir())
s.LogDir = c.MkDir()
s.PatchValue(&dummy.LogDir, s.LogDir)
versions := PreferredDefaultVersions(environ.Config(), version.Binary{Number: version.Current.Number, Series: "precise", Arch: "amd64"})
versions = append(versions, version.Current)
// Upload tools for both preferred and fake default series
envtesting.MustUploadFakeToolsVersions(environ.Storage(), versions...)
err = bootstrap.Bootstrap(ctx, environ, bootstrap.BootstrapParams{})
c.Assert(err, gc.IsNil)
s.BackingState = environ.(GetStater).GetStateInAPIServer()
s.State, err = newState(environ, s.BackingState.MongoConnectionInfo())
c.Assert(err, gc.IsNil)
s.APIState, err = juju.NewAPIState(environ, api.DialOpts{})
c.Assert(err, gc.IsNil)
s.Environ = environ
}