PageRenderTime 58ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/Godeps/_workspace/src/github.com/rackspace/gophercloud/openstack/orchestration/v1/stackresources/fixtures.go

https://gitlab.com/cybok/kubernetes
Go | 439 lines | 379 code | 31 blank | 29 comment | 1 complexity | 8db354e83d5ebcdf6a63717699fb2f1b MD5 | raw file
  1. package stackresources
  2. import (
  3. "fmt"
  4. "net/http"
  5. "testing"
  6. "time"
  7. "github.com/rackspace/gophercloud"
  8. th "github.com/rackspace/gophercloud/testhelper"
  9. fake "github.com/rackspace/gophercloud/testhelper/client"
  10. )
  11. // FindExpected represents the expected object from a Find request.
  12. var FindExpected = []Resource{
  13. Resource{
  14. Name: "hello_world",
  15. Links: []gophercloud.Link{
  16. gophercloud.Link{
  17. Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
  18. Rel: "self",
  19. },
  20. gophercloud.Link{
  21. Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
  22. Rel: "stack",
  23. },
  24. },
  25. LogicalID: "hello_world",
  26. StatusReason: "state changed",
  27. UpdatedTime: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
  28. CreationTime: time.Date(2015, 2, 5, 21, 33, 10, 0, time.UTC),
  29. RequiredBy: []interface{}{},
  30. Status: "CREATE_IN_PROGRESS",
  31. PhysicalID: "49181cd6-169a-4130-9455-31185bbfc5bf",
  32. Type: "OS::Nova::Server",
  33. Attributes: map[string]interface{}{"SXSW": "atx"},
  34. Description: "Some resource",
  35. },
  36. }
  37. // FindOutput represents the response body from a Find request.
  38. const FindOutput = `
  39. {
  40. "resources": [
  41. {
  42. "description": "Some resource",
  43. "attributes": {"SXSW": "atx"},
  44. "resource_name": "hello_world",
  45. "links": [
  46. {
  47. "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
  48. "rel": "self"
  49. },
  50. {
  51. "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
  52. "rel": "stack"
  53. }
  54. ],
  55. "logical_resource_id": "hello_world",
  56. "resource_status_reason": "state changed",
  57. "updated_time": "2015-02-05T21:33:11",
  58. "creation_time": "2015-02-05T21:33:10",
  59. "required_by": [],
  60. "resource_status": "CREATE_IN_PROGRESS",
  61. "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
  62. "resource_type": "OS::Nova::Server"
  63. }
  64. ]
  65. }`
  66. // HandleFindSuccessfully creates an HTTP handler at `/stacks/hello_world/resources`
  67. // on the test handler mux that responds with a `Find` response.
  68. func HandleFindSuccessfully(t *testing.T, output string) {
  69. th.Mux.HandleFunc("/stacks/hello_world/resources", func(w http.ResponseWriter, r *http.Request) {
  70. th.TestMethod(t, r, "GET")
  71. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  72. th.TestHeader(t, r, "Accept", "application/json")
  73. w.Header().Set("Content-Type", "application/json")
  74. w.WriteHeader(http.StatusOK)
  75. fmt.Fprintf(w, output)
  76. })
  77. }
  78. // ListExpected represents the expected object from a List request.
  79. var ListExpected = []Resource{
  80. Resource{
  81. Name: "hello_world",
  82. Links: []gophercloud.Link{
  83. gophercloud.Link{
  84. Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
  85. Rel: "self",
  86. },
  87. gophercloud.Link{
  88. Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
  89. Rel: "stack",
  90. },
  91. },
  92. LogicalID: "hello_world",
  93. StatusReason: "state changed",
  94. UpdatedTime: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
  95. CreationTime: time.Date(2015, 2, 5, 21, 33, 10, 0, time.UTC),
  96. RequiredBy: []interface{}{},
  97. Status: "CREATE_IN_PROGRESS",
  98. PhysicalID: "49181cd6-169a-4130-9455-31185bbfc5bf",
  99. Type: "OS::Nova::Server",
  100. Attributes: map[string]interface{}{"SXSW": "atx"},
  101. Description: "Some resource",
  102. },
  103. }
  104. // ListOutput represents the response body from a List request.
  105. const ListOutput = `{
  106. "resources": [
  107. {
  108. "resource_name": "hello_world",
  109. "links": [
  110. {
  111. "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
  112. "rel": "self"
  113. },
  114. {
  115. "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
  116. "rel": "stack"
  117. }
  118. ],
  119. "logical_resource_id": "hello_world",
  120. "resource_status_reason": "state changed",
  121. "updated_time": "2015-02-05T21:33:11",
  122. "required_by": [],
  123. "resource_status": "CREATE_IN_PROGRESS",
  124. "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
  125. "creation_time": "2015-02-05T21:33:10",
  126. "resource_type": "OS::Nova::Server",
  127. "attributes": {"SXSW": "atx"},
  128. "description": "Some resource"
  129. }
  130. ]
  131. }`
  132. // HandleListSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources`
  133. // on the test handler mux that responds with a `List` response.
  134. func HandleListSuccessfully(t *testing.T, output string) {
  135. th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources", func(w http.ResponseWriter, r *http.Request) {
  136. th.TestMethod(t, r, "GET")
  137. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  138. th.TestHeader(t, r, "Accept", "application/json")
  139. w.Header().Set("Content-Type", "application/json")
  140. r.ParseForm()
  141. marker := r.Form.Get("marker")
  142. switch marker {
  143. case "":
  144. fmt.Fprintf(w, output)
  145. case "49181cd6-169a-4130-9455-31185bbfc5bf":
  146. fmt.Fprintf(w, `{"resources":[]}`)
  147. default:
  148. t.Fatalf("Unexpected marker: [%s]", marker)
  149. }
  150. })
  151. }
  152. // GetExpected represents the expected object from a Get request.
  153. var GetExpected = &Resource{
  154. Name: "wordpress_instance",
  155. Links: []gophercloud.Link{
  156. gophercloud.Link{
  157. Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance",
  158. Rel: "self",
  159. },
  160. gophercloud.Link{
  161. Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e",
  162. Rel: "stack",
  163. },
  164. },
  165. LogicalID: "wordpress_instance",
  166. Attributes: map[string]interface{}{"SXSW": "atx"},
  167. StatusReason: "state changed",
  168. UpdatedTime: time.Date(2014, 12, 10, 18, 34, 35, 0, time.UTC),
  169. RequiredBy: []interface{}{},
  170. Status: "CREATE_COMPLETE",
  171. PhysicalID: "00e3a2fe-c65d-403c-9483-4db9930dd194",
  172. Type: "OS::Nova::Server",
  173. }
  174. // GetOutput represents the response body from a Get request.
  175. const GetOutput = `
  176. {
  177. "resource": {
  178. "description": "Some resource",
  179. "attributes": {"SXSW": "atx"},
  180. "resource_name": "wordpress_instance",
  181. "description": "",
  182. "links": [
  183. {
  184. "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance",
  185. "rel": "self"
  186. },
  187. {
  188. "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e",
  189. "rel": "stack"
  190. }
  191. ],
  192. "logical_resource_id": "wordpress_instance",
  193. "resource_status": "CREATE_COMPLETE",
  194. "updated_time": "2014-12-10T18:34:35",
  195. "required_by": [],
  196. "resource_status_reason": "state changed",
  197. "physical_resource_id": "00e3a2fe-c65d-403c-9483-4db9930dd194",
  198. "resource_type": "OS::Nova::Server"
  199. }
  200. }`
  201. // HandleGetSuccessfully creates an HTTP handler at `/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance`
  202. // on the test handler mux that responds with a `Get` response.
  203. func HandleGetSuccessfully(t *testing.T, output string) {
  204. th.Mux.HandleFunc("/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance", func(w http.ResponseWriter, r *http.Request) {
  205. th.TestMethod(t, r, "GET")
  206. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  207. th.TestHeader(t, r, "Accept", "application/json")
  208. w.Header().Set("Content-Type", "application/json")
  209. w.WriteHeader(http.StatusOK)
  210. fmt.Fprintf(w, output)
  211. })
  212. }
  213. // MetadataExpected represents the expected object from a Metadata request.
  214. var MetadataExpected = map[string]string{
  215. "number": "7",
  216. "animal": "auk",
  217. }
  218. // MetadataOutput represents the response body from a Metadata request.
  219. const MetadataOutput = `
  220. {
  221. "metadata": {
  222. "number": "7",
  223. "animal": "auk"
  224. }
  225. }`
  226. // HandleMetadataSuccessfully creates an HTTP handler at `/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance/metadata`
  227. // on the test handler mux that responds with a `Metadata` response.
  228. func HandleMetadataSuccessfully(t *testing.T, output string) {
  229. th.Mux.HandleFunc("/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance/metadata", func(w http.ResponseWriter, r *http.Request) {
  230. th.TestMethod(t, r, "GET")
  231. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  232. th.TestHeader(t, r, "Accept", "application/json")
  233. w.Header().Set("Content-Type", "application/json")
  234. w.WriteHeader(http.StatusOK)
  235. fmt.Fprintf(w, output)
  236. })
  237. }
  238. // ListTypesExpected represents the expected object from a ListTypes request.
  239. var ListTypesExpected = ResourceTypes{
  240. "OS::Nova::Server",
  241. "OS::Heat::RandomString",
  242. "OS::Swift::Container",
  243. "OS::Trove::Instance",
  244. "OS::Nova::FloatingIPAssociation",
  245. "OS::Cinder::VolumeAttachment",
  246. "OS::Nova::FloatingIP",
  247. "OS::Nova::KeyPair",
  248. }
  249. // same as above, but sorted
  250. var SortedListTypesExpected = ResourceTypes{
  251. "OS::Cinder::VolumeAttachment",
  252. "OS::Heat::RandomString",
  253. "OS::Nova::FloatingIP",
  254. "OS::Nova::FloatingIPAssociation",
  255. "OS::Nova::KeyPair",
  256. "OS::Nova::Server",
  257. "OS::Swift::Container",
  258. "OS::Trove::Instance",
  259. }
  260. // ListTypesOutput represents the response body from a ListTypes request.
  261. const ListTypesOutput = `
  262. {
  263. "resource_types": [
  264. "OS::Nova::Server",
  265. "OS::Heat::RandomString",
  266. "OS::Swift::Container",
  267. "OS::Trove::Instance",
  268. "OS::Nova::FloatingIPAssociation",
  269. "OS::Cinder::VolumeAttachment",
  270. "OS::Nova::FloatingIP",
  271. "OS::Nova::KeyPair"
  272. ]
  273. }`
  274. // HandleListTypesSuccessfully creates an HTTP handler at `/resource_types`
  275. // on the test handler mux that responds with a `ListTypes` response.
  276. func HandleListTypesSuccessfully(t *testing.T, output string) {
  277. th.Mux.HandleFunc("/resource_types", func(w http.ResponseWriter, r *http.Request) {
  278. th.TestMethod(t, r, "GET")
  279. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  280. th.TestHeader(t, r, "Accept", "application/json")
  281. w.Header().Set("Content-Type", "application/json")
  282. w.WriteHeader(http.StatusOK)
  283. fmt.Fprintf(w, output)
  284. })
  285. }
  286. // GetSchemaExpected represents the expected object from a Schema request.
  287. var GetSchemaExpected = &TypeSchema{
  288. Attributes: map[string]interface{}{
  289. "an_attribute": map[string]interface{}{
  290. "description": "An attribute description .",
  291. },
  292. },
  293. Properties: map[string]interface{}{
  294. "a_property": map[string]interface{}{
  295. "update_allowed": false,
  296. "required": true,
  297. "type": "string",
  298. "description": "A resource description.",
  299. },
  300. },
  301. ResourceType: "OS::Heat::AResourceName",
  302. SupportStatus: map[string]interface{}{
  303. "message": "A status message",
  304. "status": "SUPPORTED",
  305. "version": "2014.1",
  306. },
  307. }
  308. // GetSchemaOutput represents the response body from a Schema request.
  309. const GetSchemaOutput = `
  310. {
  311. "attributes": {
  312. "an_attribute": {
  313. "description": "An attribute description ."
  314. }
  315. },
  316. "properties": {
  317. "a_property": {
  318. "update_allowed": false,
  319. "required": true,
  320. "type": "string",
  321. "description": "A resource description."
  322. }
  323. },
  324. "resource_type": "OS::Heat::AResourceName",
  325. "support_status": {
  326. "message": "A status message",
  327. "status": "SUPPORTED",
  328. "version": "2014.1"
  329. }
  330. }`
  331. // HandleGetSchemaSuccessfully creates an HTTP handler at `/resource_types/OS::Heat::AResourceName`
  332. // on the test handler mux that responds with a `Schema` response.
  333. func HandleGetSchemaSuccessfully(t *testing.T, output string) {
  334. th.Mux.HandleFunc("/resource_types/OS::Heat::AResourceName", func(w http.ResponseWriter, r *http.Request) {
  335. th.TestMethod(t, r, "GET")
  336. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  337. th.TestHeader(t, r, "Accept", "application/json")
  338. w.Header().Set("Content-Type", "application/json")
  339. w.WriteHeader(http.StatusOK)
  340. fmt.Fprintf(w, output)
  341. })
  342. }
  343. // GetTemplateExpected represents the expected object from a Template request.
  344. 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}"
  345. // GetTemplateOutput represents the response body from a Template request.
  346. const GetTemplateOutput = `
  347. {
  348. "HeatTemplateFormatVersion": "2012-12-12",
  349. "Outputs": {
  350. "private_key": {
  351. "Description": "The private key if it has been saved.",
  352. "Value": "{\"Fn::GetAtt\": [\"KeyPair\", \"private_key\"]}"
  353. },
  354. "public_key": {
  355. "Description": "The public key.",
  356. "Value": "{\"Fn::GetAtt\": [\"KeyPair\", \"public_key\"]}"
  357. }
  358. },
  359. "Parameters": {
  360. "name": {
  361. "Description": "The name of the key pair.",
  362. "Type": "String"
  363. },
  364. "public_key": {
  365. "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.",
  366. "Type": "String"
  367. },
  368. "save_private_key": {
  369. "AllowedValues": [
  370. "True",
  371. "true",
  372. "False",
  373. "false"
  374. ],
  375. "Default": false,
  376. "Description": "True if the system should remember a generated private key; False otherwise.",
  377. "Type": "String"
  378. }
  379. },
  380. "Resources": {
  381. "KeyPair": {
  382. "Properties": {
  383. "name": {
  384. "Ref": "name"
  385. },
  386. "public_key": {
  387. "Ref": "public_key"
  388. },
  389. "save_private_key": {
  390. "Ref": "save_private_key"
  391. }
  392. },
  393. "Type": "OS::Nova::KeyPair"
  394. }
  395. }
  396. }`
  397. // HandleGetTemplateSuccessfully creates an HTTP handler at `/resource_types/OS::Heat::AResourceName/template`
  398. // on the test handler mux that responds with a `Template` response.
  399. func HandleGetTemplateSuccessfully(t *testing.T, output string) {
  400. th.Mux.HandleFunc("/resource_types/OS::Heat::AResourceName/template", func(w http.ResponseWriter, r *http.Request) {
  401. th.TestMethod(t, r, "GET")
  402. th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
  403. th.TestHeader(t, r, "Accept", "application/json")
  404. w.Header().Set("Content-Type", "application/json")
  405. w.WriteHeader(http.StatusOK)
  406. fmt.Fprintf(w, output)
  407. })
  408. }