Update README.md with instructions to run tests using testing-daily images
[osm/tests.git] / robot-systest / lib / vnf_lib.robot
1 #   Licensed under the Apache License, Version 2.0 (the "License");
2 #   you may not use this file except in compliance with the License.
3 #   You may obtain a copy of the License at
4 #
5 #       http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #   Unless required by applicable law or agreed to in writing, software
8 #   distributed under the License is distributed on an "AS IS" BASIS,
9 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 #   See the License for the specific language governing permissions and
11 #   limitations under the License.
12
13 *** Variables ***
14 ${success_return_code}   0
15
16
17 *** Keywords ***
18 Get Vnf List
19     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnf-list 2>&1
20     Log   ${stdout}
21     Should Be Equal As Integers   ${rc}   ${success_return_code}
22     [Return]   ${stdout}
23
24
25 Get VNF VIM ID
26     [Arguments]   ${vnf_id}
27
28     Should Not Be Empty   ${vnf_id}
29     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnf-show ${vnf_id} --literal | grep vim-id | awk '{print $2}'
30     Log   ${stdout}
31     Should Be Equal As Integers   ${rc}   ${success_return_code}
32     [Return]   ${stdout}
33
34
35 Get VDU list from VNF
36     [Documentation]   Return a list of the VDUr ids for a VNF
37
38     [Arguments]   ${vnf_id}
39
40     Should Not Be Empty   ${vnf_id}
41     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnf-show ${vnf_id} --literal | yq '.vdur[].id'
42     Log   ${stdout}
43     Should Be Equal As Integers   ${rc}   ${success_return_code}   msg=${stdout}   values=False
44     @{vdur_ids}=   Split String   ${stdout}
45     [Return]   @{vdur_ids}
46
47
48 Get VDU VIM Id
49     [Documentation]   Return the VIM VM ID for a VDU
50
51     [Arguments]   ${vnf_id}   ${vdur_id}
52
53     Should Not Be Empty   ${vnf_id}
54     ${rc}   ${vm_vim_id}=   Run and Return RC and Output   osm vnf-show ${vnf_id} --literal | yq '.vdur[] | select(.id == "'${vdur_id}'")' | yq '."vim-id"' | tr -d \\"
55     Log   ${vm_vim_id}
56     Should Be Equal As Integers   ${rc}   ${success_return_code}   msg=${vm_vim_id}   values=False
57     [Return]   ${vm_vim_id}
58
59
60 Get Vnf Vdur IPs
61     [Documentation]   Return a list with the IP addresses of the VDU records of a VNF instance.
62
63     [Arguments]   ${vnf_id}
64
65     Should Not Be Empty   ${vnf_id}
66     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnf-show ${vnf_id} --literal | yq '.vdur[].interfaces[]."ip-address"' | tr -d \\"
67     Should Be Equal As Integers   ${rc}   ${success_return_code}   msg=${stdout}   values=False
68     @{ip} =   Split String   ${stdout}
69     [Return]   @{ip}
70
71
72 Get Vdu Attribute
73     [Documentation]   Return an attribute from VDU records selected by count_index of a VNF instance.
74
75     [Arguments]   ${vnf_id}   ${attribute}   ${count_index}=0
76
77     Should Not Be Empty   ${vnf_id}
78     Should Not Be Empty   ${attribute}
79     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnf-show ${vnf_id} --literal | yq '.vdur[] | select(."count-index" == ${count_index})' | yq '."${attribute}"' | tr -d \\"
80     Should Be Equal As Integers   ${rc}   ${success_return_code}   msg=${stdout}   values=False
81     [Return]   ${stdout}