예제 #1
0
파일: image_test.go 프로젝트: bac/juju
func (s *ImageSuite) TestAddImageRemovesExistingRemoveFails(c *gc.C) {
	// Add a metadata doc and a blob at a known path, then
	// call AddImage and ensure that AddImage attempts to remove
	// the original blob, but does not return an error if it
	// fails.
	s.addMetadataDoc(c, "lxc", "trusty", "amd64", 3, "hash(abc)", "path", "http://path")
	managedStorage := imagestorage.ManagedStorage(s.storage, s.session)
	err := managedStorage.PutForBucket("my-uuid", "path", strings.NewReader("blah"), 4)
	c.Assert(err, gc.IsNil)

	storage := imagestorage.NewStorage(s.session, "my-uuid")
	s.PatchValue(imagestorage.GetManagedStorage, imagestorage.RemoveFailsManagedStorage)
	addedMetadata := &imagestorage.Metadata{
		ModelUUID: "my-uuid",
		Kind:      "lxc",
		Series:    "trusty",
		Arch:      "amd64",
		Size:      6,
		SHA256:    "hash(xyzzzz)",
		SourceURL: "http://path",
	}
	err = storage.AddImage(strings.NewReader("xyzzzz"), addedMetadata)
	c.Assert(err, gc.IsNil)

	// old blob should still be there
	r, _, err := managedStorage.GetForBucket("my-uuid", "path")
	c.Assert(err, gc.IsNil)
	r.Close()

	s.assertImage(c, addedMetadata, "xyzzzz")
}
예제 #2
0
파일: image_test.go 프로젝트: bac/juju
func (s *ImageSuite) SetUpTest(c *gc.C) {
	s.BaseSuite.SetUpTest(c)
	s.mongo = &gitjujutesting.MgoInstance{}
	s.mongo.Start(nil)

	var err error
	s.session, err = s.mongo.Dial()
	c.Assert(err, gc.IsNil)
	s.storage = imagestorage.NewStorage(s.session, "my-uuid")
	s.metadataCollection = imagestorage.MetadataCollection(s.storage)
	s.txnRunner = jujutxn.NewRunner(jujutxn.RunnerParams{Database: s.metadataCollection.Database})
	s.patchTransactionRunner()
}
예제 #3
0
파일: image_test.go 프로젝트: bac/juju
func (s *ImageSuite) TestAddImageRemovesBlobOnFailure(c *gc.C) {
	storage := imagestorage.NewStorage(s.session, "my-uuid")
	s.txnRunner = errorTransactionRunner{s.txnRunner}
	addedMetadata := &imagestorage.Metadata{
		ModelUUID: "my-uuid",
		Kind:      "lxc",
		Series:    "trusty",
		Arch:      "amd64",
		Size:      6,
		SHA256:    "hash",
	}
	err := storage.AddImage(strings.NewReader("xyzzzz"), addedMetadata)
	c.Assert(err, gc.ErrorMatches, "cannot store image metadata: Run fails")

	path := fmt.Sprintf(
		"images/%s-%s-%s:%s", addedMetadata.Kind, addedMetadata.Series, addedMetadata.Arch, addedMetadata.SHA256)
	managedStorage := imagestorage.ManagedStorage(s.storage, s.session)
	_, _, err = managedStorage.GetForBucket("my-uuid", path)
	c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
예제 #4
0
파일: image_test.go 프로젝트: bac/juju
func (s *ImageSuite) TestAddImageRemovesBlobOnFailureRemoveFails(c *gc.C) {
	storage := imagestorage.NewStorage(s.session, "my-uuid")
	s.PatchValue(imagestorage.GetManagedStorage, imagestorage.RemoveFailsManagedStorage)
	s.txnRunner = errorTransactionRunner{s.txnRunner}
	addedMetadata := &imagestorage.Metadata{
		ModelUUID: "my-uuid",
		Kind:      "lxc",
		Series:    "trusty",
		Arch:      "amd64",
		Size:      6,
		SHA256:    "hash",
	}
	err := storage.AddImage(strings.NewReader("xyzzzz"), addedMetadata)
	c.Assert(err, gc.ErrorMatches, "cannot store image metadata: Run fails")

	// blob should still be there, because the removal failed.
	path := fmt.Sprintf(
		"images/%s-%s-%s:%s", addedMetadata.Kind, addedMetadata.Series, addedMetadata.Arch, addedMetadata.SHA256)
	managedStorage := imagestorage.ManagedStorage(s.storage, s.session)
	r, _, err := managedStorage.GetForBucket("my-uuid", path)
	c.Assert(err, gc.IsNil)
	r.Close()
}