Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 827c03e

Browse files
committed
Fix api interfaces for orchestration resources
Some of the interfaces don't correspond well to the values expected by the requests and returned by api.
1 parent efd338f commit 827c03e

File tree

13 files changed

+263
-230
lines changed

13 files changed

+263
-230
lines changed

openstack/orchestration/v1/stackresources/fixtures.go

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ var FindExpected = []Resource{
2828
LogicalID: "hello_world",
2929
StatusReason: "state changed",
3030
UpdatedTime: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
31+
CreationTime: time.Date(2015, 2, 5, 21, 33, 10, 0, time.UTC),
3132
RequiredBy: []interface{}{},
3233
Status: "CREATE_IN_PROGRESS",
3334
PhysicalID: "49181cd6-169a-4130-9455-31185bbfc5bf",
3435
Type: "OS::Nova::Server",
36+
Attributes: map[string]interface{}{"SXSW": "atx"},
37+
Description: "Some resource",
3538
},
3639
}
3740

@@ -40,6 +43,8 @@ const FindOutput = `
4043
{
4144
"resources": [
4245
{
46+
"description": "Some resource",
47+
"attributes": {"SXSW": "atx"},
4348
"resource_name": "hello_world",
4449
"links": [
4550
{
@@ -54,6 +59,7 @@ const FindOutput = `
5459
"logical_resource_id": "hello_world",
5560
"resource_status_reason": "state changed",
5661
"updated_time": "2015-02-05T21:33:11",
62+
"creation_time": "2015-02-05T21:33:10",
5763
"required_by": [],
5864
"resource_status": "CREATE_IN_PROGRESS",
5965
"physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
@@ -93,10 +99,13 @@ var ListExpected = []Resource{
9399
LogicalID: "hello_world",
94100
StatusReason: "state changed",
95101
UpdatedTime: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
102+
CreationTime: time.Date(2015, 2, 5, 21, 33, 10, 0, time.UTC),
96103
RequiredBy: []interface{}{},
97104
Status: "CREATE_IN_PROGRESS",
98105
PhysicalID: "49181cd6-169a-4130-9455-31185bbfc5bf",
99106
Type: "OS::Nova::Server",
107+
Attributes: map[string]interface{}{"SXSW": "atx"},
108+
Description: "Some resource",
100109
},
101110
}
102111

@@ -121,7 +130,10 @@ const ListOutput = `{
121130
"required_by": [],
122131
"resource_status": "CREATE_IN_PROGRESS",
123132
"physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
124-
"resource_type": "OS::Nova::Server"
133+
"creation_time": "2015-02-05T21:33:10",
134+
"resource_type": "OS::Nova::Server",
135+
"attributes": {"SXSW": "atx"},
136+
"description": "Some resource"
125137
}
126138
]
127139
}`
@@ -162,6 +174,7 @@ var GetExpected = &Resource{
162174
},
163175
},
164176
LogicalID: "wordpress_instance",
177+
Attributes: map[string]interface{}{"SXSW": "atx"},
165178
StatusReason: "state changed",
166179
UpdatedTime: time.Date(2014, 12, 10, 18, 34, 35, 0, time.UTC),
167180
RequiredBy: []interface{}{},
@@ -174,6 +187,8 @@ var GetExpected = &Resource{
174187
const GetOutput = `
175188
{
176189
"resource": {
190+
"description": "Some resource",
191+
"attributes": {"SXSW": "atx"},
177192
"resource_name": "wordpress_instance",
178193
"description": "",
179194
"links": [
@@ -240,7 +255,7 @@ func HandleMetadataSuccessfully(t *testing.T, output string) {
240255
}
241256

242257
// ListTypesExpected represents the expected object from a ListTypes request.
243-
var ListTypesExpected = []string{
258+
var ListTypesExpected = resourceTypes{
244259
"OS::Nova::Server",
245260
"OS::Heat::RandomString",
246261
"OS::Swift::Container",
@@ -251,6 +266,18 @@ var ListTypesExpected = []string{
251266
"OS::Nova::KeyPair",
252267
}
253268

269+
// same as above, but sorted
270+
var SortedListTypesExpected = resourceTypes{
271+
"OS::Cinder::VolumeAttachment",
272+
"OS::Heat::RandomString",
273+
"OS::Nova::FloatingIP",
274+
"OS::Nova::FloatingIPAssociation",
275+
"OS::Nova::KeyPair",
276+
"OS::Nova::Server",
277+
"OS::Swift::Container",
278+
"OS::Trove::Instance",
279+
}
280+
254281
// ListTypesOutput represents the response body from a ListTypes request.
255282
const ListTypesOutput = `
256283
{
@@ -296,6 +323,11 @@ var GetSchemaExpected = &TypeSchema{
296323
},
297324
},
298325
ResourceType: "OS::Heat::AResourceName",
326+
SupportStatus: map[string]interface{}{
327+
"message": "A status message",
328+
"status": "SUPPORTED",
329+
"version": "2014.1",
330+
},
299331
}
300332

301333
// GetSchemaOutput represents the response body from a Schema request.
@@ -314,7 +346,12 @@ const GetSchemaOutput = `
314346
"description": "A resource description."
315347
}
316348
},
317-
"resource_type": "OS::Heat::AResourceName"
349+
"resource_type": "OS::Heat::AResourceName",
350+
"support_status": {
351+
"message": "A status message",
352+
"status": "SUPPORTED",
353+
"version": "2014.1"
354+
}
318355
}`
319356

320357
// HandleGetSchemaSuccessfully creates an HTTP handler at `/resource_types/OS::Heat::AResourceName`
@@ -332,56 +369,7 @@ func HandleGetSchemaSuccessfully(t *testing.T, output string) {
332369
}
333370

334371
// GetTemplateExpected represents the expected object from a Template request.
335-
var GetTemplateExpected = &TypeTemplate{
336-
HeatTemplateFormatVersion: "2012-12-12",
337-
Outputs: map[string]interface{}{
338-
"private_key": map[string]interface{}{
339-
"Description": "The private key if it has been saved.",
340-
"Value": "{\"Fn::GetAtt\": [\"KeyPair\", \"private_key\"]}",
341-
},
342-
"public_key": map[string]interface{}{
343-
"Description": "The public key.",
344-
"Value": "{\"Fn::GetAtt\": [\"KeyPair\", \"public_key\"]}",
345-
},
346-
},
347-
Parameters: map[string]interface{}{
348-
"name": map[string]interface{}{
349-
"Description": "The name of the key pair.",
350-
"Type": "String",
351-
},
352-
"public_key": map[string]interface{}{
353-
"Description": "The optional public key. This allows users to supply the public key from a pre-existing key pair. If not supplied, a new key pair will be generated.",
354-
"Type": "String",
355-
},
356-
"save_private_key": map[string]interface{}{
357-
"AllowedValues": []string{
358-
"True",
359-
"true",
360-
"False",
361-
"false",
362-
},
363-
"Default": false,
364-
"Description": "True if the system should remember a generated private key; False otherwise.",
365-
"Type": "String",
366-
},
367-
},
368-
Resources: map[string]interface{}{
369-
"KeyPair": map[string]interface{}{
370-
"Properties": map[string]interface{}{
371-
"name": map[string]interface{}{
372-
"Ref": "name",
373-
},
374-
"public_key": map[string]interface{}{
375-
"Ref": "public_key",
376-
},
377-
"save_private_key": map[string]interface{}{
378-
"Ref": "save_private_key",
379-
},
380-
},
381-
"Type": "OS::Nova::KeyPair",
382-
},
383-
},
384-
}
372+
var GetTemplateExpected = "{\n \"HeatTemplateFormatVersion\": \"2012-12-12\",\n \"Outputs\": {\n \"private_key\": {\n \"Description\": \"The private key if it has been saved.\",\n \"Value\": \"{\\\"Fn::GetAtt\\\": [\\\"KeyPair\\\", \\\"private_key\\\"]}\"\n },\n \"public_key\": {\n \"Description\": \"The public key.\",\n \"Value\": \"{\\\"Fn::GetAtt\\\": [\\\"KeyPair\\\", \\\"public_key\\\"]}\"\n }\n },\n \"Parameters\": {\n \"name\": {\n \"Description\": \"The name of the key pair.\",\n \"Type\": \"String\"\n },\n \"public_key\": {\n \"Description\": \"The optional public key. This allows users to supply the public key from a pre-existing key pair. If not supplied, a new key pair will be generated.\",\n \"Type\": \"String\"\n },\n \"save_private_key\": {\n \"AllowedValues\": [\n \"True\",\n \"true\",\n \"False\",\n \"false\"\n ],\n \"Default\": false,\n \"Description\": \"True if the system should remember a generated private key; False otherwise.\",\n \"Type\": \"String\"\n }\n },\n \"Resources\": {\n \"KeyPair\": {\n \"Properties\": {\n \"name\": {\n \"Ref\": \"name\"\n },\n \"public_key\": {\n \"Ref\": \"public_key\"\n },\n \"save_private_key\": {\n \"Ref\": \"save_private_key\"\n }\n },\n \"Type\": \"OS::Nova::KeyPair\"\n }\n }\n}"
385373

386374
// GetTemplateOutput represents the response body from a Template request.
387375
const GetTemplateOutput = `

openstack/orchestration/v1/stackresources/requests_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package stackresources
22

33
import (
4+
"sort"
45
"testing"
56

67
"github.com/rackspace/gophercloud/pagination"
@@ -75,6 +76,9 @@ func TestListResourceTypes(t *testing.T) {
7576
th.AssertNoErr(t, err)
7677

7778
th.CheckDeepEquals(t, ListTypesExpected, actual)
79+
// test if sorting works
80+
sort.Sort(actual)
81+
th.CheckDeepEquals(t, SortedListTypesExpected, actual)
7882

7983
return true, nil
8084
})
@@ -103,5 +107,5 @@ func TestGetResourceTemplate(t *testing.T) {
103107
th.AssertNoErr(t, err)
104108

105109
expected := GetTemplateExpected
106-
th.AssertDeepEquals(t, expected, actual)
110+
th.AssertDeepEquals(t, expected, string(actual))
107111
}

0 commit comments

Comments
 (0)