Run Docker Bench parallel on all nodes
[validation.git] / tests / docker / docker_bench / docker_bench.resource
1 ##############################################################################
2 # Copyright (c) 2019 AT&T Intellectual Property.                             #
3 # Copyright (c) 2019 Nokia.                                                  #
4 #                                                                            #
5 # Licensed under the Apache License, Version 2.0 (the "License");            #
6 # you maynot use this file except in compliance with the License.            #
7 #                                                                            #
8 # You may obtain a copy of the License at                                    #
9 #       http://www.apache.org/licenses/LICENSE-2.0                           #
10 #                                                                            #
11 # Unless required by applicable law or agreed to in writing, software        #
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT  #
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.           #
14 # See the License for the specific language governing permissions and        #
15 # limitations under the License.                                             #
16 ##############################################################################
17
18
19 *** Settings ***
20 Library            BuiltIn
21 Library            Collections
22 Library            OperatingSystem
23 Library            Process
24 Library            SSHLibrary
25 Library            String
26
27
28 *** Variables ***
29 ${REPORTDIR}       ${LOG_PATH}${/}${SUITE_NAME.replace(' ','_')}
30 ${SRCDIR}          /opt/akraino/docker-bench-security
31 ${DESTDIR}         /tmp/docker-bench-security
32 ${NODEDIR}         /tmp/docker-bench-security-run
33 ${SSH_OPTS}        -o StrictHostKeyChecking=no
34
35
36 *** Keywords ***
37 Open Connection And Log In
38     Open Connection        ${HOST}
39     Login With Public Key  ${USERNAME}  ${SSH_KEYFILE}
40
41 Upload Test Software To Nodes
42     Put Directory          ${SRCDIR}  ${DESTDIR}  recursive=True
43     Get Node Addresses
44     Copy Test Software To All Nodes
45
46 Run Test Software On Nodes
47     FOR  ${node}  IN  @{nodes}
48         Start Command  ssh ${SSH_OPTS} ${node} "cd ${NODEDIR}; sudo ./docker-bench-security.sh -b -l bench.log"
49     END
50     @{tmp}=                Copy List  ${nodes}
51     Reverse List           ${tmp}
52     FOR  ${node}  IN  @{tmp}
53         Read Command Output  return_stdout=False
54         Execute Command  scp ${SSH_OPTS} ${node}:${NODEDIR}/bench.log ${DESTDIR}/docker-bench-${node}.log
55         Execute Command  scp ${SSH_OPTS} ${node}:${NODEDIR}/bench.log.json ${DESTDIR}/docker-bench-${node}.json
56         SSHLibrary.Get File  ${DESTDIR}/docker-bench-${node}.log  ${REPORTDIR}/
57         SSHLibrary.Get File  ${DESTDIR}/docker-bench-${node}.json  ${REPORTDIR}/
58     END
59
60 Get Node Addresses
61     ${stdout}=            Execute Command
62     ...                   kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="InternalIP")].address'}
63     @{nodes}=             Split String  ${stdout}
64     Set Test Variable     @{nodes}
65
66 Copy Test Software To All Nodes
67     FOR  ${node}  IN  @{nodes}
68         Execute Command   ssh ${SSH_OPTS} ${node} "mkdir -p ${NODEDIR}"
69         Execute Command   scp ${SSH_OPTS} -rp ${DESTDIR}/. ${node}:${NODEDIR}
70     END
71
72 Remove Test Software From Nodes
73     FOR  ${node}  IN  @{nodes}
74         Execute Command   ssh ${SSH_OPTS} ${node} "rm -rf ${NODEDIR}"
75     END
76     Execute Command       rm -rf ${DESTDIR}