| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
package cloudapi_test |
| 11 |
|
| 12 |
import ( |
| 13 |
"log" |
| 14 |
"os" |
| 15 |
"strings" |
| 16 |
"time" |
| 17 |
|
| 18 |
gc "launchpad.net/gocheck" |
| 19 |
|
| 20 |
"github.com/joyent/gocommon/client" |
| 21 |
"github.com/joyent/gosdc/cloudapi" |
| 22 |
"github.com/joyent/gosign/auth" |
| 23 |
) |
| 24 |
|
| 25 |
func registerJoyentCloudTests(creds *auth.Credentials) { |
| 26 |
gc.Suite(&LiveTests{creds: creds}) |
| 27 |
} |
| 28 |
|
| 29 |
type LiveTests struct { |
| 30 |
creds *auth.Credentials |
| 31 |
testClient *cloudapi.Client |
| 32 |
} |
| 33 |
|
| 34 |
func (s *LiveTests) SetUpTest(c *gc.C) { |
| 35 |
client := client.NewClient(s.creds.SdcEndpoint.URL, cloudapi.DefaultAPIVersion, s.creds, log.New(os.Stderr, "", log.LstdFlags)) |
| 36 |
c.Assert(client, gc.NotNil) |
| 37 |
s.testClient = cloudapi.New(client) |
| 38 |
c.Assert(s.testClient, gc.NotNil) |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
func (s *LiveTests) createKey(c *gc.C) { |
| 43 |
key, err := s.testClient.CreateKey(cloudapi.CreateKeyOpts{Name: "fake-key", Key: testKey}) |
| 44 |
c.Assert(err, gc.IsNil) |
| 45 |
c.Assert(key, gc.NotNil) |
| 46 |
c.Assert(key, gc.DeepEquals, &cloudapi.Key{Name: "fake-key", Fingerprint: testKeyFingerprint, Key: testKey}) |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
func (s *LiveTests) createMachine(c *gc.C) *cloudapi.Machine { |
| 51 |
machine, err := s.testClient.CreateMachine(cloudapi.CreateMachineOpts{Package: packageName, Image: imageID}) |
| 52 |
c.Assert(err, gc.IsNil) |
| 53 |
c.Assert(machine, gc.NotNil) |
| 54 |
|
| 55 |
|
| 56 |
for !s.pollMachineState(c, machine.Id, "running") { |
| 57 |
time.Sleep(1 * time.Second) |
| 58 |
} |
| 59 |
|
| 60 |
return machine |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
func (s *LiveTests) createMachineWithTags(c *gc.C, tags map[string]string) *cloudapi.Machine { |
| 65 |
machine, err := s.testClient.CreateMachine(cloudapi.CreateMachineOpts{Package: packageName, Image: imageID, Tags: tags}) |
| 66 |
c.Assert(err, gc.IsNil) |
| 67 |
c.Assert(machine, gc.NotNil) |
| 68 |
|
| 69 |
|
| 70 |
for !s.pollMachineState(c, machine.Id, "running") { |
| 71 |
time.Sleep(1 * time.Second) |
| 72 |
} |
| 73 |
|
| 74 |
return machine |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
func (s *LiveTests) pollMachineState(c *gc.C, machineId, state string) bool { |
| 79 |
machineConfig, err := s.testClient.GetMachine(machineId) |
| 80 |
c.Assert(err, gc.IsNil) |
| 81 |
return strings.EqualFold(machineConfig.State, state) |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
func (s *LiveTests) deleteMachine(c *gc.C, machineId string) { |
| 86 |
err := s.testClient.StopMachine(machineId) |
| 87 |
c.Assert(err, gc.IsNil) |
| 88 |
|
| 89 |
|
| 90 |
for !s.pollMachineState(c, machineId, "stopped") { |
| 91 |
time.Sleep(1 * time.Second) |
| 92 |
} |
| 93 |
|
| 94 |
err = s.testClient.DeleteMachine(machineId) |
| 95 |
c.Assert(err, gc.IsNil) |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
func (s *LiveTests) listMachines(c *gc.C, filter *cloudapi.Filter) { |
| 100 |
var contains bool |
| 101 |
testMachine := s.createMachine(c) |
| 102 |
defer s.deleteMachine(c, testMachine.Id) |
| 103 |
|
| 104 |
machines, err := s.testClient.ListMachines(filter) |
| 105 |
c.Assert(err, gc.IsNil) |
| 106 |
c.Assert(machines, gc.NotNil) |
| 107 |
for _, m := range machines { |
| 108 |
if m.Id == testMachine.Id { |
| 109 |
contains = true |
| 110 |
break |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
if !contains { |
| 116 |
c.Fatalf("Obtained machines [%s] do not contain test machine [%s]", machines, *testMachine) |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
func (s *LiveTests) createMachineSnapshot(c *gc.C, machineId string) string { |
| 122 |
|
| 123 |
t := time.Now() |
| 124 |
snapshotName := "test-machine-snapshot-" + t.Format("20060102_150405") |
| 125 |
snapshot, err := s.testClient.CreateMachineSnapshot(machineId, cloudapi.SnapshotOpts{Name: snapshotName}) |
| 126 |
c.Assert(err, gc.IsNil) |
| 127 |
c.Assert(snapshot, gc.NotNil) |
| 128 |
c.Assert(snapshot, gc.DeepEquals, &cloudapi.Snapshot{Name: snapshotName, State: "queued"}) |
| 129 |
|
| 130 |
return snapshotName |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
func (s *LiveTests) createFirewallRule(c *gc.C) *cloudapi.FirewallRule { |
| 135 |
fwRule, err := s.testClient.CreateFirewallRule(cloudapi.CreateFwRuleOpts{Enabled: false, Rule: testFwRule}) |
| 136 |
c.Assert(err, gc.IsNil) |
| 137 |
c.Assert(fwRule, gc.NotNil) |
| 138 |
c.Assert(fwRule.Rule, gc.Equals, testFwRule) |
| 139 |
c.Assert(fwRule.Enabled, gc.Equals, false) |
| 140 |
time.Sleep(10 * time.Second) |
| 141 |
|
| 142 |
return fwRule |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
func (s *LiveTests) deleteFwRule(c *gc.C, fwRuleId string) { |
| 147 |
err := s.testClient.DeleteFirewallRule(fwRuleId) |
| 148 |
c.Assert(err, gc.IsNil) |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
func (s *LiveTests) TestCreateKey(c *gc.C) { |
| 153 |
s.createKey(c) |
| 154 |
} |
| 155 |
|
| 156 |
func (s *LiveTests) TestListKeys(c *gc.C) { |
| 157 |
s.createKey(c) |
| 158 |
|
| 159 |
keys, err := s.testClient.ListKeys() |
| 160 |
c.Assert(err, gc.IsNil) |
| 161 |
c.Assert(keys, gc.NotNil) |
| 162 |
fakeKey := cloudapi.Key{Name: "fake-key", Fingerprint: testKeyFingerprint, Key: testKey} |
| 163 |
for _, k := range keys { |
| 164 |
if c.Check(k, gc.DeepEquals, fakeKey) { |
| 165 |
c.SucceedNow() |
| 166 |
} |
| 167 |
} |
| 168 |
c.Fatalf("Obtained keys [%s] do not contain test key [%s]", keys, fakeKey) |
| 169 |
} |
| 170 |
|
| 171 |
func (s *LiveTests) TestGetKeyByName(c *gc.C) { |
| 172 |
s.createKey(c) |
| 173 |
|
| 174 |
key, err := s.testClient.GetKey("fake-key") |
| 175 |
c.Assert(err, gc.IsNil) |
| 176 |
c.Assert(key, gc.NotNil) |
| 177 |
c.Assert(key, gc.DeepEquals, &cloudapi.Key{Name: "fake-key", Fingerprint: testKeyFingerprint, Key: testKey}) |
| 178 |
} |
| 179 |
|
| 180 |
func (s *LiveTests) TestGetKeyByFingerprint(c *gc.C) { |
| 181 |
s.createKey(c) |
| 182 |
|
| 183 |
key, err := s.testClient.GetKey(testKeyFingerprint) |
| 184 |
c.Assert(err, gc.IsNil) |
| 185 |
c.Assert(key, gc.NotNil) |
| 186 |
c.Assert(key, gc.DeepEquals, &cloudapi.Key{Name: "fake-key", Fingerprint: testKeyFingerprint, Key: testKey}) |
| 187 |
} |
| 188 |
|
| 189 |
func (s *LiveTests) TestDeleteKey(c *gc.C) { |
| 190 |
s.createKey(c) |
| 191 |
|
| 192 |
err := s.testClient.DeleteKey("fake-key") |
| 193 |
c.Assert(err, gc.IsNil) |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
func (s *LiveTests) TestListPackages(c *gc.C) { |
| 198 |
pkgs, err := s.testClient.ListPackages(nil) |
| 199 |
c.Assert(err, gc.IsNil) |
| 200 |
c.Assert(pkgs, gc.NotNil) |
| 201 |
for _, pkg := range pkgs { |
| 202 |
c.Check(pkg.Name, gc.FitsTypeOf, string("")) |
| 203 |
c.Check(pkg.Memory, gc.FitsTypeOf, int(0)) |
| 204 |
c.Check(pkg.Disk, gc.FitsTypeOf, int(0)) |
| 205 |
c.Check(pkg.Swap, gc.FitsTypeOf, int(0)) |
| 206 |
c.Check(pkg.VCPUs, gc.FitsTypeOf, int(0)) |
| 207 |
c.Check(pkg.Default, gc.FitsTypeOf, bool(false)) |
| 208 |
c.Check(pkg.Id, gc.FitsTypeOf, string("")) |
| 209 |
c.Check(pkg.Version, gc.FitsTypeOf, string("")) |
| 210 |
c.Check(pkg.Description, gc.FitsTypeOf, string("")) |
| 211 |
c.Check(pkg.Group, gc.FitsTypeOf, string("")) |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
func (s *LiveTests) TestListPackagesWithFilter(c *gc.C) { |
| 216 |
filter := cloudapi.NewFilter() |
| 217 |
filter.Set("memory", "1024") |
| 218 |
pkgs, err := s.testClient.ListPackages(filter) |
| 219 |
c.Assert(err, gc.IsNil) |
| 220 |
c.Assert(pkgs, gc.NotNil) |
| 221 |
for _, pkg := range pkgs { |
| 222 |
c.Check(pkg.Name, gc.FitsTypeOf, string("")) |
| 223 |
c.Check(pkg.Memory, gc.Equals, 1024) |
| 224 |
c.Check(pkg.Disk, gc.FitsTypeOf, int(0)) |
| 225 |
c.Check(pkg.Swap, gc.FitsTypeOf, int(0)) |
| 226 |
c.Check(pkg.VCPUs, gc.FitsTypeOf, int(0)) |
| 227 |
c.Check(pkg.Default, gc.FitsTypeOf, bool(false)) |
| 228 |
c.Check(pkg.Id, gc.FitsTypeOf, string("")) |
| 229 |
c.Check(pkg.Version, gc.FitsTypeOf, string("")) |
| 230 |
c.Check(pkg.Description, gc.FitsTypeOf, string("")) |
| 231 |
c.Check(pkg.Group, gc.FitsTypeOf, string("")) |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
func (s *LiveTests) TestGetPackageFromName(c *gc.C) { |
| 236 |
key, err := s.testClient.GetPackage(packageName) |
| 237 |
c.Assert(err, gc.IsNil) |
| 238 |
c.Assert(key, gc.NotNil) |
| 239 |
c.Assert(key, gc.DeepEquals, &cloudapi.Package{ |
| 240 |
Name: packageName, |
| 241 |
Memory: 1024, |
| 242 |
Disk: 33792, |
| 243 |
Swap: 2048, |
| 244 |
VCPUs: 0, |
| 245 |
Default: false, |
| 246 |
Id: packageID, |
| 247 |
Version: "1.0.0", |
| 248 |
Description: "Standard 1 GB RAM 0.25 vCPU and bursting 33 GB Disk", |
| 249 |
Group: "Standard", |
| 250 |
}) |
| 251 |
} |
| 252 |
|
| 253 |
func (s *LiveTests) TestGetPackageFromId(c *gc.C) { |
| 254 |
key, err := s.testClient.GetPackage(packageID) |
| 255 |
c.Assert(err, gc.IsNil) |
| 256 |
c.Assert(key, gc.NotNil) |
| 257 |
c.Assert(key, gc.DeepEquals, &cloudapi.Package{ |
| 258 |
Name: packageName, |
| 259 |
Memory: 1024, |
| 260 |
Disk: 33792, |
| 261 |
Swap: 2048, |
| 262 |
VCPUs: 0, |
| 263 |
Default: false, |
| 264 |
Id: packageID, |
| 265 |
Version: "1.0.0", |
| 266 |
Description: "Standard 1 GB RAM 0.25 vCPU and bursting 33 GB Disk", |
| 267 |
Group: "Standard", |
| 268 |
}) |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
func (s *LiveTests) TestListImages(c *gc.C) { |
| 273 |
imgs, err := s.testClient.ListImages(nil) |
| 274 |
c.Assert(err, gc.IsNil) |
| 275 |
c.Assert(imgs, gc.NotNil) |
| 276 |
for _, img := range imgs { |
| 277 |
c.Check(img.Id, gc.FitsTypeOf, string("")) |
| 278 |
c.Check(img.Name, gc.FitsTypeOf, string("")) |
| 279 |
c.Check(img.OS, gc.FitsTypeOf, string("")) |
| 280 |
c.Check(img.Version, gc.FitsTypeOf, string("")) |
| 281 |
c.Check(img.Type, gc.FitsTypeOf, string("")) |
| 282 |
c.Check(img.Description, gc.FitsTypeOf, string("")) |
| 283 |
c.Check(img.Requirements, gc.FitsTypeOf, map[string]interface{}{"key": "value"}) |
| 284 |
c.Check(img.Homepage, gc.FitsTypeOf, string("")) |
| 285 |
c.Check(img.PublishedAt, gc.FitsTypeOf, string("")) |
| 286 |
c.Check(img.Public, gc.FitsTypeOf, bool(true)) |
| 287 |
c.Check(img.State, gc.FitsTypeOf, string("")) |
| 288 |
c.Check(img.Tags, gc.FitsTypeOf, map[string]string{"key": "value"}) |
| 289 |
c.Check(img.EULA, gc.FitsTypeOf, string("")) |
| 290 |
c.Check(img.ACL, gc.FitsTypeOf, []string{"", ""}) |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
func (s *LiveTests) TestListImagesWithFilter(c *gc.C) { |
| 295 |
filter := cloudapi.NewFilter() |
| 296 |
filter.Set("os", "smartos") |
| 297 |
imgs, err := s.testClient.ListImages(filter) |
| 298 |
c.Assert(err, gc.IsNil) |
| 299 |
c.Assert(imgs, gc.NotNil) |
| 300 |
for _, img := range imgs { |
| 301 |
c.Check(img.Id, gc.FitsTypeOf, string("")) |
| 302 |
c.Check(img.Name, gc.FitsTypeOf, string("")) |
| 303 |
c.Check(img.OS, gc.Equals, "smartos") |
| 304 |
c.Check(img.Version, gc.FitsTypeOf, string("")) |
| 305 |
c.Check(img.Type, gc.FitsTypeOf, string("")) |
| 306 |
c.Check(img.Description, gc.FitsTypeOf, string("")) |
| 307 |
c.Check(img.Requirements, gc.FitsTypeOf, map[string]interface{}{"key": "value"}) |
| 308 |
c.Check(img.Homepage, gc.FitsTypeOf, string("")) |
| 309 |
c.Check(img.PublishedAt, gc.FitsTypeOf, string("")) |
| 310 |
c.Check(img.Public, gc.FitsTypeOf, bool(true)) |
| 311 |
c.Check(img.State, gc.FitsTypeOf, string("")) |
| 312 |
c.Check(img.Tags, gc.FitsTypeOf, map[string]string{"key": "value"}) |
| 313 |
c.Check(img.EULA, gc.FitsTypeOf, string("")) |
| 314 |
c.Check(img.ACL, gc.FitsTypeOf, []string{"", ""}) |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
func (s *LiveTests) TestGetImage(c *gc.C) { |
| 321 |
requirements := map[string]interface{}{} |
| 322 |
img, err := s.testClient.GetImage(imageID) |
| 323 |
c.Assert(err, gc.IsNil) |
| 324 |
c.Assert(img, gc.NotNil) |
| 325 |
c.Assert(img, gc.DeepEquals, &cloudapi.Image{ |
| 326 |
Id: imageID, |
| 327 |
Name: "base", |
| 328 |
Version: "13.1.0", |
| 329 |
OS: "smartos", |
| 330 |
Type: "smartmachine", |
| 331 |
Description: "A 32-bit SmartOS image with just essential packages installed. Ideal for users who are comfortable with setting up their own environment and tools.", |
| 332 |
Requirements: requirements, |
| 333 |
PublishedAt: "2013-04-26T15:16:02Z", |
| 334 |
}) |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
func (s *LiveTests) TestListDatacenters(c *gc.C) { |
| 339 |
dcs, err := s.testClient.ListDatacenters() |
| 340 |
c.Assert(err, gc.IsNil) |
| 341 |
c.Assert(dcs, gc.HasLen, 4) |
| 342 |
c.Assert(dcs["us-west-1"], gc.Equals, "https://us-west-1.api.joyentcloud.com") |
| 343 |
} |
| 344 |
|
| 345 |
func (s *LiveTests) TestGetDatacenter(c *gc.C) { |
| 346 |
dc, err := s.testClient.GetDatacenter("us-west-1") |
| 347 |
c.Assert(err, gc.IsNil) |
| 348 |
c.Assert(dc, gc.Equals, "https://us-west-1.api.joyentcloud.com") |
| 349 |
} |
| 350 |
|
| 351 |
func (s *LiveTests) TestCreateMachine(c *gc.C) { |
| 352 |
testMachine := s.createMachine(c) |
| 353 |
defer s.deleteMachine(c, testMachine.Id) |
| 354 |
|
| 355 |
c.Assert(testMachine.Type, gc.Equals, "smartmachine") |
| 356 |
c.Assert(testMachine.Dataset, gc.Equals, "sdc:sdc:base:13.1.0") |
| 357 |
c.Assert(testMachine.Memory, gc.Equals, 1024) |
| 358 |
c.Assert(testMachine.Disk, gc.Equals, 33792) |
| 359 |
c.Assert(testMachine.Package, gc.Equals, packageName) |
| 360 |
c.Assert(testMachine.Image, gc.Equals, imageID) |
| 361 |
} |
| 362 |
|
| 363 |
func (s *LiveTests) TestCreateMachineWithTags(c *gc.C) { |
| 364 |
tags := map[string]string{"tag.tag1": "value1", "tag.tag2": "value2"} |
| 365 |
testMachine := s.createMachineWithTags(c, tags) |
| 366 |
defer s.deleteMachine(c, testMachine.Id) |
| 367 |
|
| 368 |
c.Assert(testMachine.Type, gc.Equals, "smartmachine") |
| 369 |
c.Assert(testMachine.Dataset, gc.Equals, "sdc:sdc:base:13.1.0") |
| 370 |
c.Assert(testMachine.Memory, gc.Equals, 1024) |
| 371 |
c.Assert(testMachine.Disk, gc.Equals, 33792) |
| 372 |
c.Assert(testMachine.Package, gc.Equals, packageName) |
| 373 |
c.Assert(testMachine.Image, gc.Equals, imageID) |
| 374 |
c.Assert(testMachine.Tags, gc.DeepEquals, map[string]string{"tag1": "value1", "tag2": "value2"}) |
| 375 |
} |
| 376 |
|
| 377 |
func (s *LiveTests) TestListMachines(c *gc.C) { |
| 378 |
s.listMachines(c, nil) |
| 379 |
} |
| 380 |
|
| 381 |
func (s *LiveTests) TestListMachinesWithFilter(c *gc.C) { |
| 382 |
filter := cloudapi.NewFilter() |
| 383 |
filter.Set("memory", "1024") |
| 384 |
|
| 385 |
s.listMachines(c, filter) |
| 386 |
} |
| 387 |
|
| 388 |
func (s *LiveTests) TestCountMachines(c *gc.C) { |
| 389 |
testMachine := s.createMachine(c) |
| 390 |
defer s.deleteMachine(c, testMachine.Id) |
| 391 |
|
| 392 |
count, err := s.testClient.CountMachines() |
| 393 |
c.Assert(err, gc.IsNil) |
| 394 |
c.Assert(count >= 1, gc.Equals, true) |
| 395 |
} |
| 396 |
|
| 397 |
func (s *LiveTests) TestGetMachine(c *gc.C) { |
| 398 |
testMachine := s.createMachine(c) |
| 399 |
defer s.deleteMachine(c, testMachine.Id) |
| 400 |
|
| 401 |
machine, err := s.testClient.GetMachine(testMachine.Id) |
| 402 |
c.Assert(err, gc.IsNil) |
| 403 |
c.Assert(machine, gc.NotNil) |
| 404 |
c.Assert(machine.Equals(*testMachine), gc.Equals, true) |
| 405 |
} |
| 406 |
|
| 407 |
func (s *LiveTests) TestStopMachine(c *gc.C) { |
| 408 |
testMachine := s.createMachine(c) |
| 409 |
defer s.deleteMachine(c, testMachine.Id) |
| 410 |
|
| 411 |
err := s.testClient.StopMachine(testMachine.Id) |
| 412 |
c.Assert(err, gc.IsNil) |
| 413 |
} |
| 414 |
|
| 415 |
func (s *LiveTests) TestStartMachine(c *gc.C) { |
| 416 |
testMachine := s.createMachine(c) |
| 417 |
defer s.deleteMachine(c, testMachine.Id) |
| 418 |
|
| 419 |
err := s.testClient.StopMachine(testMachine.Id) |
| 420 |
c.Assert(err, gc.IsNil) |
| 421 |
|
| 422 |
|
| 423 |
for !s.pollMachineState(c, testMachine.Id, "stopped") { |
| 424 |
time.Sleep(1 * time.Second) |
| 425 |
} |
| 426 |
|
| 427 |
err = s.testClient.StartMachine(testMachine.Id) |
| 428 |
c.Assert(err, gc.IsNil) |
| 429 |
} |
| 430 |
|
| 431 |
func (s *LiveTests) TestRebootMachine(c *gc.C) { |
| 432 |
testMachine := s.createMachine(c) |
| 433 |
defer s.deleteMachine(c, testMachine.Id) |
| 434 |
|
| 435 |
err := s.testClient.RebootMachine(testMachine.Id) |
| 436 |
c.Assert(err, gc.IsNil) |
| 437 |
} |
| 438 |
|
| 439 |
func (s *LiveTests) TestRenameMachine(c *gc.C) { |
| 440 |
testMachine := s.createMachine(c) |
| 441 |
defer s.deleteMachine(c, testMachine.Id) |
| 442 |
|
| 443 |
err := s.testClient.RenameMachine(testMachine.Id, "test-machine-renamed") |
| 444 |
c.Assert(err, gc.IsNil) |
| 445 |
|
| 446 |
renamed, err := s.testClient.GetMachine(testMachine.Id) |
| 447 |
c.Assert(err, gc.IsNil) |
| 448 |
c.Assert(renamed.Name, gc.Equals, "test-machine-renamed") |
| 449 |
} |
| 450 |
|
| 451 |
func (s *LiveTests) TestResizeMachine(c *gc.C) { |
| 452 |
testMachine := s.createMachine(c) |
| 453 |
defer s.deleteMachine(c, testMachine.Id) |
| 454 |
|
| 455 |
err := s.testClient.ResizeMachine(testMachine.Id, "g3-standard-1.75-smartos") |
| 456 |
c.Assert(err, gc.IsNil) |
| 457 |
|
| 458 |
resized, err := s.testClient.GetMachine(testMachine.Id) |
| 459 |
c.Assert(err, gc.IsNil) |
| 460 |
c.Assert(resized.Package, gc.Equals, "g3-standard-1.75-smartos") |
| 461 |
} |
| 462 |
|
| 463 |
func (s *LiveTests) TestListMachinesFirewallRules(c *gc.C) { |
| 464 |
testMachine := s.createMachine(c) |
| 465 |
defer s.deleteMachine(c, testMachine.Id) |
| 466 |
|
| 467 |
fwRules, err := s.testClient.ListMachineFirewallRules(testMachine.Id) |
| 468 |
c.Assert(err, gc.IsNil) |
| 469 |
c.Assert(fwRules, gc.NotNil) |
| 470 |
} |
| 471 |
|
| 472 |
func (s *LiveTests) TestEnableFirewallMachine(c *gc.C) { |
| 473 |
testMachine := s.createMachine(c) |
| 474 |
defer s.deleteMachine(c, testMachine.Id) |
| 475 |
|
| 476 |
err := s.testClient.EnableFirewallMachine(testMachine.Id) |
| 477 |
c.Assert(err, gc.IsNil) |
| 478 |
} |
| 479 |
|
| 480 |
func (s *LiveTests) TestDisableFirewallMachine(c *gc.C) { |
| 481 |
testMachine := s.createMachine(c) |
| 482 |
defer s.deleteMachine(c, testMachine.Id) |
| 483 |
|
| 484 |
err := s.testClient.DisableFirewallMachine(testMachine.Id) |
| 485 |
c.Assert(err, gc.IsNil) |
| 486 |
} |
| 487 |
|
| 488 |
func (s *LiveTests) TestCreateMachineSnapshot(c *gc.C) { |
| 489 |
testMachine := s.createMachine(c) |
| 490 |
defer s.deleteMachine(c, testMachine.Id) |
| 491 |
|
| 492 |
s.createMachineSnapshot(c, testMachine.Id) |
| 493 |
} |
| 494 |
|
| 495 |
func (s *LiveTests) TestStartMachineFromShapshot(c *gc.C) { |
| 496 |
testMachine := s.createMachine(c) |
| 497 |
defer s.deleteMachine(c, testMachine.Id) |
| 498 |
snapshotName := s.createMachineSnapshot(c, testMachine.Id) |
| 499 |
|
| 500 |
err := s.testClient.StopMachine(testMachine.Id) |
| 501 |
c.Assert(err, gc.IsNil) |
| 502 |
|
| 503 |
|
| 504 |
for !s.pollMachineState(c, testMachine.Id, "stopped") { |
| 505 |
time.Sleep(1 * time.Second) |
| 506 |
} |
| 507 |
|
| 508 |
err = s.testClient.StartMachineFromSnapshot(testMachine.Id, snapshotName) |
| 509 |
c.Assert(err, gc.IsNil) |
| 510 |
} |
| 511 |
|
| 512 |
func (s *LiveTests) TestListMachineSnapshots(c *gc.C) { |
| 513 |
testMachine := s.createMachine(c) |
| 514 |
defer s.deleteMachine(c, testMachine.Id) |
| 515 |
s.createMachineSnapshot(c, testMachine.Id) |
| 516 |
|
| 517 |
snapshots, err := s.testClient.ListMachineSnapshots(testMachine.Id) |
| 518 |
c.Assert(err, gc.IsNil) |
| 519 |
c.Assert(snapshots, gc.HasLen, 1) |
| 520 |
} |
| 521 |
|
| 522 |
func (s *LiveTests) TestGetMachineSnapshot(c *gc.C) { |
| 523 |
testMachine := s.createMachine(c) |
| 524 |
defer s.deleteMachine(c, testMachine.Id) |
| 525 |
snapshotName := s.createMachineSnapshot(c, testMachine.Id) |
| 526 |
|
| 527 |
snapshot, err := s.testClient.GetMachineSnapshot(testMachine.Id, snapshotName) |
| 528 |
c.Assert(err, gc.IsNil) |
| 529 |
c.Assert(snapshot, gc.NotNil) |
| 530 |
c.Assert(snapshot, gc.DeepEquals, &cloudapi.Snapshot{Name: snapshotName, State: "created"}) |
| 531 |
} |
| 532 |
|
| 533 |
func (s *LiveTests) TestDeleteMachineSnapshot(c *gc.C) { |
| 534 |
testMachine := s.createMachine(c) |
| 535 |
defer s.deleteMachine(c, testMachine.Id) |
| 536 |
snapshotName := s.createMachineSnapshot(c, testMachine.Id) |
| 537 |
|
| 538 |
err := s.testClient.DeleteMachineSnapshot(testMachine.Id, snapshotName) |
| 539 |
c.Assert(err, gc.IsNil) |
| 540 |
} |
| 541 |
|
| 542 |
func (s *LiveTests) TestUpdateMachineMetadata(c *gc.C) { |
| 543 |
testMachine := s.createMachine(c) |
| 544 |
defer s.deleteMachine(c, testMachine.Id) |
| 545 |
|
| 546 |
md, err := s.testClient.UpdateMachineMetadata(testMachine.Id, map[string]string{"test-metadata": "md value", "test": "test"}) |
| 547 |
metadata := map[string]interface{}{"root_authorized_keys": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyucy41MNcPxEkNUneeRT0j4mXX5zzW4cFYZ0G/Wpqrb/A+JZV6xlwmAwsGPAvebeEp40CSc0gzauR0nsQ+0Hefdp+dHdEEZlZ7WhedknponA8cQURU38cmTnGweaw2B0+vkULo5AUPAjv0Y1nGPZVlKWNeR6NJhq51pEtj4eLYCJ+kylHEIjQbP5Q1LQHxxotoY29N/xMx+ZVYGprHUJ5ihMOC1nrz2kqUjbCvvMLC0yzAI3vfKtL14BQs9Aq9ggl9oZZylmsgy9CnrPa5t98/wqG+snGyrPSL27km0rll1Jz6xcraGkXQP0adFJxw7mFrXItAt6TUyAuLoohhjHd [email protected]\n", |
| 548 |
"origin": "cloudapi", "creator_uuid": "ff0c4a2b-f89a-4f14-81ee-5b31e7c89ece", "test": "test", "test-metadata": "md value", |
| 549 |
"context": map[string]interface{}{"caller": map[string]interface{}{"type": "signature", "ip": "127.0.0.1", "keyId": "/dstroppa/keys/12:c3:a7:cb:a2:29:e2:90:88:3f:04:53:3b:4e:75:40"}, |
| 550 |
"params": map[string]interface{}{"account": "dstroppa", "machine": testMachine.Id, "test": "test", "test-metadata": "md value"}}} |
| 551 |
c.Assert(err, gc.IsNil) |
| 552 |
c.Assert(md, gc.NotNil) |
| 553 |
c.Assert(md, gc.DeepEquals, metadata) |
| 554 |
} |
| 555 |
|
| 556 |
func (s *LiveTests) TestGetMachineMetadata(c *gc.C) { |
| 557 |
testMachine := s.createMachine(c) |
| 558 |
defer s.deleteMachine(c, testMachine.Id) |
| 559 |
|
| 560 |
md, err := s.testClient.GetMachineMetadata(testMachine.Id) |
| 561 |
c.Assert(err, gc.IsNil) |
| 562 |
c.Assert(md, gc.NotNil) |
| 563 |
c.Assert(md, gc.HasLen, 5) |
| 564 |
} |
| 565 |
|
| 566 |
func (s *LiveTests) TestDeleteMachineMetadata(c *gc.C) { |
| 567 |
testMachine := s.createMachine(c) |
| 568 |
defer s.deleteMachine(c, testMachine.Id) |
| 569 |
|
| 570 |
_, err := s.testClient.UpdateMachineMetadata(testMachine.Id, map[string]string{"test-metadata": "md value"}) |
| 571 |
c.Assert(err, gc.IsNil) |
| 572 |
|
| 573 |
time.Sleep(10 * time.Second) |
| 574 |
|
| 575 |
err = s.testClient.DeleteMachineMetadata(testMachine.Id, "test-metadata") |
| 576 |
c.Assert(err, gc.IsNil) |
| 577 |
} |
| 578 |
|
| 579 |
func (s *LiveTests) TestDeleteAllMachineMetadata(c *gc.C) { |
| 580 |
testMachine := s.createMachine(c) |
| 581 |
defer s.deleteMachine(c, testMachine.Id) |
| 582 |
|
| 583 |
err := s.testClient.DeleteAllMachineMetadata(testMachine.Id) |
| 584 |
c.Assert(err, gc.IsNil) |
| 585 |
} |
| 586 |
|
| 587 |
func (s *LiveTests) TestAddMachineTags(c *gc.C) { |
| 588 |
testMachine := s.createMachine(c) |
| 589 |
defer s.deleteMachine(c, testMachine.Id) |
| 590 |
|
| 591 |
machineTags := map[string]string{"test-tag": "test-tag-value", "test": "test", "tag1": "tagtag"} |
| 592 |
tags, err := s.testClient.AddMachineTags(testMachine.Id, map[string]string{"test-tag": "test-tag-value", "test": "test", "tag1": "tagtag"}) |
| 593 |
c.Assert(err, gc.IsNil) |
| 594 |
c.Assert(tags, gc.NotNil) |
| 595 |
c.Assert(tags, gc.DeepEquals, machineTags) |
| 596 |
} |
| 597 |
|
| 598 |
func (s *LiveTests) TestReplaceMachineTags(c *gc.C) { |
| 599 |
testMachine := s.createMachine(c) |
| 600 |
defer s.deleteMachine(c, testMachine.Id) |
| 601 |
|
| 602 |
machineTags := map[string]string{"origin": "cloudapi", "creator_uuid": "ff0c4a2b-f89a-4f14-81ee-5b31e7c89ece", "test-tag": "test-tag-value", "test": "test tag", "tag1": "tag2"} |
| 603 |
tags, err := s.testClient.ReplaceMachineTags(testMachine.Id, map[string]string{"test-tag": "test-tag-value", "test": "test tag", "tag1": "tag2"}) |
| 604 |
c.Assert(err, gc.IsNil) |
| 605 |
c.Assert(tags, gc.NotNil) |
| 606 |
c.Assert(tags, gc.DeepEquals, machineTags) |
| 607 |
} |
| 608 |
|
| 609 |
func (s *LiveTests) TestListMachineTags(c *gc.C) { |
| 610 |
testMachine := s.createMachine(c) |
| 611 |
defer s.deleteMachine(c, testMachine.Id) |
| 612 |
|
| 613 |
tags, err := s.testClient.ListMachineTags(testMachine.Id) |
| 614 |
c.Assert(err, gc.IsNil) |
| 615 |
c.Assert(tags, gc.NotNil) |
| 616 |
c.Assert(tags, gc.HasLen, 5) |
| 617 |
} |
| 618 |
|
| 619 |
func (s *LiveTests) TestGetMachineTag(c *gc.C) { |
| 620 |
testMachine := s.createMachine(c) |
| 621 |
defer s.deleteMachine(c, testMachine.Id) |
| 622 |
|
| 623 |
_, err := s.testClient.AddMachineTags(testMachine.Id, map[string]string{"test-tag": "test-tag-value"}) |
| 624 |
c.Assert(err, gc.IsNil) |
| 625 |
|
| 626 |
time.Sleep(15 * time.Second) |
| 627 |
|
| 628 |
tag, err := s.testClient.GetMachineTag(testMachine.Id, "test-tag") |
| 629 |
c.Assert(err, gc.IsNil) |
| 630 |
c.Assert(tag, gc.NotNil) |
| 631 |
c.Assert(tag, gc.Equals, "test-tag-value") |
| 632 |
} |
| 633 |
|
| 634 |
func (s *LiveTests) TestDeleteMachineTag(c *gc.C) { |
| 635 |
testMachine := s.createMachine(c) |
| 636 |
defer s.deleteMachine(c, testMachine.Id) |
| 637 |
|
| 638 |
_, err := s.testClient.AddMachineTags(testMachine.Id, map[string]string{"test-tag": "test-tag-value"}) |
| 639 |
c.Assert(err, gc.IsNil) |
| 640 |
|
| 641 |
time.Sleep(15 * time.Second) |
| 642 |
|
| 643 |
err = s.testClient.DeleteMachineTag(testMachine.Id, "test-tag") |
| 644 |
c.Assert(err, gc.IsNil) |
| 645 |
} |
| 646 |
|
| 647 |
func (s *LiveTests) TestDeleteMachineTags(c *gc.C) { |
| 648 |
testMachine := s.createMachine(c) |
| 649 |
defer s.deleteMachine(c, testMachine.Id) |
| 650 |
|
| 651 |
err := s.testClient.DeleteMachineTags(testMachine.Id) |
| 652 |
c.Assert(err, gc.IsNil) |
| 653 |
} |
| 654 |
|
| 655 |
func (s *LiveTests) TestMachineAudit(c *gc.C) { |
| 656 |
testMachine := s.createMachine(c) |
| 657 |
defer s.deleteMachine(c, testMachine.Id) |
| 658 |
|
| 659 |
actions, err := s.testClient.MachineAudit(testMachine.Id) |
| 660 |
c.Assert(err, gc.IsNil) |
| 661 |
c.Assert(actions, gc.NotNil) |
| 662 |
c.Assert(len(actions) > 0, gc.Equals, true) |
| 663 |
} |
| 664 |
|
| 665 |
func (s *LiveTests) TestDeleteMachine(c *gc.C) { |
| 666 |
testMachine := s.createMachine(c) |
| 667 |
|
| 668 |
s.deleteMachine(c, testMachine.Id) |
| 669 |
} |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
func (s *LiveTests) TestCreateFirewallRule(c *gc.C) { |
| 676 |
testFwRule := s.createFirewallRule(c) |
| 677 |
|
| 678 |
|
| 679 |
s.deleteFwRule(c, testFwRule.Id) |
| 680 |
} |
| 681 |
|
| 682 |
func (s *LiveTests) TestListFirewallRules(c *gc.C) { |
| 683 |
testFwRule := s.createFirewallRule(c) |
| 684 |
defer s.deleteFwRule(c, testFwRule.Id) |
| 685 |
|
| 686 |
rules, err := s.testClient.ListFirewallRules() |
| 687 |
c.Assert(err, gc.IsNil) |
| 688 |
c.Assert(rules, gc.NotNil) |
| 689 |
} |
| 690 |
|
| 691 |
func (s *LiveTests) TestGetFirewallRule(c *gc.C) { |
| 692 |
testFwRule := s.createFirewallRule(c) |
| 693 |
defer s.deleteFwRule(c, testFwRule.Id) |
| 694 |
|
| 695 |
fwRule, err := s.testClient.GetFirewallRule(testFwRule.Id) |
| 696 |
c.Assert(err, gc.IsNil) |
| 697 |
c.Assert(fwRule, gc.NotNil) |
| 698 |
c.Assert((*fwRule), gc.DeepEquals, (*testFwRule)) |
| 699 |
} |
| 700 |
|
| 701 |
func (s *LiveTests) TestUpdateFirewallRule(c *gc.C) { |
| 702 |
testFwRule := s.createFirewallRule(c) |
| 703 |
defer s.deleteFwRule(c, testFwRule.Id) |
| 704 |
|
| 705 |
fwRule, err := s.testClient.UpdateFirewallRule(testFwRule.Id, cloudapi.CreateFwRuleOpts{Rule: testUpdatedFwRule}) |
| 706 |
c.Assert(err, gc.IsNil) |
| 707 |
c.Assert(fwRule, gc.NotNil) |
| 708 |
c.Assert(fwRule.Rule, gc.Equals, testUpdatedFwRule) |
| 709 |
} |
| 710 |
|
| 711 |
func (s *LiveTests) TestEnableFirewallRule(c *gc.C) { |
| 712 |
testFwRule := s.createFirewallRule(c) |
| 713 |
defer s.deleteFwRule(c, testFwRule.Id) |
| 714 |
|
| 715 |
fwRule, err := s.testClient.EnableFirewallRule((*testFwRule).Id) |
| 716 |
c.Assert(err, gc.IsNil) |
| 717 |
c.Assert(fwRule, gc.NotNil) |
| 718 |
} |
| 719 |
|
| 720 |
func (s *LiveTests) TestListFirewallRuleMachines(c *gc.C) { |
| 721 |
testFwRule := s.createFirewallRule(c) |
| 722 |
defer s.deleteFwRule(c, testFwRule.Id) |
| 723 |
|
| 724 |
machines, err := s.testClient.ListFirewallRuleMachines((*testFwRule).Id) |
| 725 |
c.Assert(err, gc.IsNil) |
| 726 |
c.Assert(machines, gc.NotNil) |
| 727 |
} |
| 728 |
|
| 729 |
func (s *LiveTests) TestDisableFirewallRule(c *gc.C) { |
| 730 |
testFwRule := s.createFirewallRule(c) |
| 731 |
defer s.deleteFwRule(c, testFwRule.Id) |
| 732 |
|
| 733 |
fwRule, err := s.testClient.DisableFirewallRule((*testFwRule).Id) |
| 734 |
c.Assert(err, gc.IsNil) |
| 735 |
c.Assert(fwRule, gc.NotNil) |
| 736 |
} |
| 737 |
|
| 738 |
func (s *LiveTests) TestDeleteFirewallRule(c *gc.C) { |
| 739 |
testFwRule := s.createFirewallRule(c) |
| 740 |
|
| 741 |
s.deleteFwRule(c, testFwRule.Id) |
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
func (s *LiveTests) TestListNetworks(c *gc.C) { |
| 746 |
nets, err := s.testClient.ListNetworks() |
| 747 |
c.Assert(err, gc.IsNil) |
| 748 |
c.Assert(nets, gc.NotNil) |
| 749 |
} |
| 750 |
|
| 751 |
func (s *LiveTests) TestGetNetwork(c *gc.C) { |
| 752 |
net, err := s.testClient.GetNetwork(networkID) |
| 753 |
c.Assert(err, gc.IsNil) |
| 754 |
c.Assert(net, gc.NotNil) |
| 755 |
c.Assert(net, gc.DeepEquals, &cloudapi.Network{ |
| 756 |
Id: networkID, |
| 757 |
Name: "Joyent-SDC-Public", |
| 758 |
Public: true, |
| 759 |
Description: "", |
| 760 |
}) |
| 761 |
} |