blob: bdb64b986c58022438aa45f0f1c1850aed5414e5 [file] [log] [blame]
DR695Hccff30b2017-02-17 18:44:24 -05001*** Settings ***
2Documentation The main interface for interacting with Openstack. It handles low level stuff like managing the authtoken and Openstack required fields
3Library OpenstackLibrary
4Library RequestsLibrary
jf986099c63292017-03-09 15:28:42 -05005Library UUID
DR695Hccff30b2017-02-17 18:44:24 -05006Library OperatingSystem
7Library Collections
8Resource ../global_properties.robot
9Resource ../json_templater.robot
10Resource 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 ***
21Get Openstack Network
22 [Documentation] Runs an Openstack Request and returns the network info
23 [Arguments] ${alias} ${network_id}
jf986099c63292017-03-09 15:28:42 -050024 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_NETWORK_PATH} /${network_id}
DR695Hccff30b2017-02-17 18:44:24 -050025 [Return] ${resp.json()}
26
27Get Openstack Networks
28 [Documentation] Runs an Openstack Request and returns the network info
jf986099c63292017-03-09 15:28:42 -050029 [Arguments] ${alias}
30 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_NETWORK_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050031 [Return] ${resp.json()}
32
33Get Openstack Subnets
34 [Documentation] Runs an Openstack Request and returns the network info
jf986099c63292017-03-09 15:28:42 -050035 [Arguments] ${alias}
36 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_SUBNET_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050037 [Return] ${resp.json()}
38
39Get Openstack Ports
40 [Documentation] Runs an Openstack Request and returns the network info
jf986099c63292017-03-09 15:28:42 -050041 [Arguments] ${alias}
42 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_PORT_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050043 [Return] ${resp.json()}
44
45Add 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}
jf986099c63292017-03-09 15:28:42 -050051 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_NETWORK_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -050052 Should Be Equal As Strings 201 ${resp.status_code}
53 [Return] ${resp.json()['network']['id']}
54
55Delete Openstack Network
56 [Documentation] Runs an Openstack Request to delete a network
57 [Arguments] ${alias} ${network_id}
jf986099c63292017-03-09 15:28:42 -050058 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_NETWORK_PATH} /${network_id}
DR695Hccff30b2017-02-17 18:44:24 -050059 ${status_string}= Convert To String ${resp.status_code}
jf986099c63292017-03-09 15:28:42 -050060 Should Match Regexp ${status_string} ^(204|200)$
DR695Hccff30b2017-02-17 18:44:24 -050061 [Return] ${resp.text}
62
63Add 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}
jf986099c63292017-03-09 15:28:42 -050067 ${pass} ${v}= Run Keyword and Ignore Error Dictionary Should Contain Key ${network} id
DR695Hccff30b2017-02-17 18:44:24 -050068 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}
jf986099c63292017-03-09 15:28:42 -050072
DR695Hccff30b2017-02-17 18:44:24 -050073
74Add 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}
jf986099c63292017-03-09 15:28:42 -050081 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_SUBNET_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -050082 Should Be Equal As Strings 201 ${resp.status_code}
83 [Return] ${network_id}
jf986099c63292017-03-09 15:28:42 -050084
DR695Hccff30b2017-02-17 18:44:24 -050085Get 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
jf986099c63292017-03-09 15:28:42 -050090 ${returnnet}= Set Variable
DR695Hccff30b2017-02-17 18:44:24 -050091 :for ${net} in @{list}
92 \ ${name}= Get From Dictionary ${net} name
93 \ ${cidr}= Get From Dictionary ${net} cidr
94 \ ${returnnet}= Set Variable ${net}
jf986099c63292017-03-09 15:28:42 -050095 \ Exit For Loop If '${name}'=='${network_name}' and '${cidr}'=='${network_cidr}'
DR695Hccff30b2017-02-17 18:44:24 -050096 \ ${returnnet}= Create DIctionary
97 [Return] ${returnnet}
98
jf986099c63292017-03-09 15:28:42 -050099Get Openstack IP By Name
DR695Hccff30b2017-02-17 18:44:24 -0500100 [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
107Get 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}
jf986075010a42017-02-22 16:52:54 -0500115
116Get Openstack Port By Id
117 [Arguments] ${alias} ${port_id}
jf986099c63292017-03-09 15:28:42 -0500118 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_PORT_PATH}/${port_id}
jf986075010a42017-02-22 16:52:54 -0500119 [Return] ${resp}
120
jf986099c63292017-03-09 15:28:42 -0500121
DR695Hccff30b2017-02-17 18:44:24 -0500122Delete Openstack Port
jf986099c63292017-03-09 15:28:42 -0500123 [Arguments] ${alias} ${port_id}
124 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_PORT_PATH} /${port_id}
DR695Hccff30b2017-02-17 18:44:24 -0500125 ${status_string}= Convert To String ${resp.status_code}
jf986099c63292017-03-09 15:28:42 -0500126 Should Match Regexp ${status_string} ^(204|200)$
DR695Hccff30b2017-02-17 18:44:24 -0500127 [Return] ${resp.text}
jf986099c63292017-03-09 15:28:42 -0500128