blob: e216a2f9566e8e51d2f522642f8f0b33fd0af523 [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
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}
34 ${data_template}= OperatingSystem.Get File ${OPENSTACK_NOVA_KEYPAIR_ADD_BODY_FILE}
35 ${ssh_key}= OperatingSystem.Get File ${OPENSTACK_NOVA_KEYPAIR_SSH_KEY}
36 ${arguments}= Create Dictionary name=${name} publickey=${ssh_key}
37 ${data}= Fill JSON Template ${data_template} ${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}
jf986099c63292017-03-09 15:28:42 -050088 ${data}= Fill JSON Template File ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict}
89 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -050090 [Return] ${resp}
91
92Add Server For Image Name
93 [Documentation] Adds a server for the passed if
Jerry Flood339809a2017-10-30 20:19:16 -040094 [Arguments] ${alias} ${name} ${imageName} ${flavorName} ${public_net_id}
DR695Hccff30b2017-02-17 18:44:24 -050095 ${images}= Get Openstack Images ${alias}
96 ${flavors}= Get Openstack Flavors ${alias}
97 ${images}= Get From Dictionary ${images} images
98 ${flavors}= Get From Dictionary ${flavors} flavors
99 ${imageRef}= Get Id For Name ${images} ${imageName}
100 ${flavorRef}= Get Id For Name ${flavors} ${flavorName}
Jerry Flood339809a2017-10-30 20:19:16 -0400101 ${dict}= Create Dictionary name=${name} imageRef=${imageRef} flavorRef=${flavorRef} public_net_id=${public_net_id}
jf986099c63292017-03-09 15:28:42 -0500102 ${data}= Fill JSON Template File ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict}
103 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -0500104 ${status_string}= Convert To String ${resp.status_code}
105 Should Match Regexp ${status_string} ^(202)$
106 [Return] ${resp.json()}
107
108Wait for Server to Be Active
109 [Arguments] ${alias} ${server_id} ${timeout}=300s
jf986099c63292017-03-09 15:28:42 -0500110 ${server_info}= Wait Until Keyword Succeeds ${timeout} 10 sec Get Active Server ${alias} ${server_id}
DR695Hccff30b2017-02-17 18:44:24 -0500111 ${status}= Get From Dictionary ${server_info} status
112 Should Be Equal ${status} ACTIVE
113 [Return] ${server_info}
114
115 Get Active Server
jf986099c63292017-03-09 15:28:42 -0500116 [Arguments] ${alias} ${server_id}
DR695Hccff30b2017-02-17 18:44:24 -0500117 ${resp}= Get Openstack Server By Id ${alias} ${server_id}
118 Should Be Equal As Strings ${resp.status_code} 200
jf986099c63292017-03-09 15:28:42 -0500119 ${server_info}= Set Variable ${resp.json()}
DR695Hccff30b2017-02-17 18:44:24 -0500120 ${server_info}= Get From Dictionary ${server_info} server
121 ${status}= Get From Dictionary ${server_info} status
122 Should Not Be Equal ${status} BUILD
jf986099c63292017-03-09 15:28:42 -0500123 [Return] ${server_info}
DR695Hccff30b2017-02-17 18:44:24 -0500124
125Wait for Server to Be Deleted
126 [Arguments] ${alias} ${server_id}
127 Wait Until Keyword Succeeds 300s 10s Get Deleted Server ${alias} ${server_id}
128
129Get Deleted Server
130 [Arguments] ${alias} ${server_id}
131 ${resp}= Get Openstack Server By Id ${alias} ${server_id}
132 Should Be Equal As Strings ${resp.status_code} 404
133
134Delete Server
135 [Documentation] Runs an Openstack Request to delete a keypair
136 [Arguments] ${alias} ${server_id}
jf986099c63292017-03-09 15:28:42 -0500137 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}
DR695Hccff30b2017-02-17 18:44:24 -0500138 ${status_string}= Convert To String ${resp.status_code}
jf986099c63292017-03-09 15:28:42 -0500139 Should Match Regexp ${status_string} ^(204)$
DR695Hccff30b2017-02-17 18:44:24 -0500140 [Return] ${resp.text}
141
142Get Id For Name
143 [Arguments] ${list} ${name}
DR695H910097e2019-05-08 13:55:32 -0400144 :FOR ${item} IN @{list}
jf986099c63292017-03-09 15:28:42 -0500145 \ ${id}= Get From Dictionary ${item} id
DR695Hccff30b2017-02-17 18:44:24 -0500146 \ ${n}= Get From Dictionary ${item} name
jf986099c63292017-03-09 15:28:42 -0500147 \ Return from Keyword If '${n}' == '${name}' ${id}
148 [Return] None