27
25
c.Skip("-live not provided")
30
username, password, tenant, region, auth_url := client.GetEnvVars()
31
for i, p := range []string{username, password, tenant, region, auth_url} {
28
cred := identity.CredentialsFromEnv()
29
for i, p := range []string{cred.User, cred.Secrets, cred.TenantName, cred.Region, cred.URL} {
33
31
c.Fatalf("required environment variable not set: %d", i)
37
s.client = &client.OpenStackClient{IdentityEndpoint: auth_url, Region: region}
35
s.client = client.NewOpenStackClient(cred, identity.AUTH_USERPASS)
41
36
s.skipAuth = true // set after TestAuthenticate
54
49
ImageId: "3fc0ef0b-82a9-4f44-a797-a43f0f73b20e", // smoser-cloud-images/ubuntu-precise-12.04-i386-server-20120424.manifest.xml
56
51
err := s.client.RunServer(ro)
53
c.Fatal("Error starting test server: " + err.Error())
59
56
// Now find it and save its ID
60
57
servers, err := s.client.ListServers()
91
88
var suite = Suite(&ClientSuite{})
93
var authTests = []struct {
99
summary: "empty args",
100
inputs: []string{"", "", ""},
101
err: "required arg.*missing",
104
summary: "dummy args",
105
inputs: []string{"phony", "fake", "dummy"},
106
err: "authentication failed.*",
109
summary: "valid args",
110
inputs: []string{"!", "", ""},
90
func (s *ClientSuite) TestAuthenticateFail(c *C) {
91
cred := identity.CredentialsFromEnv()
93
cred.Secrets = "broken"
95
var osclient *client.OpenStackClient = client.NewOpenStackClient(cred, identity.AUTH_USERPASS)
96
c.Assert(osclient.IsAuthenticated(), Equals, false)
98
err = osclient.Authenticate()
99
c.Assert(err, ErrorMatches, "authentication failed.*")
115
102
func (s *ClientSuite) TestAuthenticate(c *C) {
116
c.Assert(s.client.IsAuthenticated(), Equals, false)
117
for _, t := range authTests {
118
c.Logf("test: %s", t.summary)
120
if t.inputs[0] == "!" {
121
err = s.client.Authenticate(s.username, s.password, s.tenant)
123
err = s.client.Authenticate(t.inputs[0], t.inputs[1], t.inputs[2])
127
c.Assert(s.client.IsAuthenticated(), Equals, true)
129
c.Assert(err, ErrorMatches, t.err)
104
err = s.client.Authenticate()
106
c.Assert(s.client.IsAuthenticated(), Equals, true)
133
108
// Check service endpoints are discovered
134
c.Assert(s.client.Services["compute"], NotNil)
135
c.Assert(s.client.Services["swift"], NotNil)
109
c.Assert(s.client.ServiceURLs["compute"], NotNil)
110
c.Assert(s.client.ServiceURLs["swift"], NotNil)
137
112
s.skipAuth = false
204
179
c.Assert(sr.Updated, Matches, `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.*`)
205
180
c.Assert(sr.Id, Not(Equals), "")
206
181
c.Assert(sr.HostId, Not(Equals), "")
207
c.Assert(sr.TenantId, Equals, s.client.Token.Tenant.Id)
208
c.Assert(sr.UserId, Equals, s.client.User.Id)
182
c.Assert(sr.TenantId, Equals, s.client.TenantId)
183
c.Assert(sr.UserId, Equals, s.client.UserId)
209
184
c.Assert(sr.Status, Not(Equals), "")
210
185
c.Assert(sr.Name, Not(Equals), "")
211
186
if sr.Id == s.testServerId {
241
216
c.Fatalf("no security groups found (expected at least 1)")
243
218
for _, g := range groups {
244
c.Assert(g.TenantId, Equals, s.client.Token.Tenant.Id)
219
c.Assert(g.TenantId, Equals, s.client.TenantId)
245
220
c.Assert(g.Name, Not(Equals), "")
246
221
c.Assert(g.Description, Not(Equals), "")
247
222
c.Assert(g.Rules, NotNil)
302
277
rule, err = s.client.CreateSecurityGroupRule(ri)
303
278
c.Check(err, IsNil)
304
279
c.Check(rule.ParentGroupId, Equals, group1.Id)
305
c.Check(rule.Group["tenant_id"], Equals, s.client.Token.Tenant.Id)
280
c.Check(rule.Group["tenant_id"], Equals, s.client.TenantId)
306
281
c.Check(rule.Group["name"], Equals, "test_secgroup2")
307
282
err = s.client.DeleteSecurityGroupRule(rule.Id)
308
283
c.Check(err, IsNil)
325
300
func (s *ClientSuite) waitTestServerToStart(c *C) {
326
301
// Wait until the test server is actually running
327
c.Logf("waiting the test server to start...")
302
c.Logf("waiting the test server %s to start...", s.testServerId)
329
304
server, err := s.client.GetServer(s.testServerId)
330
305
c.Check(err, IsNil)