23
24
"github.com/juju/juju/environs"
24
25
"github.com/juju/juju/environs/bootstrap"
25
26
"github.com/juju/juju/environs/config"
26
"github.com/juju/juju/environs/configstore"
27
27
"github.com/juju/juju/environs/filestorage"
28
28
sstesting "github.com/juju/juju/environs/simplestreams/testing"
29
29
"github.com/juju/juju/environs/storage"
43
43
"github.com/juju/juju/testcharms"
44
44
coretesting "github.com/juju/juju/testing"
45
45
coretools "github.com/juju/juju/tools"
46
"github.com/juju/juju/version"
46
jujuversion "github.com/juju/juju/version"
49
49
// LiveTests contains tests that are designed to run against a live server
84
84
// This is set by PrepareOnce and BootstrapOnce.
85
85
Env environs.Environ
87
// ConfigStore holds the configuration storage
88
// used when preparing the environment.
89
// This is initialized by SetUpSuite.
90
ConfigStore configstore.Storage
92
87
// ControllerStore holds the controller related informtion
93
88
// such as controllers, accounts, etc., used when preparing
94
89
// the environment. This is initialized by SetUpSuite.
102
97
func (t *LiveTests) SetUpSuite(c *gc.C) {
103
98
t.CleanupSuite.SetUpSuite(c)
104
99
t.TestDataSuite.SetUpSuite(c)
105
t.ConfigStore = configstore.NewMem()
106
100
t.ControllerStore = jujuclienttesting.NewMemStore()
107
101
t.PatchValue(&juju.JujuPublicKey, sstesting.SignedMetadataPublicKey)
110
104
func (t *LiveTests) SetUpTest(c *gc.C) {
111
105
t.CleanupSuite.SetUpTest(c)
112
t.PatchValue(&version.Current, coretesting.FakeVersionNumber)
106
t.PatchValue(&jujuversion.Current, coretesting.FakeVersionNumber)
113
107
storageDir := c.MkDir()
114
108
t.DefaultBaseURL = "file://" + storageDir + "/tools"
115
109
t.ToolsFixture.SetUpTest(c)
120
114
t.CleanupSuite.PatchValue(&envtools.BundleTools, envtoolstesting.GetMockBundleTools(c))
123
func publicAttrs(e environs.Environ) map[string]interface{} {
125
secrets, err := e.Provider().SecretAttrs(cfg)
129
attrs := cfg.AllAttrs()
130
for attr := range secrets {
136
117
func (t *LiveTests) TearDownSuite(c *gc.C) {
138
119
t.TestDataSuite.TearDownSuite(c)
153
134
args := t.prepareForBootstrapParams(c)
154
e, err := environs.Prepare(envtesting.BootstrapContext(c), t.ConfigStore, t.ControllerStore, args.Config.Name(), args)
135
e, err := environs.Prepare(envtesting.BootstrapContext(c), t.ControllerStore, args)
155
136
c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", t.TestConfig))
156
137
c.Assert(e, gc.NotNil)
158
139
t.prepared = true
161
func (t *LiveTests) prepareForBootstrapParams(c *gc.C) environs.PrepareForBootstrapParams {
162
cfg, err := config.New(config.NoDefaults, t.TestConfig)
163
c.Assert(err, jc.ErrorIsNil)
142
func (t *LiveTests) prepareForBootstrapParams(c *gc.C) environs.PrepareParams {
164
143
credential := t.Credential
165
144
if credential.AuthType() == "" {
166
145
credential = cloud.NewEmptyCredential()
168
return environs.PrepareForBootstrapParams{
170
Credentials: credential,
171
CloudEndpoint: t.CloudEndpoint,
172
CloudRegion: t.CloudRegion,
147
return environs.PrepareParams{
148
BaseConfig: t.TestConfig,
149
Credential: credential,
150
CloudEndpoint: t.CloudEndpoint,
151
CloudRegion: t.CloudRegion,
152
ControllerName: t.TestConfig["name"].(string),
153
CloudName: t.TestConfig["type"].(string),
188
169
err := bootstrap.Bootstrap(envtesting.BootstrapContext(c), t.Env, bootstrap.BootstrapParams{
189
170
BootstrapConstraints: cons,
190
EnvironConstraints: cons,
171
ModelConstraints: cons,
192
173
c.Assert(err, jc.ErrorIsNil)
193
174
t.bootstrapped = true
197
178
if t.Env == nil {
200
err := environs.Destroy(t.Env.Config().Name(), t.Env, t.ConfigStore, t.ControllerStore)
181
err := environs.Destroy(t.Env.Config().Name(), t.Env, t.ControllerStore)
201
182
c.Assert(err, jc.ErrorIsNil)
202
183
t.bootstrapped = false
203
184
t.prepared = false
470
451
c.Assert(err, jc.ErrorIsNil)
471
452
agentVersion, ok := cfg.AgentVersion()
472
453
c.Check(ok, jc.IsTrue)
473
c.Check(agentVersion, gc.Equals, version.Current)
454
c.Check(agentVersion, gc.Equals, jujuversion.Current)
475
456
// Check that the constraints have been set in the environment.
476
457
cons, err := st.ModelConstraints()
496
477
// If the series has not been specified, we expect the most recent Ubuntu LTS release to be used.
497
478
expectedVersion := version.Binary{
498
Number: version.Current,
479
Number: jujuversion.Current,
499
480
Arch: arch.HostArch(),
500
481
Series: config.LatestLtsSeries(),
709
690
Delay: 1 * time.Second,
712
func (t *LiveTests) assertStartInstance(c *gc.C, m *state.Machine) {
713
// Wait for machine to get an instance id.
714
for a := waitAgent.Start(); a.Next(); {
716
c.Assert(err, jc.ErrorIsNil)
717
instId, err := m.InstanceId()
719
c.Assert(err, jc.Satisfies, errors.IsNotProvisioned)
722
_, err = t.Env.Instances([]instance.Id{instId})
723
c.Assert(err, jc.ErrorIsNil)
726
c.Fatalf("provisioner failed to start machine after %v", waitAgent.Total)
729
693
func (t *LiveTests) assertStopInstance(c *gc.C, env environs.Environ, instId instance.Id) {
731
695
for a := waitAgent.Start(); a.Next(); {
741
705
c.Fatalf("provisioner failed to stop machine after %v", waitAgent.Total)
744
// assertInstanceId asserts that the machine has an instance id
745
// that matches that of the given instance. If the instance is nil,
746
// It asserts that the instance id is unset.
747
func assertInstanceId(c *gc.C, m *state.Machine, inst instance.Instance) {
748
var wantId, gotId instance.Id
753
for a := waitAgent.Start(); a.Next(); {
755
c.Assert(err, jc.ErrorIsNil)
756
gotId, err = m.InstanceId()
758
c.Assert(err, jc.Satisfies, errors.IsNotProvisioned)
766
c.Assert(err, jc.ErrorIsNil)
767
c.Assert(gotId, gc.Equals, wantId)
770
708
// Check that we get a consistent error when asking for an instance without
771
709
// a valid machine config.
772
710
func (t *LiveTests) TestStartInstanceWithEmptyNonceFails(c *gc.C) {
816
754
other.Series = "precise"
819
dummyCfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(coretesting.Attrs{
757
dummyCfg := dummy.SampleConfig().Merge(coretesting.Attrs{
820
758
"controller": false,
821
759
"name": "dummy storage",
823
761
args := t.prepareForBootstrapParams(c)
824
args.Config = dummyCfg
762
args.BaseConfig = dummyCfg
825
763
dummyenv, err := environs.Prepare(envtesting.BootstrapContext(c),
826
configstore.NewMem(),
827
764
jujuclienttesting.NewMemStore(),
830
767
c.Assert(err, jc.ErrorIsNil)
831
768
defer dummyenv.Destroy()
835
attrs := t.TestConfig.Merge(coretesting.Attrs{"default-series": other.Series})
836
cfg, err := config.New(config.NoDefaults, attrs)
837
c.Assert(err, jc.ErrorIsNil)
772
attrs := t.TestConfig.Merge(coretesting.Attrs{
774
"default-series": other.Series,
776
args.BaseConfig = attrs
839
777
env, err := environs.Prepare(envtesting.BootstrapContext(c),
841
778
t.ControllerStore,
843
780
c.Assert(err, jc.ErrorIsNil)
844
defer environs.Destroy("livetests", env, t.ConfigStore, t.ControllerStore)
781
defer environs.Destroy("livetests", env, t.ControllerStore)
846
783
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{})
847
784
c.Assert(err, jc.ErrorIsNil)