summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorricolin <rico.lin@easystack.cn>2018-02-01 21:32:45 +0800
committerricolin <rico.lin@easystack.cn>2018-02-01 23:26:29 +0800
commited766c5facc6fe52cd8ce7af15a1325d78f8d5ad (patch)
tree2127c8187155e03f302a311bde8920f250e32962
parent756fcafdf025351ea862ae57f29b8eff9beee362 (diff)
Fix heat docker agent tests
Test for Docker agent seems broken after paunch release. Change-Id: I10213ee8274ccd8222e5e4855d1b4144a4d39c47
Notes
Notes (review): Code-Review+2: Zane Bitter <zbitter@redhat.com> Code-Review+2: Rabi Mishra <ramishra@redhat.com> Workflow+1: Rabi Mishra <ramishra@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 02 Feb 2018 04:46:32 +0000 Reviewed-on: https://review.openstack.org/539949 Project: openstack/heat-agents Branch: refs/heads/master
-rw-r--r--tests/test_hook_docker_cmd.py606
1 files changed, 298 insertions, 308 deletions
diff --git a/tests/test_hook_docker_cmd.py b/tests/test_hook_docker_cmd.py
index 9ca6f12..a01e915 100644
--- a/tests/test_hook_docker_cmd.py
+++ b/tests/test_hook_docker_cmd.py
@@ -17,6 +17,7 @@ import os
17import tempfile 17import tempfile
18 18
19import fixtures 19import fixtures
20import six
20 21
21from tests import common 22from tests import common
22 23
@@ -98,9 +99,9 @@ class HookDockerCmdTest(common.RunScriptTest):
98 'heat-config-docker-cmd/', 99 'heat-config-docker-cmd/',
99 'os-refresh-config/configure.d/50-heat-config-docker-cmd') 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 __file__, 103 __file__,
103 'config-tool-fake.py') 104 'config-tool-fake.py'))
104 105
105 self.working_dir = self.useFixture(fixtures.TempDir()) 106 self.working_dir = self.useFixture(fixtures.TempDir())
106 self.outputs_dir = self.useFixture(fixtures.TempDir()) 107 self.outputs_dir = self.useFixture(fixtures.TempDir())
@@ -112,6 +113,76 @@ class HookDockerCmdTest(common.RunScriptTest):
112 'TEST_STATE_PATH': self.test_state_path, 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 def assert_args_and_labels(self, expected_args, expected_labels, observed): 186 def assert_args_and_labels(self, expected_args, expected_labels, observed):
116 '''Assert the labels arguments separately to other arguments. 187 '''Assert the labels arguments separately to other arguments.
117 188
@@ -141,6 +212,14 @@ class HookDockerCmdTest(common.RunScriptTest):
141 212
142 self.env.update({ 213 self.env.update({
143 'TEST_RESPONSE': json.dumps([ 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 # ps for delete missing 223 # ps for delete missing
145 {}, 224 {},
146 # ps for renames 225 # ps for renames
@@ -174,114 +253,79 @@ class HookDockerCmdTest(common.RunScriptTest):
174 'deploy_status_code': 0 253 'deploy_status_code': 0
175 }, json.loads(stdout.decode('utf-8'))) 254 }, json.loads(stdout.decode('utf-8')))
176 255
177 state = list(self.json_from_files(self.test_state_path, 9)) 256 state = list(self.json_from_files(self.test_state_path, 13))
178 self.assertEqual([ 257 self.check_basic_response(state)
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'])
216 self.assert_args_and_labels([ 258 self.assert_args_and_labels([
217 self.fake_tool_path, 259 self.fake_tool_path,
218 'run', 260 u'run',
219 '--name', 261 u'--name',
220 'db', 262 u'db',
221 '--detach=true', 263 u'--detach=true',
222 '--env-file=env.file', 264 u'--env-file=env.file',
223 '--env=foo=bar', 265 u'--env=foo=bar',
224 '--privileged=false', 266 u'--privileged=false',
225 'xxx' 267 u'xxx'
226 '' 268 u''
227 ], [ 269 ], [
228 'deploy_stack_id=the_stack', 270 u'deploy_stack_id=the_stack',
229 'deploy_resource_name=the_deployment', 271 u'deploy_resource_name=the_deployment',
230 'config_id=abc123', 272 u'config_id=abc123',
231 'container_name=db', 273 u'container_name=db',
232 'managed_by=docker-cmd', 274 u'managed_by=docker-cmd',
233 ], state[4]['args']) 275 ], state[8]['args'])
234 self.assertEqual([ 276 self.assertEqual([
235 self.fake_tool_path, 277 self.fake_tool_path,
236 'inspect', 278 u'inspect',
237 '--format', 279 u'--type',
238 'exists', 280 u'container',
239 'web', 281 u'--format',
240 ], state[5]['args']) 282 u'exists',
283 u'web',
284 ], state[9]['args'])
241 self.assert_args_and_labels([ 285 self.assert_args_and_labels([
242 self.fake_tool_path, 286 self.fake_tool_path,
243 'run', 287 u'run',
244 '--name', 288 u'--name',
245 'web', 289 u'web',
246 '--detach=true', 290 u'--detach=true',
247 '--env-file=foo.env', 291 u'--env-file=foo.env',
248 '--env-file=bar.conf', 292 u'--env-file=bar.conf',
249 '--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS', 293 u'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
250 '--env=FOO=BAR', 294 u'--env=FOO=BAR',
251 '--net=host', 295 u'--net=host',
252 '--privileged=true', 296 u'--privileged=true',
253 '--restart=always', 297 u'--restart=always',
254 '--user=root', 298 u'--user=root',
255 '--volume=/run:/run', 299 u'--volume=/run:/run',
256 '--volume=db:/var/lib/db', 300 u'--volume=db:/var/lib/db',
257 'yyy', 301 u'yyy',
258 '/bin/webserver', 302 u'/bin/webserver',
259 'start' 303 u'start'
260 ], [ 304 ], [
261 'deploy_stack_id=the_stack', 305 u'deploy_stack_id=the_stack',
262 'deploy_resource_name=the_deployment', 306 u'deploy_resource_name=the_deployment',
263 'config_id=abc123', 307 u'config_id=abc123',
264 'container_name=web', 308 u'container_name=web',
265 'managed_by=docker-cmd', 309 u'managed_by=docker-cmd',
266 ], state[6]['args']) 310 ], state[10]['args'])
267 self.assertEqual([ 311 self.assertEqual([
268 self.fake_tool_path, 312 self.fake_tool_path,
269 'ps', 313 u'ps',
270 '-a', 314 u'-a',
271 '--filter', 315 u'--filter',
272 'label=container_name=web', 316 u'label=container_name=web',
273 '--filter', 317 u'--filter',
274 'label=config_id=abc123', 318 u'label=config_id=abc123',
275 '--format', 319 u'--format',
276 '{{.Names}}', 320 u'{{.Names}}',
277 ], state[7]['args']) 321 ], state[11]['args'])
278 self.assertEqual([ 322 self.assertEqual([
279 self.fake_tool_path, 323 self.fake_tool_path,
280 'exec', 324 u'exec',
281 'web', 325 u'web',
282 '/bin/ls', 326 u'/bin/ls',
283 '-l' 327 u'-l'
284 ], state[8]['args']) 328 ], state[12]['args'])
285 329
286 def test_hook_exit_codes(self): 330 def test_hook_exit_codes(self):
287 331
@@ -365,6 +409,14 @@ class HookDockerCmdTest(common.RunScriptTest):
365 409
366 self.env.update({ 410 self.env.update({
367 'TEST_RESPONSE': json.dumps([ 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 # ps for delete missing 420 # ps for delete missing
369 {}, 421 {},
370 # ps for renames 422 # ps for renames
@@ -400,118 +452,91 @@ class HookDockerCmdTest(common.RunScriptTest):
400 'deploy_status_code': 2 452 'deploy_status_code': 2
401 }, json.loads(stdout.decode('utf-8'))) 453 }, json.loads(stdout.decode('utf-8')))
402 454
403 state = list(self.json_from_files(self.test_state_path, 9)) 455 state = list(self.json_from_files(self.test_state_path, 13))
404 self.assertEqual([ 456 self.check_basic_response(state)
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'])
442 self.assert_args_and_labels([ 457 self.assert_args_and_labels([
443 self.fake_tool_path, 458 self.fake_tool_path,
444 'run', 459 u'run',
445 '--name', 460 u'--name',
446 'db', 461 u'db',
447 '--detach=true', 462 u'--detach=true',
448 '--env-file=env.file', 463 u'--env-file=env.file',
449 '--env=foo=bar', 464 u'--env=foo=bar',
450 '--privileged=false', 465 u'--privileged=false',
451 'xxx' 466 u'xxx'
452 '' 467 u''
453 ], [ 468 ], [
454 'deploy_stack_id=the_stack', 469 u'deploy_stack_id=the_stack',
455 'deploy_resource_name=the_deployment', 470 u'deploy_resource_name=the_deployment',
456 'config_id=abc123', 471 u'config_id=abc123',
457 'container_name=db', 472 u'container_name=db',
458 'managed_by=docker-cmd', 473 u'managed_by=docker-cmd',
459 ], state[4]['args']) 474 ], state[8]['args'])
460 self.assertEqual([ 475 self.assertEqual([
461 self.fake_tool_path, 476 self.fake_tool_path,
462 'inspect', 477 u'inspect',
463 '--format', 478 u'--type',
464 'exists', 479 u'container',
465 'web', 480 u'--format',
466 ], state[5]['args']) 481 u'exists',
482 u'web',
483 ], state[9]['args'])
467 self.assert_args_and_labels([ 484 self.assert_args_and_labels([
468 self.fake_tool_path, 485 self.fake_tool_path,
469 'run', 486 u'run',
470 '--name', 487 u'--name',
471 'web', 488 u'web',
472 '--detach=true', 489 u'--detach=true',
473 '--env-file=foo.env', 490 u'--env-file=foo.env',
474 '--env-file=bar.conf', 491 u'--env-file=bar.conf',
475 '--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS', 492 u'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
476 '--env=FOO=BAR', 493 u'--env=FOO=BAR',
477 '--net=host', 494 u'--net=host',
478 '--privileged=true', 495 u'--privileged=true',
479 '--restart=always', 496 u'--restart=always',
480 '--user=root', 497 u'--user=root',
481 '--volume=/run:/run', 498 u'--volume=/run:/run',
482 '--volume=db:/var/lib/db', 499 u'--volume=db:/var/lib/db',
483 'yyy', 500 u'yyy',
484 '/bin/webserver', 501 u'/bin/webserver',
485 'start' 502 u'start'
486 ], [ 503 ], [
487 'deploy_stack_id=the_stack', 504 u'deploy_stack_id=the_stack',
488 'deploy_resource_name=the_deployment', 505 u'deploy_resource_name=the_deployment',
489 'config_id=abc123', 506 u'config_id=abc123',
490 'container_name=web', 507 u'container_name=web',
491 'managed_by=docker-cmd', 508 u'managed_by=docker-cmd',
492 ], state[6]['args']) 509 ], state[10]['args'])
493 self.assertEqual([ 510 self.assertEqual([
494 self.fake_tool_path, 511 self.fake_tool_path,
495 'ps', 512 u'ps',
496 '-a', 513 u'-a',
497 '--filter', 514 u'--filter',
498 'label=container_name=web', 515 u'label=container_name=web',
499 '--filter', 516 u'--filter',
500 'label=config_id=abc123', 517 u'label=config_id=abc123',
501 '--format', 518 u'--format',
502 '{{.Names}}', 519 u'{{.Names}}',
503 ], state[7]['args']) 520 ], state[11]['args'])
504 self.assertEqual([ 521 self.assertEqual([
505 self.fake_tool_path, 522 self.fake_tool_path,
506 'exec', 523 u'exec',
507 'web', 524 u'web',
508 '/bin/ls', 525 u'/bin/ls',
509 '-l' 526 u'-l'
510 ], state[8]['args']) 527 ], state[12]['args'])
511 528
512 def test_hook_unique_names(self): 529 def test_hook_unique_names(self):
513 self.env.update({ 530 self.env.update({
514 'TEST_RESPONSE': json.dumps([ 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 # ps for delete missing in this config id 540 # ps for delete missing in this config id
516 {}, 541 {},
517 # ps for renames 542 # ps for renames
@@ -546,139 +571,104 @@ class HookDockerCmdTest(common.RunScriptTest):
546 571
547 self.assertEqual(0, returncode, stderr) 572 self.assertEqual(0, returncode, stderr)
548 573
549 self.assertEqual({ 574 state = list(self.json_from_files(self.test_state_path, 15))
550 'deploy_stdout': '', 575 dd = []
551 'deploy_stderr': 'Creating db...\n' 576 for i in state:
552 'Creating web...\n' 577 dd.append(i['args'])
553 'one.txt\ntwo.txt\nthree.txt',
554 'deploy_status_code': 0
555 }, json.loads(stdout.decode('utf-8')))
556 578
557 state = list(self.json_from_files(self.test_state_path, 11)) 579 db_container_name = state[8]['args'][6]
558 db_container_name = state[4]['args'][4] 580 web_container_name = state[11]['args'][6]
559 web_container_name = state[7]['args'][4]
560 self.assertRegex(db_container_name, 'db-[0-9a-z]{8}') 581 self.assertRegex(db_container_name, 'db-[0-9a-z]{8}')
561 self.assertRegex(web_container_name, 'web-[0-9a-z]{8}') 582 self.assertRegex(web_container_name, 'web-[0-9a-z]{8}')
583 self.check_basic_response(state)
562 self.assertEqual([ 584 self.assertEqual([
563 self.fake_tool_path, 585 self.fake_tool_path,
564 'ps', 586 u'inspect',
565 '-a', 587 u'--type',
566 '--filter', 588 u'container',
567 'label=managed_by=docker-cmd', 589 u'--format',
568 '--filter', 590 u'exists',
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',
605 db_container_name, 591 db_container_name,
606 ], state[4]['args']) 592 ], state[8]['args'])
607 self.assert_args_and_labels([ 593 self.assert_args_and_labels([
608 self.fake_tool_path, 594 self.fake_tool_path,
609 'run', 595 u'run',
610 '--name', 596 u'--name',
611 db_container_name, 597 db_container_name,
612 '--detach=true', 598 u'--detach=true',
613 '--env-file=env.file', 599 u'--env-file=env.file',
614 '--env=foo=bar', 600 u'--env=foo=bar',
615 '--privileged=false', 601 u'--privileged=false',
616 'xxx' 602 u'xxx'
617 ], [ 603 ], [
618 'deploy_stack_id=the_stack', 604 u'deploy_stack_id=the_stack',
619 'deploy_resource_name=the_deployment', 605 u'deploy_resource_name=the_deployment',
620 'config_id=abc123', 606 u'config_id=abc123',
621 'container_name=db', 607 u'container_name=db',
622 'managed_by=docker-cmd', 608 u'managed_by=docker-cmd',
623 ], state[5]['args']) 609 ], state[9]['args'])
624 self.assertEqual([ 610 self.assertEqual([
625 self.fake_tool_path, 611 self.fake_tool_path,
626 'inspect', 612 u'inspect',
627 '--format', 613 u'--type',
628 'exists', 614 u'container',
629 'web', 615 u'--format',
630 ], state[6]['args']) 616 u'exists',
617 u'web',
618 ], state[10]['args'])
631 self.assertEqual([ 619 self.assertEqual([
632 self.fake_tool_path, 620 self.fake_tool_path,
633 'inspect', 621 u'inspect',
634 '--format', 622 u'--type',
635 'exists', 623 u'container',
624 u'--format',
625 u'exists',
636 web_container_name, 626 web_container_name,
637 ], state[7]['args']) 627 ], state[11]['args'])
638 self.assert_args_and_labels([ 628 self.assert_args_and_labels([
639 self.fake_tool_path, 629 self.fake_tool_path,
640 'run', 630 u'run',
641 '--name', 631 u'--name',
642 web_container_name, 632 web_container_name,
643 '--detach=true', 633 u'--detach=true',
644 '--env-file=foo.env', 634 u'--env-file=foo.env',
645 '--env-file=bar.conf', 635 u'--env-file=bar.conf',
646 '--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS', 636 u'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
647 '--env=FOO=BAR', 637 u'--env=FOO=BAR',
648 '--net=host', 638 u'--net=host',
649 '--privileged=true', 639 u'--privileged=true',
650 '--restart=always', 640 u'--restart=always',
651 '--user=root', 641 u'--user=root',
652 '--volume=/run:/run', 642 u'--volume=/run:/run',
653 '--volume=db:/var/lib/db', 643 u'--volume=db:/var/lib/db',
654 'yyy', 644 u'yyy',
655 '/bin/webserver', 645 u'/bin/webserver',
656 'start' 646 u'start'
657 ], [ 647 ], [
658 'deploy_stack_id=the_stack', 648 u'deploy_stack_id=the_stack',
659 'deploy_resource_name=the_deployment', 649 u'deploy_resource_name=the_deployment',
660 'config_id=abc123', 650 u'config_id=abc123',
661 'container_name=web', 651 u'container_name=web',
662 'managed_by=docker-cmd', 652 u'managed_by=docker-cmd',
663 ], state[8]['args']) 653 ], state[12]['args'])
664 self.assertEqual([ 654 self.assertEqual([
665 self.fake_tool_path, 655 self.fake_tool_path,
666 'ps', 656 u'ps',
667 '-a', 657 u'-a',
668 '--filter', 658 u'--filter',
669 'label=container_name=web', 659 u'label=container_name=web',
670 '--filter', 660 u'--filter',
671 'label=config_id=abc123', 661 u'label=config_id=abc123',
672 '--format', 662 u'--format',
673 '{{.Names}}', 663 u'{{.Names}}',
674 ], state[9]['args']) 664 ], state[13]['args'])
675 self.assertEqual([ 665 self.assertEqual([
676 self.fake_tool_path, 666 self.fake_tool_path,
677 'exec', 667 u'exec',
678 'web-asdf1234', 668 u'web-asdf1234',
679 '/bin/ls', 669 u'/bin/ls',
680 '-l' 670 u'-l'
681 ], state[10]['args']) 671 ], state[14]['args'])
682 672
683 def test_cleanup_deleted(self): 673 def test_cleanup_deleted(self):
684 self.env.update({ 674 self.env.update({