PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

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