Correctly space expected_status
[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 Request    session    ${RFC8040_OPERATIONAL_NODES_API}
16     Should Be Equal As Strings    ${resp.status_code}    200
17     Log    ${resp.text}
18     Should Contain    ${resp.text}    didm
19     RETURN    ${resp.text}
20
21 Find Device Data
22     [Documentation]    Extract device information
23     ${resp.text}=    Check DIDM Registered With Device
24     ${json_resp}=    RequestsLibrary.To_Json    ${resp.text}
25     ${nodes_resp}=    Get From Dictionary    ${json_resp}    nodes
26     ${node_resp}=    Get From Dictionary    ${nodes_resp}    node
27     ${node_data}=    Get From List    ${node_resp}    0
28     Log    ${node_data}
29     Set Suite Variable    ${node_data}
30     RETURN    ${node_data}
31
32 Check Device IP
33     [Documentation]    Check for the device IP address
34     ${dev_ip}=    Set Variable    flow-node-inventory:ip-address
35     ${node_data}=    Find Device Data
36     ${device_keys}=    Get Dictionary Keys    ${node_data}
37     Log    ${device_keys}
38     ${length}=    Get Length    ${device_keys}
39     FOR    ${index}    IN RANGE    0    ${length}
40         ${line}=    Get From List    ${device_keys}    ${index}
41         Run Keyword And Return If    '${dev_ip}' == '${line}'    Get From Dictionary    ${node_data}    ${dev_ip}
42     END
43     RETURN    ${dev_ip}
44
45 Find Device Type
46     [Documentation]    Look for the device type
47     ${device_type}=    Set Variable    didm-identification:device-type
48     ${device_ip}=    Check Device IP
49     Should Match    ${DEVICE_IP}    ${device_ip}
50     ${device_keys}=    Get Dictionary Keys    ${node_data}
51     Log    ${device_keys}
52     ${length}=    Get Length    ${device_keys}
53     FOR    ${index}    IN RANGE    0    ${length}
54         ${line}=    Get From List    ${device_keys}    ${index}
55         Run Keyword And Return If
56         ...    '${device_type}' == '${line}'
57         ...    Get From Dictionary
58         ...    ${node_data}
59         ...    ${device_type}
60     END
61     RETURN    ${device_type}
62
63 Find Device Hardware
64     [Documentation]    Look for the device hardware information
65     ${device_hw}=    Set Variable    flow-node-inventory:hardware
66     ${device_keys}=    Get Dictionary Keys    ${node_data}
67     Log    ${device_keys}
68     ${length}=    Get Length    ${device_keys}
69     FOR    ${index}    IN RANGE    0    ${length}
70         ${line}=    Get From List    ${device_keys}    ${index}
71         Run Keyword And Return If    '${device_hw}' == '${line}'    Get From Dictionary    ${node_data}    ${device_hw}
72     END
73     RETURN    ${device_hw}
74
75 Find Device Software
76     [Documentation]    Look for the device software information
77     ${device_sw}=    Set Variable    flow-node-inventory:software
78     ${device_keys}=    Get Dictionary Keys    ${node_data}
79     Log    ${device_keys}
80     ${length}=    Get Length    ${device_keys}
81     FOR    ${index}    IN RANGE    0    ${length}
82         ${line}=    Get From List    ${device_keys}    ${index}
83         Run Keyword And Return If    '${device_sw}' == '${line}'    Get From Dictionary    ${node_data}    ${device_sw}
84     END
85     RETURN    ${device_sw}
86
87 Find Device Manufacturer
88     [Documentation]    Look for the device manufacture
89     ${manufacture}=    Set Variable    flow-node-inventory:manufacturer
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
96         ...    '${manufacture}' == '${line}'
97         ...    Get From Dictionary
98         ...    ${node_data}
99         ...    ${manufacture}
100     END
101     RETURN    ${manufacture}
102
103 Find Serial Number
104     [Documentation]    Look for the device serial number
105     ${serial_number}=    Set Variable    flow-node-inventory:serial-number
106     ${device_keys}=    Get Dictionary Keys    ${node_data}
107     Log    ${device_keys}
108     ${length}=    Get Length    ${device_keys}
109     FOR    ${index}    IN RANGE    0    ${length}
110         ${line}=    Get From List    ${device_keys}    ${index}
111         Run Keyword And Return If
112         ...    '${serial_number}' == '${line}'
113         ...    Get From Dictionary
114         ...    ${node_data}
115         ...    ${serial_number}
116     END
117     RETURN    ${serial_number}
118
119 Find Device Description
120     [Documentation]    Look for the device description
121     ${description}=    Set Variable    flow-node-inventory:description
122     ${device_keys}=    Get Dictionary Keys    ${node_data}
123     Log    ${device_keys}
124     ${length}=    Get Length    ${device_keys}
125     FOR    ${index}    IN RANGE    0    ${length}
126         ${line}=    Get From List    ${device_keys}    ${index}
127         Run Keyword And Return If
128         ...    '${description}' == '${line}'
129         ...    Get From Dictionary
130         ...    ${node_data}
131         ...    ${description}
132     END
133     RETURN    ${description}