blob: 77635cdd2e7d37900e41eacd05ab252285adf612 [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
5Library UUID
6Library 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}
24 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NEUTRON_NETWORK_PATH} /${network_id}
25 [Return] ${resp.json()}
26
27Get Openstack Networks
28 [Documentation] Runs an Openstack Request and returns the network info
29 [Arguments] ${alias}
30 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NEUTRON_NETWORK_PATH}
31 [Return] ${resp.json()}
32
33Get Openstack Subnets
34 [Documentation] Runs an Openstack Request and returns the network info
35 [Arguments] ${alias}
36 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NEUTRON_SUBNET_PATH}
37 [Return] ${resp.json()}
38
39Get Openstack Ports
40 [Documentation] Runs an Openstack Request and returns the network info
41 [Arguments] ${alias}
42 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NEUTRON_PORT_PATH}
43 [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}
51 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NEUTRON_NETWORK_PATH} data_path= data=${data}
52 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}
58 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NEUTRON_NETWORK_PATH} /${network_id}
59 ${status_string}= Convert To String ${resp.status_code}
60 Should Match Regexp ${status_string} ^(204|200)$
61 [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}
67 ${pass} ${v}= Run Keyword and Ignore Error Dictionary Should Contain Key ${network} id
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}
72
73
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}
81 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NEUTRON_SUBNET_PATH} data_path= data=${data}
82 Should Be Equal As Strings 201 ${resp.status_code}
83 [Return] ${network_id}
84
85Get 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
90 ${returnnet}= Set Variable
91 :for ${net} in @{list}
92 \ ${name}= Get From Dictionary ${net} name
93 \ ${cidr}= Get From Dictionary ${net} cidr
94 \ ${returnnet}= Set Variable ${net}
95 \ Exit For Loop If '${name}'=='${network_name}' and '${cidr}'=='${network_cidr}'
96 \ ${returnnet}= Create DIctionary
97 [Return] ${returnnet}
98
99Get Openstack IP By Name
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
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}
115
116Delete Openstack Port
117 [Arguments] ${alias} ${port_id}
118 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NEUTRON_PORT_PATH} /${port_id}
119 ${status_string}= Convert To String ${resp.status_code}
120 Should Match Regexp ${status_string} ^(204|200)$
121 [Return] ${resp.text}
122
123