Browse Source

Merge "Fix heat docker agent tests"

Zuul 1 year ago
parent
commit
40cd47d30a
1 changed files with 298 additions and 308 deletions
  1. 298
    308
      tests/test_hook_docker_cmd.py

+ 298
- 308
tests/test_hook_docker_cmd.py View File

@@ -17,6 +17,7 @@ import os
17 17
 import tempfile
18 18
 
19 19
 import fixtures
20
+import six
20 21
 
21 22
 from tests import common
22 23
 
@@ -98,9 +99,9 @@ class HookDockerCmdTest(common.RunScriptTest):
98 99
             'heat-config-docker-cmd/',
99 100
             'os-refresh-config/configure.d/50-heat-config-docker-cmd')
100 101
 
101
-        self.fake_tool_path = self.relative_path(
102
+        self.fake_tool_path = six.text_type(self.relative_path(
102 103
             __file__,
103
-            'config-tool-fake.py')
104
+            'config-tool-fake.py'))
104 105
 
105 106
         self.working_dir = self.useFixture(fixtures.TempDir())
106 107
         self.outputs_dir = self.useFixture(fixtures.TempDir())
@@ -112,6 +113,76 @@ class HookDockerCmdTest(common.RunScriptTest):
112 113
             'TEST_STATE_PATH': self.test_state_path,
113 114
         })
114 115
 
116
+    def check_basic_response(self, state):
117
+        self.assertEqual([
118
+            self.fake_tool_path,
119
+            u'inspect',
120
+            u'--type',
121
+            u'image',
122
+            u'--format',
123
+            u'exists',
124
+            u'xxx'
125
+        ], state[0]['args'])
126
+        self.assertEqual([
127
+            self.fake_tool_path,
128
+            u'pull',
129
+            u'xxx'
130
+        ], state[1]['args'])
131
+        self.assertEqual([
132
+            self.fake_tool_path,
133
+            u'inspect',
134
+            u'--type',
135
+            u'image',
136
+            u'--format',
137
+            u'exists',
138
+            u'yyy'
139
+        ], state[2]['args'])
140
+        self.assertEqual([
141
+            self.fake_tool_path,
142
+            u'pull',
143
+            u'yyy'
144
+        ], state[3]['args'])
145
+        self.assertEqual([
146
+            self.fake_tool_path,
147
+            u'ps',
148
+            u'-a',
149
+            u'--filter',
150
+            u'label=managed_by=docker-cmd',
151
+            u'--filter',
152
+            u'label=config_id=abc123',
153
+            u'--format',
154
+            u'{{.Names}} {{.Label "container_name"}}'
155
+        ], state[4]['args'])
156
+        self.assertEqual([
157
+            self.fake_tool_path,
158
+            u'ps',
159
+            u'-a',
160
+            u'--filter',
161
+            u'label=managed_by=docker-cmd',
162
+            u'--format',
163
+            u'{{.Names}} {{.Label "container_name"}}'
164
+        ], state[5]['args'])
165
+        self.assertEqual([
166
+            self.fake_tool_path,
167
+            u'ps',
168
+            u'-a',
169
+            u'--filter',
170
+            u'label=managed_by=docker-cmd',
171
+            u'--filter',
172
+            u'label=config_id=abc123',
173
+            u'--format',
174
+            u'{{.Names}} {{.Label "container_name"}}'
175
+        ], state[6]['args'])
176
+        self.assertEqual([
177
+            self.fake_tool_path,
178
+            u'inspect',
179
+            u'--type',
180
+            u'container',
181
+            u'--format',
182
+            u'exists',
183
+            u'db'
184
+        ], state[7]['args'])
185
+
115 186
     def assert_args_and_labels(self, expected_args, expected_labels, observed):
116 187
         '''Assert the labels arguments separately to other arguments.
117 188
 
@@ -141,6 +212,14 @@ class HookDockerCmdTest(common.RunScriptTest):
141 212
 
142 213
         self.env.update({
143 214
             'TEST_RESPONSE': json.dumps([
215
+                # inspect for image xxx
216
+                {},
217
+                # poll for image xxx
218
+                {},
219
+                # inspect for image yyy
220
+                {},
221
+                # poll for image yyy
222
+                {},
144 223
                 # ps for delete missing
145 224
                 {},
146 225
                 # ps for renames
@@ -174,114 +253,79 @@ class HookDockerCmdTest(common.RunScriptTest):
174 253
             'deploy_status_code': 0
175 254
         }, json.loads(stdout.decode('utf-8')))
176 255
 
177
-        state = list(self.json_from_files(self.test_state_path, 9))
178
-        self.assertEqual([
179
-            self.fake_tool_path,
180
-            'ps',
181
-            '-a',
182
-            '--filter',
183
-            'label=managed_by=docker-cmd',
184
-            '--filter',
185
-            'label=config_id=abc123',
186
-            '--format',
187
-            '{{.Names}} {{.Label "container_name"}}'
188
-        ], state[0]['args'])
189
-        self.assertEqual([
190
-            self.fake_tool_path,
191
-            'ps',
192
-            '-a',
193
-            '--filter',
194
-            'label=managed_by=docker-cmd',
195
-            '--format',
196
-            '{{.Names}} {{.Label "container_name"}}'
197
-        ], state[1]['args'])
198
-        self.assertEqual([
199
-            self.fake_tool_path,
200
-            'ps',
201
-            '-a',
202
-            '--filter',
203
-            'label=managed_by=docker-cmd',
204
-            '--filter',
205
-            'label=config_id=abc123',
206
-            '--format',
207
-            '{{.Names}} {{.Label "container_name"}}'
208
-        ], state[2]['args'])
209
-        self.assertEqual([
210
-            self.fake_tool_path,
211
-            'inspect',
212
-            '--format',
213
-            'exists',
214
-            'db'
215
-        ], state[3]['args'])
256
+        state = list(self.json_from_files(self.test_state_path, 13))
257
+        self.check_basic_response(state)
216 258
         self.assert_args_and_labels([
217 259
             self.fake_tool_path,
218
-            'run',
219
-            '--name',
220
-            'db',
221
-            '--detach=true',
222
-            '--env-file=env.file',
223
-            '--env=foo=bar',
224
-            '--privileged=false',
225
-            'xxx'
226
-            ''
260
+            u'run',
261
+            u'--name',
262
+            u'db',
263
+            u'--detach=true',
264
+            u'--env-file=env.file',
265
+            u'--env=foo=bar',
266
+            u'--privileged=false',
267
+            u'xxx'
268
+            u''
227 269
         ], [
228
-            'deploy_stack_id=the_stack',
229
-            'deploy_resource_name=the_deployment',
230
-            'config_id=abc123',
231
-            'container_name=db',
232
-            'managed_by=docker-cmd',
233
-        ], state[4]['args'])
270
+            u'deploy_stack_id=the_stack',
271
+            u'deploy_resource_name=the_deployment',
272
+            u'config_id=abc123',
273
+            u'container_name=db',
274
+            u'managed_by=docker-cmd',
275
+        ], state[8]['args'])
234 276
         self.assertEqual([
235 277
             self.fake_tool_path,
236
-            'inspect',
237
-            '--format',
238
-            'exists',
239
-            'web',
240
-        ], state[5]['args'])
278
+            u'inspect',
279
+            u'--type',
280
+            u'container',
281
+            u'--format',
282
+            u'exists',
283
+            u'web',
284
+        ], state[9]['args'])
241 285
         self.assert_args_and_labels([
242 286
             self.fake_tool_path,
243
-            'run',
244
-            '--name',
245
-            'web',
246
-            '--detach=true',
247
-            '--env-file=foo.env',
248
-            '--env-file=bar.conf',
249
-            '--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
250
-            '--env=FOO=BAR',
251
-            '--net=host',
252
-            '--privileged=true',
253
-            '--restart=always',
254
-            '--user=root',
255
-            '--volume=/run:/run',
256
-            '--volume=db:/var/lib/db',
257
-            'yyy',
258
-            '/bin/webserver',
259
-            'start'
287
+            u'run',
288
+            u'--name',
289
+            u'web',
290
+            u'--detach=true',
291
+            u'--env-file=foo.env',
292
+            u'--env-file=bar.conf',
293
+            u'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
294
+            u'--env=FOO=BAR',
295
+            u'--net=host',
296
+            u'--privileged=true',
297
+            u'--restart=always',
298
+            u'--user=root',
299
+            u'--volume=/run:/run',
300
+            u'--volume=db:/var/lib/db',
301
+            u'yyy',
302
+            u'/bin/webserver',
303
+            u'start'
260 304
         ], [
261
-            'deploy_stack_id=the_stack',
262
-            'deploy_resource_name=the_deployment',
263
-            'config_id=abc123',
264
-            'container_name=web',
265
-            'managed_by=docker-cmd',
266
-        ], state[6]['args'])
305
+            u'deploy_stack_id=the_stack',
306
+            u'deploy_resource_name=the_deployment',
307
+            u'config_id=abc123',
308
+            u'container_name=web',
309
+            u'managed_by=docker-cmd',
310
+        ], state[10]['args'])
267 311
         self.assertEqual([
268 312
             self.fake_tool_path,
269
-            'ps',
270
-            '-a',
271
-            '--filter',
272
-            'label=container_name=web',
273
-            '--filter',
274
-            'label=config_id=abc123',
275
-            '--format',
276
-            '{{.Names}}',
277
-        ], state[7]['args'])
313
+            u'ps',
314
+            u'-a',
315
+            u'--filter',
316
+            u'label=container_name=web',
317
+            u'--filter',
318
+            u'label=config_id=abc123',
319
+            u'--format',
320
+            u'{{.Names}}',
321
+        ], state[11]['args'])
278 322
         self.assertEqual([
279 323
             self.fake_tool_path,
280
-            'exec',
281
-            'web',
282
-            '/bin/ls',
283
-            '-l'
284
-        ], state[8]['args'])
324
+            u'exec',
325
+            u'web',
326
+            u'/bin/ls',
327
+            u'-l'
328
+        ], state[12]['args'])
285 329
 
286 330
     def test_hook_exit_codes(self):
287 331
 
@@ -365,6 +409,14 @@ class HookDockerCmdTest(common.RunScriptTest):
365 409
 
366 410
         self.env.update({
367 411
             'TEST_RESPONSE': json.dumps([
412
+                # inspect for image xxx
413
+                {},
414
+                # poll for image xxx
415
+                {},
416
+                # inspect for image yyy
417
+                {},
418
+                # poll for image yyy
419
+                {},
368 420
                 # ps for delete missing
369 421
                 {},
370 422
                 # ps for renames
@@ -400,118 +452,91 @@ class HookDockerCmdTest(common.RunScriptTest):
400 452
             'deploy_status_code': 2
401 453
         }, json.loads(stdout.decode('utf-8')))
402 454
 
403
-        state = list(self.json_from_files(self.test_state_path, 9))
404
-        self.assertEqual([
405
-            self.fake_tool_path,
406
-            'ps',
407
-            '-a',
408
-            '--filter',
409
-            'label=managed_by=docker-cmd',
410
-            '--filter',
411
-            'label=config_id=abc123',
412
-            '--format',
413
-            '{{.Names}} {{.Label "container_name"}}'
414
-        ], state[0]['args'])
415
-        self.assertEqual([
416
-            self.fake_tool_path,
417
-            'ps',
418
-            '-a',
419
-            '--filter',
420
-            'label=managed_by=docker-cmd',
421
-            '--format',
422
-            '{{.Names}} {{.Label "container_name"}}'
423
-        ], state[1]['args'])
424
-        self.assertEqual([
425
-            self.fake_tool_path,
426
-            'ps',
427
-            '-a',
428
-            '--filter',
429
-            'label=managed_by=docker-cmd',
430
-            '--filter',
431
-            'label=config_id=abc123',
432
-            '--format',
433
-            '{{.Names}} {{.Label "container_name"}}'
434
-        ], state[2]['args'])
435
-        self.assertEqual([
436
-            self.fake_tool_path,
437
-            'inspect',
438
-            '--format',
439
-            'exists',
440
-            'db'
441
-        ], state[3]['args'])
455
+        state = list(self.json_from_files(self.test_state_path, 13))
456
+        self.check_basic_response(state)
442 457
         self.assert_args_and_labels([
443 458
             self.fake_tool_path,
444
-            'run',
445
-            '--name',
446
-            'db',
447
-            '--detach=true',
448
-            '--env-file=env.file',
449
-            '--env=foo=bar',
450
-            '--privileged=false',
451
-            'xxx'
452
-            ''
459
+            u'run',
460
+            u'--name',
461
+            u'db',
462
+            u'--detach=true',
463
+            u'--env-file=env.file',
464
+            u'--env=foo=bar',
465
+            u'--privileged=false',
466
+            u'xxx'
467
+            u''
453 468
         ], [
454
-            'deploy_stack_id=the_stack',
455
-            'deploy_resource_name=the_deployment',
456
-            'config_id=abc123',
457
-            'container_name=db',
458
-            'managed_by=docker-cmd',
459
-        ], state[4]['args'])
469
+            u'deploy_stack_id=the_stack',
470
+            u'deploy_resource_name=the_deployment',
471
+            u'config_id=abc123',
472
+            u'container_name=db',
473
+            u'managed_by=docker-cmd',
474
+        ], state[8]['args'])
460 475
         self.assertEqual([
461 476
             self.fake_tool_path,
462
-            'inspect',
463
-            '--format',
464
-            'exists',
465
-            'web',
466
-        ], state[5]['args'])
477
+            u'inspect',
478
+            u'--type',
479
+            u'container',
480
+            u'--format',
481
+            u'exists',
482
+            u'web',
483
+        ], state[9]['args'])
467 484
         self.assert_args_and_labels([
468 485
             self.fake_tool_path,
469
-            'run',
470
-            '--name',
471
-            'web',
472
-            '--detach=true',
473
-            '--env-file=foo.env',
474
-            '--env-file=bar.conf',
475
-            '--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
476
-            '--env=FOO=BAR',
477
-            '--net=host',
478
-            '--privileged=true',
479
-            '--restart=always',
480
-            '--user=root',
481
-            '--volume=/run:/run',
482
-            '--volume=db:/var/lib/db',
483
-            'yyy',
484
-            '/bin/webserver',
485
-            'start'
486
+            u'run',
487
+            u'--name',
488
+            u'web',
489
+            u'--detach=true',
490
+            u'--env-file=foo.env',
491
+            u'--env-file=bar.conf',
492
+            u'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
493
+            u'--env=FOO=BAR',
494
+            u'--net=host',
495
+            u'--privileged=true',
496
+            u'--restart=always',
497
+            u'--user=root',
498
+            u'--volume=/run:/run',
499
+            u'--volume=db:/var/lib/db',
500
+            u'yyy',
501
+            u'/bin/webserver',
502
+            u'start'
486 503
         ], [
487
-            'deploy_stack_id=the_stack',
488
-            'deploy_resource_name=the_deployment',
489
-            'config_id=abc123',
490
-            'container_name=web',
491
-            'managed_by=docker-cmd',
492
-        ], state[6]['args'])
504
+            u'deploy_stack_id=the_stack',
505
+            u'deploy_resource_name=the_deployment',
506
+            u'config_id=abc123',
507
+            u'container_name=web',
508
+            u'managed_by=docker-cmd',
509
+        ], state[10]['args'])
493 510
         self.assertEqual([
494 511
             self.fake_tool_path,
495
-            'ps',
496
-            '-a',
497
-            '--filter',
498
-            'label=container_name=web',
499
-            '--filter',
500
-            'label=config_id=abc123',
501
-            '--format',
502
-            '{{.Names}}',
503
-        ], state[7]['args'])
512
+            u'ps',
513
+            u'-a',
514
+            u'--filter',
515
+            u'label=container_name=web',
516
+            u'--filter',
517
+            u'label=config_id=abc123',
518
+            u'--format',
519
+            u'{{.Names}}',
520
+        ], state[11]['args'])
504 521
         self.assertEqual([
505 522
             self.fake_tool_path,
506
-            'exec',
507
-            'web',
508
-            '/bin/ls',
509
-            '-l'
510
-        ], state[8]['args'])
523
+            u'exec',
524
+            u'web',
525
+            u'/bin/ls',
526
+            u'-l'
527
+        ], state[12]['args'])
511 528
 
512 529
     def test_hook_unique_names(self):
513 530
         self.env.update({
514 531
             'TEST_RESPONSE': json.dumps([
532
+                # inspect for image xxx
533
+                {},
534
+                # poll for image xxx
535
+                {},
536
+                # inspect for image yyy
537
+                {},
538
+                # poll for image yyy
539
+                {},
515 540
                 # ps for delete missing in this config id
516 541
                 {},
517 542
                 # ps for renames
@@ -546,139 +571,104 @@ class HookDockerCmdTest(common.RunScriptTest):
546 571
 
547 572
         self.assertEqual(0, returncode, stderr)
548 573
 
549
-        self.assertEqual({
550
-            'deploy_stdout': '',
551
-            'deploy_stderr': 'Creating db...\n'
552
-                             'Creating web...\n'
553
-                             'one.txt\ntwo.txt\nthree.txt',
554
-            'deploy_status_code': 0
555
-        }, json.loads(stdout.decode('utf-8')))
574
+        state = list(self.json_from_files(self.test_state_path, 15))
575
+        dd = []
576
+        for i in state:
577
+            dd.append(i['args'])
556 578
 
557
-        state = list(self.json_from_files(self.test_state_path, 11))
558
-        db_container_name = state[4]['args'][4]
559
-        web_container_name = state[7]['args'][4]
579
+        db_container_name = state[8]['args'][6]
580
+        web_container_name = state[11]['args'][6]
560 581
         self.assertRegex(db_container_name, 'db-[0-9a-z]{8}')
561 582
         self.assertRegex(web_container_name, 'web-[0-9a-z]{8}')
583
+        self.check_basic_response(state)
562 584
         self.assertEqual([
563 585
             self.fake_tool_path,
564
-            'ps',
565
-            '-a',
566
-            '--filter',
567
-            'label=managed_by=docker-cmd',
568
-            '--filter',
569
-            'label=config_id=abc123',
570
-            '--format',
571
-            '{{.Names}} {{.Label "container_name"}}'
572
-        ], state[0]['args'])
573
-        self.assertEqual([
574
-            self.fake_tool_path,
575
-            'ps',
576
-            '-a',
577
-            '--filter',
578
-            'label=managed_by=docker-cmd',
579
-            '--format',
580
-            '{{.Names}} {{.Label "container_name"}}'
581
-        ], state[1]['args'])
582
-        self.assertEqual([
583
-            self.fake_tool_path,
584
-            'ps',
585
-            '-a',
586
-            '--filter',
587
-            'label=managed_by=docker-cmd',
588
-            '--filter',
589
-            'label=config_id=abc123',
590
-            '--format',
591
-            '{{.Names}} {{.Label "container_name"}}'
592
-        ], state[2]['args'])
593
-        self.assertEqual([
594
-            self.fake_tool_path,
595
-            'inspect',
596
-            '--format',
597
-            'exists',
598
-            'db'
599
-        ], state[3]['args'])
600
-        self.assertEqual([
601
-            self.fake_tool_path,
602
-            'inspect',
603
-            '--format',
604
-            'exists',
586
+            u'inspect',
587
+            u'--type',
588
+            u'container',
589
+            u'--format',
590
+            u'exists',
605 591
             db_container_name,
606
-        ], state[4]['args'])
592
+        ], state[8]['args'])
607 593
         self.assert_args_and_labels([
608 594
             self.fake_tool_path,
609
-            'run',
610
-            '--name',
595
+            u'run',
596
+            u'--name',
611 597
             db_container_name,
612
-            '--detach=true',
613
-            '--env-file=env.file',
614
-            '--env=foo=bar',
615
-            '--privileged=false',
616
-            'xxx'
598
+            u'--detach=true',
599
+            u'--env-file=env.file',
600
+            u'--env=foo=bar',
601
+            u'--privileged=false',
602
+            u'xxx'
617 603
         ], [
618
-            'deploy_stack_id=the_stack',
619
-            'deploy_resource_name=the_deployment',
620
-            'config_id=abc123',
621
-            'container_name=db',
622
-            'managed_by=docker-cmd',
623
-        ], state[5]['args'])
604
+            u'deploy_stack_id=the_stack',
605
+            u'deploy_resource_name=the_deployment',
606
+            u'config_id=abc123',
607
+            u'container_name=db',
608
+            u'managed_by=docker-cmd',
609
+        ], state[9]['args'])
624 610
         self.assertEqual([
625 611
             self.fake_tool_path,
626
-            'inspect',
627
-            '--format',
628
-            'exists',
629
-            'web',
630
-        ], state[6]['args'])
612
+            u'inspect',
613
+            u'--type',
614
+            u'container',
615
+            u'--format',
616
+            u'exists',
617
+            u'web',
618
+        ], state[10]['args'])
631 619
         self.assertEqual([
632 620
             self.fake_tool_path,
633
-            'inspect',
634
-            '--format',
635
-            'exists',
621
+            u'inspect',
622
+            u'--type',
623
+            u'container',
624
+            u'--format',
625
+            u'exists',
636 626
             web_container_name,
637
-        ], state[7]['args'])
627
+        ], state[11]['args'])
638 628
         self.assert_args_and_labels([
639 629
             self.fake_tool_path,
640
-            'run',
641
-            '--name',
630
+            u'run',
631
+            u'--name',
642 632
             web_container_name,
643
-            '--detach=true',
644
-            '--env-file=foo.env',
645
-            '--env-file=bar.conf',
646
-            '--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
647
-            '--env=FOO=BAR',
648
-            '--net=host',
649
-            '--privileged=true',
650
-            '--restart=always',
651
-            '--user=root',
652
-            '--volume=/run:/run',
653
-            '--volume=db:/var/lib/db',
654
-            'yyy',
655
-            '/bin/webserver',
656
-            'start'
633
+            u'--detach=true',
634
+            u'--env-file=foo.env',
635
+            u'--env-file=bar.conf',
636
+            u'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
637
+            u'--env=FOO=BAR',
638
+            u'--net=host',
639
+            u'--privileged=true',
640
+            u'--restart=always',
641
+            u'--user=root',
642
+            u'--volume=/run:/run',
643
+            u'--volume=db:/var/lib/db',
644
+            u'yyy',
645
+            u'/bin/webserver',
646
+            u'start'
657 647
         ], [
658
-            'deploy_stack_id=the_stack',
659
-            'deploy_resource_name=the_deployment',
660
-            'config_id=abc123',
661
-            'container_name=web',
662
-            'managed_by=docker-cmd',
663
-        ], state[8]['args'])
664
-        self.assertEqual([
665
-            self.fake_tool_path,
666
-            'ps',
667
-            '-a',
668
-            '--filter',
669
-            'label=container_name=web',
670
-            '--filter',
671
-            'label=config_id=abc123',
672
-            '--format',
673
-            '{{.Names}}',
674
-        ], state[9]['args'])
675
-        self.assertEqual([
676
-            self.fake_tool_path,
677
-            'exec',
678
-            'web-asdf1234',
679
-            '/bin/ls',
680
-            '-l'
681
-        ], state[10]['args'])
648
+            u'deploy_stack_id=the_stack',
649
+            u'deploy_resource_name=the_deployment',
650
+            u'config_id=abc123',
651
+            u'container_name=web',
652
+            u'managed_by=docker-cmd',
653
+        ], state[12]['args'])
654
+        self.assertEqual([
655
+            self.fake_tool_path,
656
+            u'ps',
657
+            u'-a',
658
+            u'--filter',
659
+            u'label=container_name=web',
660
+            u'--filter',
661
+            u'label=config_id=abc123',
662
+            u'--format',
663
+            u'{{.Names}}',
664
+        ], state[13]['args'])
665
+        self.assertEqual([
666
+            self.fake_tool_path,
667
+            u'exec',
668
+            u'web-asdf1234',
669
+            u'/bin/ls',
670
+            u'-l'
671
+        ], state[14]['args'])
682 672
 
683 673
     def test_cleanup_deleted(self):
684 674
         self.env.update({

Loading…
Cancel
Save