1414
1515*** Settings ***
1616Documentation This resource contains keywords which are helpful for using curl to test the vic-machine API.
17-
17+ Library Process
1818
1919*** Variables ***
20- ${HTTP_PORT } 1337
21- ${HTTPS_PORT } 31337
22-
2320${RC } The return code of the last curl invocation
2421${OUTPUT } The output of the last curl invocation
2522${STATUS } The HTTP status of the last curl invocation
2623
24+ ${VIC_MACHINE_SERVER_LOG } vic-machine-server.log
25+ ${SERVING_AT_TEXT } Serving vic machine at
26+
2727
2828*** Keywords ***
2929Start VIC Machine Server
30- Start Process ./bin/vic-machine-server --port ${HTTP_PORT } --scheme http shell=True cwd=/go/src/github.com/vmware/vic
30+ ${dir_name } = Evaluate 'group23_log_dir' + str(random.randint(1000,9999)) modules=random
31+
32+ ${handle } = Start Process ./bin/vic-machine-server --scheme http --log-directory ${dir_name } / shell=True cwd=/go/src/github.com/vmware/vic
33+ Set Suite Variable ${server_handle } ${handle }
34+ Process Should Be Running ${handle }
35+ Sleep 5sec
36+
37+ ${output } = Run cat ${dir_name } /${VIC_MACHINE_SERVER_LOG }
38+ @{output } = Split To Lines ${output }
39+ :FOR ${line } IN @{output }
40+ \ ${status } = Run Keyword And Return Status Should Contain ${line } ${SERVING_AT_TEXT }
41+ \ ${server_url } = Run Keyword If ${status } Fetch From Right ${line } ${SPACE }
42+ \ Run Keyword If ${status } Set Suite Variable ${VIC_MACHINE_SERVER_URL } ${server_url }
3143
44+ Stop VIC Machine Server
45+ Terminate Process ${server_handle } kill=true
46+ Process Should Be Stopped ${server_handle }
3247
3348Get Path
3449 [Arguments] ${path }
35- ${RC } ${OUTPUT } = Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X GET "http://127.0.0.1: ${ HTTP_PORT } /container/${PATH } "
50+ ${RC } ${OUTPUT } = Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X GET "${ VIC_MACHINE_SERVER_URL } /container/${PATH } "
3651 ${OUTPUT } ${STATUS } = Split String From Right ${OUTPUT } \n 1
3752 Set Test Variable ${RC }
3853 Set Test Variable ${OUTPUT }
@@ -42,7 +57,7 @@ Get Path Under Target
4257 [Arguments] ${path } @{query }
4358 ${fullQuery } = Catenate SEPARATOR=& thumbprint=%{TEST_THUMBPRINT } @{query }
4459 ${auth } = Evaluate base64.b64encode("%{TEST_USERNAME } :%{TEST_PASSWORD } ") modules=base64
45- ${RC } ${OUTPUT } = Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X GET "http://127.0.0.1: ${ HTTP_PORT } /container/target/%{TEST_URL } /${PATH } ?${fullQuery } " -H "Accept: application/json" -H "Authorization: Basic ${auth } "
60+ ${RC } ${OUTPUT } = Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X GET "${ VIC_MACHINE_SERVER_URL } /container/target/%{TEST_URL } /${PATH } ?${fullQuery } " -H "Accept: application/json" -H "Authorization: Basic ${auth } "
4661 ${OUTPUT } ${STATUS } = Split String From Right ${OUTPUT } \n 1
4762 Set Test Variable ${RC }
4863 Set Test Variable ${OUTPUT }
@@ -52,7 +67,7 @@ Get Path Under Target Using Session
5267 [Arguments] ${path } @{query }
5368 ${fullQuery } = Catenate SEPARATOR=& thumbprint=%{TEST_THUMBPRINT } @{query }
5469 ${ticket } = Run govc vm.console %{VCH-NAME } | awk -F'[:@]' '{print $3}'
55- ${RC } ${OUTPUT } = Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X GET "http://127.0.0.1: ${ HTTP_PORT } /container/target/%{TEST_URL } /${path } ?${fullQuery } " -H "Accept: application/json" -H "X-VMWARE-TICKET: ${ticket } "
70+ ${RC } ${OUTPUT } = Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X GET "${ VIC_MACHINE_SERVER_URL } /container/target/%{TEST_URL } /${path } ?${fullQuery } " -H "Accept: application/json" -H "X-VMWARE-TICKET: ${ticket } "
5671 ${OUTPUT } ${STATUS } = Split String From Right ${OUTPUT } \n 1
5772 Set Test Variable ${RC }
5873 Set Test Variable ${OUTPUT }
@@ -62,7 +77,7 @@ Post Path Under Target
6277 [Arguments] ${path } ${data } @{query }
6378 ${fullQuery } = Catenate SEPARATOR=& thumbprint=%{TEST_THUMBPRINT } @{query }
6479 ${auth } = Evaluate base64.b64encode("%{TEST_USERNAME } :%{TEST_PASSWORD } ") modules=base64
65- ${RC } ${OUTPUT } = Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X POST "http://127.0.0.1: ${ HTTP_PORT } /container/target/%{TEST_URL } /${PATH } ?${fullQuery } " -H "Accept: application/json" -H "Authorization: Basic ${auth } " -H "Content-Type: application/json" --data ${data }
80+ ${RC } ${OUTPUT } = Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X POST "${ VIC_MACHINE_SERVER_URL } /container/target/%{TEST_URL } /${PATH } ?${fullQuery } " -H "Accept: application/json" -H "Authorization: Basic ${auth } " -H "Content-Type: application/json" --data ${data }
6681 ${OUTPUT } ${STATUS } = Split String From Right ${OUTPUT } \n 1
6782 Set Test Variable ${RC }
6883 Set Test Variable ${OUTPUT }
@@ -72,17 +87,15 @@ Delete Path Under Target
7287 [Arguments] ${path } ${data } ='' @{query }
7388 ${fullQuery } = Catenate SEPARATOR=& thumbprint=%{TEST_THUMBPRINT } @{query }
7489 ${auth } = Evaluate base64.b64encode("%{TEST_USERNAME } :%{TEST_PASSWORD } ") modules=base64
75- ${RC } ${OUTPUT } = Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X DELETE "http://127.0.0.1: ${ HTTP_PORT } /container/target/%{TEST_URL } /${PATH } ?${fullQuery } " -H "Accept: application/json" -H "Authorization: Basic ${auth } " -H "Content-Type: application/json" --data ${data }
90+ ${RC } ${OUTPUT } = Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X DELETE "${ VIC_MACHINE_SERVER_URL } /container/target/%{TEST_URL } /${PATH } ?${fullQuery } " -H "Accept: application/json" -H "Authorization: Basic ${auth } " -H "Content-Type: application/json" --data ${data }
7691 ${OUTPUT } ${STATUS } = Split String From Right ${OUTPUT } \n 1
7792 Set Test Variable ${RC }
7893 Set Test Variable ${OUTPUT }
7994 Set Test Variable ${STATUS }
8095
81-
8296Verify Return Code
8397 Should Be Equal As Integers ${RC } 0
8498
85-
8699Verify Status
87100 [Arguments] ${expected }
88101 Should Be Equal As Integers ${expected } ${STATUS }
@@ -108,7 +121,6 @@ Verify Status Unprocessable Entity
108121Verify Status Internal Server Error
109122 Verify Status 500
110123
111-
112124Output Should Contain
113125 [Arguments] ${expected }
114126 Should Contain ${OUTPUT } ${expected }
@@ -121,7 +133,6 @@ Output Should Match Regexp
121133 [Arguments] ${expected }
122134 Should Match Regexp ${OUTPUT } ${expected }
123135
124-
125136Property Should Be Equal
126137 [Arguments] ${jq } ${expected }
127138
@@ -154,7 +165,7 @@ Property Length Should Be
154165
155166
156167Get Service Version String
157- ${rc } ${output } = Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X GET "http://127.0.0.1: ${ HTTP_PORT } /container/version"
168+ ${rc } ${output } = Run And Return Rc And Output curl -s -w "\n\%{http_code}\n" -X GET "${ VIC_MACHINE_SERVER_URL } /container/version"
158169 ${output } ${status } = Split String From Right ${output } \n 1
159170 Should Be Equal As Integers ${rc } 0
160171 Should Be Equal As Integers ${status } 200
0 commit comments