036105c4a19ba8d86c1047f2f0974514b05268db
[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     [Return]    ${dev_ip}
40
41 Find Device Type
42     [Documentation]    Look for the device type
43     ${device_type}=    Set Variable    didm-identification:device-type
44     ${device_ip}=    Check Device IP
45     Should Match    ${DEVICE_IP}    ${device_ip}
46     ${device_keys}=    Get Dictionary Keys    ${node_data}
47     Log    ${device_keys}
48     ${length}=    Get Length    ${device_keys}
49     : FOR    ${index}    IN RANGE    0    ${length}
50     \    ${line}=    Get From List    ${device_keys}    ${index}
51     \    Run Keyword And Return If    '${device_type}' == '${line}'    Get From Dictionary    ${node_data}    ${device_type}
52     [Return]    ${device_type}
53
54 Find Device Hardware
55     [Documentation]    Look for the device hardware information
56     ${device_hw}=    Set Variable    flow-node-inventory:hardware
57     ${device_keys}=    Get Dictionary Keys    ${node_data}
58     Log    ${device_keys}
59     ${length}=    Get Length    ${device_keys}
60     : FOR    ${index}    IN RANGE    0    ${length}
61     \    ${line}=    Get From List    ${device_keys}    ${index}
62     \    Run Keyword And Return If    '${device_hw}' == '${line}'    Get From Dictionary    ${node_data}    ${device_hw}
63     [Return]    ${device_hw}
64
65 Find Device Software
66     [Documentation]    Look for the device software information
67     ${device_sw}=    Set Variable    flow-node-inventory:software
68     ${device_keys}=    Get Dictionary Keys    ${node_data}
69     Log    ${device_keys}
70     ${length}=    Get Length    ${device_keys}
71     : FOR    ${index}    IN RANGE    0    ${length}
72     \    ${line}=    Get From List    ${device_keys}    ${index}
73     \    Run Keyword And Return If    '${device_sw}' == '${line}'    Get From Dictionary    ${node_data}    ${device_sw}
74     [Return]    ${device_sw}
75
76 Find Device Manufacturer
77     [Documentation]    Look for the device manufacture
78     ${manufacture}=    Set Variable    flow-node-inventory:manufacturer
79     ${device_keys}=    Get Dictionary Keys    ${node_data}
80     Log    ${device_keys}
81     ${length}=    Get Length    ${device_keys}
82     : FOR    ${index}    IN RANGE    0    ${length}
83     \    ${line}=    Get From List    ${device_keys}    ${index}
84     \    Run Keyword And Return If    '${manufacture}' == '${line}'    Get From Dictionary    ${node_data}    ${manufacture}
85     [Return]    ${manufacture}
86
87 Find Serial Number
88     [Documentation]    Look for the device serial number
89     ${serial_number}=    Set Variable    flow-node-inventory:serial-number
90     ${device_keys}=    Get Dictionary Keys    ${node_data}
91     Log    ${device_keys}
92     ${length}=    Get Length    ${device_keys}
93     : FOR    ${index}    IN RANGE    0    ${length}
94     \    ${line}=    Get From List    ${device_keys}    ${index}
95     \    Run Keyword And Return If    '${serial_number}' == '${line}'    Get From Dictionary    ${node_data}    ${serial_number}
96     [Return]    ${serial_number}
97
98 Find Device Description
99     [Documentation]    Look for the device description
100     ${description}=    Set Variable    flow-node-inventory:description
101     ${device_keys}=    Get Dictionary Keys    ${node_data}
102     Log    ${device_keys}
103     ${length}=    Get Length    ${device_keys}
104     : FOR    ${index}    IN RANGE    0    ${length}
105     \    ${line}=    Get From List    ${device_keys}    ${index}
106     \    Run Keyword And Return If    '${description}' == '${line}'    Get From Dictionary    ${node_data}    ${description}
107     [Return]    ${description}