summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-01-23 14:36:19 +0000
committerGerrit Code Review <review@openstack.org>2019-01-23 14:36:19 +0000
commit44ae87c3105b44e3c21aa6c4077e4792d9bcb2a0 (patch)
tree0f6e9f0efe7edae9098ba249fb42035938311261
parentbf5a206c0889b8d71214ca6702575d60695f3d79 (diff)
parentd5027ff6a9b6139037acb706a79dbeab7d72a04f (diff)
Merge "Support userdata for instances in openstack"
-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 1373b4e..94effed 100644
--- a/devstack/plugin.sh
+++ b/devstack/plugin.sh
@@ -328,6 +328,12 @@ providers:
328 key-name: $NODEPOOL_KEY_NAME 328 key-name: $NODEPOOL_KEY_NAME
329 instance-properties: 329 instance-properties:
330 nodepool_devstack: testing 330 nodepool_devstack: testing
331 userdata: |
332 #cloud-config
333 write_files:
334 - content: |
335 testpassed
336 path: /etc/testfile_nodepool_userdata
331 - name: debian-stretch 337 - name: debian-stretch
332 diskimage: debian-stretch 338 diskimage: debian-stretch
333 min-ram: 512 339 min-ram: 512
@@ -336,6 +342,12 @@ providers:
336 key-name: $NODEPOOL_KEY_NAME 342 key-name: $NODEPOOL_KEY_NAME
337 instance-properties: 343 instance-properties:
338 nodepool_devstack: testing 344 nodepool_devstack: testing
345 userdata: |
346 #cloud-config
347 write_files:
348 - content: |
349 testpassed
350 path: /etc/testfile_nodepool_userdata
339 - name: fedora-29 351 - name: fedora-29
340 diskimage: fedora-29 352 diskimage: fedora-29
341 min-ram: 1024 353 min-ram: 1024
@@ -344,6 +356,12 @@ providers:
344 key-name: $NODEPOOL_KEY_NAME 356 key-name: $NODEPOOL_KEY_NAME
345 instance-properties: 357 instance-properties:
346 nodepool_devstack: testing 358 nodepool_devstack: testing
359 userdata: |
360 #cloud-config
361 write_files:
362 - content: |
363 testpassed
364 path: /etc/testfile_nodepool_userdata
347 - name: ubuntu-bionic 365 - name: ubuntu-bionic
348 diskimage: ubuntu-bionic 366 diskimage: ubuntu-bionic
349 min-ram: 512 367 min-ram: 512
@@ -352,6 +370,12 @@ providers:
352 key-name: $NODEPOOL_KEY_NAME 370 key-name: $NODEPOOL_KEY_NAME
353 instance-properties: 371 instance-properties:
354 nodepool_devstack: testing 372 nodepool_devstack: testing
373 userdata: |
374 #cloud-config
375 write_files:
376 - content: |
377 testpassed
378 path: /etc/testfile_nodepool_userdata
355 - name: ubuntu-trusty 379 - name: ubuntu-trusty
356 diskimage: ubuntu-trusty 380 diskimage: ubuntu-trusty
357 min-ram: 512 381 min-ram: 512
@@ -360,6 +384,12 @@ providers:
360 key-name: $NODEPOOL_KEY_NAME 384 key-name: $NODEPOOL_KEY_NAME
361 instance-properties: 385 instance-properties:
362 nodepool_devstack: testing 386 nodepool_devstack: testing
387 userdata: |
388 #cloud-config
389 write_files:
390 - content: |
391 testpassed
392 path: /etc/testfile_nodepool_userdata
363 - name: ubuntu-xenial 393 - name: ubuntu-xenial
364 diskimage: ubuntu-xenial 394 diskimage: ubuntu-xenial
365 min-ram: 512 395 min-ram: 512
@@ -368,6 +398,12 @@ providers:
368 key-name: $NODEPOOL_KEY_NAME 398 key-name: $NODEPOOL_KEY_NAME
369 instance-properties: 399 instance-properties:
370 nodepool_devstack: testing 400 nodepool_devstack: testing
401 userdata: |
402 #cloud-config
403 write_files:
404 - content: |
405 testpassed
406 path: /etc/testfile_nodepool_userdata
371 - name: opensuse-423 407 - name: opensuse-423
372 diskimage: opensuse-423 408 diskimage: opensuse-423
373 min-ram: 512 409 min-ram: 512
@@ -376,6 +412,12 @@ providers:
376 key-name: $NODEPOOL_KEY_NAME 412 key-name: $NODEPOOL_KEY_NAME
377 instance-properties: 413 instance-properties:
378 nodepool_devstack: testing 414 nodepool_devstack: testing
415 userdata: |
416 #cloud-config
417 write_files:
418 - content: |
419 testpassed
420 path: /etc/testfile_nodepool_userdata
379 - name: opensuse-150 421 - name: opensuse-150
380 diskimage: opensuse-150 422 diskimage: opensuse-150
381 min-ram: 512 423 min-ram: 512
@@ -384,6 +426,12 @@ providers:
384 key-name: $NODEPOOL_KEY_NAME 426 key-name: $NODEPOOL_KEY_NAME
385 instance-properties: 427 instance-properties:
386 nodepool_devstack: testing 428 nodepool_devstack: testing
429 userdata: |
430 #cloud-config
431 write_files:
432 - content: |
433 testpassed
434 path: /etc/testfile_nodepool_userdata
387 - name: opensuse-tumbleweed 435 - name: opensuse-tumbleweed
388 diskimage: opensuse-tumbleweed 436 diskimage: opensuse-tumbleweed
389 min-ram: 512 437 min-ram: 512
@@ -392,6 +440,12 @@ providers:
392 key-name: $NODEPOOL_KEY_NAME 440 key-name: $NODEPOOL_KEY_NAME
393 instance-properties: 441 instance-properties:
394 nodepool_devstack: testing 442 nodepool_devstack: testing
443 userdata: |
444 #cloud-config
445 write_files:
446 - content: |
447 testpassed
448 path: /etc/testfile_nodepool_userdata
395 - name: gentoo-17-0-systemd 449 - name: gentoo-17-0-systemd
396 diskimage: gentoo-17-0-systemd 450 diskimage: gentoo-17-0-systemd
397 min-ram: 512 451 min-ram: 512
@@ -400,6 +454,12 @@ providers:
400 key-name: $NODEPOOL_KEY_NAME 454 key-name: $NODEPOOL_KEY_NAME
401 instance-properties: 455 instance-properties:
402 nodepool_devstack: testing 456 nodepool_devstack: testing
457 userdata: |
458 #cloud-config
459 write_files:
460 - content: |
461 testpassed
462 path: /etc/testfile_nodepool_userdata
403 463
404diskimages: 464diskimages:
405 - name: centos-7 465 - name: centos-7
diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst
index 4e772fa..34dcdd8 100644
--- a/doc/source/configuration.rst
+++ b/doc/source/configuration.rst
@@ -921,6 +921,15 @@ Selecting the OpenStack driver adds the following options to the
921 ``meta-data`` on the active server (e.g. within 921 ``meta-data`` on the active server (e.g. within
922 ``config-drive:openstack/latest/meta_data.json``) 922 ``config-drive:openstack/latest/meta_data.json``)
923 923
924 .. attr:: userdata
925 :type: str
926 :default: None
927
928 A string of userdata for a node. Example usage is to install
929 cloud-init package on image which will apply the userdata.
930 Additional info about options in cloud-config:
931 https://cloudinit.readthedocs.io/en/latest/topics/examples.html
932
924 933
925Static Driver 934Static Driver
926------------- 935-------------
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 0990261..9aba134 100644
--- a/nodepool/tests/fixtures/config_validate/good.yaml
+++ b/nodepool/tests/fixtures/config_validate/good.yaml
@@ -56,6 +56,12 @@ providers:
56 instance-properties: 56 instance-properties:
57 a_key: a_value 57 a_key: a_value
58 b_key: b_value 58 b_key: b_value
59 userdata: |
60 #cloud-config
61 password: password
62 chpasswd: { expire: False }
63 ssh_pwauth: True
64 hostname: test
59 65
60 - name: cloud2 66 - name: cloud2
61 driver: openstack 67 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