~jaywink/juju-core/juju-core

« back to all changes in this revision

Viewing changes to environs/jujutest/livetests.go

  • Committer: Jason Robinson
  • Date: 2013-09-20 18:19:37 UTC
  • mfrom: (1828.2.34 juju-core)
  • Revision ID: mail@jasonrobinson.me-20130920181937-02pl68iuf36v647k
Merged latest

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
46
        testbase.LoggingSuite
45
47
        envtesting.ToolsFixture
46
48
 
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)
486
488
        environ := t.Env
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")
495
497
}
496
498
 
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)
503
505
}
513
515
        conn, err := juju.NewConn(t.Env)
514
516
        c.Assert(err, gc.IsNil)
515
517
        conn.Close()
 
518
 
 
519
        apiConn, err := juju.NewAPIConn(t.Env, api.DefaultDialOpts())
 
520
        c.Assert(err, gc.IsNil)
 
521
        apiConn.Close()
516
522
}
517
523
 
518
524
func (t *LiveTests) TestCheckEnvironmentOnConnectNoVerificationFile(c *gc.C) {
526
532
        }
527
533
        t.BootstrapOnce(c)
528
534
        environ := t.Env
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)
533
539
 
534
540
        conn, err := juju.NewConn(t.Env)
535
541
        c.Assert(err, gc.IsNil)
547
553
        }
548
554
        t.BootstrapOnce(c)
549
555
        environ := t.Env
550
 
        storage := environ.Storage()
 
556
        stor := environ.Storage()
551
557
 
552
558
        // Finally, replace the content with an arbitrary string.
553
559
        badVerificationContent := "bootstrap storage verification"
554
560
        reader := strings.NewReader(badVerificationContent)
555
 
        err := storage.Put(
 
561
        err := stor.Put(
556
562
                "bootstrap-verify",
557
563
                reader,
558
564
                int64(len(badVerificationContent)))
559
565
        c.Assert(err, gc.IsNil)
560
 
        defer restoreBootstrapVerificationFile(c, storage)
 
566
        defer restoreBootstrapVerificationFile(c, stor)
561
567
 
562
568
        // Running NewConn() should fail.
563
569
        _, err = juju.NewConn(t.Env)
753
759
 
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()
757
763
 
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)
763
769
 
764
770
        // check that the listed contents include the
765
771
        // expected name.
768
774
attempt:
769
775
        for a := t.Attempt.Start(); a.Next(); {
770
776
                var err error
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 {
780
786
        if !found {
781
787
                c.Errorf("file name %q not found in file list %q", name, names)
782
788
        }
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)
789
795
 
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)
797
803
}
798
804
 
799
805
// Check that we can't start an instance running tools that correspond with no
809
815
        }
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")
813
818
}
814
819
 
815
820
// Check that we can't start an instance with an empty nonce value.
892
897
        waitAgentTools(c, mw0, other)
893
898
}
894
899
 
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)
897
902
        if err != nil {
898
903
                return err
899
904
        }