ソースを参照

Support userdata for instances in openstack

Use "userdata" from Nova API to pass cloud-init config to nova
instances in openstack.

Change-Id: I1c6a1cbc5377d268901210631a376ca26f4887d8
tags/3.5.0
Sagi Shnaidman 7ヶ月前
コミット
d5027ff6a9

+ 60
- 0
devstack/plugin.sh ファイルの表示

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

+ 9
- 0
doc/source/configuration.rst ファイルの表示

@@ -914,6 +914,15 @@ Selecting the OpenStack driver adds the following options to the
914 914
            ``meta-data`` on the active server (e.g. within
915 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
 
918 927
 Static Driver
919 928
 -------------

+ 5
- 1
nodepool/driver/openstack/config.py ファイルの表示

@@ -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 ファイルの表示

@@ -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 ファイルの表示

@@ -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 ファイルの表示

@@ -54,6 +54,12 @@ providers:
54 54
             instance-properties:
55 55
               a_key: a_value
56 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 64
   - name: cloud2
59 65
     driver: openstack

+ 50
- 0
tools/check_devstack_plugin.sh ファイルの表示

@@ -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

読み込み中…
キャンセル
保存