DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation The main interface for interacting with Openstack. It handles low level stuff like managing the authtoken and Openstack required fields |
DR695H | d92b007 | 2019-06-17 17:23:14 -0400 | [diff] [blame] | 3 | Library ONAPLibrary.Openstack |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 4 | Library RequestsLibrary |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 5 | Library Collections |
DR695H | 3bb6cf4 | 2019-06-20 15:04:04 -0400 | [diff] [blame] | 6 | Library ONAPLibrary.Templating |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 7 | Resource ../global_properties.robot |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 8 | Resource openstack_common.robot |
| 9 | |
| 10 | *** Variables *** |
| 11 | ${OPENSTACK_NEUTRON_API_VERSION} /v2.0 |
| 12 | ${OPENSTACK_NEUTRON_NETWORK_PATH} /networks |
DR695H | 3bb6cf4 | 2019-06-20 15:04:04 -0400 | [diff] [blame] | 13 | ${OPENSTACK_NEUTRON_NETWORK_ADD_BODY_FILE} openstack/neutron_add_network.jinja |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 14 | ${OPENSTACK_NEUTRON_SUBNET_PATH} /subnets |
DR695H | 3bb6cf4 | 2019-06-20 15:04:04 -0400 | [diff] [blame] | 15 | ${OPENSTACK_NEUTRON_SUBNET_ADD_BODY_FILE} openstack/neutron_add_subnet.jinja |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 16 | ${OPENSTACK_NEUTRON_PORT_PATH} /ports |
| 17 | |
| 18 | *** Keywords *** |
| 19 | Get Openstack Network |
| 20 | [Documentation] Runs an Openstack Request and returns the network info |
| 21 | [Arguments] ${alias} ${network_id} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 22 | ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_NETWORK_PATH} /${network_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 23 | [Return] ${resp.json()} |
| 24 | |
| 25 | Get Openstack Networks |
| 26 | [Documentation] Runs an Openstack Request and returns the network info |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 27 | [Arguments] ${alias} |
| 28 | ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_NETWORK_PATH} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 29 | [Return] ${resp.json()} |
| 30 | |
| 31 | Get Openstack Subnets |
| 32 | [Documentation] Runs an Openstack Request and returns the network info |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 33 | [Arguments] ${alias} |
| 34 | ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_SUBNET_PATH} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 35 | [Return] ${resp.json()} |
| 36 | |
| 37 | Get Openstack Ports |
| 38 | [Documentation] Runs an Openstack Request and returns the network info |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 39 | [Arguments] ${alias} |
| 40 | ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_PORT_PATH} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 41 | [Return] ${resp.json()} |
| 42 | |
| 43 | Add Openstack Network |
| 44 | [Documentation] Runs an Openstack Request to add a network and returns that network id of the created network |
| 45 | [Arguments] ${alias} ${name} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 46 | ${arguments}= Create Dictionary name=${name} |
DR695H | 3bb6cf4 | 2019-06-20 15:04:04 -0400 | [diff] [blame] | 47 | Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER} |
| 48 | ${data}= Apply Template openstack ${OPENSTACK_NEUTRON_NETWORK_ADD_BODY_FILE} ${arguments} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 49 | ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_NETWORK_PATH} data_path= data=${data} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 50 | Should Be Equal As Strings 201 ${resp.status_code} |
| 51 | [Return] ${resp.json()['network']['id']} |
| 52 | |
| 53 | Delete Openstack Network |
| 54 | [Documentation] Runs an Openstack Request to delete a network |
| 55 | [Arguments] ${alias} ${network_id} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 56 | ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_NETWORK_PATH} /${network_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 57 | ${status_string}= Convert To String ${resp.status_code} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 58 | Should Match Regexp ${status_string} ^(204|200)$ |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 59 | [Return] ${resp.text} |
| 60 | |
| 61 | Add Openstack Network With Subnet If Not Exists |
| 62 | [Documentation] Runs an Openstack Request to add a network and returns that network id of the created network |
| 63 | [Arguments] ${alias} ${name} ${cidr} |
| 64 | ${network}= Get Openstack Subnet By Name ${alias} ${name} ${cidr} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 65 | ${pass} ${v}= Run Keyword and Ignore Error Dictionary Should Contain Key ${network} id |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 66 | Run Keyword If '${pass}' == 'FAIL' Add Openstack Network With Subnet ${alias} ${name} ${cidr} |
| 67 | ${network}= Get Openstack Subnet By Name ${alias} ${name} ${cidr} |
| 68 | ${network_id}= Get From Dictionary ${network} id |
| 69 | [Return] ${network_id} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 70 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 71 | |
| 72 | Add Openstack Network With Subnet |
| 73 | [Documentation] Runs an Openstack Request to add a network and returns that network id of the created network |
| 74 | [Arguments] ${alias} ${name} ${cidr} |
| 75 | ${network_id}= Add Openstack Network ${alias} ${name} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 76 | ${arguments}= Create Dictionary network_id=${network_id} cidr=${cidr} subnet_name=${name} |
DR695H | 3bb6cf4 | 2019-06-20 15:04:04 -0400 | [diff] [blame] | 77 | Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER} |
| 78 | ${data}= Apply Template openstack ${OPENSTACK_NEUTRON_SUBNET_ADD_BODY_FILE} ${arguments} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 79 | ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_SUBNET_PATH} data_path= data=${data} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 80 | Should Be Equal As Strings 201 ${resp.status_code} |
| 81 | [Return] ${network_id} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 82 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 83 | Get Openstack Subnet By Name |
| 84 | [Documentation] Retrieve the subnet from openstack by it's name. |
| 85 | [Arguments] ${alias} ${network_name} ${network_cidr} |
| 86 | ${resp}= Get Openstack Subnets ${alias} |
| 87 | @{list}= Get From Dictionary ${resp} subnets |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 88 | ${returnnet}= Set Variable |
DR695H | 910097e | 2019-05-08 13:55:32 -0400 | [diff] [blame] | 89 | :FOR ${net} IN @{list} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 90 | \ ${name}= Get From Dictionary ${net} name |
| 91 | \ ${cidr}= Get From Dictionary ${net} cidr |
| 92 | \ ${returnnet}= Set Variable ${net} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 93 | \ Exit For Loop If '${name}'=='${network_name}' and '${cidr}'=='${network_cidr}' |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 94 | \ ${returnnet}= Create DIctionary |
| 95 | [Return] ${returnnet} |
| 96 | |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 97 | Get Openstack IP By Name |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 98 | [Arguments] ${alias} ${network_name} ${cidr} ${ip} |
| 99 | ${ports}= Get Openstack Ports For Subnet ${alias} ${network_name} ${cidr} |
| 100 | Log ${ports} |
DR695H | 910097e | 2019-05-08 13:55:32 -0400 | [diff] [blame] | 101 | :FOR ${port} IN @{ports} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 102 | \ Return From Keyword If '${port['fixed_ips'][0]['ip_address']}' == '${ip}' ${port} |
| 103 | [Return] None |
| 104 | |
| 105 | Get Openstack Ports For Subnet |
| 106 | [Arguments] ${alias} ${network_name} ${cidr} |
| 107 | ${net}= Get Openstack Subnet By Name ${alias} ${network_name} ${cidr} |
| 108 | ${ports}= Get Openstack Ports ${alias} |
| 109 | ${net_ports}= Create List |
DR695H | 910097e | 2019-05-08 13:55:32 -0400 | [diff] [blame] | 110 | :FOR ${port} IN @{ports['ports']} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 111 | \ Run Keyword If '${net['network_id']}' == '${port['network_id']}' Append To List ${net_ports} ${port} |
| 112 | [Return] ${net_ports} |
jf9860 | 75010a4 | 2017-02-22 16:52:54 -0500 | [diff] [blame] | 113 | |
| 114 | Get Openstack Port By Id |
| 115 | [Arguments] ${alias} ${port_id} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 116 | ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_PORT_PATH}/${port_id} |
jf9860 | 75010a4 | 2017-02-22 16:52:54 -0500 | [diff] [blame] | 117 | [Return] ${resp} |
| 118 | |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 119 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 120 | Delete Openstack Port |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 121 | [Arguments] ${alias} ${port_id} |
| 122 | ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_PORT_PATH} /${port_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 123 | ${status_string}= Convert To String ${resp.status_code} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 124 | Should Match Regexp ${status_string} ^(204|200)$ |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 125 | [Return] ${resp.text} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 126 | |