Index: environs/jujutest/livetests.go |
=== modified file 'environs/jujutest/livetests.go' |
--- environs/jujutest/livetests.go 2013-06-26 13:19:16 +0000 |
+++ environs/jujutest/livetests.go 2013-06-29 02:49:49 +0000 |
@@ -23,6 +23,7 @@ |
coretesting "launchpad.net/juju-core/testing" |
"launchpad.net/juju-core/utils" |
"launchpad.net/juju-core/version" |
+ "strings" |
"time" |
) |
@@ -471,6 +472,67 @@ |
"juju-core storage writing verified: ok\n") |
} |
+func restoreBootstrapVerificationFile(c *C, storage environs.Storage) { |
+ content := "juju-core storage writing verified: ok\n" |
+ contentReader := strings.NewReader(content) |
+ err := storage.Put("bootstrap-verify", contentReader, |
+ int64(len(content))) |
+ c.Assert(err, IsNil) |
+} |
+ |
+func (t *LiveTests) TestCheckEnvironmentOnConnect(c *C) { |
+ // When new connection is established to a bootstraped environment, |
+ // it is checked that we are running against a juju-core environment. |
+ t.BootstrapOnce(c) |
+ |
+ conn, err := juju.NewConn(t.Env) |
+ c.Assert(err, IsNil) |
+ conn.Close() |
+} |
+ |
+func (t *LiveTests) TestCheckEnvironmentOnConnectNoVerificationFile(c *C) { |
+ // When new connection is established to a bootstraped environment, |
+ // it is checked that we are running against a juju-core environment. |
+ // |
+ // Absence of a verification file means it is a juju-core environment |
+ // with an older version, which is fine. |
+ t.BootstrapOnce(c) |
+ environ := t.Env |
+ storage := environ.Storage() |
+ err := storage.Remove("bootstrap-verify") |
+ c.Assert(err, IsNil) |
+ defer restoreBootstrapVerificationFile(c, storage) |
+ |
+ conn, err := juju.NewConn(t.Env) |
+ c.Assert(err, IsNil) |
+ conn.Close() |
+} |
+ |
+func (t *LiveTests) TestCheckEnvironmentOnConnectBadVerificationFile(c *C) { |
+ // When new connection is established to a bootstraped environment, |
+ // it is checked that we are running against a juju-core environment. |
+ // |
+ // If the verification file has unexpected content, it is not |
+ // a juju-core environment (likely to a Python juju environment). |
+ t.BootstrapOnce(c) |
+ environ := t.Env |
+ storage := environ.Storage() |
+ |
+ // Finally, replace the content with an arbitrary string. |
+ badVerificationContent := "bootstrap storage verification" |
+ reader := strings.NewReader(badVerificationContent) |
+ err := storage.Put( |
+ "bootstrap-verify", |
+ reader, |
+ int64(len(badVerificationContent))) |
+ c.Assert(err, IsNil) |
+ defer restoreBootstrapVerificationFile(c, storage) |
+ |
+ // Running NewConn() should fail. |
+ _, err = juju.NewConn(t.Env) |
+ c.Assert(err, Equals, environs.InvalidEnvironmentError) |
+} |
+ |
type tooler interface { |
Life() state.Life |
AgentTools() (*state.Tools, error) |