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