blob: 058809def86f54fe8b3a10e76630efd34618c721 [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
DR695Hd92b0072019-06-17 17:23:14 -04003Library ONAPLibrary.Openstack
DR695Hccff30b2017-02-17 18:44:24 -05004Library RequestsLibrary
DR695Hccff30b2017-02-17 18:44:24 -05005Library Collections
DR695H3bb6cf42019-06-20 15:04:04 -04006Library ONAPLibrary.Templating
DR695Hccff30b2017-02-17 18:44:24 -05007Resource ../global_properties.robot
DR695Hccff30b2017-02-17 18:44:24 -05008Resource openstack_common.robot
9
10*** Variables ***
11${OPENSTACK_NEUTRON_API_VERSION} /v2.0
12${OPENSTACK_NEUTRON_NETWORK_PATH} /networks
DR695H3bb6cf42019-06-20 15:04:04 -040013${OPENSTACK_NEUTRON_NETWORK_ADD_BODY_FILE} openstack/neutron_add_network.jinja
DR695Hccff30b2017-02-17 18:44:24 -050014${OPENSTACK_NEUTRON_SUBNET_PATH} /subnets
DR695H3bb6cf42019-06-20 15:04:04 -040015${OPENSTACK_NEUTRON_SUBNET_ADD_BODY_FILE} openstack/neutron_add_subnet.jinja
DR695Hccff30b2017-02-17 18:44:24 -050016${OPENSTACK_NEUTRON_PORT_PATH} /ports
17
18*** Keywords ***
19Get Openstack Network
20 [Documentation] Runs an Openstack Request and returns the network info
21 [Arguments] ${alias} ${network_id}
jf986099c63292017-03-09 15:28:42 -050022 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_NETWORK_PATH} /${network_id}
DR695Hccff30b2017-02-17 18:44:24 -050023 [Return] ${resp.json()}
24
25Get Openstack Networks
26 [Documentation] Runs an Openstack Request and returns the network info
jf986099c63292017-03-09 15:28:42 -050027 [Arguments] ${alias}
28 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_NETWORK_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050029 [Return] ${resp.json()}
30
31Get Openstack Subnets
32 [Documentation] Runs an Openstack Request and returns the network info
jf986099c63292017-03-09 15:28:42 -050033 [Arguments] ${alias}
34 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_SUBNET_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050035 [Return] ${resp.json()}
36
37Get Openstack Ports
38 [Documentation] Runs an Openstack Request and returns the network info
jf986099c63292017-03-09 15:28:42 -050039 [Arguments] ${alias}
40 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_PORT_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050041 [Return] ${resp.json()}
42
43Add 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}
DR695Hccff30b2017-02-17 18:44:24 -050046 ${arguments}= Create Dictionary name=${name}
DR695H3bb6cf42019-06-20 15:04:04 -040047 Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER}
48 ${data}= Apply Template openstack ${OPENSTACK_NEUTRON_NETWORK_ADD_BODY_FILE} ${arguments}
jf986099c63292017-03-09 15:28:42 -050049 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_NETWORK_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -050050 Should Be Equal As Strings 201 ${resp.status_code}
51 [Return] ${resp.json()['network']['id']}
52
53Delete Openstack Network
54 [Documentation] Runs an Openstack Request to delete a network
55 [Arguments] ${alias} ${network_id}
jf986099c63292017-03-09 15:28:42 -050056 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_NETWORK_PATH} /${network_id}
DR695Hccff30b2017-02-17 18:44:24 -050057 ${status_string}= Convert To String ${resp.status_code}
jf986099c63292017-03-09 15:28:42 -050058 Should Match Regexp ${status_string} ^(204|200)$
DR695Hccff30b2017-02-17 18:44:24 -050059 [Return] ${resp.text}
60
61Add 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}
jf986099c63292017-03-09 15:28:42 -050065 ${pass} ${v}= Run Keyword and Ignore Error Dictionary Should Contain Key ${network} id
DR695Hccff30b2017-02-17 18:44:24 -050066 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}
jf986099c63292017-03-09 15:28:42 -050070
DR695Hccff30b2017-02-17 18:44:24 -050071
72Add 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}
DR695Hccff30b2017-02-17 18:44:24 -050076 ${arguments}= Create Dictionary network_id=${network_id} cidr=${cidr} subnet_name=${name}
DR695H3bb6cf42019-06-20 15:04:04 -040077 Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER}
78 ${data}= Apply Template openstack ${OPENSTACK_NEUTRON_SUBNET_ADD_BODY_FILE} ${arguments}
jf986099c63292017-03-09 15:28:42 -050079 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_SUBNET_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -050080 Should Be Equal As Strings 201 ${resp.status_code}
81 [Return] ${network_id}
jf986099c63292017-03-09 15:28:42 -050082
DR695Hccff30b2017-02-17 18:44:24 -050083Get 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
jf986099c63292017-03-09 15:28:42 -050088 ${returnnet}= Set Variable
DR695H910097e2019-05-08 13:55:32 -040089 :FOR ${net} IN @{list}
DR695Hccff30b2017-02-17 18:44:24 -050090 \ ${name}= Get From Dictionary ${net} name
91 \ ${cidr}= Get From Dictionary ${net} cidr
92 \ ${returnnet}= Set Variable ${net}
jf986099c63292017-03-09 15:28:42 -050093 \ Exit For Loop If '${name}'=='${network_name}' and '${cidr}'=='${network_cidr}'
DR695Hccff30b2017-02-17 18:44:24 -050094 \ ${returnnet}= Create DIctionary
95 [Return] ${returnnet}
96
jf986099c63292017-03-09 15:28:42 -050097Get Openstack IP By Name
DR695Hccff30b2017-02-17 18:44:24 -050098 [Arguments] ${alias} ${network_name} ${cidr} ${ip}
99 ${ports}= Get Openstack Ports For Subnet ${alias} ${network_name} ${cidr}
100 Log ${ports}
DR695H910097e2019-05-08 13:55:32 -0400101 :FOR ${port} IN @{ports}
DR695Hccff30b2017-02-17 18:44:24 -0500102 \ Return From Keyword If '${port['fixed_ips'][0]['ip_address']}' == '${ip}' ${port}
103 [Return] None
104
105Get 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
DR695H910097e2019-05-08 13:55:32 -0400110 :FOR ${port} IN @{ports['ports']}
DR695Hccff30b2017-02-17 18:44:24 -0500111 \ Run Keyword If '${net['network_id']}' == '${port['network_id']}' Append To List ${net_ports} ${port}
112 [Return] ${net_ports}
jf986075010a42017-02-22 16:52:54 -0500113
114Get Openstack Port By Id
115 [Arguments] ${alias} ${port_id}
jf986099c63292017-03-09 15:28:42 -0500116 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_PORT_PATH}/${port_id}
jf986075010a42017-02-22 16:52:54 -0500117 [Return] ${resp}
118
jf986099c63292017-03-09 15:28:42 -0500119
DR695Hccff30b2017-02-17 18:44:24 -0500120Delete Openstack Port
jf986099c63292017-03-09 15:28:42 -0500121 [Arguments] ${alias} ${port_id}
122 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NEUTRON_SERVICE_TYPE} ${OPENSTACK_NEUTRON_PORT_PATH} /${port_id}
DR695Hccff30b2017-02-17 18:44:24 -0500123 ${status_string}= Convert To String ${resp.status_code}
jf986099c63292017-03-09 15:28:42 -0500124 Should Match Regexp ${status_string} ^(204|200)$
DR695Hccff30b2017-02-17 18:44:24 -0500125 [Return] ${resp.text}
jf986099c63292017-03-09 15:28:42 -0500126