blob: b1f07f86236087040172338efda796d041b9dc17 [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
DR695H7aca1a42019-06-03 17:08:34 -04005Library ONAPLibrary.JSON
DR695H3bb6cf42019-06-20 15:04:04 -04006Library ONAPLibrary.Templating
DR695Hccff30b2017-02-17 18:44:24 -05007Library OperatingSystem
8Library Collections
9Resource ../global_properties.robot
DR695Hccff30b2017-02-17 18:44:24 -050010Resource openstack_common.robot
11
12*** Variables ***
13${OPENSTACK_NOVA_API_VERSION} /v2
14${OPENSTACK_NOVA_KEYPAIR_PATH} /os-keypairs
DR695H3bb6cf42019-06-20 15:04:04 -040015${OPENSTACK_NOVA_KEYPAIR_ADD_BODY_FILE} openstack/nova_add_keypair.jinja
DR695Hccff30b2017-02-17 18:44:24 -050016${OPENSTACK_NOVA_KEYPAIR_SSH_KEY} robot/assets/keys/robot_ssh_public_key.txt
17${OPENSTACK_NOVA_FLAVORS_PATH} /flavors
18${OPENSTACK_NOVA_SERVERS_PATH} /servers
19${OPENSTACK_NOVA_IMAGES_PATH} /images
20${OPENSTACK_NOVA_SERVERS_REBOOT_BODY} {"reboot" : { "type" : "SOFT" }}
DR695H3bb6cf42019-06-20 15:04:04 -040021${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} openstack/nova_add_server.jinja
DR695Hccff30b2017-02-17 18:44:24 -050022
23
24*** Keywords ***
25Get Openstack Keypair
26 [Documentation] Runs an Openstack Request and returns the keypair info
27 [Arguments] ${alias} ${keypair_name}
jf986099c63292017-03-09 15:28:42 -050028 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} /${keypair_name}
DR695Hccff30b2017-02-17 18:44:24 -050029 [Return] ${resp.json()}
30
31Add Openstack Keypair
32 [Documentation] Runs an Openstack Request to add a keypair and returns the keypair name
33 [Arguments] ${alias} ${name}
DR695Hccff30b2017-02-17 18:44:24 -050034 ${ssh_key}= OperatingSystem.Get File ${OPENSTACK_NOVA_KEYPAIR_SSH_KEY}
35 ${arguments}= Create Dictionary name=${name} publickey=${ssh_key}
DR695H3bb6cf42019-06-20 15:04:04 -040036 Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER}
37 ${data}= Apply Template openstack ${OPENSTACK_NOVA_KEYPAIR_ADD_BODY_FILE} ${arguments}
jf986099c63292017-03-09 15:28:42 -050038 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -050039 Should Be Equal As Strings 200 ${resp.status_code}
40 [Return] ${resp.json()['keypair']['name']}
41
42Delete Openstack Keypair
43 [Documentation] Runs an Openstack Request to delete a keypair
44 [Arguments] ${alias} ${keypair_name}
jf986099c63292017-03-09 15:28:42 -050045 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} /${keypair_name}
DR695Hccff30b2017-02-17 18:44:24 -050046 ${status_string}= Convert To String ${resp.status_code}
jf986099c63292017-03-09 15:28:42 -050047 Should Match Regexp ${status_string} ^(204|202|200)$
DR695Hccff30b2017-02-17 18:44:24 -050048 [Return] ${resp.text}
49
50
51Get Openstack Servers
52 [Documentation] Returns the list of servers as a dictionary by name
53 [Arguments] ${alias}
jf986099c63292017-03-09 15:28:42 -050054 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /detail
DR695Hccff30b2017-02-17 18:44:24 -050055 Log Returned from Internal Get Openstack
56 ${by_name}= Make List Into Dict ${resp.json()['servers']} name
57 Log got it
58 [Return] ${by_name}
jf986099c63292017-03-09 15:28:42 -050059
DR695Hccff30b2017-02-17 18:44:24 -050060Get Openstack Server By Id
61 [Documentation] Returns the openstack stacks info for the given stack name
jf986099c63292017-03-09 15:28:42 -050062 [Arguments] ${alias} ${server_id}
63 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}
DR695Hccff30b2017-02-17 18:44:24 -050064 [Return] ${resp}
jf986099c63292017-03-09 15:28:42 -050065
DR695Hccff30b2017-02-17 18:44:24 -050066Get Openstack Flavors
67 [Documentation] Runs an Openstack Request and returns the flavor list
68 [Arguments] ${alias}
jf986099c63292017-03-09 15:28:42 -050069 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_FLAVORS_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050070 [Return] ${resp.json()}
71
72Get Openstack Images
73 [Documentation] Runs an Openstack Request and returns the flavor list
74 [Arguments] ${alias}
jf986099c63292017-03-09 15:28:42 -050075 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_IMAGES_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050076 [Return] ${resp.json()}
77
78Reboot Server
79 [Documentation] Requests a reboot of the passed server id
jf986099c63292017-03-09 15:28:42 -050080 [Arguments] ${alias} ${server_id}
81 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}/action ${OPENSTACK_NOVA_SERVERS_REBOOT_BODY}
DR695Hccff30b2017-02-17 18:44:24 -050082 [Return] ${resp}
83
84Add Server
85 [Documentation] Adds a server for the passed if
86 [Arguments] ${alias} ${name} ${imageRef} ${flavorRef}
87 ${dict}= Create Dictionary name=${name} imageRef=${imageRef} flavorRef=${flavorRef}
DR695H3bb6cf42019-06-20 15:04:04 -040088 Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER}
89 ${data}= Apply Template openstack ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict}
jf986099c63292017-03-09 15:28:42 -050090 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -050091 [Return] ${resp}
92
93Add Server For Image Name
94 [Documentation] Adds a server for the passed if
Jerry Flood339809a2017-10-30 20:19:16 -040095 [Arguments] ${alias} ${name} ${imageName} ${flavorName} ${public_net_id}
DR695Hccff30b2017-02-17 18:44:24 -050096 ${images}= Get Openstack Images ${alias}
97 ${flavors}= Get Openstack Flavors ${alias}
98 ${images}= Get From Dictionary ${images} images
99 ${flavors}= Get From Dictionary ${flavors} flavors
100 ${imageRef}= Get Id For Name ${images} ${imageName}
101 ${flavorRef}= Get Id For Name ${flavors} ${flavorName}
Jerry Flood339809a2017-10-30 20:19:16 -0400102 ${dict}= Create Dictionary name=${name} imageRef=${imageRef} flavorRef=${flavorRef} public_net_id=${public_net_id}
DR695H3bb6cf42019-06-20 15:04:04 -0400103 Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER}
104 ${data}= Apply Template openstack ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict}
jf986099c63292017-03-09 15:28:42 -0500105 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -0500106 ${status_string}= Convert To String ${resp.status_code}
107 Should Match Regexp ${status_string} ^(202)$
108 [Return] ${resp.json()}
109
110Wait for Server to Be Active
111 [Arguments] ${alias} ${server_id} ${timeout}=300s
jf986099c63292017-03-09 15:28:42 -0500112 ${server_info}= Wait Until Keyword Succeeds ${timeout} 10 sec Get Active Server ${alias} ${server_id}
DR695Hccff30b2017-02-17 18:44:24 -0500113 ${status}= Get From Dictionary ${server_info} status
114 Should Be Equal ${status} ACTIVE
115 [Return] ${server_info}
116
117 Get Active Server
jf986099c63292017-03-09 15:28:42 -0500118 [Arguments] ${alias} ${server_id}
DR695Hccff30b2017-02-17 18:44:24 -0500119 ${resp}= Get Openstack Server By Id ${alias} ${server_id}
120 Should Be Equal As Strings ${resp.status_code} 200
jf986099c63292017-03-09 15:28:42 -0500121 ${server_info}= Set Variable ${resp.json()}
DR695Hccff30b2017-02-17 18:44:24 -0500122 ${server_info}= Get From Dictionary ${server_info} server
123 ${status}= Get From Dictionary ${server_info} status
124 Should Not Be Equal ${status} BUILD
jf986099c63292017-03-09 15:28:42 -0500125 [Return] ${server_info}
DR695Hccff30b2017-02-17 18:44:24 -0500126
127Wait for Server to Be Deleted
128 [Arguments] ${alias} ${server_id}
129 Wait Until Keyword Succeeds 300s 10s Get Deleted Server ${alias} ${server_id}
130
131Get Deleted Server
132 [Arguments] ${alias} ${server_id}
133 ${resp}= Get Openstack Server By Id ${alias} ${server_id}
134 Should Be Equal As Strings ${resp.status_code} 404
135
136Delete Server
137 [Documentation] Runs an Openstack Request to delete a keypair
138 [Arguments] ${alias} ${server_id}
jf986099c63292017-03-09 15:28:42 -0500139 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}
DR695Hccff30b2017-02-17 18:44:24 -0500140 ${status_string}= Convert To String ${resp.status_code}
jf986099c63292017-03-09 15:28:42 -0500141 Should Match Regexp ${status_string} ^(204)$
DR695Hccff30b2017-02-17 18:44:24 -0500142 [Return] ${resp.text}
143
144Get Id For Name
145 [Arguments] ${list} ${name}
DR695H910097e2019-05-08 13:55:32 -0400146 :FOR ${item} IN @{list}
jf986099c63292017-03-09 15:28:42 -0500147 \ ${id}= Get From Dictionary ${item} id
DR695Hccff30b2017-02-17 18:44:24 -0500148 \ ${n}= Get From Dictionary ${item} name
jf986099c63292017-03-09 15:28:42 -0500149 \ Return from Keyword If '${n}' == '${name}' ${id}
150 [Return] None