DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation The main interface for interacting with Openstack. It handles low level stuff like managing the authtoken and Openstack required fields |
| 3 | Library OpenstackLibrary |
| 4 | Library RequestsLibrary |
| 5 | Library UUID |
| 6 | Library OperatingSystem |
| 7 | Resource ../global_properties.robot |
| 8 | Resource ../json_templater.robot |
| 9 | Resource openstack_common.robot |
| 10 | |
| 11 | |
| 12 | *** Variables *** |
| 13 | ${OPENSTACK_CINDER_API_VERSION} /v1 |
| 14 | ${OPENSTACK_CINDER_TYPES_PATH} /types |
| 15 | ${OPENSTACK_CINDER_VOLUMES_PATH} /volumes |
| 16 | ${OPENSTACK_CINDER_VOLUMES_ADD_BODY_FILE} robot/assets/templates/cinder_add_volume.template |
| 17 | ${OPENSTACK_CINDER_VOLUMES_TYPE} SSD |
| 18 | ${OPENSTACK_CINDER_AVAILABILITY_ZONE} nova |
| 19 | |
| 20 | *** Keywords *** |
| 21 | Get Openstack Volume Types |
| 22 | [Documentation] Returns the openstack volume types information |
| 23 | [Arguments] ${alias} |
| 24 | ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_CINDER_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_CINDER_TYPES_PATH} |
| 25 | [Return] ${resp.json()} |
| 26 | |
| 27 | Get Openstack Volume |
| 28 | [Documentation] Returns the openstack volume information for the passed in volume id |
| 29 | [Arguments] ${alias} ${volume_id} |
| 30 | ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_CINDER_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_CINDER_VOLUMES_PATH} /${volume_id} |
| 31 | [Return] ${resp.json()} |
| 32 | |
| 33 | Add Openstack Volume |
| 34 | [Documentation] Runs an Openstack Request to add a volume and returns that volume id of the created volume |
| 35 | [Arguments] ${alias} ${name} ${size} |
| 36 | ${data_template}= OperatingSystem.Get File ${OPENSTACK_CINDER_VOLUMES_ADD_BODY_FILE} |
| 37 | ${uuid}= Generate UUID |
| 38 | ${arguments}= Create Dictionary name=${name} description=${GLOBAL_APPLICATION_ID}${uuid} size=${size} type=${OPENSTACK_CINDER_VOLUMES_TYPE} availability_zone=${OPENSTACK_CINDER_AVAILABILITY_ZONE} |
| 39 | ${data}= Fill JSON Template ${data_template} ${arguments} |
| 40 | ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_CINDER_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_CINDER_VOLUMES_PATH} data_path= data=${data} |
| 41 | Should Be Equal As Strings 200 ${resp.status_code} |
| 42 | [Return] ${resp.json()['volume']['id']} |
| 43 | |
| 44 | Delete Openstack Volume |
| 45 | [Documentation] Runs an Openstack Request to delete a volume |
| 46 | [Arguments] ${alias} ${volume_id} |
| 47 | ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_CINDER_SERVICE_TYPE} ${GLOBAL_OPENSTACK_SERVICE_REGION} ${OPENSTACK_CINDER_VOLUMES_PATH} /${volume_id} |
| 48 | ${status_string}= Convert To String ${resp.status_code} |
| 49 | Should Match Regexp ${status_string} ^(204|200|404)$ |
| 50 | [Return] ${resp.text} |