~gz/goose/novaservice_preserve_negative_ports

« back to all changes in this revision

Viewing changes to nova/live_test.go

  • Committer: Tarmac
  • Author(s): Ian Booth
  • Date: 2013-02-08 02:38:12 UTC
  • mfrom: (66.1.7 hpopenstack)
  • Revision ID: tarmac-20130208023812-llhkeo6vitwmf3co
[r=wallyworld] Add HP Cloud support

A few major changes here. HP Cloud sends many core data structures over the wire with int IDs rather than string.
It also lacks a security groups API but instead adds the groups to the server detail record.

To make everything work in the least invasive way, I added custom json (un)marshallers to the affected data structures. The affected
data structures are Entity, ServerDetail, FloatingIP, FlavorDetail. The approach allows the built in marshalling to be used for everything except
the IDs, which are converted from int or string as required.

The live tests are enhanced to allow them to be run against HP Cloud or Canonistack as required:
go test -gocheck.v -live -vendor canonistack
or
go test -gocheck.v -live -vendor hpcloud

The local tests are configured to run twice - once with nemric ids and one with string ids.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
import (
4
4
        "bytes"
 
5
        "fmt"
5
6
        . "launchpad.net/gocheck"
6
7
        "launchpad.net/goose/client"
7
8
        "launchpad.net/goose/errors"
13
14
)
14
15
 
15
16
const (
16
 
        // Known, pre-existing image details to use when creating a test server instance.
17
 
        testImageId   = "0f602ea9-c09e-440c-9e29-cfae5635afa3" // smoser-cloud-images/ubuntu-quantal-12.10-i386-server-20121017
18
 
        testFlavourId = "1"                                    // m1.tiny
19
17
        // A made up name we use for the test server instance.
20
18
        testImageName = "nova_test_server"
21
19
)
22
20
 
23
 
func registerOpenStackTests(cred *identity.Credentials) {
 
21
func registerOpenStackTests(cred *identity.Credentials, testImageDetails imageDetails) {
24
22
        Suite(&LiveTests{
25
 
                cred: cred,
 
23
                cred:        cred,
 
24
                testImageId: testImageDetails.imageId,
 
25
                testFlavor:  testImageDetails.flavor,
 
26
                vendor:      testImageDetails.vendor,
26
27
        })
27
28
}
28
29
 
29
30
type LiveTests struct {
30
 
        cred       *identity.Credentials
31
 
        client     client.AuthenticatingClient
32
 
        nova       *nova.Client
33
 
        testServer *nova.Entity
34
 
        userId     string
35
 
        tenantId   string
 
31
        cred          *identity.Credentials
 
32
        client        client.AuthenticatingClient
 
33
        nova          *nova.Client
 
34
        testServer    *nova.Entity
 
35
        userId        string
 
36
        tenantId      string
 
37
        testImageId   string
 
38
        testFlavor    string
 
39
        testFlavorId  string
 
40
        vendor        string
 
41
        useNumericIds bool
36
42
}
37
43
 
38
44
func (s *LiveTests) SetUpSuite(c *C) {
39
45
        s.client = client.NewClient(s.cred, identity.AuthUserPass, nil)
40
46
        s.nova = nova.New(s.client)
41
47
        var err error
 
48
        s.testFlavorId, err = s.findFlavorId(s.testFlavor)
 
49
        c.Assert(err, IsNil)
42
50
        s.testServer, err = s.createInstance(c, testImageName)
43
51
        c.Assert(err, IsNil)
44
52
        s.waitTestServerToStart(c)
47
55
        s.tenantId = s.client.TenantId()
48
56
}
49
57
 
 
58
func (s *LiveTests) findFlavorId(flavorName string) (string, error) {
 
59
        flavors, err := s.nova.ListFlavors()
 
60
        if err != nil {
 
61
                return "", err
 
62
        }
 
63
        var flavorId string
 
64
        for _, flavor := range flavors {
 
65
                if flavor.Name == flavorName {
 
66
                        flavorId = flavor.Id
 
67
                        break
 
68
                }
 
69
        }
 
70
        if flavorId == "" {
 
71
                return "", fmt.Errorf("No such flavor %s", flavorName)
 
72
        }
 
73
        return flavorId, nil
 
74
}
 
75
 
50
76
func (s *LiveTests) TearDownSuite(c *C) {
51
77
        if s.testServer != nil {
52
78
                err := s.nova.DeleteServer(s.testServer.Id)
65
91
func (s *LiveTests) createInstance(c *C, name string) (instance *nova.Entity, err error) {
66
92
        opts := nova.RunServerOpts{
67
93
                Name:     name,
68
 
                FlavorId: testFlavourId,
69
 
                ImageId:  testImageId,
 
94
                FlavorId: s.testFlavorId,
 
95
                ImageId:  s.testImageId,
70
96
                UserData: nil,
71
97
        }
72
98
        instance, err = s.nova.RunServer(opts)
80
106
func (s *LiveTests) assertServerDetails(c *C, sr *nova.ServerDetail) {
81
107
        c.Check(sr.Id, Equals, s.testServer.Id)
82
108
        c.Check(sr.Name, Equals, testImageName)
83
 
        c.Check(sr.Flavor.Id, Equals, testFlavourId)
84
 
        c.Check(sr.Image.Id, Equals, testImageId)
 
109
        c.Check(sr.Flavor.Id, Equals, s.testFlavorId)
 
110
        c.Check(sr.Image.Id, Equals, s.testImageId)
85
111
}
86
112
 
87
113
func (s *LiveTests) TestListFlavors(c *C) {
367
393
        c.Assert(err, IsNil)
368
394
        defer s.nova.DeleteFloatingIP(ip.Id)
369
395
        c.Check(ip.IP, Not(Equals), "")
370
 
        c.Check(ip.Pool, Not(Equals), "")
371
396
        c.Check(ip.FixedIP, IsNil)
372
397
        c.Check(ip.InstanceId, IsNil)
373
398
 
379
404
                found := false
380
405
                for _, i := range ips {
381
406
                        c.Check(i.IP, Not(Equals), "")
382
 
                        c.Check(i.Pool, Not(Equals), "")
383
407
                        if i.Id == ip.Id {
384
408
                                c.Check(i.IP, Equals, ip.IP)
385
409
                                c.Check(i.Pool, Equals, ip.Pool)
427
451
// TestRateLimitRetry checks that when we make too many requests and receive a Retry-After response, the retry
428
452
// occurs and the request ultimately succeeds.
429
453
func (s *LiveTests) TestRateLimitRetry(c *C) {
 
454
        if s.vendor != "canonistack" {
 
455
                c.Skip("TestRateLimitRetry is only run for Canonistack")
 
456
        }
430
457
        // Capture the logged output so we can check for retry messages.
431
458
        var logout bytes.Buffer
432
459
        logger := log.New(&logout, "", log.LstdFlags)
433
460
        client := client.NewClient(s.cred, identity.AuthUserPass, logger)
434
 
        nova := nova.New(client)
 
461
        novaClient := nova.New(client)
435
462
        // Delete the artifact if it already exists.
436
 
        testGroup, err := nova.SecurityGroupByName("test_group")
 
463
        testGroup, err := novaClient.SecurityGroupByName("test_group")
437
464
        if err != nil {
438
465
                c.Assert(errors.IsNotFound(err), Equals, true)
439
466
        } else {
440
 
                nova.DeleteSecurityGroup(testGroup.Id)
 
467
                novaClient.DeleteSecurityGroup(testGroup.Id)
441
468
                c.Assert(err, IsNil)
442
469
        }
443
470
        // Create some artifacts a number of times in succession and ensure each time is successful,
444
471
        // even with retries being required. As soon as we see a retry message, the test has passed
445
472
        // and we exit.
446
473
        for i := 0; i < 50; i++ {
447
 
                testGroup, err = nova.CreateSecurityGroup("test_group", "test")
 
474
                testGroup, err = novaClient.CreateSecurityGroup("test_group", "test")
448
475
                c.Assert(err, IsNil)
449
 
                nova.DeleteSecurityGroup(testGroup.Id)
 
476
                novaClient.DeleteSecurityGroup(testGroup.Id)
450
477
                c.Assert(err, IsNil)
451
478
                output := logout.String()
452
479
                if strings.Contains(output, "Too many requests, retrying in") == true {