Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(82)

Side by Side Diff: environs/jujutest/livetests.go

Issue 10733044: Fail when run against Python juju environment
Patch Set: Fail when run against Python juju environment Created 11 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « [revision details] ('k') | environs/open.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011, 2012, 2013 Canonical Ltd. 1 // Copyright 2011, 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package jujutest 4 package jujutest
5 5
6 import ( 6 import (
7 "bytes" 7 "bytes"
8 "fmt" 8 "fmt"
9 "io" 9 "io"
10 "io/ioutil" 10 "io/ioutil"
11 . "launchpad.net/gocheck" 11 . "launchpad.net/gocheck"
12 "launchpad.net/juju-core/charm" 12 "launchpad.net/juju-core/charm"
13 "launchpad.net/juju-core/constraints" 13 "launchpad.net/juju-core/constraints"
14 "launchpad.net/juju-core/environs" 14 "launchpad.net/juju-core/environs"
15 "launchpad.net/juju-core/environs/config" 15 "launchpad.net/juju-core/environs/config"
16 "launchpad.net/juju-core/environs/tools" 16 "launchpad.net/juju-core/environs/tools"
17 "launchpad.net/juju-core/errors" 17 "launchpad.net/juju-core/errors"
18 "launchpad.net/juju-core/instance" 18 "launchpad.net/juju-core/instance"
19 "launchpad.net/juju-core/juju" 19 "launchpad.net/juju-core/juju"
20 "launchpad.net/juju-core/juju/testing" 20 "launchpad.net/juju-core/juju/testing"
21 "launchpad.net/juju-core/state" 21 "launchpad.net/juju-core/state"
22 "launchpad.net/juju-core/state/api" 22 "launchpad.net/juju-core/state/api"
23 coretesting "launchpad.net/juju-core/testing" 23 coretesting "launchpad.net/juju-core/testing"
24 "launchpad.net/juju-core/utils" 24 "launchpad.net/juju-core/utils"
25 "launchpad.net/juju-core/version" 25 "launchpad.net/juju-core/version"
26 "strings"
26 "time" 27 "time"
27 ) 28 )
28 29
29 // LiveTests contains tests that are designed to run against a live server 30 // LiveTests contains tests that are designed to run against a live server
30 // (e.g. Amazon EC2). The Environ is opened once only for all the tests 31 // (e.g. Amazon EC2). The Environ is opened once only for all the tests
31 // in the suite, stored in Env, and Destroyed after the suite has completed. 32 // in the suite, stored in Env, and Destroyed after the suite has completed.
32 type LiveTests struct { 33 type LiveTests struct {
33 coretesting.LoggingSuite 34 coretesting.LoggingSuite
34 35
35 // TestConfig contains the configuration attributes for opening an envir onment. 36 // TestConfig contains the configuration attributes for opening an envir onment.
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 storage := environ.Storage() 465 storage := environ.Storage()
465 reader, err := storage.Get("bootstrap-verify") 466 reader, err := storage.Get("bootstrap-verify")
466 c.Assert(err, IsNil) 467 c.Assert(err, IsNil)
467 defer reader.Close() 468 defer reader.Close()
468 contents, err := ioutil.ReadAll(reader) 469 contents, err := ioutil.ReadAll(reader)
469 c.Assert(err, IsNil) 470 c.Assert(err, IsNil)
470 c.Check(string(contents), Equals, 471 c.Check(string(contents), Equals,
471 "juju-core storage writing verified: ok\n") 472 "juju-core storage writing verified: ok\n")
472 } 473 }
473 474
475 func restoreBootstrapVerificationFile(c *C, storage environs.Storage) {
476 content := "juju-core storage writing verified: ok\n"
477 contentReader := strings.NewReader(content)
478 err := storage.Put("bootstrap-verify", contentReader,
479 int64(len(content)))
480 c.Assert(err, IsNil)
481 }
482
483 func (t *LiveTests) TestCheckEnvironmentOnConnect(c *C) {
484 // When new connection is established to a bootstraped environment,
485 // it is checked that we are running against a juju-core environment.
486 t.BootstrapOnce(c)
487
488 conn, err := juju.NewConn(t.Env)
489 c.Assert(err, IsNil)
490 conn.Close()
491 }
492
493 func (t *LiveTests) TestCheckEnvironmentOnConnectNoVerificationFile(c *C) {
494 // When new connection is established to a bootstraped environment,
495 // it is checked that we are running against a juju-core environment.
496 //
497 // Absence of a verification file means it is a juju-core environment
498 // with an older version, which is fine.
499 t.BootstrapOnce(c)
500 environ := t.Env
501 storage := environ.Storage()
502 err := storage.Remove("bootstrap-verify")
503 c.Assert(err, IsNil)
504 defer restoreBootstrapVerificationFile(c, storage)
505
506 conn, err := juju.NewConn(t.Env)
507 c.Assert(err, IsNil)
508 conn.Close()
509 }
510
511 func (t *LiveTests) TestCheckEnvironmentOnConnectBadVerificationFile(c *C) {
512 // When new connection is established to a bootstraped environment,
513 // it is checked that we are running against a juju-core environment.
514 //
515 // If the verification file has unexpected content, it is not
516 // a juju-core environment (likely to a Python juju environment).
517 t.BootstrapOnce(c)
518 environ := t.Env
519 storage := environ.Storage()
520
521 // Finally, replace the content with an arbitrary string.
522 badVerificationContent := "bootstrap storage verification"
523 reader := strings.NewReader(badVerificationContent)
524 err := storage.Put(
525 "bootstrap-verify",
526 reader,
527 int64(len(badVerificationContent)))
528 c.Assert(err, IsNil)
529 defer restoreBootstrapVerificationFile(c, storage)
530
531 // Running NewConn() should fail.
532 _, err = juju.NewConn(t.Env)
533 c.Assert(err, Equals, environs.InvalidEnvironmentError)
534 }
535
474 type tooler interface { 536 type tooler interface {
475 Life() state.Life 537 Life() state.Life
476 AgentTools() (*state.Tools, error) 538 AgentTools() (*state.Tools, error)
477 Refresh() error 539 Refresh() error
478 String() string 540 String() string
479 } 541 }
480 542
481 type watcher interface { 543 type watcher interface {
482 Stop() error 544 Stop() error
483 Err() error 545 Err() error
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 return err 874 return err
813 } 875 }
814 var buf bytes.Buffer 876 var buf bytes.Buffer
815 _, err = io.Copy(&buf, rc) 877 _, err = io.Copy(&buf, rc)
816 rc.Close() 878 rc.Close()
817 if err != nil { 879 if err != nil {
818 return err 880 return err
819 } 881 }
820 return target.Put(targetPath, &buf, int64(buf.Len())) 882 return target.Put(targetPath, &buf, int64(buf.Len()))
821 } 883 }
OLDNEW
« no previous file with comments | « [revision details] ('k') | environs/open.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b