summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSagi Shnaidman <sshnaidm@redhat.com>2019-01-14 13:18:52 +0200
committerSagi Shnaidman <sshnaidm@redhat.com>2019-01-22 19:14:52 +0200
commitd5027ff6a9b6139037acb706a79dbeab7d72a04f (patch)
tree8663ee1e931ddbdab7c88fff9352b237687b748b
parent7fd6411dac109384a47b672b2f97313980cee687 (diff)
Support userdata for instances in openstack
Use "userdata" from Nova API to pass cloud-init config to nova instances in openstack. Change-Id: I1c6a1cbc5377d268901210631a376ca26f4887d8
Notes
Notes (review): Code-Review+2: Tobias Henkel <tobias.henkel@bmw.de> Code-Review+1: Jesse Pretorius (odyssey4me) <jesse.pretorius@rackspace.co.uk> Code-Review+2: Monty Taylor <mordred@inaugust.com> Workflow+1: Monty Taylor <mordred@inaugust.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 23 Jan 2019 14:36:19 +0000 Reviewed-on: https://review.openstack.org/630649 Project: openstack-infra/nodepool Branch: refs/heads/master
-rw-r--r--devstack/plugin.sh60
-rw-r--r--doc/source/configuration.rst9
-rw-r--r--nodepool/driver/openstack/config.py6
-rw-r--r--nodepool/driver/openstack/handler.py3
-rwxr-xr-xnodepool/driver/openstack/provider.py4
-rw-r--r--nodepool/tests/fixtures/config_validate/good.yaml6
-rwxr-xr-xtools/check_devstack_plugin.sh50
7 files changed, 135 insertions, 3 deletions
diff --git a/devstack/plugin.sh b/devstack/plugin.sh
index 80fafe7..c6569f7 100644
--- a/devstack/plugin.sh
+++ b/devstack/plugin.sh
@@ -315,6 +315,12 @@ providers:
315 key-name: $NODEPOOL_KEY_NAME 315 key-name: $NODEPOOL_KEY_NAME
316 instance-properties: 316 instance-properties:
317 nodepool_devstack: testing 317 nodepool_devstack: testing
318 userdata: |
319 #cloud-config
320 write_files:
321 - content: |
322 testpassed
323 path: /etc/testfile_nodepool_userdata
318 - name: debian-stretch 324 - name: debian-stretch
319 diskimage: debian-stretch 325 diskimage: debian-stretch
320 min-ram: 512 326 min-ram: 512
@@ -323,6 +329,12 @@ providers:
323 key-name: $NODEPOOL_KEY_NAME 329 key-name: $NODEPOOL_KEY_NAME
324 instance-properties: 330 instance-properties:
325 nodepool_devstack: testing 331 nodepool_devstack: testing
332 userdata: |
333 #cloud-config
334 write_files:
335 - content: |
336 testpassed
337 path: /etc/testfile_nodepool_userdata
326 - name: fedora-29 338 - name: fedora-29
327 diskimage: fedora-29 339 diskimage: fedora-29
328 min-ram: 1024 340 min-ram: 1024
@@ -331,6 +343,12 @@ providers:
331 key-name: $NODEPOOL_KEY_NAME 343 key-name: $NODEPOOL_KEY_NAME
332 instance-properties: 344 instance-properties:
333 nodepool_devstack: testing 345 nodepool_devstack: testing
346 userdata: |
347 #cloud-config
348 write_files:
349 - content: |
350 testpassed
351 path: /etc/testfile_nodepool_userdata
334 - name: ubuntu-bionic 352 - name: ubuntu-bionic
335 diskimage: ubuntu-bionic 353 diskimage: ubuntu-bionic
336 min-ram: 512 354 min-ram: 512
@@ -339,6 +357,12 @@ providers:
339 key-name: $NODEPOOL_KEY_NAME 357 key-name: $NODEPOOL_KEY_NAME
340 instance-properties: 358 instance-properties:
341 nodepool_devstack: testing 359 nodepool_devstack: testing
360 userdata: |
361 #cloud-config
362 write_files:
363 - content: |
364 testpassed
365 path: /etc/testfile_nodepool_userdata
342 - name: ubuntu-trusty 366 - name: ubuntu-trusty
343 diskimage: ubuntu-trusty 367 diskimage: ubuntu-trusty
344 min-ram: 512 368 min-ram: 512
@@ -347,6 +371,12 @@ providers:
347 key-name: $NODEPOOL_KEY_NAME 371 key-name: $NODEPOOL_KEY_NAME
348 instance-properties: 372 instance-properties:
349 nodepool_devstack: testing 373 nodepool_devstack: testing
374 userdata: |
375 #cloud-config
376 write_files:
377 - content: |
378 testpassed
379 path: /etc/testfile_nodepool_userdata
350 - name: ubuntu-xenial 380 - name: ubuntu-xenial
351 diskimage: ubuntu-xenial 381 diskimage: ubuntu-xenial
352 min-ram: 512 382 min-ram: 512
@@ -355,6 +385,12 @@ providers:
355 key-name: $NODEPOOL_KEY_NAME 385 key-name: $NODEPOOL_KEY_NAME
356 instance-properties: 386 instance-properties:
357 nodepool_devstack: testing 387 nodepool_devstack: testing
388 userdata: |
389 #cloud-config
390 write_files:
391 - content: |
392 testpassed
393 path: /etc/testfile_nodepool_userdata
358 - name: opensuse-423 394 - name: opensuse-423
359 diskimage: opensuse-423 395 diskimage: opensuse-423
360 min-ram: 512 396 min-ram: 512
@@ -363,6 +399,12 @@ providers:
363 key-name: $NODEPOOL_KEY_NAME 399 key-name: $NODEPOOL_KEY_NAME
364 instance-properties: 400 instance-properties:
365 nodepool_devstack: testing 401 nodepool_devstack: testing
402 userdata: |
403 #cloud-config
404 write_files:
405 - content: |
406 testpassed
407 path: /etc/testfile_nodepool_userdata
366 - name: opensuse-150 408 - name: opensuse-150
367 diskimage: opensuse-150 409 diskimage: opensuse-150
368 min-ram: 512 410 min-ram: 512
@@ -371,6 +413,12 @@ providers:
371 key-name: $NODEPOOL_KEY_NAME 413 key-name: $NODEPOOL_KEY_NAME
372 instance-properties: 414 instance-properties:
373 nodepool_devstack: testing 415 nodepool_devstack: testing
416 userdata: |
417 #cloud-config
418 write_files:
419 - content: |
420 testpassed
421 path: /etc/testfile_nodepool_userdata
374 - name: opensuse-tumbleweed 422 - name: opensuse-tumbleweed
375 diskimage: opensuse-tumbleweed 423 diskimage: opensuse-tumbleweed
376 min-ram: 512 424 min-ram: 512
@@ -379,6 +427,12 @@ providers:
379 key-name: $NODEPOOL_KEY_NAME 427 key-name: $NODEPOOL_KEY_NAME
380 instance-properties: 428 instance-properties:
381 nodepool_devstack: testing 429 nodepool_devstack: testing
430 userdata: |
431 #cloud-config
432 write_files:
433 - content: |
434 testpassed
435 path: /etc/testfile_nodepool_userdata
382 - name: gentoo-17-0-systemd 436 - name: gentoo-17-0-systemd
383 diskimage: gentoo-17-0-systemd 437 diskimage: gentoo-17-0-systemd
384 min-ram: 512 438 min-ram: 512
@@ -387,6 +441,12 @@ providers:
387 key-name: $NODEPOOL_KEY_NAME 441 key-name: $NODEPOOL_KEY_NAME
388 instance-properties: 442 instance-properties:
389 nodepool_devstack: testing 443 nodepool_devstack: testing
444 userdata: |
445 #cloud-config
446 write_files:
447 - content: |
448 testpassed
449 path: /etc/testfile_nodepool_userdata
390 450
391diskimages: 451diskimages:
392 - name: centos-7 452 - name: centos-7
diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst
index 27abacf..3cc3d5c 100644
--- a/doc/source/configuration.rst
+++ b/doc/source/configuration.rst
@@ -914,6 +914,15 @@ Selecting the OpenStack driver adds the following options to the
914 ``meta-data`` on the active server (e.g. within 914 ``meta-data`` on the active server (e.g. within
915 ``config-drive:openstack/latest/meta_data.json``) 915 ``config-drive:openstack/latest/meta_data.json``)
916 916
917 .. attr:: userdata
918 :type: str
919 :default: None
920
921 A string of userdata for a node. Example usage is to install
922 cloud-init package on image which will apply the userdata.
923 Additional info about options in cloud-config:
924 https://cloudinit.readthedocs.io/en/latest/topics/examples.html
925
917 926
918Static Driver 927Static Driver
919------------- 928-------------
diff --git a/nodepool/driver/openstack/config.py b/nodepool/driver/openstack/config.py
index 2f25997..9586096 100644
--- a/nodepool/driver/openstack/config.py
+++ b/nodepool/driver/openstack/config.py
@@ -87,6 +87,7 @@ class ProviderLabel(ConfigValue):
87 self.boot_from_volume = False 87 self.boot_from_volume = False
88 self.volume_size = None 88 self.volume_size = None
89 self.instance_properties = None 89 self.instance_properties = None
90 self.userdata = None
90 # The ProviderPool object that owns this label. 91 # The ProviderPool object that owns this label.
91 self.pool = None 92 self.pool = None
92 93
@@ -103,7 +104,8 @@ class ProviderLabel(ConfigValue):
103 other.console_log == self.console_log and 104 other.console_log == self.console_log and
104 other.boot_from_volume == self.boot_from_volume and 105 other.boot_from_volume == self.boot_from_volume and
105 other.volume_size == self.volume_size and 106 other.volume_size == self.volume_size and
106 other.instance_properties == self.instance_properties) 107 other.instance_properties == self.instance_properties and
108 other.userdata == self.userdata)
107 return False 109 return False
108 110
109 def __repr__(self): 111 def __repr__(self):
@@ -203,6 +205,7 @@ class ProviderPool(ConfigPool):
203 pl.volume_size = label.get('volume-size', 50) 205 pl.volume_size = label.get('volume-size', 50)
204 pl.instance_properties = label.get('instance-properties', 206 pl.instance_properties = label.get('instance-properties',
205 None) 207 None)
208 pl.userdata = label.get('userdata', None)
206 209
207 top_label = full_config.labels[pl.name] 210 top_label = full_config.labels[pl.name]
208 top_label.pools.append(self) 211 top_label.pools.append(self)
@@ -355,6 +358,7 @@ class OpenStackProviderConfig(ProviderConfig):
355 'boot-from-volume': bool, 358 'boot-from-volume': bool,
356 'volume-size': int, 359 'volume-size': int,
357 'instance-properties': dict, 360 'instance-properties': dict,
361 'userdata': str,
358 } 362 }
359 363
360 label_min_ram = v.Schema({v.Required('min-ram'): int}, extra=True) 364 label_min_ram = v.Schema({v.Required('min-ram'): int}, extra=True)
diff --git a/nodepool/driver/openstack/handler.py b/nodepool/driver/openstack/handler.py
index b72de91..16f426a 100644
--- a/nodepool/driver/openstack/handler.py
+++ b/nodepool/driver/openstack/handler.py
@@ -139,7 +139,8 @@ class OpenStackNodeLauncher(NodeLauncher):
139 security_groups=self.pool.security_groups, 139 security_groups=self.pool.security_groups,
140 boot_from_volume=self.label.boot_from_volume, 140 boot_from_volume=self.label.boot_from_volume,
141 volume_size=self.label.volume_size, 141 volume_size=self.label.volume_size,
142 instance_properties=self.label.instance_properties) 142 instance_properties=self.label.instance_properties,
143 userdata=self.label.userdata)
143 except openstack.cloud.exc.OpenStackCloudCreateException as e: 144 except openstack.cloud.exc.OpenStackCloudCreateException as e:
144 if e.resource_id: 145 if e.resource_id:
145 self.node.external_id = e.resource_id 146 self.node.external_id = e.resource_id
diff --git a/nodepool/driver/openstack/provider.py b/nodepool/driver/openstack/provider.py
index b9a1462..3c07c13 100755
--- a/nodepool/driver/openstack/provider.py
+++ b/nodepool/driver/openstack/provider.py
@@ -280,7 +280,7 @@ class OpenStackProvider(Provider):
280 nodepool_image_name=None, 280 nodepool_image_name=None,
281 networks=None, security_groups=None, 281 networks=None, security_groups=None,
282 boot_from_volume=False, volume_size=50, 282 boot_from_volume=False, volume_size=50,
283 instance_properties=None): 283 instance_properties=None, userdata=None):
284 if not networks: 284 if not networks:
285 networks = [] 285 networks = []
286 if not isinstance(image, dict): 286 if not isinstance(image, dict):
@@ -303,6 +303,8 @@ class OpenStackProvider(Provider):
303 create_args['availability_zone'] = az 303 create_args['availability_zone'] = az
304 if security_groups: 304 if security_groups:
305 create_args['security_groups'] = security_groups 305 create_args['security_groups'] = security_groups
306 if userdata:
307 create_args['userdata'] = userdata
306 nics = [] 308 nics = []
307 for network in networks: 309 for network in networks:
308 net_id = self.findNetwork(network)['id'] 310 net_id = self.findNetwork(network)['id']
diff --git a/nodepool/tests/fixtures/config_validate/good.yaml b/nodepool/tests/fixtures/config_validate/good.yaml
index db7d1ec..c46ec3f 100644
--- a/nodepool/tests/fixtures/config_validate/good.yaml
+++ b/nodepool/tests/fixtures/config_validate/good.yaml
@@ -54,6 +54,12 @@ providers:
54 instance-properties: 54 instance-properties:
55 a_key: a_value 55 a_key: a_value
56 b_key: b_value 56 b_key: b_value
57 userdata: |
58 #cloud-config
59 password: password
60 chpasswd: { expire: False }
61 ssh_pwauth: True
62 hostname: test
57 63
58 - name: cloud2 64 - name: cloud2
59 driver: openstack 65 driver: openstack
diff --git a/tools/check_devstack_plugin.sh b/tools/check_devstack_plugin.sh
index 6f7a05d..db7c808 100755
--- a/tools/check_devstack_plugin.sh
+++ b/tools/check_devstack_plugin.sh
@@ -61,6 +61,36 @@ function sshintonode {
61 fi 61 fi
62} 62}
63 63
64function showserver {
65 name=$1
66 state='ready'
67
68 node_id=`$NODEPOOL list | grep $name | grep $state | cut -d '|' -f5 | tr -d ' '`
69 EXPECTED=$(mktemp)
70 RESULT=$(mktemp)
71 source /opt/stack/devstack/openrc admin admin
72
73 nova show $node_id | grep -Eo "user_data[ ]+.*|[ ]*$" | awk {'print $3'} |\
74 base64 --decode > $RESULT
75 cat <<EOF >$EXPECTED
76#cloud-config
77write_files:
78- content: |
79 testpassed
80 path: /etc/testfile_nodepool_userdata
81EOF
82 diff $EXPECTED $RESULT
83 if [[ $? -ne 0 ]]; then
84 echo "*** Failed to find userdata on server!"
85 FAILURE_REASON="Failed to find userdata on server for $node"
86 echo "Expected userdata:"
87 cat $EXPECTED
88 echo "Found userdata:"
89 cat $RESULT
90 RETURN=1
91 fi
92}
93
64function checknm { 94function checknm {
65 name=$1 95 name=$1
66 state='ready' 96 state='ready'
@@ -116,6 +146,8 @@ if [ ${NODEPOOL_PAUSE_CENTOS_7_DIB,,} = 'false' ]; then
116 sshintonode centos-7 146 sshintonode centos-7
117 # networkmanager check 147 # networkmanager check
118 checknm centos-7 148 checknm centos-7
149 # userdata check
150 showserver centos-7
119fi 151fi
120 152
121if [ ${NODEPOOL_PAUSE_DEBIAN_STRETCH_DIB,,} = 'false' ]; then 153if [ ${NODEPOOL_PAUSE_DEBIAN_STRETCH_DIB,,} = 'false' ]; then
@@ -125,6 +157,8 @@ if [ ${NODEPOOL_PAUSE_DEBIAN_STRETCH_DIB,,} = 'false' ]; then
125 waitfornode debian-stretch 157 waitfornode debian-stretch
126 # check ssh for root user 158 # check ssh for root user
127 sshintonode debian-stretch 159 sshintonode debian-stretch
160 # userdata check
161 showserver debian-stretch
128fi 162fi
129 163
130if [ ${NODEPOOL_PAUSE_FEDORA_29_DIB,,} = 'false' ]; then 164if [ ${NODEPOOL_PAUSE_FEDORA_29_DIB,,} = 'false' ]; then
@@ -136,6 +170,8 @@ if [ ${NODEPOOL_PAUSE_FEDORA_29_DIB,,} = 'false' ]; then
136 sshintonode fedora-29 170 sshintonode fedora-29
137 # networkmanager check 171 # networkmanager check
138 checknm fedora-29 172 checknm fedora-29
173 # userdata check
174 showserver fedora-29
139fi 175fi
140 176
141if [ ${NODEPOOL_PAUSE_UBUNTU_BIONIC_DIB,,} = 'false' ]; then 177if [ ${NODEPOOL_PAUSE_UBUNTU_BIONIC_DIB,,} = 'false' ]; then
@@ -145,6 +181,8 @@ if [ ${NODEPOOL_PAUSE_UBUNTU_BIONIC_DIB,,} = 'false' ]; then
145 waitfornode ubuntu-bionic 181 waitfornode ubuntu-bionic
146 # check ssh for root user 182 # check ssh for root user
147 sshintonode ubuntu-bionic 183 sshintonode ubuntu-bionic
184 # userdata check
185 showserver ubuntu-bionic
148fi 186fi
149 187
150if [ ${NODEPOOL_PAUSE_UBUNTU_TRUSTY_DIB,,} = 'false' ]; then 188if [ ${NODEPOOL_PAUSE_UBUNTU_TRUSTY_DIB,,} = 'false' ]; then
@@ -154,6 +192,8 @@ if [ ${NODEPOOL_PAUSE_UBUNTU_TRUSTY_DIB,,} = 'false' ]; then
154 waitfornode ubuntu-trusty 192 waitfornode ubuntu-trusty
155 # check ssh for root user 193 # check ssh for root user
156 sshintonode ubuntu-trusty 194 sshintonode ubuntu-trusty
195 # userdata check
196 showserver ubuntu-trusty
157fi 197fi
158 198
159if [ ${NODEPOOL_PAUSE_UBUNTU_XENIAL_DIB,,} = 'false' ]; then 199if [ ${NODEPOOL_PAUSE_UBUNTU_XENIAL_DIB,,} = 'false' ]; then
@@ -163,6 +203,8 @@ if [ ${NODEPOOL_PAUSE_UBUNTU_XENIAL_DIB,,} = 'false' ]; then
163 waitfornode ubuntu-xenial 203 waitfornode ubuntu-xenial
164 # check ssh for root user 204 # check ssh for root user
165 sshintonode ubuntu-xenial 205 sshintonode ubuntu-xenial
206 # userdata check
207 showserver ubuntu-xenial
166fi 208fi
167 209
168if [ ${NODEPOOL_PAUSE_OPENSUSE_423_DIB,,} = 'false' ]; then 210if [ ${NODEPOOL_PAUSE_OPENSUSE_423_DIB,,} = 'false' ]; then
@@ -172,6 +214,8 @@ if [ ${NODEPOOL_PAUSE_OPENSUSE_423_DIB,,} = 'false' ]; then
172 waitfornode opensuse-423 214 waitfornode opensuse-423
173 # check ssh for root user 215 # check ssh for root user
174 sshintonode opensuse-423 216 sshintonode opensuse-423
217 # userdata check
218 showserver opensuse-423
175fi 219fi
176if [ ${NODEPOOL_PAUSE_OPENSUSE_150_DIB,,} = 'false' ]; then 220if [ ${NODEPOOL_PAUSE_OPENSUSE_150_DIB,,} = 'false' ]; then
177 # check that image built 221 # check that image built
@@ -180,6 +224,8 @@ if [ ${NODEPOOL_PAUSE_OPENSUSE_150_DIB,,} = 'false' ]; then
180 waitfornode opensuse-150 224 waitfornode opensuse-150
181 # check ssh for root user 225 # check ssh for root user
182 sshintonode opensuse-150 226 sshintonode opensuse-150
227 # userdata check
228 showserver opensuse-150
183fi 229fi
184if [ ${NODEPOOL_PAUSE_OPENSUSE_TUMBLEWEED_DIB,,} = 'false' ]; then 230if [ ${NODEPOOL_PAUSE_OPENSUSE_TUMBLEWEED_DIB,,} = 'false' ]; then
185 # check that image built 231 # check that image built
@@ -188,6 +234,8 @@ if [ ${NODEPOOL_PAUSE_OPENSUSE_TUMBLEWEED_DIB,,} = 'false' ]; then
188 waitfornode opensuse-tumbleweed 234 waitfornode opensuse-tumbleweed
189 # check ssh for root user 235 # check ssh for root user
190 sshintonode opensuse-tumbleweed 236 sshintonode opensuse-tumbleweed
237 # userdata check
238 showserver opensuse-tumbleweed
191fi 239fi
192if [ ${NODEPOOL_PAUSE_GENTOO_17_0_SYSTEMD_DIB,,} = 'false' ]; then 240if [ ${NODEPOOL_PAUSE_GENTOO_17_0_SYSTEMD_DIB,,} = 'false' ]; then
193 # check that image built 241 # check that image built
@@ -196,6 +244,8 @@ if [ ${NODEPOOL_PAUSE_GENTOO_17_0_SYSTEMD_DIB,,} = 'false' ]; then
196 waitfornode gentoo-17-0-systemd 244 waitfornode gentoo-17-0-systemd
197 # check ssh for root user 245 # check ssh for root user
198 sshintonode gentoo-17-0-systemd 246 sshintonode gentoo-17-0-systemd
247 # userdata check
248 showserver gentoo-17-0-systemd
199fi 249fi
200 250
201set -o errexit 251set -o errexit