blob: efee279a5b71fa088e8073adb11c79ca4538a459 [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
6Library UUID
7Library 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}
29 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NOVA_KEYPAIR_PATH} /${keypair_name}
30 [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}
39 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NOVA_KEYPAIR_PATH} data_path= data=${data}
40 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}
46 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NOVA_KEYPAIR_PATH} /${keypair_name}
47 ${status_string}= Convert To String ${resp.status_code}
48 Should Match Regexp ${status_string} ^(204|202|200)$
49 [Return] ${resp.text}
50
51
52Get Openstack Servers
53 [Documentation] Returns the list of servers as a dictionary by name
54 [Arguments] ${alias}
55 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NOVA_SERVERS_PATH} /detail
56 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}
60
61Get Openstack Server By Id
62 [Documentation] Returns the openstack stacks info for the given stack name
63 [Arguments] ${alias} ${server_id}
64 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}
65 [Return] ${resp}
66
67Get Openstack Flavors
68 [Documentation] Runs an Openstack Request and returns the flavor list
69 [Arguments] ${alias}
70 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NOVA_FLAVORS_PATH}
71 [Return] ${resp.json()}
72
73Get Openstack Images
74 [Documentation] Runs an Openstack Request and returns the flavor list
75 [Arguments] ${alias}
76 ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NOVA_IMAGES_PATH}
77 [Return] ${resp.json()}
78
79Reboot Server
80 [Documentation] Requests a reboot of the passed server id
81 [Arguments] ${alias} ${server_id}
82 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}/action ${OPENSTACK_NOVA_SERVERS_REBOOT_BODY}
83 [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}
89 ${data}= Fill JSON Template File ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict}
90 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data}
91 [Return] ${resp}
92
93Add Server For Image Name
94 [Documentation] Adds a server for the passed if
95 [Arguments] ${alias} ${name} ${imageName} ${flavorName}
96 ${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}
102 ${dict}= Create Dictionary name=${name} imageRef=${imageRef} flavorRef=${flavorRef}
103 ${data}= Fill JSON Template File ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict}
104 ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data}
105 ${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
111 ${server_info}= Wait Until Keyword Succeeds ${timeout} 10 sec Get Active Server ${alias} ${server_id}
112 ${status}= Get From Dictionary ${server_info} status
113 Should Be Equal ${status} ACTIVE
114 [Return] ${server_info}
115
116 Get Active Server
117 [Arguments] ${alias} ${server_id}
118 ${resp}= Get Openstack Server By Id ${alias} ${server_id}
119 Should Be Equal As Strings ${resp.status_code} 200
120 ${server_info}= Set Variable ${resp.json()}
121 ${server_info}= Get From Dictionary ${server_info} server
122 ${status}= Get From Dictionary ${server_info} status
123 Should Not Be Equal ${status} BUILD
124 [Return] ${server_info}
125
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}
138 ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}
139 ${status_string}= Convert To String ${resp.status_code}
140 Should Match Regexp ${status_string} ^(204)$
141 [Return] ${resp.text}
142
143Get Id For Name
144 [Arguments] ${list} ${name}
145 :for ${item} in @{list}
146 \ ${id}= Get From Dictionary ${item} id
147 \ ${n}= Get From Dictionary ${item} name
148 \ Return from Keyword If '${n}' == '${name}' ${id}
149 [Return] None