Kailash Khalasi | 7261480 | 2018-05-02 09:21:23 -0700 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Setup and Teardown Functionality for XOS API Tests |
| 3 | Library Collections |
| 4 | Library String |
| 5 | Library OperatingSystem |
| 6 | Library XML |
| 7 | Library RequestsLibrary |
| 8 | Library HttpLibrary.HTTP |
| 9 | Library ../Framework/utils/utils.py |
| 10 | Library ../Framework/restApi.py |
| 11 | Variables ../Properties/RestApiProperties.py |
| 12 | |
| 13 | *** Keywords *** |
| 14 | Verify API Functionality |
| 15 | [Arguments] ${type} ${endpoint} ${data}=${EMPTY} ${data_id}=${EMPTY} ${key}=${EMPTY} |
| 16 | Run Keyword If "${type}" == "RETRIEVE" CORD Get ${endpoint} ${data_id} ${data} ${key} |
| 17 | Run Keyword If "${type}" == "CREATE" CORD Post ${endpoint} ${data} |
| 18 | Run Keyword If "${type}" == "UPDATE" CORD Put ${endpoint} ${data} ${data_id} |
| 19 | Run Keyword If "${type}" == "DELETE" CORD Delete ${endpoint} ${data_id} |
| 20 | |
| 21 | CORD Get |
| 22 | [Documentation] Make a GET call to the CORD controller |
| 23 | [Arguments] ${service} ${id} ${value} ${key} |
| 24 | ${resp}= Get Request ${SERVER_IP} ${service}/${id} |
| 25 | Log ${resp.content} |
| 26 | Should Be Equal As Strings ${resp.status_code} 200 |
| 27 | ${updated_value}= Run Keyword If '${key}' != 'null' Get Json Value ${resp.content} /${key} |
| 28 | ${updated_value}= Run Keyword If '${key}' != 'null' Remove String ${updated_value} " |
| 29 | Run Keyword If '${key}' != 'null' Should Contain "${value}" ${updated_value} |
| 30 | [Return] ${resp} |
| 31 | |
| 32 | CORD Post |
| 33 | [Documentation] Make a POST call to the CORD controller |
| 34 | [Arguments] ${service} ${data} |
| 35 | ${data}= Evaluate json.dumps(${data}) json |
| 36 | ${resp}= Post Request ${SERVER_IP} uri=${service} data=${data} |
| 37 | Log ${resp.content} |
| 38 | Should Be Equal As Strings ${resp.status_code} 200 |
| 39 | ${id}= Get Json Value ${resp.content} /id |
| 40 | Set Suite Variable ${id} |
| 41 | [Return] ${resp} |
| 42 | |
| 43 | CORD Put |
| 44 | [Documentation] Make a PUT call to the CORD controller |
| 45 | [Arguments] ${service} ${data} ${data_id} |
| 46 | ${data}= Evaluate json.dumps(${data}) json |
| 47 | ${resp}= Put Request ${SERVER_IP} uri=${service}/${data_id} data=${data} |
| 48 | Log ${resp.content} |
| 49 | Should Be Equal As Strings ${resp.status_code} 200 |
| 50 | ${id}= Get Json Value ${resp.content} /id |
| 51 | Set Suite Variable ${id} |
| 52 | [Return] ${resp} |
| 53 | |
| 54 | CORD Delete |
| 55 | [Documentation] Make a DELETE call to the CORD controller |
| 56 | [Arguments] ${service} ${data_id} |
| 57 | ${resp}= Delete Request ${SERVER_IP} uri=${service}/${data_id} |
| 58 | Log ${resp.content} |
| 59 | Should Be Equal As Strings ${resp.status_code} 200 |
| 60 | [Return] ${resp} |
| 61 | |
| 62 | Generate JSON Data |
| 63 | {% for m in proto.messages %} |
| 64 | {%- if m.name not in ['XOSBase'] -%} |
| 65 | {% autoescape false %} |
| 66 | {% endautoescape %} |
| 67 | ${json_{{ m.name | lower }}_1}= Set Variable { } |
| 68 | ${json_{{ m.name | lower }}_updated_1}= Set Variable { } |
| 69 | ${json_{{ m.name | lower}}_updated_key}= Set Variable null |
| 70 | Set Suite Variable ${json_{{ m.name | lower}}_updated_key} |
| 71 | # set required fields for {{ m.name | lower }} object |
| 72 | {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%} |
| 73 | {% if f.modifier == "required" -%} |
| 74 | {% if f.options.blank == "False" -%} |
| 75 | {% if not f.options.default -%} |
| 76 | {% if f.link -%} |
| 77 | ${tmp_{{ f.options.model | lower }}_id}= Create {{ f.options.model }} |
| 78 | ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }}_id ${tmp_{{ f.options.model | lower }}_id} |
| 79 | {% else -%} |
| 80 | ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value {{ f.type }} |
| 81 | ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}" |
| 82 | {% if loop.index0 == 0 -%} |
| 83 | ${json_{{ m.name | lower}}_updated_key}= Set Variable {{ f.name }} |
| 84 | ${json_{{ m.name | lower}}_{{ f.name }}_updated_1}= Generate Random Value {{ f.type }} |
| 85 | ${json_{{ m.name | lower }}_updated_1}= Set Json Value ${json_{{ m.name | lower }}_updated__1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_updated_1}" |
| 86 | {% endif -%} |
| 87 | {% endif -%} |
| 88 | {% endif -%} |
| 89 | {% endif -%} |
| 90 | {% endif -%} |
| 91 | {% endfor -%} |
| 92 | {% if m.name == "Site" -%} |
| 93 | ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase |
| 94 | ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /login_base "${json_{{ m.name | lower }}_login_base_tmp}" |
| 95 | {% endif -%} |
| 96 | {% if m.name == "Slice" -%} |
| 97 | ${json_{{ m.name | lower}}_name}= Generate Random Slice Name |
| 98 | ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "${json_{{ m.name | lower }}_name}" |
| 99 | ${json_{{ m.name | lower}}_name_updated_1}= Generate Random Slice Name |
| 100 | ${json_{{ m.name | lower}}_updated_1}= Set Json Value ${json_{{ m.name | lower }}_updated_1} /name "${json_{{ m.name | lower}}_name_updated_1}" |
| 101 | {% endif -%} |
Kailash Khalasi | db41afa | 2018-07-05 15:16:02 -0700 | [diff] [blame] | 102 | {% if m.name == "ProgranServiceInstance" -%} |
| 103 | ${json_{{ m.name | lower}}_name}= Generate Random Value string |
| 104 | ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "${json_{{ m.name | lower }}_name}" |
Kailash Khalasi | 19e5720 | 2018-07-13 10:21:41 -0700 | [diff] [blame] | 105 | ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /CellIndividualOffset "1" |
Kailash Khalasi | db41afa | 2018-07-05 15:16:02 -0700 | [diff] [blame] | 106 | ${json_{{ m.name | lower}}_name_updated_1}= Generate Random Value string |
| 107 | ${json_{{ m.name | lower}}_updated_1}= Set Json Value ${json_{{ m.name | lower }}_updated_1} /name "${json_{{ m.name | lower}}_name_updated_1}" |
Kailash Khalasi | 19e5720 | 2018-07-13 10:21:41 -0700 | [diff] [blame] | 108 | ${json_{{ m.name | lower}}_updated_1}= Set Json Value ${json_{{ m.name | lower }}_updated_1} /CellIndividualOffset "1" |
Kailash Khalasi | db41afa | 2018-07-05 15:16:02 -0700 | [diff] [blame] | 109 | {% endif %} |
Kailash Khalasi | 62ab403 | 2018-07-09 14:01:21 -0700 | [diff] [blame] | 110 | {% if m.name == "RCORDSubscriber" -%} |
Kailash Khalasi | ad9acf5 | 2018-07-12 10:06:06 -0700 | [diff] [blame] | 111 | ## Create req objects for subscriber (voltservice -> oltdevice -> ponport -> onudevice) |
| 112 | CORD Post /xosapi/v1/volt/voltservices {"name": "testvoltservice123"} |
| 113 | CORD Post /xosapi/v1/volt/oltdevices {"volt_service_id": ${id}, "uplink": "testoltdevice123"} |
| 114 | CORD Post /xosapi/v1/volt/ponports {"s_tag": "1234", "olt_device_id": ${id}, "port_no": "123", "name": "testponport123"} |
Kailash Khalasi | 62ab403 | 2018-07-09 14:01:21 -0700 | [diff] [blame] | 115 | ${json_{{ m.name | lower}}_onudevice}= Set Variable onudevice123 |
| 116 | ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /onu_device "${json_{{ m.name | lower}}_onudevice}" |
Kailash Khalasi | ad9acf5 | 2018-07-12 10:06:06 -0700 | [diff] [blame] | 117 | CORD Post /xosapi/v1/volt/onudevices {"serial_number": "onudevice123", "pon_port_id": ${id}, "vendor": "abcdefg"} |
Kailash Khalasi | 62ab403 | 2018-07-09 14:01:21 -0700 | [diff] [blame] | 118 | {% endif %} |
Kailash Khalasi | 7261480 | 2018-05-02 09:21:23 -0700 | [diff] [blame] | 119 | ${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1} |
| 120 | ${json_{{ m.name | lower }}_updated_1}= To JSON ${json_{{ m.name | lower }}_updated_1} |
| 121 | Set Suite Variable ${json_{{ m.name | lower }}_1} |
| 122 | Set Suite Variable ${json_{{ m.name | lower }}_updated_1} |
| 123 | {% endif -%} |
| 124 | {% endfor %} |
| 125 | |
| 126 | {% for m in proto.messages %} |
| 127 | {%- if m.name not in ['XOSBase'] -%} |
| 128 | Create {{ m.name }} |
| 129 | ##Creating {{ m.name | lower }} object |
| 130 | ${json_{{ m.name | lower }}_tmp}= Set Variable { } |
| 131 | # set required fields for {{ m.name | lower }} object |
| 132 | {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%} |
| 133 | {% if f.link -%} |
| 134 | {% if f.modifier == "required" -%} |
| 135 | {% if f.options.blank == "False" -%} |
| 136 | # create dependent {{ f.options.model }} |
| 137 | ${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }} |
| 138 | ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id} |
| 139 | {% endif -%} |
| 140 | {% endif -%} |
| 141 | {% else -%} |
| 142 | {% if f.modifier == "required" -%} |
| 143 | {% if f.options.blank == "False" -%} |
| 144 | {% if not f.options.default -%} |
| 145 | ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value {{ f.type }} |
| 146 | ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}" |
| 147 | {% endif -%} |
| 148 | {% endif -%} |
| 149 | {% endif -%} |
| 150 | {% endif -%} |
| 151 | {% endfor -%} |
| 152 | {% if m.name == "Site" -%} |
| 153 | ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase |
| 154 | ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /login_base "${json_{{ m.name | lower }}_login_base_tmp}" |
| 155 | {% endif -%} |
| 156 | {% if m.name == "Slice" -%} |
| 157 | ${json_{{ m.name | lower}}_name}= Generate Random Slice Name |
| 158 | ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower }}_name}" |
| 159 | {% endif -%} |
| 160 | {% if m.name == "Network" -%} |
| 161 | ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true |
| 162 | {% endif -%} |
| 163 | ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp} |
Kailash Khalasi | 9302c18 | 2018-05-07 13:46:15 -0600 | [diff] [blame] | 164 | ${resp}= CORD Post /xosapi/v1/{{ xproto_unquote(m.options.app_label) }}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower }}_tmp} |
Kailash Khalasi | 7261480 | 2018-05-02 09:21:23 -0700 | [diff] [blame] | 165 | ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id |
| 166 | Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp} |
| 167 | [Return] ${id_{{ m.name | lower }}_tmp} |
| 168 | {% endif -%} |
| 169 | {% endfor -%} |
| 170 | |
| 171 | Setup Tests |
| 172 | [Documentation] Find all dependent objects per model and create them and store them for later use |
| 173 | {% for m in proto.messages %} |
| 174 | {%- if m.name not in ['XOSBase'] -%} |
| 175 | ${model}= Set Variable {{ m.name | lower }}s |
| 176 | @{dependent_{{ m.name | lower }}_ids}= Create List ${model} |
| 177 | Set Suite Variable @{dependent_{{ m.name | lower }}_ids} |
| 178 | {% endif -%} |
| 179 | {% endfor -%} |
| 180 | @{dependent_models}= Create List |
| 181 | Set Suite Variable ${dependent_models} |
| 182 | ${auth} = Create List ${XOS_USER} ${XOS_PASSWD} |
| 183 | ${HEADERS} Create Dictionary Content-Type=application/json |
| 184 | Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS} |
| 185 | Generate JSON Data |
| 186 | |
| 187 | Teardown Tests |
| 188 | [Documentation] Delete all dependent objects created in Setup |
| 189 | {% for m in proto.messages %} |
| 190 | {%- if m.name not in ['XOSBase'] -%} |
| 191 | ${len}= Get Length ${dependent_{{ m.name | lower }}_ids} |
| 192 | : FOR ${INDEX} IN RANGE 1 ${len} |
| 193 | \ Run Keyword And Ignore Error CORD Delete /xosapi/v1/{{ xproto_unquote(m.options.app_label) }}/${dependent_{{ m.name | lower }}_ids[0]} ${dependent_{{ m.name | lower }}_ids[${INDEX}]} |
| 194 | {% endif -%} |
| 195 | {% endfor -%} |
Kailash Khalasi | ad9acf5 | 2018-07-12 10:06:06 -0700 | [diff] [blame] | 196 | Delete All Sessions |