Browse Source

Merge "Support userdata for instances in openstack"

tags/3.5.0
Zuul 6 months ago
parent
commit
44ae87c310

+ 60
- 0
devstack/plugin.sh View File

@@ -328,6 +328,12 @@ providers:
328 328
             key-name: $NODEPOOL_KEY_NAME
329 329
             instance-properties:
330 330
               nodepool_devstack: testing
331
+            userdata: |
332
+              #cloud-config
333
+              write_files:
334
+              - content: |
335
+                  testpassed
336
+                path: /etc/testfile_nodepool_userdata
331 337
           - name: debian-stretch
332 338
             diskimage: debian-stretch
333 339
             min-ram: 512
@@ -336,6 +342,12 @@ providers:
336 342
             key-name: $NODEPOOL_KEY_NAME
337 343
             instance-properties:
338 344
               nodepool_devstack: testing
345
+            userdata: |
346
+              #cloud-config
347
+              write_files:
348
+              - content: |
349
+                  testpassed
350
+                path: /etc/testfile_nodepool_userdata
339 351
           - name: fedora-29
340 352
             diskimage: fedora-29
341 353
             min-ram: 1024
@@ -344,6 +356,12 @@ providers:
344 356
             key-name: $NODEPOOL_KEY_NAME
345 357
             instance-properties:
346 358
               nodepool_devstack: testing
359
+            userdata: |
360
+              #cloud-config
361
+              write_files:
362
+              - content: |
363
+                  testpassed
364
+                path: /etc/testfile_nodepool_userdata
347 365
           - name: ubuntu-bionic
348 366
             diskimage: ubuntu-bionic
349 367
             min-ram: 512
@@ -352,6 +370,12 @@ providers:
352 370
             key-name: $NODEPOOL_KEY_NAME
353 371
             instance-properties:
354 372
               nodepool_devstack: testing
373
+            userdata: |
374
+              #cloud-config
375
+              write_files:
376
+              - content: |
377
+                  testpassed
378
+                path: /etc/testfile_nodepool_userdata
355 379
           - name: ubuntu-trusty
356 380
             diskimage: ubuntu-trusty
357 381
             min-ram: 512
@@ -360,6 +384,12 @@ providers:
360 384
             key-name: $NODEPOOL_KEY_NAME
361 385
             instance-properties:
362 386
               nodepool_devstack: testing
387
+            userdata: |
388
+              #cloud-config
389
+              write_files:
390
+              - content: |
391
+                  testpassed
392
+                path: /etc/testfile_nodepool_userdata
363 393
           - name: ubuntu-xenial
364 394
             diskimage: ubuntu-xenial
365 395
             min-ram: 512
@@ -368,6 +398,12 @@ providers:
368 398
             key-name: $NODEPOOL_KEY_NAME
369 399
             instance-properties:
370 400
               nodepool_devstack: testing
401
+            userdata: |
402
+              #cloud-config
403
+              write_files:
404
+              - content: |
405
+                  testpassed
406
+                path: /etc/testfile_nodepool_userdata
371 407
           - name: opensuse-423
372 408
             diskimage: opensuse-423
373 409
             min-ram: 512
@@ -376,6 +412,12 @@ providers:
376 412
             key-name: $NODEPOOL_KEY_NAME
377 413
             instance-properties:
378 414
               nodepool_devstack: testing
415
+            userdata: |
416
+              #cloud-config
417
+              write_files:
418
+              - content: |
419
+                  testpassed
420
+                path: /etc/testfile_nodepool_userdata
379 421
           - name: opensuse-150
380 422
             diskimage: opensuse-150
381 423
             min-ram: 512
@@ -384,6 +426,12 @@ providers:
384 426
             key-name: $NODEPOOL_KEY_NAME
385 427
             instance-properties:
386 428
               nodepool_devstack: testing
429
+            userdata: |
430
+              #cloud-config
431
+              write_files:
432
+              - content: |
433
+                  testpassed
434
+                path: /etc/testfile_nodepool_userdata
387 435
           - name: opensuse-tumbleweed
388 436
             diskimage: opensuse-tumbleweed
389 437
             min-ram: 512
@@ -392,6 +440,12 @@ providers:
392 440
             key-name: $NODEPOOL_KEY_NAME
393 441
             instance-properties:
394 442
               nodepool_devstack: testing
443
+            userdata: |
444
+              #cloud-config
445
+              write_files:
446
+              - content: |
447
+                  testpassed
448
+                path: /etc/testfile_nodepool_userdata
395 449
           - name: gentoo-17-0-systemd
396 450
             diskimage: gentoo-17-0-systemd
397 451
             min-ram: 512
@@ -400,6 +454,12 @@ providers:
400 454
             key-name: $NODEPOOL_KEY_NAME
401 455
             instance-properties:
402 456
               nodepool_devstack: testing
457
+            userdata: |
458
+              #cloud-config
459
+              write_files:
460
+              - content: |
461
+                  testpassed
462
+                path: /etc/testfile_nodepool_userdata
403 463
 
404 464
 diskimages:
405 465
   - name: centos-7

+ 9
- 0
doc/source/configuration.rst View File

@@ -921,6 +921,15 @@ Selecting the OpenStack driver adds the following options to the
921 921
            ``meta-data`` on the active server (e.g. within
922 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
 
925 934
 Static Driver
926 935
 -------------

+ 5
- 1
nodepool/driver/openstack/config.py View File

@@ -87,6 +87,7 @@ class ProviderLabel(ConfigValue):
87 87
         self.boot_from_volume = False
88 88
         self.volume_size = None
89 89
         self.instance_properties = None
90
+        self.userdata = None
90 91
         # The ProviderPool object that owns this label.
91 92
         self.pool = None
92 93
 
@@ -103,7 +104,8 @@ class ProviderLabel(ConfigValue):
103 104
                     other.console_log == self.console_log and
104 105
                     other.boot_from_volume == self.boot_from_volume and
105 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 109
         return False
108 110
 
109 111
     def __repr__(self):
@@ -203,6 +205,7 @@ class ProviderPool(ConfigPool):
203 205
             pl.volume_size = label.get('volume-size', 50)
204 206
             pl.instance_properties = label.get('instance-properties',
205 207
                                                None)
208
+            pl.userdata = label.get('userdata', None)
206 209
 
207 210
             top_label = full_config.labels[pl.name]
208 211
             top_label.pools.append(self)
@@ -355,6 +358,7 @@ class OpenStackProviderConfig(ProviderConfig):
355 358
             'boot-from-volume': bool,
356 359
             'volume-size': int,
357 360
             'instance-properties': dict,
361
+            'userdata': str,
358 362
         }
359 363
 
360 364
         label_min_ram = v.Schema({v.Required('min-ram'): int}, extra=True)

+ 2
- 1
nodepool/driver/openstack/handler.py View File

@@ -139,7 +139,8 @@ class OpenStackNodeLauncher(NodeLauncher):
139 139
                 security_groups=self.pool.security_groups,
140 140
                 boot_from_volume=self.label.boot_from_volume,
141 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 144
         except openstack.cloud.exc.OpenStackCloudCreateException as e:
144 145
             if e.resource_id:
145 146
                 self.node.external_id = e.resource_id

+ 3
- 1
nodepool/driver/openstack/provider.py View File

@@ -280,7 +280,7 @@ class OpenStackProvider(Provider):
280 280
                      nodepool_image_name=None,
281 281
                      networks=None, security_groups=None,
282 282
                      boot_from_volume=False, volume_size=50,
283
-                     instance_properties=None):
283
+                     instance_properties=None, userdata=None):
284 284
         if not networks:
285 285
             networks = []
286 286
         if not isinstance(image, dict):
@@ -303,6 +303,8 @@ class OpenStackProvider(Provider):
303 303
             create_args['availability_zone'] = az
304 304
         if security_groups:
305 305
             create_args['security_groups'] = security_groups
306
+        if userdata:
307
+            create_args['userdata'] = userdata
306 308
         nics = []
307 309
         for network in networks:
308 310
             net_id = self.findNetwork(network)['id']

+ 6
- 0
nodepool/tests/fixtures/config_validate/good.yaml View File

@@ -56,6 +56,12 @@ providers:
56 56
             instance-properties:
57 57
               a_key: a_value
58 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 66
   - name: cloud2
61 67
     driver: openstack

+ 50
- 0
tools/check_devstack_plugin.sh View File

@@ -61,6 +61,36 @@ function sshintonode {
61 61
     fi
62 62
 }
63 63
 
64
+function 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
77
+write_files:
78
+- content: |
79
+    testpassed
80
+  path: /etc/testfile_nodepool_userdata
81
+EOF
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
+
64 94
 function checknm {
65 95
     name=$1
66 96
     state='ready'
@@ -116,6 +146,8 @@ if [ ${NODEPOOL_PAUSE_CENTOS_7_DIB,,} = 'false' ]; then
116 146
     sshintonode centos-7
117 147
     # networkmanager check
118 148
     checknm centos-7
149
+    # userdata check
150
+    showserver centos-7
119 151
 fi
120 152
 
121 153
 if [ ${NODEPOOL_PAUSE_DEBIAN_STRETCH_DIB,,} = 'false' ]; then
@@ -125,6 +157,8 @@ if [ ${NODEPOOL_PAUSE_DEBIAN_STRETCH_DIB,,} = 'false' ]; then
125 157
     waitfornode debian-stretch
126 158
     # check ssh for root user
127 159
     sshintonode debian-stretch
160
+    # userdata check
161
+    showserver debian-stretch
128 162
 fi
129 163
 
130 164
 if [ ${NODEPOOL_PAUSE_FEDORA_29_DIB,,} = 'false' ]; then
@@ -136,6 +170,8 @@ if [ ${NODEPOOL_PAUSE_FEDORA_29_DIB,,} = 'false' ]; then
136 170
     sshintonode fedora-29
137 171
     # networkmanager check
138 172
     checknm fedora-29
173
+    # userdata check
174
+    showserver fedora-29
139 175
 fi
140 176
 
141 177
 if [ ${NODEPOOL_PAUSE_UBUNTU_BIONIC_DIB,,} = 'false' ]; then
@@ -145,6 +181,8 @@ if [ ${NODEPOOL_PAUSE_UBUNTU_BIONIC_DIB,,} = 'false' ]; then
145 181
     waitfornode ubuntu-bionic
146 182
     # check ssh for root user
147 183
     sshintonode ubuntu-bionic
184
+    # userdata check
185
+    showserver ubuntu-bionic
148 186
 fi
149 187
 
150 188
 if [ ${NODEPOOL_PAUSE_UBUNTU_TRUSTY_DIB,,} = 'false' ]; then
@@ -154,6 +192,8 @@ if [ ${NODEPOOL_PAUSE_UBUNTU_TRUSTY_DIB,,} = 'false' ]; then
154 192
     waitfornode ubuntu-trusty
155 193
     # check ssh for root user
156 194
     sshintonode ubuntu-trusty
195
+    # userdata check
196
+    showserver ubuntu-trusty
157 197
 fi
158 198
 
159 199
 if [ ${NODEPOOL_PAUSE_UBUNTU_XENIAL_DIB,,} = 'false' ]; then
@@ -163,6 +203,8 @@ if [ ${NODEPOOL_PAUSE_UBUNTU_XENIAL_DIB,,} = 'false' ]; then
163 203
     waitfornode ubuntu-xenial
164 204
     # check ssh for root user
165 205
     sshintonode ubuntu-xenial
206
+    # userdata check
207
+    showserver ubuntu-xenial
166 208
 fi
167 209
 
168 210
 if [ ${NODEPOOL_PAUSE_OPENSUSE_423_DIB,,} = 'false' ]; then
@@ -172,6 +214,8 @@ if [ ${NODEPOOL_PAUSE_OPENSUSE_423_DIB,,} = 'false' ]; then
172 214
     waitfornode opensuse-423
173 215
     # check ssh for root user
174 216
     sshintonode opensuse-423
217
+    # userdata check
218
+    showserver opensuse-423
175 219
 fi
176 220
 if [ ${NODEPOOL_PAUSE_OPENSUSE_150_DIB,,} = 'false' ]; then
177 221
     # check that image built
@@ -180,6 +224,8 @@ if [ ${NODEPOOL_PAUSE_OPENSUSE_150_DIB,,} = 'false' ]; then
180 224
     waitfornode opensuse-150
181 225
     # check ssh for root user
182 226
     sshintonode opensuse-150
227
+    # userdata check
228
+    showserver opensuse-150
183 229
 fi
184 230
 if [ ${NODEPOOL_PAUSE_OPENSUSE_TUMBLEWEED_DIB,,} = 'false' ]; then
185 231
     # check that image built
@@ -188,6 +234,8 @@ if [ ${NODEPOOL_PAUSE_OPENSUSE_TUMBLEWEED_DIB,,} = 'false' ]; then
188 234
     waitfornode opensuse-tumbleweed
189 235
     # check ssh for root user
190 236
     sshintonode opensuse-tumbleweed
237
+    # userdata check
238
+    showserver opensuse-tumbleweed
191 239
 fi
192 240
 if [ ${NODEPOOL_PAUSE_GENTOO_17_0_SYSTEMD_DIB,,} = 'false' ]; then
193 241
     # check that image built
@@ -196,6 +244,8 @@ if [ ${NODEPOOL_PAUSE_GENTOO_17_0_SYSTEMD_DIB,,} = 'false' ]; then
196 244
     waitfornode gentoo-17-0-systemd
197 245
     # check ssh for root user
198 246
     sshintonode gentoo-17-0-systemd
247
+    # userdata check
248
+    showserver gentoo-17-0-systemd
199 249
 fi
200 250
 
201 251
 set -o errexit

Loading…
Cancel
Save