blob: b1f07f86236087040172338efda796d041b9dc17 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
*** Settings ***
Documentation The main interface for interacting with Openstack. It handles low level stuff like managing the authtoken and Openstack required fields
Library ONAPLibrary.Openstack
Library RequestsLibrary
Library ONAPLibrary.JSON
Library ONAPLibrary.Templating
Library OperatingSystem
Library Collections
Resource ../global_properties.robot
Resource openstack_common.robot
*** Variables ***
${OPENSTACK_NOVA_API_VERSION} /v2
${OPENSTACK_NOVA_KEYPAIR_PATH} /os-keypairs
${OPENSTACK_NOVA_KEYPAIR_ADD_BODY_FILE} openstack/nova_add_keypair.jinja
${OPENSTACK_NOVA_KEYPAIR_SSH_KEY} robot/assets/keys/robot_ssh_public_key.txt
${OPENSTACK_NOVA_FLAVORS_PATH} /flavors
${OPENSTACK_NOVA_SERVERS_PATH} /servers
${OPENSTACK_NOVA_IMAGES_PATH} /images
${OPENSTACK_NOVA_SERVERS_REBOOT_BODY} {"reboot" : { "type" : "SOFT" }}
${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} openstack/nova_add_server.jinja
*** Keywords ***
Get Openstack Keypair
[Documentation] Runs an Openstack Request and returns the keypair info
[Arguments] ${alias} ${keypair_name}
${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} /${keypair_name}
[Return] ${resp.json()}
Add Openstack Keypair
[Documentation] Runs an Openstack Request to add a keypair and returns the keypair name
[Arguments] ${alias} ${name}
${ssh_key}= OperatingSystem.Get File ${OPENSTACK_NOVA_KEYPAIR_SSH_KEY}
${arguments}= Create Dictionary name=${name} publickey=${ssh_key}
Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER}
${data}= Apply Template openstack ${OPENSTACK_NOVA_KEYPAIR_ADD_BODY_FILE} ${arguments}
${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} data_path= data=${data}
Should Be Equal As Strings 200 ${resp.status_code}
[Return] ${resp.json()['keypair']['name']}
Delete Openstack Keypair
[Documentation] Runs an Openstack Request to delete a keypair
[Arguments] ${alias} ${keypair_name}
${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_KEYPAIR_PATH} /${keypair_name}
${status_string}= Convert To String ${resp.status_code}
Should Match Regexp ${status_string} ^(204|202|200)$
[Return] ${resp.text}
Get Openstack Servers
[Documentation] Returns the list of servers as a dictionary by name
[Arguments] ${alias}
${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /detail
Log Returned from Internal Get Openstack
${by_name}= Make List Into Dict ${resp.json()['servers']} name
Log got it
[Return] ${by_name}
Get Openstack Server By Id
[Documentation] Returns the openstack stacks info for the given stack name
[Arguments] ${alias} ${server_id}
${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}
[Return] ${resp}
Get Openstack Flavors
[Documentation] Runs an Openstack Request and returns the flavor list
[Arguments] ${alias}
${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_FLAVORS_PATH}
[Return] ${resp.json()}
Get Openstack Images
[Documentation] Runs an Openstack Request and returns the flavor list
[Arguments] ${alias}
${resp}= Internal Get Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_IMAGES_PATH}
[Return] ${resp.json()}
Reboot Server
[Documentation] Requests a reboot of the passed server id
[Arguments] ${alias} ${server_id}
${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}/action ${OPENSTACK_NOVA_SERVERS_REBOOT_BODY}
[Return] ${resp}
Add Server
[Documentation] Adds a server for the passed if
[Arguments] ${alias} ${name} ${imageRef} ${flavorRef}
${dict}= Create Dictionary name=${name} imageRef=${imageRef} flavorRef=${flavorRef}
Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER}
${data}= Apply Template openstack ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict}
${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data}
[Return] ${resp}
Add Server For Image Name
[Documentation] Adds a server for the passed if
[Arguments] ${alias} ${name} ${imageName} ${flavorName} ${public_net_id}
${images}= Get Openstack Images ${alias}
${flavors}= Get Openstack Flavors ${alias}
${images}= Get From Dictionary ${images} images
${flavors}= Get From Dictionary ${flavors} flavors
${imageRef}= Get Id For Name ${images} ${imageName}
${flavorRef}= Get Id For Name ${flavors} ${flavorName}
${dict}= Create Dictionary name=${name} imageRef=${imageRef} flavorRef=${flavorRef} public_net_id=${public_net_id}
Create Environment openstack ${GLOBAL_TEMPLATE_FOLDER}
${data}= Apply Template openstack ${OPENSTACK_NOVA_SERVER_ADD_BODY_FILE} ${dict}
${resp}= Internal Post Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} data_path= data=${data}
${status_string}= Convert To String ${resp.status_code}
Should Match Regexp ${status_string} ^(202)$
[Return] ${resp.json()}
Wait for Server to Be Active
[Arguments] ${alias} ${server_id} ${timeout}=300s
${server_info}= Wait Until Keyword Succeeds ${timeout} 10 sec Get Active Server ${alias} ${server_id}
${status}= Get From Dictionary ${server_info} status
Should Be Equal ${status} ACTIVE
[Return] ${server_info}
Get Active Server
[Arguments] ${alias} ${server_id}
${resp}= Get Openstack Server By Id ${alias} ${server_id}
Should Be Equal As Strings ${resp.status_code} 200
${server_info}= Set Variable ${resp.json()}
${server_info}= Get From Dictionary ${server_info} server
${status}= Get From Dictionary ${server_info} status
Should Not Be Equal ${status} BUILD
[Return] ${server_info}
Wait for Server to Be Deleted
[Arguments] ${alias} ${server_id}
Wait Until Keyword Succeeds 300s 10s Get Deleted Server ${alias} ${server_id}
Get Deleted Server
[Arguments] ${alias} ${server_id}
${resp}= Get Openstack Server By Id ${alias} ${server_id}
Should Be Equal As Strings ${resp.status_code} 404
Delete Server
[Documentation] Runs an Openstack Request to delete a keypair
[Arguments] ${alias} ${server_id}
${resp}= Internal Delete Openstack ${alias} ${GLOBAL_OPENSTACK_NOVA_SERVICE_TYPE} ${OPENSTACK_NOVA_SERVERS_PATH} /${server_id}
${status_string}= Convert To String ${resp.status_code}
Should Match Regexp ${status_string} ^(204)$
[Return] ${resp.text}
Get Id For Name
[Arguments] ${list} ${name}
:FOR ${item} IN @{list}
\ ${id}= Get From Dictionary ${item} id
\ ${n}= Get From Dictionary ${item} name
\ Return from Keyword If '${n}' == '${name}' ${id}
[Return] None
|