7
. "launchpad.net/gocheck"
8
"launchpad.net/goose/client"
9
"launchpad.net/goose/identity"
10
"launchpad.net/juju-core/environs"
11
"launchpad.net/juju-core/environs/jujutest"
12
"launchpad.net/juju-core/environs/openstack"
13
envtesting "launchpad.net/juju-core/environs/testing"
14
coretesting "launchpad.net/juju-core/testing"
17
// generate a different bucket name for each config instance, so that
18
// we are not polluted by previous test state.
19
func randomName() string {
20
buf := make([]byte, 8)
21
_, err := io.ReadFull(rand.Reader, buf)
23
panic(fmt.Sprintf("error from crypto rand: %v", err))
25
return fmt.Sprintf("%x", buf)
28
func makeTestConfig(cred *identity.Credentials) map[string]interface{} {
29
// The following attributes hold the environment configuration
30
// for running the OpenStack integration tests.
32
// This is missing keys for security reasons; set the following
33
// environment variables to make the OpenStack testing work:
34
// access-key: $OS_USERNAME
35
// secret-key: $OS_PASSWORD
37
attrs := map[string]interface{}{
38
"name": "sample-" + randomName(),
40
"auth-mode": "userpass",
41
"control-bucket": "juju-test-" + randomName(),
42
"ca-cert": coretesting.CACert,
43
"ca-private-key": coretesting.CAKey,
44
"authorized-keys": "fakekey",
45
"admin-secret": "secret",
46
"username": cred.User,
47
"password": cred.Secrets,
48
"region": cred.Region,
50
"tenant-name": cred.TenantName,
55
// Register tests to run against a real Openstack instance.
56
func registerLiveTests(cred *identity.Credentials, testImageDetails openstack.ImageDetails) {
57
config := makeTestConfig(cred)
58
config["default-image-id"] = testImageDetails.ImageId
59
config["default-instance-type"] = testImageDetails.Flavor
62
LiveTests: jujutest.LiveTests{
63
TestConfig: jujutest.TestConfig{config},
64
Attempt: *openstack.ShortAttempt,
65
// TODO: Bug #1133263, once the infrastructure is set up,
66
// enable The state tests on openstack
68
// TODO: Bug #1133272, enabling this requires mapping from
69
// 'series' to an image id, when we have support, set
71
HasProvisioner: false,
73
testImageId: testImageDetails.ImageId,
74
testFlavor: testImageDetails.Flavor,
78
// LiveTests contains tests that can be run against OpenStack deployments.
79
// The deployment can be a real live instance or service doubles.
80
// Each test runs using the same connection.
81
type LiveTests struct {
82
coretesting.LoggingSuite
84
cred *identity.Credentials
87
writeablePublicStorage environs.Storage
90
func (t *LiveTests) SetUpSuite(c *C) {
91
t.LoggingSuite.SetUpSuite(c)
92
// Update some Config items now that we have services running.
93
// This is setting the public-bucket-url and auth-url because that
94
// information is set during startup of the localLiveSuite
95
cl := client.NewClient(t.cred, identity.AuthUserPass, nil)
96
err := cl.Authenticate()
98
publicBucketURL, err := cl.MakeServiceURL("object-store", nil)
100
t.TestConfig.UpdateConfig(map[string]interface{}{
101
"public-bucket-url": publicBucketURL,
102
"auth-url": t.cred.URL,
104
t.LiveTests.SetUpSuite(c)
105
// Environ.PublicStorage() is read only.
106
// For testing, we create a specific storage instance which is authorised to write to
107
// the public storage bucket so that we can upload files for testing.
108
t.writeablePublicStorage = openstack.WritablePublicStorage(t.Env)
109
// Put some fake tools in place so that tests that are simply
110
// starting instances without any need to check if those instances
111
// are running will find them in the public bucket.
112
envtesting.UploadFakeTools(c, t.writeablePublicStorage)
115
func (t *LiveTests) TearDownSuite(c *C) {
117
// This can happen if SetUpSuite fails.
120
if t.writeablePublicStorage != nil {
121
err := openstack.DeleteStorageContent(t.writeablePublicStorage)
124
t.LiveTests.TearDownSuite(c)
125
t.LoggingSuite.TearDownSuite(c)
128
func (t *LiveTests) SetUpTest(c *C) {
129
t.LoggingSuite.SetUpTest(c)
130
t.LiveTests.SetUpTest(c)
133
func (t *LiveTests) TearDownTest(c *C) {
134
t.LiveTests.TearDownTest(c)
135
t.LoggingSuite.TearDownTest(c)