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 |
DR695H | d92b007 | 2019-06-17 17:23:14 -0400 | [diff] [blame] | 3 | Library ONAPLibrary.Openstack |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 4 | Library RequestsLibrary |
DR695H | 7aca1a4 | 2019-06-03 17:08:34 -0400 | [diff] [blame] | 5 | Library ONAPLibrary.JSON |
DR695H | 3bb6cf4 | 2019-06-20 15:04:04 -0400 | [diff] [blame] | 6 | Library ONAPLibrary.Templating |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 7 | Library OperatingSystem |
| 8 | Library Collections |
| 9 | Resource ../global_properties.robot |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 10 | Resource openstack_common.robot |
| 11 | |
| 12 | *** Variables *** |
| 13 | ${OPENSTACK_NOVA_API_VERSION} /v2 |
| 14 | ${OPENSTACK_NOVA_KEYPAIR_PATH} /os-keypairs |
DR695H | 3bb6cf4 | 2019-06-20 15:04:04 -0400 | [diff] [blame] | 15 | ${OPENSTACK_NOVA_KEYPAIR_ADD_BODY_FILE} openstack/nova_add_keypair.jinja |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 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" }} |
DR695H | 3bb6cf4 | 2019-06-20 15:04:04 -0400 | [diff] [blame] | 21 | ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} openstack/nova_add_server.jinja |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 22 | |
| 23 | |
| 24 | *** Keywords *** |
| 25 | Get Openstack Keypair |
| 26 | [Documentation] Runs an Openstack Request and returns the keypair info |
| 27 | [Arguments] ${alias} ${keypair_name} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 28 | ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} /${keypair_name} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 29 | [Return] ${resp.json()} |
| 30 | |
| 31 | Add Openstack Keypair |
| 32 | [Documentation] Runs an Openstack Request to add a keypair and returns the keypair name |
| 33 | [Arguments] ${alias} ${name} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 34 | ${ssh_key}= OperatingSystem.Get File ${OPENSTACK_NOVA_KEYPAIR_SSH_KEY} |
| 35 | ${arguments}= Create Dictionary name=${name} publickey=${ssh_key} |
DR695H | 3bb6cf4 | 2019-06-20 15:04:04 -0400 | [diff] [blame] | 36 | Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER} |
| 37 | ${data}= Apply Template openstack ${OPENSTACK_NOVA_KEYPAIR_ADD_BODY_FILE} ${arguments} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 38 | ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} data_path= data=${data} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 39 | Should Be Equal As Strings 200 ${resp.status_code} |
| 40 | [Return] ${resp.json()['keypair']['name']} |
| 41 | |
| 42 | Delete Openstack Keypair |
| 43 | [Documentation] Runs an Openstack Request to delete a keypair |
| 44 | [Arguments] ${alias} ${keypair_name} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 45 | ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} /${keypair_name} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 46 | ${status_string}= Convert To String ${resp.status_code} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 47 | Should Match Regexp ${status_string} ^(204|202|200)$ |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 48 | [Return] ${resp.text} |
| 49 | |
| 50 | |
| 51 | Get Openstack Servers |
| 52 | [Documentation] Returns the list of servers as a dictionary by name |
| 53 | [Arguments] ${alias} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 54 | ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /detail |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 55 | 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} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 59 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 60 | Get Openstack Server By Id |
| 61 | [Documentation] Returns the openstack stacks info for the given stack name |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 62 | [Arguments] ${alias} ${server_id} |
| 63 | ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 64 | [Return] ${resp} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 65 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 66 | Get Openstack Flavors |
| 67 | [Documentation] Runs an Openstack Request and returns the flavor list |
| 68 | [Arguments] ${alias} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 69 | ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_FLAVORS_PATH} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 70 | [Return] ${resp.json()} |
| 71 | |
| 72 | Get Openstack Images |
| 73 | [Documentation] Runs an Openstack Request and returns the flavor list |
| 74 | [Arguments] ${alias} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 75 | ${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_IMAGES_PATH} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 76 | [Return] ${resp.json()} |
| 77 | |
| 78 | Reboot Server |
| 79 | [Documentation] Requests a reboot of the passed server id |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 80 | [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} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 82 | [Return] ${resp} |
| 83 | |
| 84 | Add 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} |
DR695H | 3bb6cf4 | 2019-06-20 15:04:04 -0400 | [diff] [blame] | 88 | Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER} |
| 89 | ${data}= Apply Template openstack ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 90 | ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 91 | [Return] ${resp} |
| 92 | |
| 93 | Add Server For Image Name |
| 94 | [Documentation] Adds a server for the passed if |
Jerry Flood | 339809a | 2017-10-30 20:19:16 -0400 | [diff] [blame] | 95 | [Arguments] ${alias} ${name} ${imageName} ${flavorName} ${public_net_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 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} |
Jerry Flood | 339809a | 2017-10-30 20:19:16 -0400 | [diff] [blame] | 102 | ${dict}= Create Dictionary name=${name} imageRef=${imageRef} flavorRef=${flavorRef} public_net_id=${public_net_id} |
DR695H | 3bb6cf4 | 2019-06-20 15:04:04 -0400 | [diff] [blame] | 103 | Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER} |
| 104 | ${data}= Apply Template openstack ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 105 | ${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 106 | ${status_string}= Convert To String ${resp.status_code} |
| 107 | Should Match Regexp ${status_string} ^(202)$ |
| 108 | [Return] ${resp.json()} |
| 109 | |
| 110 | Wait for Server to Be Active |
| 111 | [Arguments] ${alias} ${server_id} ${timeout}=300s |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 112 | ${server_info}= Wait Until Keyword Succeeds ${timeout} 10 sec Get Active Server ${alias} ${server_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 113 | ${status}= Get From Dictionary ${server_info} status |
| 114 | Should Be Equal ${status} ACTIVE |
| 115 | [Return] ${server_info} |
| 116 | |
| 117 | Get Active Server |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 118 | [Arguments] ${alias} ${server_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 119 | ${resp}= Get Openstack Server By Id ${alias} ${server_id} |
| 120 | Should Be Equal As Strings ${resp.status_code} 200 |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 121 | ${server_info}= Set Variable ${resp.json()} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 122 | ${server_info}= Get From Dictionary ${server_info} server |
| 123 | ${status}= Get From Dictionary ${server_info} status |
| 124 | Should Not Be Equal ${status} BUILD |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 125 | [Return] ${server_info} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 126 | |
| 127 | Wait for Server to Be Deleted |
| 128 | [Arguments] ${alias} ${server_id} |
| 129 | Wait Until Keyword Succeeds 300s 10s Get Deleted Server ${alias} ${server_id} |
| 130 | |
| 131 | Get Deleted Server |
| 132 | [Arguments] ${alias} ${server_id} |
| 133 | ${resp}= Get Openstack Server By Id ${alias} ${server_id} |
| 134 | Should Be Equal As Strings ${resp.status_code} 404 |
| 135 | |
| 136 | Delete Server |
| 137 | [Documentation] Runs an Openstack Request to delete a keypair |
| 138 | [Arguments] ${alias} ${server_id} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 139 | ${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 140 | ${status_string}= Convert To String ${resp.status_code} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 141 | Should Match Regexp ${status_string} ^(204)$ |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 142 | [Return] ${resp.text} |
| 143 | |
| 144 | Get Id For Name |
| 145 | [Arguments] ${list} ${name} |
DR695H | 910097e | 2019-05-08 13:55:32 -0400 | [diff] [blame] | 146 | :FOR ${item} IN @{list} |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 147 | \ ${id}= Get From Dictionary ${item} id |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 148 | \ ${n}= Get From Dictionary ${item} name |
jf9860 | 99c6329 | 2017-03-09 15:28:42 -0500 | [diff] [blame] | 149 | \ Return from Keyword If '${n}' == '${name}' ${id} |
| 150 | [Return] None |