Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / libraries / DIDMKeywords.robot
1 *** Settings ***
2 Documentation     Keywords for DIDM suites
3 Library           SSHLibrary
4 Library           Collections
5 Library           RequestsLibrary
6 Variables         ../variables/Variables.py
7 Resource          ./Utils.robot
8
9 *** Keywords ***
10 Check DIDM Registered With Device
11     [Documentation]    Check for DIDM registered with the device
12     ${resp}=    RequestsLibrary.Get Request    session    ${OPERATIONAL_NODES_API}
13     Should Be Equal As Strings    ${resp.status_code}    200
14     Log    ${resp.content}
15     Should Contain    ${resp.content}    didm
16     [Return]    ${resp.content}
17
18 Find Device Data
19     [Documentation]    Extract device information
20     ${resp.content}=    Check DIDM Registered With Device
21     ${json_resp}=    RequestsLibrary.To_Json    ${resp.content}
22     ${nodes_resp}=    Get From Dictionary    ${json_resp}    nodes
23     ${node_resp}=    Get From Dictionary    ${nodes_resp}    node
24     ${node_data}=    Get From List    ${node_resp}    0
25     Log    ${node_data}
26     Set Suite Variable    ${node_data}
27     [Return]    ${node_data}
28
29 Check Device IP
30     [Documentation]    Check for the device IP address
31     ${dev_ip}=    Set Variable    flow-node-inventory:ip-address
32     ${node_data}=    Find Device Data
33     ${device_keys}=    Get Dictionary Keys    ${node_data}
34     Log    ${device_keys}
35     ${length}=    Get Length    ${device_keys}
36     FOR    ${index}    IN RANGE    0    ${length}
37         ${line}=    Get From List    ${device_keys}    ${index}
38         Run Keyword And Return If    '${dev_ip}' == '${line}'    Get From Dictionary    ${node_data}    ${dev_ip}
39     END
40     [Return]    ${dev_ip}
41
42 Find Device Type
43     [Documentation]    Look for the device type
44     ${device_type}=    Set Variable    didm-identification:device-type
45     ${device_ip}=    Check Device IP
46     Should Match    ${DEVICE_IP}    ${device_ip}
47     ${device_keys}=    Get Dictionary Keys    ${node_data}
48     Log    ${device_keys}
49     ${length}=    Get Length    ${device_keys}
50     FOR    ${index}    IN RANGE    0    ${length}
51         ${line}=    Get From List    ${device_keys}    ${index}
52         Run Keyword And Return If    '${device_type}' == '${line}'    Get From Dictionary    ${node_data}    ${device_type}
53     END
54     [Return]    ${device_type}
55
56 Find Device Hardware
57     [Documentation]    Look for the device hardware information
58     ${device_hw}=    Set Variable    flow-node-inventory:hardware
59     ${device_keys}=    Get Dictionary Keys    ${node_data}
60     Log    ${device_keys}
61     ${length}=    Get Length    ${device_keys}
62     FOR    ${index}    IN RANGE    0    ${length}
63         ${line}=    Get From List    ${device_keys}    ${index}
64         Run Keyword And Return If    '${device_hw}' == '${line}'    Get From Dictionary    ${node_data}    ${device_hw}
65     END
66     [Return]    ${device_hw}
67
68 Find Device Software
69     [Documentation]    Look for the device software information
70     ${device_sw}=    Set Variable    flow-node-inventory:software
71     ${device_keys}=    Get Dictionary Keys    ${node_data}
72     Log    ${device_keys}
73     ${length}=    Get Length    ${device_keys}
74     FOR    ${index}    IN RANGE    0    ${length}
75         ${line}=    Get From List    ${device_keys}    ${index}
76         Run Keyword And Return If    '${device_sw}' == '${line}'    Get From Dictionary    ${node_data}    ${device_sw}
77     END
78     [Return]    ${device_sw}
79
80 Find Device Manufacturer
81     [Documentation]    Look for the device manufacture
82     ${manufacture}=    Set Variable    flow-node-inventory:manufacturer
83     ${device_keys}=    Get Dictionary Keys    ${node_data}
84     Log    ${device_keys}
85     ${length}=    Get Length    ${device_keys}
86     FOR    ${index}    IN RANGE    0    ${length}
87         ${line}=    Get From List    ${device_keys}    ${index}
88         Run Keyword And Return If    '${manufacture}' == '${line}'    Get From Dictionary    ${node_data}    ${manufacture}
89     END
90     [Return]    ${manufacture}
91
92 Find Serial Number
93     [Documentation]    Look for the device serial number
94     ${serial_number}=    Set Variable    flow-node-inventory:serial-number
95     ${device_keys}=    Get Dictionary Keys    ${node_data}
96     Log    ${device_keys}
97     ${length}=    Get Length    ${device_keys}
98     FOR    ${index}    IN RANGE    0    ${length}
99         ${line}=    Get From List    ${device_keys}    ${index}
100         Run Keyword And Return If    '${serial_number}' == '${line}'    Get From Dictionary    ${node_data}    ${serial_number}
101     END
102     [Return]    ${serial_number}
103
104 Find Device Description
105     [Documentation]    Look for the device description
106     ${description}=    Set Variable    flow-node-inventory:description
107     ${device_keys}=    Get Dictionary Keys    ${node_data}
108     Log    ${device_keys}
109     ${length}=    Get Length    ${device_keys}
110     FOR    ${index}    IN RANGE    0    ${length}
111         ${line}=    Get From List    ${device_keys}    ${index}
112         Run Keyword And Return If    '${description}' == '${line}'    Get From Dictionary    ${node_data}    ${description}
113     END
114     [Return]    ${description}