blob: 94a07479ce9a4aeb7c7229c0d7f7037858acf4b9 [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
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_NOVA_API_VERSION} /v2
14${OPENSTACK_NOVA_KEYPAIR_PATH} /os-keypairs
15${OPENSTACK_NOVA_KEYPAIR_ADD_BODY_FILE} robot/assets/templates/nova_add_keypair.template
16${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" }}
21${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} robot/assets/templates/nova_add_server.template
22
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}
DR695Hdaec16c2019-06-19 17:40:26 -040036 ${data}= Fill JSON Template File ${OPENSTACK_NOVA_KEYPAIR_ADD_BODY_FILE} ${arguments}
jf986099c63292017-03-09 15:28:42 -050037 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -050038 Should Be Equal As Strings 200 ${resp.status_code}
39 [Return] ${resp.json()['keypair']['name']}
40
41Delete Openstack Keypair
42 [Documentation] Runs an Openstack Request to delete a keypair
43 [Arguments] ${alias} ${keypair_name}
jf986099c63292017-03-09 15:28:42 -050044 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} /${keypair_name}
DR695Hccff30b2017-02-17 18:44:24 -050045 ${status_string}= Convert To String ${resp.status_code}
jf986099c63292017-03-09 15:28:42 -050046 Should Match Regexp ${status_string} ^(204|202|200)$
DR695Hccff30b2017-02-17 18:44:24 -050047 [Return] ${resp.text}
48
49
50Get Openstack Servers
51 [Documentation] Returns the list of servers as a dictionary by name
52 [Arguments] ${alias}
jf986099c63292017-03-09 15:28:42 -050053 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /detail
DR695Hccff30b2017-02-17 18:44:24 -050054 Log Returned from Internal Get Openstack
55 ${by_name}= Make List Into Dict ${resp.json()['servers']} name
56 Log got it
57 [Return] ${by_name}
jf986099c63292017-03-09 15:28:42 -050058
DR695Hccff30b2017-02-17 18:44:24 -050059Get Openstack Server By Id
60 [Documentation] Returns the openstack stacks info for the given stack name
jf986099c63292017-03-09 15:28:42 -050061 [Arguments] ${alias} ${server_id}
62 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}
DR695Hccff30b2017-02-17 18:44:24 -050063 [Return] ${resp}
jf986099c63292017-03-09 15:28:42 -050064
DR695Hccff30b2017-02-17 18:44:24 -050065Get Openstack Flavors
66 [Documentation] Runs an Openstack Request and returns the flavor list
67 [Arguments] ${alias}
jf986099c63292017-03-09 15:28:42 -050068 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_FLAVORS_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050069 [Return] ${resp.json()}
70
71Get Openstack Images
72 [Documentation] Runs an Openstack Request and returns the flavor list
73 [Arguments] ${alias}
jf986099c63292017-03-09 15:28:42 -050074 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_IMAGES_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050075 [Return] ${resp.json()}
76
77Reboot Server
78 [Documentation] Requests a reboot of the passed server id
jf986099c63292017-03-09 15:28:42 -050079 [Arguments] ${alias} ${server_id}
80 ${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 -050081 [Return] ${resp}
82
83Add Server
84 [Documentation] Adds a server for the passed if
85 [Arguments] ${alias} ${name} ${imageRef} ${flavorRef}
86 ${dict}= Create Dictionary name=${name} imageRef=${imageRef} flavorRef=${flavorRef}
jf986099c63292017-03-09 15:28:42 -050087 ${data}= Fill JSON Template File ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict}
88 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -050089 [Return] ${resp}
90
91Add Server For Image Name
92 [Documentation] Adds a server for the passed if
Jerry Flood339809a2017-10-30 20:19:16 -040093 [Arguments] ${alias} ${name} ${imageName} ${flavorName} ${public_net_id}
DR695Hccff30b2017-02-17 18:44:24 -050094 ${images}= Get Openstack Images ${alias}
95 ${flavors}= Get Openstack Flavors ${alias}
96 ${images}= Get From Dictionary ${images} images
97 ${flavors}= Get From Dictionary ${flavors} flavors
98 ${imageRef}= Get Id For Name ${images} ${imageName}
99 ${flavorRef}= Get Id For Name ${flavors} ${flavorName}
Jerry Flood339809a2017-10-30 20:19:16 -0400100 ${dict}= Create Dictionary name=${name} imageRef=${imageRef} flavorRef=${flavorRef} public_net_id=${public_net_id}
jf986099c63292017-03-09 15:28:42 -0500101 ${data}= Fill JSON Template File ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict}
102 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -0500103 ${status_string}= Convert To String ${resp.status_code}
104 Should Match Regexp ${status_string} ^(202)$
105 [Return] ${resp.json()}
106
107Wait for Server to Be Active
108 [Arguments] ${alias} ${server_id} ${timeout}=300s
jf986099c63292017-03-09 15:28:42 -0500109 ${server_info}= Wait Until Keyword Succeeds ${timeout} 10 sec Get Active Server ${alias} ${server_id}
DR695Hccff30b2017-02-17 18:44:24 -0500110 ${status}= Get From Dictionary ${server_info} status
111 Should Be Equal ${status} ACTIVE
112 [Return] ${server_info}
113
114 Get Active Server
jf986099c63292017-03-09 15:28:42 -0500115 [Arguments] ${alias} ${server_id}
DR695Hccff30b2017-02-17 18:44:24 -0500116 ${resp}= Get Openstack Server By Id ${alias} ${server_id}
117 Should Be Equal As Strings ${resp.status_code} 200
jf986099c63292017-03-09 15:28:42 -0500118 ${server_info}= Set Variable ${resp.json()}
DR695Hccff30b2017-02-17 18:44:24 -0500119 ${server_info}= Get From Dictionary ${server_info} server
120 ${status}= Get From Dictionary ${server_info} status
121 Should Not Be Equal ${status} BUILD
jf986099c63292017-03-09 15:28:42 -0500122 [Return] ${server_info}
DR695Hccff30b2017-02-17 18:44:24 -0500123
124Wait for Server to Be Deleted
125 [Arguments] ${alias} ${server_id}
126 Wait Until Keyword Succeeds 300s 10s Get Deleted Server ${alias} ${server_id}
127
128Get Deleted Server
129 [Arguments] ${alias} ${server_id}
130 ${resp}= Get Openstack Server By Id ${alias} ${server_id}
131 Should Be Equal As Strings ${resp.status_code} 404
132
133Delete Server
134 [Documentation] Runs an Openstack Request to delete a keypair
135 [Arguments] ${alias} ${server_id}
jf986099c63292017-03-09 15:28:42 -0500136 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}
DR695Hccff30b2017-02-17 18:44:24 -0500137 ${status_string}= Convert To String ${resp.status_code}
jf986099c63292017-03-09 15:28:42 -0500138 Should Match Regexp ${status_string} ^(204)$
DR695Hccff30b2017-02-17 18:44:24 -0500139 [Return] ${resp.text}
140
141Get Id For Name
142 [Arguments] ${list} ${name}
DR695H910097e2019-05-08 13:55:32 -0400143 :FOR ${item} IN @{list}
jf986099c63292017-03-09 15:28:42 -0500144 \ ${id}= Get From Dictionary ${item} id
DR695Hccff30b2017-02-17 18:44:24 -0500145 \ ${n}= Get From Dictionary ${item} name
jf986099c63292017-03-09 15:28:42 -0500146 \ Return from Keyword If '${n}' == '${name}' ${id}
147 [Return] None