blob: 2c9ec4c5e3b62bc919041a29db8eed28c17cea2d [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 JSONUtils
jf986099c63292017-03-09 15:28:42 -05006Library UUID
DR695Hccff30b2017-02-17 18:44:24 -05007Library OperatingSystem
8Library Collections
9Resource ../global_properties.robot
10Resource ../json_templater.robot
11Resource openstack_common.robot
12
13*** Variables ***
14${OPENSTACK_NOVA_API_VERSION} /v2
15${OPENSTACK_NOVA_KEYPAIR_PATH} /os-keypairs
16${OPENSTACK_NOVA_KEYPAIR_ADD_BODY_FILE} robot/assets/templates/nova_add_keypair.template
17${OPENSTACK_NOVA_KEYPAIR_SSH_KEY} robot/assets/keys/robot_ssh_public_key.txt
18${OPENSTACK_NOVA_FLAVORS_PATH} /flavors
19${OPENSTACK_NOVA_SERVERS_PATH} /servers
20${OPENSTACK_NOVA_IMAGES_PATH} /images
21${OPENSTACK_NOVA_SERVERS_REBOOT_BODY} {"reboot" : { "type" : "SOFT" }}
22${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} robot/assets/templates/nova_add_server.template
23
24
25*** Keywords ***
26Get Openstack Keypair
27 [Documentation] Runs an Openstack Request and returns the keypair info
28 [Arguments] ${alias} ${keypair_name}
jf986099c63292017-03-09 15:28:42 -050029 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} /${keypair_name}
DR695Hccff30b2017-02-17 18:44:24 -050030 [Return] ${resp.json()}
31
32Add Openstack Keypair
33 [Documentation] Runs an Openstack Request to add a keypair and returns the keypair name
34 [Arguments] ${alias} ${name}
35 ${data_template}= OperatingSystem.Get File ${OPENSTACK_NOVA_KEYPAIR_ADD_BODY_FILE}
36 ${ssh_key}= OperatingSystem.Get File ${OPENSTACK_NOVA_KEYPAIR_SSH_KEY}
37 ${arguments}= Create Dictionary name=${name} publickey=${ssh_key}
38 ${data}= Fill JSON Template ${data_template} ${arguments}
jf986099c63292017-03-09 15:28:42 -050039 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -050040 Should Be Equal As Strings 200 ${resp.status_code}
41 [Return] ${resp.json()['keypair']['name']}
42
43Delete Openstack Keypair
44 [Documentation] Runs an Openstack Request to delete a keypair
45 [Arguments] ${alias} ${keypair_name}
jf986099c63292017-03-09 15:28:42 -050046 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} /${keypair_name}
DR695Hccff30b2017-02-17 18:44:24 -050047 ${status_string}= Convert To String ${resp.status_code}
jf986099c63292017-03-09 15:28:42 -050048 Should Match Regexp ${status_string} ^(204|202|200)$
DR695Hccff30b2017-02-17 18:44:24 -050049 [Return] ${resp.text}
50
51
52Get Openstack Servers
53 [Documentation] Returns the list of servers as a dictionary by name
54 [Arguments] ${alias}
jf986099c63292017-03-09 15:28:42 -050055 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /detail
DR695Hccff30b2017-02-17 18:44:24 -050056 Log Returned from Internal Get Openstack
57 ${by_name}= Make List Into Dict ${resp.json()['servers']} name
58 Log got it
59 [Return] ${by_name}
jf986099c63292017-03-09 15:28:42 -050060
DR695Hccff30b2017-02-17 18:44:24 -050061Get Openstack Server By Id
62 [Documentation] Returns the openstack stacks info for the given stack name
jf986099c63292017-03-09 15:28:42 -050063 [Arguments] ${alias} ${server_id}
64 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}
DR695Hccff30b2017-02-17 18:44:24 -050065 [Return] ${resp}
jf986099c63292017-03-09 15:28:42 -050066
DR695Hccff30b2017-02-17 18:44:24 -050067Get Openstack Flavors
68 [Documentation] Runs an Openstack Request and returns the flavor list
69 [Arguments] ${alias}
jf986099c63292017-03-09 15:28:42 -050070 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_FLAVORS_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050071 [Return] ${resp.json()}
72
73Get Openstack Images
74 [Documentation] Runs an Openstack Request and returns the flavor list
75 [Arguments] ${alias}
jf986099c63292017-03-09 15:28:42 -050076 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_IMAGES_PATH}
DR695Hccff30b2017-02-17 18:44:24 -050077 [Return] ${resp.json()}
78
79Reboot Server
80 [Documentation] Requests a reboot of the passed server id
jf986099c63292017-03-09 15:28:42 -050081 [Arguments] ${alias} ${server_id}
82 ${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 -050083 [Return] ${resp}
84
85Add Server
86 [Documentation] Adds a server for the passed if
87 [Arguments] ${alias} ${name} ${imageRef} ${flavorRef}
88 ${dict}= Create Dictionary name=${name} imageRef=${imageRef} flavorRef=${flavorRef}
jf986099c63292017-03-09 15:28:42 -050089 ${data}= Fill JSON Template File ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict}
90 ${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}
jf986099c63292017-03-09 15:28:42 -0500103 ${data}= Fill JSON Template File ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict}
104 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data}
DR695Hccff30b2017-02-17 18:44:24 -0500105 ${status_string}= Convert To String ${resp.status_code}
106 Should Match Regexp ${status_string} ^(202)$
107 [Return] ${resp.json()}
108
109Wait for Server to Be Active
110 [Arguments] ${alias} ${server_id} ${timeout}=300s
jf986099c63292017-03-09 15:28:42 -0500111 ${server_info}= Wait Until Keyword Succeeds ${timeout} 10 sec Get Active Server ${alias} ${server_id}
DR695Hccff30b2017-02-17 18:44:24 -0500112 ${status}= Get From Dictionary ${server_info} status
113 Should Be Equal ${status} ACTIVE
114 [Return] ${server_info}
115
116 Get Active Server
jf986099c63292017-03-09 15:28:42 -0500117 [Arguments] ${alias} ${server_id}
DR695Hccff30b2017-02-17 18:44:24 -0500118 ${resp}= Get Openstack Server By Id ${alias} ${server_id}
119 Should Be Equal As Strings ${resp.status_code} 200
jf986099c63292017-03-09 15:28:42 -0500120 ${server_info}= Set Variable ${resp.json()}
DR695Hccff30b2017-02-17 18:44:24 -0500121 ${server_info}= Get From Dictionary ${server_info} server
122 ${status}= Get From Dictionary ${server_info} status
123 Should Not Be Equal ${status} BUILD
jf986099c63292017-03-09 15:28:42 -0500124 [Return] ${server_info}
DR695Hccff30b2017-02-17 18:44:24 -0500125
126Wait for Server to Be Deleted
127 [Arguments] ${alias} ${server_id}
128 Wait Until Keyword Succeeds 300s 10s Get Deleted Server ${alias} ${server_id}
129
130Get Deleted Server
131 [Arguments] ${alias} ${server_id}
132 ${resp}= Get Openstack Server By Id ${alias} ${server_id}
133 Should Be Equal As Strings ${resp.status_code} 404
134
135Delete Server
136 [Documentation] Runs an Openstack Request to delete a keypair
137 [Arguments] ${alias} ${server_id}
jf986099c63292017-03-09 15:28:42 -0500138 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}
DR695Hccff30b2017-02-17 18:44:24 -0500139 ${status_string}= Convert To String ${resp.status_code}
jf986099c63292017-03-09 15:28:42 -0500140 Should Match Regexp ${status_string} ^(204)$
DR695Hccff30b2017-02-17 18:44:24 -0500141 [Return] ${resp.text}
142
143Get Id For Name
144 [Arguments] ${list} ${name}
145 :for ${item} in @{list}
jf986099c63292017-03-09 15:28:42 -0500146 \ ${id}= Get From Dictionary ${item} id
DR695Hccff30b2017-02-17 18:44:24 -0500147 \ ${n}= Get From Dictionary ${item} name
jf986099c63292017-03-09 15:28:42 -0500148 \ Return from Keyword If '${n}' == '${name}' ${id}
149 [Return] None