18
18
"launchpad.net/juju-core/environs"
19
19
"launchpad.net/juju-core/environs/bootstrap"
20
20
"launchpad.net/juju-core/environs/config"
21
"launchpad.net/juju-core/environs/storage"
21
22
"launchpad.net/juju-core/environs/sync"
22
23
envtesting "launchpad.net/juju-core/environs/testing"
23
24
envtools "launchpad.net/juju-core/environs/tools"
32
33
statetesting "launchpad.net/juju-core/state/testing"
33
34
coretesting "launchpad.net/juju-core/testing"
34
35
jc "launchpad.net/juju-core/testing/checkers"
36
"launchpad.net/juju-core/testing/testbase"
35
37
coretools "launchpad.net/juju-core/tools"
36
38
"launchpad.net/juju-core/utils"
37
39
"launchpad.net/juju-core/version"
41
43
// (e.g. Amazon EC2). The Environ is opened once only for all the tests
42
44
// in the suite, stored in Env, and Destroyed after the suite has completed.
43
45
type LiveTests struct {
44
coretesting.LoggingSuite
45
47
envtesting.ToolsFixture
47
49
// TestConfig contains the configuration attributes for opening an environment.
484
486
// Bootstrap automatically verifies that storage is writable.
485
487
t.BootstrapOnce(c)
487
storage := environ.Storage()
488
reader, err := storage.Get("bootstrap-verify")
489
stor := environ.Storage()
490
reader, err := storage.Get(stor, "bootstrap-verify")
489
491
c.Assert(err, gc.IsNil)
490
492
defer reader.Close()
491
493
contents, err := ioutil.ReadAll(reader)
494
496
"juju-core storage writing verified: ok\n")
497
func restoreBootstrapVerificationFile(c *gc.C, storage environs.Storage) {
499
func restoreBootstrapVerificationFile(c *gc.C, stor storage.Storage) {
498
500
content := "juju-core storage writing verified: ok\n"
499
501
contentReader := strings.NewReader(content)
500
err := storage.Put("bootstrap-verify", contentReader,
502
err := stor.Put("bootstrap-verify", contentReader,
501
503
int64(len(content)))
502
504
c.Assert(err, gc.IsNil)
513
515
conn, err := juju.NewConn(t.Env)
514
516
c.Assert(err, gc.IsNil)
519
apiConn, err := juju.NewAPIConn(t.Env, api.DefaultDialOpts())
520
c.Assert(err, gc.IsNil)
518
524
func (t *LiveTests) TestCheckEnvironmentOnConnectNoVerificationFile(c *gc.C) {
527
533
t.BootstrapOnce(c)
529
storage := environ.Storage()
530
err := storage.Remove("bootstrap-verify")
535
stor := environ.Storage()
536
err := stor.Remove("bootstrap-verify")
531
537
c.Assert(err, gc.IsNil)
532
defer restoreBootstrapVerificationFile(c, storage)
538
defer restoreBootstrapVerificationFile(c, stor)
534
540
conn, err := juju.NewConn(t.Env)
535
541
c.Assert(err, gc.IsNil)
548
554
t.BootstrapOnce(c)
550
storage := environ.Storage()
556
stor := environ.Storage()
552
558
// Finally, replace the content with an arbitrary string.
553
559
badVerificationContent := "bootstrap storage verification"
554
560
reader := strings.NewReader(badVerificationContent)
556
562
"bootstrap-verify",
558
564
int64(len(badVerificationContent)))
559
565
c.Assert(err, gc.IsNil)
560
defer restoreBootstrapVerificationFile(c, storage)
566
defer restoreBootstrapVerificationFile(c, stor)
562
568
// Running NewConn() should fail.
563
569
_, err = juju.NewConn(t.Env)
754
760
func (t *LiveTests) TestFile(c *gc.C) {
755
761
name := fmt.Sprint("testfile", time.Now().UnixNano())
756
storage := t.Env.Storage()
762
stor := t.Env.Storage()
758
checkFileDoesNotExist(c, storage, name, t.Attempt)
759
checkPutFile(c, storage, name, contents)
760
checkFileHasContents(c, storage, name, contents, t.Attempt)
761
checkPutFile(c, storage, name, contents2) // check that we can overwrite the file
762
checkFileHasContents(c, storage, name, contents2, t.Attempt)
764
checkFileDoesNotExist(c, stor, name, t.Attempt)
765
checkPutFile(c, stor, name, contents)
766
checkFileHasContents(c, stor, name, contents, t.Attempt)
767
checkPutFile(c, stor, name, contents2) // check that we can overwrite the file
768
checkFileHasContents(c, stor, name, contents2, t.Attempt)
764
770
// check that the listed contents include the
765
771
// expected name.
769
775
for a := t.Attempt.Start(); a.Next(); {
771
names, err = storage.List("")
777
names, err = stor.List("")
772
778
c.Assert(err, gc.IsNil)
773
779
for _, lname := range names {
774
780
if lname == name {
781
787
c.Errorf("file name %q not found in file list %q", name, names)
783
err := storage.Remove(name)
789
err := stor.Remove(name)
784
790
c.Check(err, gc.IsNil)
785
checkFileDoesNotExist(c, storage, name, t.Attempt)
791
checkFileDoesNotExist(c, stor, name, t.Attempt)
786
792
// removing a file that does not exist should not be an error.
787
err = storage.Remove(name)
793
err = stor.Remove(name)
788
794
c.Check(err, gc.IsNil)
790
796
// RemoveAll deletes all files from storage.
791
checkPutFile(c, storage, "file-1.txt", contents)
792
checkPutFile(c, storage, "file-2.txt", contents)
793
err = storage.RemoveAll()
797
checkPutFile(c, stor, "file-1.txt", contents)
798
checkPutFile(c, stor, "file-2.txt", contents)
799
err = stor.RemoveAll()
794
800
c.Check(err, gc.IsNil)
795
checkFileDoesNotExist(c, storage, "file-1.txt", t.Attempt)
796
checkFileDoesNotExist(c, storage, "file-2.txt", t.Attempt)
801
checkFileDoesNotExist(c, stor, "file-1.txt", t.Attempt)
802
checkFileDoesNotExist(c, stor, "file-2.txt", t.Attempt)
799
805
// Check that we can't start an instance running tools that correspond with no
810
816
c.Assert(inst, gc.IsNil)
811
817
c.Assert(err, jc.Satisfies, errors.IsNotFoundError)
812
c.Assert(err, gc.ErrorMatches, "no matching tools available")
815
820
// Check that we can't start an instance with an empty nonce value.
892
897
waitAgentTools(c, mw0, other)
895
func storageCopy(source environs.Storage, sourcePath string, target environs.Storage, targetPath string) error {
896
rc, err := source.Get(sourcePath)
900
func storageCopy(source storage.Storage, sourcePath string, target storage.Storage, targetPath string) error {
901
rc, err := storage.Get(source, sourcePath)