Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 package nova_test | 1 package nova_test |
2 | 2 |
3 import ( | 3 import ( |
4 "flag" | 4 "flag" |
5 . "launchpad.net/gocheck" | 5 . "launchpad.net/gocheck" |
6 "launchpad.net/goose/client" | 6 "launchpad.net/goose/client" |
7 "launchpad.net/goose/identity" | 7 "launchpad.net/goose/identity" |
8 "launchpad.net/goose/nova" | 8 "launchpad.net/goose/nova" |
9 "testing" | 9 "testing" |
10 "time" | 10 "time" |
11 ) | 11 ) |
12 | 12 |
13 const ( | |
14 // Known, pre-existing image details to use when creating a test server instance. | |
15 testImageId = "0f602ea9-c09e-440c-9e29-cfae5635afa3" // smoser-cloud-i mages/ubuntu-quantal-12.10-i386-server-20121017 | |
16 testFlavourId = "1" // m1.tiny | |
17 // A made up name we use for the test server instance. | |
18 testImageName = "nova_test_server" | |
19 ) | |
20 | |
13 func Test(t *testing.T) { TestingT(t) } | 21 func Test(t *testing.T) { TestingT(t) } |
14 | 22 |
15 var live = flag.Bool("live", false, "Include live OpenStack (Canonistack) tests" ) | 23 var live = flag.Bool("live", false, "Include live OpenStack (Canonistack) tests" ) |
16 | 24 |
17 type NovaSuite struct { | 25 type NovaSuite struct { |
18 nova *nova.Client | 26 nova *nova.Client |
19 testServer *nova.Entity | 27 testServer *nova.Entity |
20 userId string | 28 userId string |
21 tenantId string | 29 tenantId string |
22 } | 30 } |
23 | 31 |
24 func (s *NovaSuite) SetUpSuite(c *C) { | 32 func (s *NovaSuite) SetUpSuite(c *C) { |
25 if !*live { | 33 if !*live { |
26 c.Skip("-live not provided") | 34 c.Skip("-live not provided") |
27 } | 35 } |
28 | 36 |
29 cred, err := identity.CompleteCredentialsFromEnv() | 37 cred, err := identity.CompleteCredentialsFromEnv() |
30 c.Assert(err, IsNil) | 38 c.Assert(err, IsNil) |
31 client := client.NewClient(cred, identity.AuthUserPass) | 39 client := client.NewClient(cred, identity.AuthUserPass) |
32 s.nova = nova.New(client) | 40 s.nova = nova.New(client) |
33 s.testServer, err = s.createInstance(c) | 41 s.testServer, err = s.createInstance(c) |
34 c.Assert(err, IsNil) | 42 c.Assert(err, IsNil) |
43 s.waitTestServerToStart(c) | |
35 // These will not be filled in until a client has authorised which will happen creating the instance above. | 44 // These will not be filled in until a client has authorised which will happen creating the instance above. |
36 s.userId = client.UserId | 45 s.userId = client.UserId |
37 s.tenantId = client.TenantId | 46 s.tenantId = client.TenantId |
38 } | 47 } |
39 | 48 |
40 func (s *NovaSuite) TearDownSuite(c *C) { | 49 func (s *NovaSuite) TearDownSuite(c *C) { |
41 » err := s.nova.DeleteServer(s.testServer.Id) | 50 » if *live { |
42 » c.Check(err, IsNil) | 51 » » err := s.nova.DeleteServer(s.testServer.Id) |
52 » » c.Check(err, IsNil) | |
53 » } | |
43 } | 54 } |
44 | 55 |
45 func (s *NovaSuite) createInstance(c *C) (instance *nova.Entity, err error) { | 56 func (s *NovaSuite) createInstance(c *C) (instance *nova.Entity, err error) { |
46 opts := nova.RunServerOpts{ | 57 opts := nova.RunServerOpts{ |
47 » » Name: "nova_test_server", | 58 » » Name: testImageName, |
48 » » FlavorId: "1", // m1.tiny | 59 » » FlavorId: testFlavourId, |
49 » » ImageId: "0f602ea9-c09e-440c-9e29-cfae5635afa3", | 60 » » ImageId: testImageId, |
50 UserData: nil, | 61 UserData: nil, |
51 } | 62 } |
52 instance, err = s.nova.RunServer(opts) | 63 instance, err = s.nova.RunServer(opts) |
53 if err != nil { | 64 if err != nil { |
54 return nil, err | 65 return nil, err |
55 } | 66 } |
56 s.waitTestServerToStart(c) | |
57 return instance, nil | 67 return instance, nil |
58 } | 68 } |
59 | 69 |
60 var suite = Suite(&NovaSuite{}) | 70 var suite = Suite(&NovaSuite{}) |
61 | 71 |
62 func (n *NovaSuite) TestListFlavors(c *C) { | 72 // Assert that the server record matches the details of the test server image. |
63 » flavors, err := n.nova.ListFlavors() | 73 func (s *NovaSuite) assertServerDetails(c *C, sr *nova.ServerDetail) { |
74 » c.Assert(sr.Id, Equals, s.testServer.Id) | |
75 » c.Assert(sr.Name, Equals, testImageName) | |
76 » c.Assert(sr.Flavor.Id, Equals, testFlavourId) | |
77 » c.Assert(sr.Image.Id, Equals, testImageId) | |
78 } | |
79 | |
80 func (s *NovaSuite) TestListFlavors(c *C) { | |
81 » flavors, err := s.nova.ListFlavors() | |
64 c.Assert(err, IsNil) | 82 c.Assert(err, IsNil) |
65 if len(flavors) < 1 { | 83 if len(flavors) < 1 { |
66 c.Fatalf("no flavors to list") | 84 c.Fatalf("no flavors to list") |
67 } | 85 } |
68 for _, f := range flavors { | 86 for _, f := range flavors { |
69 c.Assert(f.Id, Not(Equals), "") | 87 c.Assert(f.Id, Not(Equals), "") |
70 c.Assert(f.Name, Not(Equals), "") | 88 c.Assert(f.Name, Not(Equals), "") |
71 for _, l := range f.Links { | 89 for _, l := range f.Links { |
72 c.Assert(l.Href, Matches, "https?://.*") | 90 c.Assert(l.Href, Matches, "https?://.*") |
73 c.Assert(l.Rel, Matches, "self|bookmark") | 91 c.Assert(l.Rel, Matches, "self|bookmark") |
74 } | 92 } |
75 } | 93 } |
76 } | 94 } |
77 | 95 |
78 func (n *NovaSuite) TestListFlavorsDetail(c *C) { | 96 func (s *NovaSuite) TestListFlavorsDetail(c *C) { |
79 » flavors, err := n.nova.ListFlavorsDetail() | 97 » flavors, err := s.nova.ListFlavorsDetail() |
80 c.Assert(err, IsNil) | 98 c.Assert(err, IsNil) |
81 if len(*flavors) < 1 { | 99 if len(*flavors) < 1 { |
82 c.Fatalf("no flavors (details) to list") | 100 c.Fatalf("no flavors (details) to list") |
83 } | 101 } |
84 for _, f := range *flavors { | 102 for _, f := range *flavors { |
85 c.Assert(f.Name, Not(Equals), "") | 103 c.Assert(f.Name, Not(Equals), "") |
86 c.Assert(f.Id, Not(Equals), "") | 104 c.Assert(f.Id, Not(Equals), "") |
87 if f.RAM < 0 || f.VCPUs < 0 || f.Disk < 0 { | 105 if f.RAM < 0 || f.VCPUs < 0 || f.Disk < 0 { |
88 c.Fatalf("invalid flavor found: %#v", f) | 106 c.Fatalf("invalid flavor found: %#v", f) |
89 } | 107 } |
90 } | 108 } |
91 } | 109 } |
92 | 110 |
93 func (n *NovaSuite) TestListServers(c *C) { | 111 func (s *NovaSuite) TestListServers(c *C) { |
94 » servers, err := n.nova.ListServers() | 112 » servers, err := s.nova.ListServers() |
95 c.Assert(err, IsNil) | 113 c.Assert(err, IsNil) |
96 foundTest := false | 114 foundTest := false |
97 for _, sr := range *servers { | 115 for _, sr := range *servers { |
98 c.Assert(sr.Id, Not(Equals), "") | 116 c.Assert(sr.Id, Not(Equals), "") |
99 c.Assert(sr.Name, Not(Equals), "") | 117 c.Assert(sr.Name, Not(Equals), "") |
100 » » if sr.Id == n.testServer.Id { | 118 » » if sr.Id == s.testServer.Id { |
101 » » » c.Assert(sr.Name, Equals, "nova_test_server") | 119 » » » c.Assert(sr.Name, Equals, testImageName) |
gz
2012/12/03 12:24:35
Good change.
| |
102 foundTest = true | 120 foundTest = true |
103 } | 121 } |
104 for _, l := range sr.Links { | 122 for _, l := range sr.Links { |
105 c.Assert(l.Href, Matches, "https?://.*") | 123 c.Assert(l.Href, Matches, "https?://.*") |
106 c.Assert(l.Rel, Matches, "self|bookmark") | 124 c.Assert(l.Rel, Matches, "self|bookmark") |
107 } | 125 } |
108 } | 126 } |
109 if !foundTest { | 127 if !foundTest { |
110 » » c.Fatalf("test server (%s) not found in server list", n.testServ er.Id) | 128 » » c.Fatalf("test server (%s) not found in server list", s.testServ er.Id) |
111 » } | 129 » } |
112 } | 130 } |
113 | 131 |
114 func (n *NovaSuite) TestListServersDetail(c *C) { | 132 func (s *NovaSuite) TestListServersDetail(c *C) { |
115 » servers, err := n.nova.ListServersDetail() | 133 » servers, err := s.nova.ListServersDetail() |
116 c.Assert(err, IsNil) | 134 c.Assert(err, IsNil) |
117 if len(*servers) < 1 { | 135 if len(*servers) < 1 { |
118 c.Fatalf("no servers to list (expected at least 1)") | 136 c.Fatalf("no servers to list (expected at least 1)") |
119 } | 137 } |
120 foundTest := false | 138 foundTest := false |
121 for _, sr := range *servers { | 139 for _, sr := range *servers { |
122 c.Assert(sr.Created, Matches, `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{ 2}.*`) | 140 c.Assert(sr.Created, Matches, `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{ 2}.*`) |
123 c.Assert(sr.Updated, Matches, `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{ 2}.*`) | 141 c.Assert(sr.Updated, Matches, `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{ 2}.*`) |
124 c.Assert(sr.Id, Not(Equals), "") | 142 c.Assert(sr.Id, Not(Equals), "") |
125 c.Assert(sr.HostId, Not(Equals), "") | 143 c.Assert(sr.HostId, Not(Equals), "") |
126 » » c.Assert(sr.TenantId, Equals, n.tenantId) | 144 » » c.Assert(sr.TenantId, Equals, s.tenantId) |
127 » » c.Assert(sr.UserId, Equals, n.userId) | 145 » » c.Assert(sr.UserId, Equals, s.userId) |
128 c.Assert(sr.Status, Not(Equals), "") | 146 c.Assert(sr.Status, Not(Equals), "") |
129 c.Assert(sr.Name, Not(Equals), "") | 147 c.Assert(sr.Name, Not(Equals), "") |
130 » » if sr.Id == n.testServer.Id { | 148 » » if sr.Id == s.testServer.Id { |
131 » » » c.Assert(sr.Name, Equals, "nova_test_server") | 149 » » » s.assertServerDetails(c, &sr) |
132 » » » c.Assert(sr.Flavor.Id, Equals, "1") | |
133 » » » c.Assert(sr.Image.Id, Equals, "0f602ea9-c09e-440c-9e29-c fae5635afa3") | |
gz
2012/12/03 12:24:35
I'd stick this image id in the a file level consta
wallyworld
2012/12/03 23:53:55
Yeah, I had meant to do that but it slipped my min
| |
134 foundTest = true | 150 foundTest = true |
135 } | 151 } |
136 for _, l := range sr.Links { | 152 for _, l := range sr.Links { |
137 c.Assert(l.Href, Matches, "https?://.*") | 153 c.Assert(l.Href, Matches, "https?://.*") |
138 c.Assert(l.Rel, Matches, "self|bookmark") | 154 c.Assert(l.Rel, Matches, "self|bookmark") |
139 } | 155 } |
140 c.Assert(sr.Flavor.Id, Not(Equals), "") | 156 c.Assert(sr.Flavor.Id, Not(Equals), "") |
141 for _, f := range sr.Flavor.Links { | 157 for _, f := range sr.Flavor.Links { |
142 c.Assert(f.Href, Matches, "https?://.*") | 158 c.Assert(f.Href, Matches, "https?://.*") |
143 c.Assert(f.Rel, Matches, "self|bookmark") | 159 c.Assert(f.Rel, Matches, "self|bookmark") |
144 } | 160 } |
145 c.Assert(sr.Image.Id, Not(Equals), "") | 161 c.Assert(sr.Image.Id, Not(Equals), "") |
146 for _, i := range sr.Image.Links { | 162 for _, i := range sr.Image.Links { |
147 c.Assert(i.Href, Matches, "https?://.*") | 163 c.Assert(i.Href, Matches, "https?://.*") |
148 c.Assert(i.Rel, Matches, "self|bookmark") | 164 c.Assert(i.Rel, Matches, "self|bookmark") |
149 } | 165 } |
150 } | 166 } |
151 if !foundTest { | 167 if !foundTest { |
152 » » c.Fatalf("test server (%s) not found in server list (details)", n.testServer.Id) | 168 » » c.Fatalf("test server (%s) not found in server list (details)", s.testServer.Id) |
153 » } | 169 » } |
154 } | 170 } |
155 | 171 |
156 func (n *NovaSuite) TestListSecurityGroups(c *C) { | 172 func (s *NovaSuite) TestListSecurityGroups(c *C) { |
157 » groups, err := n.nova.ListSecurityGroups() | 173 » groups, err := s.nova.ListSecurityGroups() |
158 c.Assert(err, IsNil) | 174 c.Assert(err, IsNil) |
159 if len(*groups) < 1 { | 175 if len(*groups) < 1 { |
160 c.Fatalf("no security groups found (expected at least 1)") | 176 c.Fatalf("no security groups found (expected at least 1)") |
161 } | 177 } |
162 for _, g := range *groups { | 178 for _, g := range *groups { |
163 » » c.Assert(g.TenantId, Equals, n.tenantId) | 179 » » c.Assert(g.TenantId, Equals, s.tenantId) |
164 c.Assert(g.Name, Not(Equals), "") | 180 c.Assert(g.Name, Not(Equals), "") |
165 c.Assert(g.Description, Not(Equals), "") | 181 c.Assert(g.Description, Not(Equals), "") |
166 c.Assert(g.Rules, NotNil) | 182 c.Assert(g.Rules, NotNil) |
167 } | 183 } |
168 } | 184 } |
169 | 185 |
170 func (n *NovaSuite) TestCreateAndDeleteSecurityGroup(c *C) { | 186 func (s *NovaSuite) TestCreateAndDeleteSecurityGroup(c *C) { |
171 » group, err := n.nova.CreateSecurityGroup("test_secgroup", "test_desc") | 187 » group, err := s.nova.CreateSecurityGroup("test_secgroup", "test_desc") |
172 c.Assert(err, IsNil) | 188 c.Assert(err, IsNil) |
173 c.Check(group.Name, Equals, "test_secgroup") | 189 c.Check(group.Name, Equals, "test_secgroup") |
174 c.Check(group.Description, Equals, "test_desc") | 190 c.Check(group.Description, Equals, "test_desc") |
175 | 191 |
176 » groups, err := n.nova.ListSecurityGroups() | 192 » groups, err := s.nova.ListSecurityGroups() |
177 found := false | 193 found := false |
178 for _, g := range *groups { | 194 for _, g := range *groups { |
179 if g.Id == group.Id { | 195 if g.Id == group.Id { |
180 found = true | 196 found = true |
181 break | 197 break |
182 } | 198 } |
183 } | 199 } |
184 if found { | 200 if found { |
185 » » err = n.nova.DeleteSecurityGroup(group.Id) | 201 » » err = s.nova.DeleteSecurityGroup(group.Id) |
186 c.Check(err, IsNil) | 202 c.Check(err, IsNil) |
187 } else { | 203 } else { |
188 c.Fatalf("test security group (%d) not found", group.Id) | 204 c.Fatalf("test security group (%d) not found", group.Id) |
189 } | 205 } |
190 } | 206 } |
191 | 207 |
192 func (n *NovaSuite) TestCreateAndDeleteSecurityGroupRules(c *C) { | 208 func (s *NovaSuite) TestCreateAndDeleteSecurityGroupRules(c *C) { |
193 » group1, err := n.nova.CreateSecurityGroup("test_secgroup1", "test_desc") | 209 » group1, err := s.nova.CreateSecurityGroup("test_secgroup1", "test_desc") |
194 » c.Assert(err, IsNil) | 210 » c.Assert(err, IsNil) |
195 » group2, err := n.nova.CreateSecurityGroup("test_secgroup2", "test_desc") | 211 » group2, err := s.nova.CreateSecurityGroup("test_secgroup2", "test_desc") |
196 c.Assert(err, IsNil) | 212 c.Assert(err, IsNil) |
197 | 213 |
198 // First type of rule - port range + protocol | 214 // First type of rule - port range + protocol |
199 ri := nova.RuleInfo{ | 215 ri := nova.RuleInfo{ |
200 IPProtocol: "tcp", | 216 IPProtocol: "tcp", |
201 FromPort: 1234, | 217 FromPort: 1234, |
202 ToPort: 4321, | 218 ToPort: 4321, |
203 Cidr: "10.0.0.0/8", | 219 Cidr: "10.0.0.0/8", |
204 ParentGroupId: group1.Id, | 220 ParentGroupId: group1.Id, |
205 } | 221 } |
206 » rule, err := n.nova.CreateSecurityGroupRule(ri) | 222 » rule, err := s.nova.CreateSecurityGroupRule(ri) |
207 c.Assert(err, IsNil) | 223 c.Assert(err, IsNil) |
208 c.Check(*rule.FromPort, Equals, 1234) | 224 c.Check(*rule.FromPort, Equals, 1234) |
209 c.Check(*rule.ToPort, Equals, 4321) | 225 c.Check(*rule.ToPort, Equals, 4321) |
210 c.Check(rule.ParentGroupId, Equals, group1.Id) | 226 c.Check(rule.ParentGroupId, Equals, group1.Id) |
211 c.Check(*rule.IPProtocol, Equals, "tcp") | 227 c.Check(*rule.IPProtocol, Equals, "tcp") |
212 c.Check(rule.Group, HasLen, 0) | 228 c.Check(rule.Group, HasLen, 0) |
213 » err = n.nova.DeleteSecurityGroupRule(rule.Id) | 229 » err = s.nova.DeleteSecurityGroupRule(rule.Id) |
214 c.Check(err, IsNil) | 230 c.Check(err, IsNil) |
215 | 231 |
216 // Second type of rule - inherited from another group | 232 // Second type of rule - inherited from another group |
217 ri = nova.RuleInfo{ | 233 ri = nova.RuleInfo{ |
218 GroupId: &group2.Id, | 234 GroupId: &group2.Id, |
219 ParentGroupId: group1.Id, | 235 ParentGroupId: group1.Id, |
220 } | 236 } |
221 » rule, err = n.nova.CreateSecurityGroupRule(ri) | 237 » rule, err = s.nova.CreateSecurityGroupRule(ri) |
222 c.Assert(err, IsNil) | 238 c.Assert(err, IsNil) |
223 c.Check(rule.ParentGroupId, Equals, group1.Id) | 239 c.Check(rule.ParentGroupId, Equals, group1.Id) |
224 » c.Check(rule.Group["tenant_id"], Equals, n.tenantId) | 240 » c.Check(rule.Group["tenant_id"], Equals, s.tenantId) |
225 c.Check(rule.Group["name"], Equals, "test_secgroup2") | 241 c.Check(rule.Group["name"], Equals, "test_secgroup2") |
226 » err = n.nova.DeleteSecurityGroupRule(rule.Id) | 242 » err = s.nova.DeleteSecurityGroupRule(rule.Id) |
227 » c.Check(err, IsNil) | 243 » c.Check(err, IsNil) |
228 | 244 |
229 » err = n.nova.DeleteSecurityGroup(group1.Id) | 245 » err = s.nova.DeleteSecurityGroup(group1.Id) |
230 » c.Check(err, IsNil) | 246 » c.Check(err, IsNil) |
231 » err = n.nova.DeleteSecurityGroup(group2.Id) | 247 » err = s.nova.DeleteSecurityGroup(group2.Id) |
232 » c.Check(err, IsNil) | 248 » c.Check(err, IsNil) |
233 } | 249 } |
234 | 250 |
235 func (n *NovaSuite) TestGetServer(c *C) { | 251 func (s *NovaSuite) TestGetServer(c *C) { |
236 » server, err := n.nova.GetServer(n.testServer.Id) | 252 » server, err := s.nova.GetServer(s.testServer.Id) |
237 » c.Assert(err, IsNil) | 253 » c.Assert(err, IsNil) |
238 » c.Assert(server.Id, Equals, n.testServer.Id) | 254 » s.assertServerDetails(c, server) |
239 » c.Assert(server.Name, Equals, "nova_test_server") | 255 } |
240 » c.Assert(server.Flavor.Id, Equals, "1") | 256 |
241 » c.Assert(server.Image.Id, Equals, "0f602ea9-c09e-440c-9e29-cfae5635afa3" ) | 257 func (s *NovaSuite) waitTestServerToStart(c *C) { |
gz
2012/12/03 12:24:35
If reasserting this, move inside a helper?
| |
242 } | |
243 | |
244 func (n *NovaSuite) waitTestServerToStart(c *C) { | |
245 // Wait until the test server is actually running | 258 // Wait until the test server is actually running |
246 » c.Logf("waiting the test server %s to start...", n.testServer.Id) | 259 » c.Logf("waiting the test server %s to start...", s.testServer.Id) |
247 for { | 260 for { |
248 » » server, err := n.nova.GetServer(n.testServer.Id) | 261 » » server, err := s.nova.GetServer(s.testServer.Id) |
249 c.Assert(err, IsNil) | 262 c.Assert(err, IsNil) |
250 if server.Status == "ACTIVE" { | 263 if server.Status == "ACTIVE" { |
251 break | 264 break |
252 } | 265 } |
253 // There's a rate limit of max 10 POSTs per minute! | 266 // There's a rate limit of max 10 POSTs per minute! |
254 time.Sleep(10 * time.Second) | 267 time.Sleep(10 * time.Second) |
255 } | 268 } |
256 c.Logf("started") | 269 c.Logf("started") |
257 } | 270 } |
258 | 271 |
259 func (n *NovaSuite) TestServerAddGetRemoveSecurityGroup(c *C) { | 272 func (s *NovaSuite) TestServerAddGetRemoveSecurityGroup(c *C) { |
260 » group, err := n.nova.CreateSecurityGroup("test_server_secgroup", "test d esc") | 273 » group, err := s.nova.CreateSecurityGroup("test_server_secgroup", "test d esc") |
261 » c.Assert(err, IsNil) | 274 » c.Assert(err, IsNil) |
262 | 275 |
263 » n.waitTestServerToStart(c) | 276 » s.waitTestServerToStart(c) |
264 » err = n.nova.AddServerSecurityGroup(n.testServer.Id, group.Name) | 277 » err = s.nova.AddServerSecurityGroup(s.testServer.Id, group.Name) |
265 » c.Assert(err, IsNil) | 278 » c.Assert(err, IsNil) |
266 » groups, err := n.nova.GetServerSecurityGroups(n.testServer.Id) | 279 » groups, err := s.nova.GetServerSecurityGroups(s.testServer.Id) |
267 c.Assert(err, IsNil) | 280 c.Assert(err, IsNil) |
268 found := false | 281 found := false |
269 for _, g := range *groups { | 282 for _, g := range *groups { |
270 if g.Id == group.Id || g.Name == group.Name { | 283 if g.Id == group.Id || g.Name == group.Name { |
271 found = true | 284 found = true |
272 break | 285 break |
273 } | 286 } |
274 } | 287 } |
275 » err = n.nova.RemoveServerSecurityGroup(n.testServer.Id, group.Name) | 288 » err = s.nova.RemoveServerSecurityGroup(s.testServer.Id, group.Name) |
276 » c.Check(err, IsNil) | 289 » c.Check(err, IsNil) |
277 | 290 |
278 » err = n.nova.DeleteSecurityGroup(group.Id) | 291 » err = s.nova.DeleteSecurityGroup(group.Id) |
279 c.Assert(err, IsNil) | 292 c.Assert(err, IsNil) |
280 | 293 |
281 if !found { | 294 if !found { |
282 c.Fail() | 295 c.Fail() |
283 } | 296 } |
284 } | 297 } |
285 | 298 |
286 func (n *NovaSuite) TestFloatingIPs(c *C) { | 299 func (s *NovaSuite) TestFloatingIPs(c *C) { |
287 » ip, err := n.nova.AllocateFloatingIP() | 300 » ip, err := s.nova.AllocateFloatingIP() |
288 c.Assert(err, IsNil) | 301 c.Assert(err, IsNil) |
289 c.Check(ip.IP, Not(Equals), "") | 302 c.Check(ip.IP, Not(Equals), "") |
290 c.Check(ip.Pool, Not(Equals), "") | 303 c.Check(ip.Pool, Not(Equals), "") |
291 c.Check(ip.FixedIP, IsNil) | 304 c.Check(ip.FixedIP, IsNil) |
292 c.Check(ip.InstanceId, IsNil) | 305 c.Check(ip.InstanceId, IsNil) |
293 | 306 |
294 » ips, err := n.nova.ListFloatingIPs() | 307 » ips, err := s.nova.ListFloatingIPs() |
295 c.Assert(err, IsNil) | 308 c.Assert(err, IsNil) |
296 if len(*ips) < 1 { | 309 if len(*ips) < 1 { |
297 c.Errorf("no floating IPs found (expected at least 1)") | 310 c.Errorf("no floating IPs found (expected at least 1)") |
298 } else { | 311 } else { |
299 found := false | 312 found := false |
300 for _, i := range *ips { | 313 for _, i := range *ips { |
301 c.Check(i.IP, Not(Equals), "") | 314 c.Check(i.IP, Not(Equals), "") |
302 c.Check(i.Pool, Not(Equals), "") | 315 c.Check(i.Pool, Not(Equals), "") |
303 if i.Id == ip.Id { | 316 if i.Id == ip.Id { |
304 c.Check(i.IP, Equals, ip.IP) | 317 c.Check(i.IP, Equals, ip.IP) |
305 c.Check(i.Pool, Equals, ip.Pool) | 318 c.Check(i.Pool, Equals, ip.Pool) |
306 found = true | 319 found = true |
307 } | 320 } |
308 } | 321 } |
309 if !found { | 322 if !found { |
310 c.Errorf("expected to find added floating IP: %#v", ip) | 323 c.Errorf("expected to find added floating IP: %#v", ip) |
311 } | 324 } |
312 | 325 |
313 » » fip, err := n.nova.GetFloatingIP(ip.Id) | 326 » » fip, err := s.nova.GetFloatingIP(ip.Id) |
314 c.Assert(err, IsNil) | 327 c.Assert(err, IsNil) |
315 c.Check(fip.Id, Equals, ip.Id) | 328 c.Check(fip.Id, Equals, ip.Id) |
316 c.Check(fip.IP, Equals, ip.IP) | 329 c.Check(fip.IP, Equals, ip.IP) |
317 c.Check(fip.Pool, Equals, ip.Pool) | 330 c.Check(fip.Pool, Equals, ip.Pool) |
318 } | 331 } |
319 » err = n.nova.DeleteFloatingIP(ip.Id) | 332 » err = s.nova.DeleteFloatingIP(ip.Id) |
320 » c.Check(err, IsNil) | 333 » c.Check(err, IsNil) |
321 } | 334 } |
322 | 335 |
323 func (n *NovaSuite) TestServerFloatingIPs(c *C) { | 336 func (s *NovaSuite) TestServerFloatingIPs(c *C) { |
324 » ip, err := n.nova.AllocateFloatingIP() | 337 » ip, err := s.nova.AllocateFloatingIP() |
325 c.Assert(err, IsNil) | 338 c.Assert(err, IsNil) |
326 c.Check(ip.IP, Matches, `\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}`) | 339 c.Check(ip.IP, Matches, `\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}`) |
327 | 340 |
328 » n.waitTestServerToStart(c) | 341 » s.waitTestServerToStart(c) |
329 » err = n.nova.AddServerFloatingIP(n.testServer.Id, ip.IP) | 342 » err = s.nova.AddServerFloatingIP(s.testServer.Id, ip.IP) |
330 » c.Assert(err, IsNil) | 343 » c.Assert(err, IsNil) |
331 | 344 |
332 » fip, err := n.nova.GetFloatingIP(ip.Id) | 345 » fip, err := s.nova.GetFloatingIP(ip.Id) |
333 c.Assert(err, IsNil) | 346 c.Assert(err, IsNil) |
334 c.Check(fip.FixedIP, Matches, `\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}`) | 347 c.Check(fip.FixedIP, Matches, `\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}`) |
335 » c.Check(fip.InstanceId, Equals, n.testServer.Id) | 348 » c.Check(fip.InstanceId, Equals, s.testServer.Id) |
336 | 349 |
337 » err = n.nova.RemoveServerFloatingIP(n.testServer.Id, ip.IP) | 350 » err = s.nova.RemoveServerFloatingIP(s.testServer.Id, ip.IP) |
338 » c.Check(err, IsNil) | 351 » c.Check(err, IsNil) |
339 » fip, err = n.nova.GetFloatingIP(ip.Id) | 352 » fip, err = s.nova.GetFloatingIP(ip.Id) |
340 c.Assert(err, IsNil) | 353 c.Assert(err, IsNil) |
341 c.Check(fip.FixedIP, IsNil) | 354 c.Check(fip.FixedIP, IsNil) |
342 c.Check(fip.InstanceId, IsNil) | 355 c.Check(fip.InstanceId, IsNil) |
343 | 356 |
344 » err = n.nova.DeleteFloatingIP(ip.Id) | 357 » err = s.nova.DeleteFloatingIP(ip.Id) |
345 » c.Check(err, IsNil) | 358 » c.Check(err, IsNil) |
346 } | 359 } |
LEFT | RIGHT |