Skip to content

Commit 2c3bc65

Browse files
author
rogeliosanchez
authored
Enable Group 23 - Vic Machine Service to run in parallel under CI
* Implement thread safe VIC Machine Server keywords
1 parent 0852114 commit 2c3bc65

File tree

8 files changed

+37
-26
lines changed

8 files changed

+37
-26
lines changed

tests/resources/Group23-VIC-Machine-Service-Util.robot

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,40 @@
1414

1515
*** Settings ***
1616
Documentation 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 ***
2929
Start 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

3348
Get 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-
8296
Verify Return Code
8397
Should Be Equal As Integers ${RC} 0
8498

85-
8699
Verify Status
87100
[Arguments] ${expected}
88101
Should Be Equal As Integers ${expected} ${STATUS}
@@ -108,7 +121,6 @@ Verify Status Unprocessable Entity
108121
Verify Status Internal Server Error
109122
Verify Status 500
110123

111-
112124
Output 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-
125136
Property Should Be Equal
126137
[Arguments] ${jq} ${expected}
127138

@@ -154,7 +165,7 @@ Property Length Should Be
154165

155166

156167
Get 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

tests/test-cases/Group23-VIC-Machine-Service/23-01-Metadata.robot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Documentation Test 23-01 - Version
1717
Resource ../../resources/Util.robot
1818
Resource ../../resources/Group23-VIC-Machine-Service-Util.robot
1919
Suite Setup Start VIC Machine Server
20-
Suite Teardown Terminate All Processes kill=True
20+
Suite Teardown Stop VIC Machine Server
2121
Default Tags
2222

2323

@@ -44,7 +44,7 @@ Verify Hello
4444

4545
*** Test Cases ***
4646
Get Version
47-
Wait Until Keyword Succeeds 5x 1s Get Version
47+
Wait Until Keyword Succeeds 5x 1s Get Version
4848

4949
Verify Status Ok
5050
Verify Version

tests/test-cases/Group23-VIC-Machine-Service/23-02-VCH-List.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Setup
2828

2929
Teardown
3030
Run Keyword And Continue On Failure Cleanup VIC Appliance On Test Server
31-
Terminate All Processes kill=True
31+
Stop VIC Machine Server
3232

3333
Get VCH List
3434
Get Path Under Target vch

tests/test-cases/Group23-VIC-Machine-Service/23-03-VCH-Create.robot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Setup
3232

3333

3434
Teardown
35-
Terminate All Processes kill=True
35+
Stop VIC Machine Server
3636
Cleanup Test Server
3737

3838

@@ -340,7 +340,7 @@ Fail to create VCH with a name that is already in use
340340
Verify Status Created
341341

342342
Create VCH '{"name":"${there_can_only_be_one}","compute":{"resource":{"name":"%{TEST_RESOURCE}"}},"storage":{"image_stores":["ds://%{TEST_DATASTORE}"]},"network":{"bridge":{"ip_range":"172.16.0.0/12","port_group":{"name":"%{BRIDGE_NETWORK}"}},"public":{"port_group":{"name":"${PUBLIC_NETWORK}"}}},"auth":{"server":{"generate":{"cname":"vch.example.com","organization":["VMware, Inc."],"size":{"value":2048,"units":"bits"}}},"client":{"no_tls_verify": true}}}'
343-
343+
344344
Verify Return Code
345345

346346
${status}= Get State Of Github Issue 7749
@@ -355,7 +355,7 @@ Fail to create VCH with a name that is already in use
355355

356356
Fail to create a VCH with an invalid container name name convention
357357
${invalid_name_convention}= Set Variable 192.168.1.1-mycontainer
358-
358+
359359
Create VCH '{"name":"%{VCH-NAME}-api-test-minimal","compute":{"resource":{"name":"%{TEST_RESOURCE}"}},"storage":{"image_stores":["ds://%{TEST_DATASTORE}"]},"network":{"bridge":{"ip_range":"172.16.0.0/12","port_group":{"name":"%{BRIDGE_NETWORK}"}},"public":{"port_group":{"name":"${PUBLIC_NETWORK}"}}},"auth":{"server":{"generate":{"cname":"vch.example.com","organization":["VMware, Inc."],"size":{"value":2048,"units":"bits"}}},"client":{"no_tls_verify": true}}, "container":{"name_convention": "${invalid_name_convention}"}}'
360360

361361
Verify Return Code

tests/test-cases/Group23-VIC-Machine-Service/23-04-VCH-Inspect.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ Setup
3939

4040

4141
Teardown
42+
Stop VIC Machine Server
4243
Cleanup VIC Appliance On Test Server
43-
Terminate All Processes kill=True
4444

4545
Inspect VCH
4646
Get Path Under Target vch/${VCH-ID}

tests/test-cases/Group23-VIC-Machine-Service/23-05-VCH-Logs.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Documentation Test 23-05 - VCH Logs
1717
Resource ../../resources/Util.robot
1818
Resource ../../resources/Group23-VIC-Machine-Service-Util.robot
1919
Suite Setup Start VIC Machine Server
20-
Suite Teardown Terminate All Processes kill=True
20+
Suite Teardown Stop VIC Machine Server
2121
Test Setup Install VIC Appliance To Test Server
2222
Test Teardown Cleanup VIC Appliance On Test Server
2323
Default Tags

tests/test-cases/Group23-VIC-Machine-Service/23-06-VCH-Certificate.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Documentation Test 23-06 - VCH Certificate
1717
Resource ../../resources/Util.robot
1818
Resource ../../resources/Group23-VIC-Machine-Service-Util.robot
1919
Suite Setup Start VIC Machine Server
20-
Suite Teardown Terminate All Processes kill=True
20+
Suite Teardown Stop VIC Machine Server
2121
Test Teardown Cleanup VIC Appliance On Test Server
2222
Default Tags
2323

tests/test-cases/Group23-VIC-Machine-Service/23-08-VCH-Delete.robot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Documentation Test 23-08 - VCH Delete
1717
Resource ../../resources/Util.robot
1818
Resource ../../resources/Group23-VIC-Machine-Service-Util.robot
1919
Suite Setup Start VIC Machine Server
20-
Suite Teardown Terminate All Processes kill=True
20+
Suite Teardown Stop VIC Machine Server
2121
Test Setup Install And Prepare VIC Appliance
2222
Test Teardown Run govc datastore.rm %{VCH-NAME}-VOL
2323

@@ -257,7 +257,7 @@ Verify Volume Store Not Exists
257257
Cleanup VIC Appliance and Specified Volume
258258
[Arguments] ${volume-cleanup}
259259
Run Keyword And Continue On Failure Run govc datastore.rm ${volume-cleanup}-VOL
260-
Cleanup VIC Appliance On Test Server
260+
Cleanup VIC Appliance On Test Server
261261

262262
*** Test Cases ***
263263
Delete VCH

0 commit comments

Comments
 (0)