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