Replicates a mechanism used by python juju to test if private bucket
storage is writeable by juju on bootstrap. It, however, uses a
different content inside the bootstrap-verify file since we want to use
the differences to detect a Python environment and fail on it (this is
coming in a follow-up branch).
This has been tested with ec2, but not with openstack or maas. Any
suggestions on how to best do that are welcome.
Affected files:
A [revision details]
M environs/dummy/environs.go
M environs/ec2/ec2.go
M environs/maas/environ.go
M environs/openstack/provider.go
M environs/storage.go
M environs/storage_test.go
Reviewers: mp+166481_ code.launchpad. net,
Message:
Please take a look.
Description:
Verify storage writing on bootstrap
Replicates a mechanism used by python juju to test if private bucket
storage is writeable by juju on bootstrap. It, however, uses a
different content inside the bootstrap-verify file since we want to use
the differences to detect a Python environment and fail on it (this is
coming in a follow-up branch).
This has been tested with ec2, but not with openstack or maas. Any
suggestions on how to best do that are welcome.
https:/ /code.launchpad .net/~danilo/ juju-core/ bootstrap- verify/ +merge/ 166481
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/9876043/
Affected files: dummy/environs. go maas/environ. go openstack/ provider. go storage_ test.go
A [revision details]
M environs/
M environs/ec2/ec2.go
M environs/
M environs/
M environs/storage.go
M environs/
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision:
<email address hidden>
+New revision: <email address hidden>
Index: environs/storage.go storage. go'
=== modified file 'environs/
--- environs/storage.go 2013-05-02 15:55:42 +0000
+++ environs/storage.go 2013-05-30 10:54:02 +0000
@@ -6,6 +6,7 @@
import (
"fmt"
"io"
+ "strings"
)
// EmptyStorage holds a StorageReader object that contains no files and
@@ -14,6 +15,9 @@
type emptyStorage struct{}
+const VERIFICATION_ FILENAME string = "bootstrap-verify" CONTENT = "juju-core storage writing verified: ok" fmt.Errorf( "file %q not found", name)} storage Storage) error { NewReader( VERIFICATION_ CONTENT) Put(VERIFICATIO N_FILENAME, reader, VERIFICATION_ CONTENT) ))
+const VERIFICATION_
+
func (s emptyStorage) Get(name string) (io.ReadCloser, error) {
return nil, &NotFoundError{
}
@@ -25,3 +29,10 @@
func (s emptyStorage) List(prefix string) ([]string, error) {
return nil, nil
}
+
+func VerifyStorage(
+ reader := strings.
+ err := storage.
+ int64(len(
+ return err
+}
Index: environs/ storage_ test.go storage_ test.go' storage_ test.go 2013-05-02 15:55:42 +0000 storage_ test.go 2013-05-30 11:09:25 +0000
=== modified file 'environs/
--- environs/
+++ environs/
@@ -4,6 +4,9 @@
package environs_test
import ( net/gocheck" net/juju- core/environs" ReadAll( reader) ms.StorageReque sts, log_message) "Get('% s')", name) ms.StorageReque sts, log_message) NotFoundError{ fmt.Errorf( "file %q not found", name)} VerifyStorageSu ite{}) uite) TestVerifyStorage(c *C) { VerifyStorage( &storage) storage. StorageRequests [0], Equals, -verify' , 'juju-core storage writing verified: ok', 38)")
+ "fmt"
+ "io"
+ "io/ioutil"
. "launchpad.
"launchpad.
)
@@ -29,3 +32,46 @@
c.Assert(names, IsNil)
c.Assert(err, IsNil)
}
+
+type MockStorage struct {
+ StorageRequests []string
+}
+
+func (ms *MockStorage) Put(filename string, reader io.Reader, length
int64) error {
+ var content []byte
+ content, _ = ioutil.
+ log_message := fmt.Sprintf(
+ "Put('%s', '%s', %d)", filename, content, length)
+ ms.StorageRequests = append(
+ return nil
+}
+
+func (ms *MockStorage) Get(name string) (io.ReadCloser, error) {
+ log_message := fmt.Sprintf(
+ ms.StorageRequests = append(
+ return nil, &environs.
+}
+
+func (ms *MockStorage) List(prefix string) ([]string, error) {
+ return nil, nil
+}
+
+func (ms *MockStorage) Remove(file string) error {
+ return nil
+}
+
+func (ms *MockStorage) URL(name string) (string, error) {
+ return "", fmt.Errorf("file %q not found", name)
+}
+
+type VerifyStorageSuite struct{}
+
+var _ = Suite(&
+
+func (s *VerifyStorageS
+ storage := MockStorage{}
+ error := environs.
+ c.Assert(error, IsNil)
+ c.Assert(
+ "Put('bootstrap
+}
Index: environs/ dummy/environs. go dummy/environs. go' dummy/environs. go 2013-05-02 15:55:42 +0000 dummy/environs. go 2013-05-28 14:22:25 +0000 ).CACert( ); !ok { VerifyStorage( e.Storage( )); err != nil { "Provider storage is not writeable.")
=== modified file 'environs/
--- environs/
+++ environs/
@@ -433,6 +433,9 @@
if _, ok := e.Config(
return fmt.Errorf("no CA certificate in environment configuration")
}
+ if err := environs.
+ return fmt.Errorf(
+ }
possibleTools, err := environs. FindBootstrapTo ols(e, cons)
if err != nil {
Index: environs/ec2/ec2.go ec2/ec2. go' "environment is already bootstrapped") VerifyStorage( e.Storage( )) "Provider storage is not writeable.") IsNotFoundError (err) {
=== modified file 'environs/
--- environs/ec2/ec2.go 2013-05-21 22:11:27 +0000
+++ environs/ec2/ec2.go 2013-05-28 14:22:25 +0000
@@ -258,6 +258,12 @@
if err == nil {
return fmt.Errorf(
}
+
+ err = environs.
+ if err != nil {
+ return fmt.Errorf(
+ }
+
if !environs.
return fmt.Errorf("cannot query old bootstrap state: %v", err)
}
Index: environs/ maas/environ. go maas/environ. go' maas/environ. go 2013-05-02 15:55:42 +0000 maas/environ. go 2013-05-28 14:22:25 +0000 VerifyStorage( env.Storage( )); err != nil { "Provider storage is not writeable.") rapNode( cons)
=== modified file 'environs/
--- environs/
+++ environs/
@@ -113,6 +113,10 @@
func (env *maasEnviron) Bootstrap(cons constraints.Value) error {
// TODO(fwereade): this should check for an existing environment before
// starting a new one -- even given raciness, it's better than nothing.
+ if err := environs.
+ return fmt.Errorf(
+ }
+
inst, err := env.startBootst
if err != nil {
return err
Index: environs/ openstack/ provider. go openstack/ provider. go' openstack/ provider. go 2013-05-22 23:25:13 +0000 openstack/ provider. go 2013-05-28 14:22:25 +0000 IsNotFoundError (err) { VerifyStorage( e.Storage( )) "Provider storage is not writeable.")
=== modified file 'environs/
--- environs/
+++ environs/
@@ -489,6 +489,10 @@
if !environs.
return fmt.Errorf("cannot query old bootstrap state: %v", err)
}
+ err = environs.
+ if err != nil {
+ return fmt.Errorf(
+ }
possibleTools, err := environs. FindBootstrapTo ols(e, cons)
if err != nil {