test_dockermod.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # -*- coding: utf-8 -*-
  2. """
  3. Integration tests for the docker_container states
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import random
  7. import string
  8. import sys
  9. import salt.utils.path
  10. from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
  11. from tests.support.case import ModuleCase
  12. from tests.support.helpers import destructiveTest, slowTest
  13. from tests.support.mixins import SaltReturnAssertsMixin
  14. # Import Salt Testing Libs
  15. from tests.support.unit import skipIf
  16. def _random_name(prefix=""):
  17. ret = prefix
  18. for _ in range(8):
  19. ret += random.choice(string.ascii_lowercase)
  20. return ret
  21. @destructiveTest
  22. @skipIf(not salt.utils.path.which("dockerd"), "Docker not installed")
  23. class DockerCallTestCase(ModuleCase, SaltReturnAssertsMixin):
  24. """
  25. Test docker_container states
  26. """
  27. def setUp(self):
  28. """
  29. setup docker.call tests
  30. """
  31. # Create temp dir
  32. self.random_name = _random_name(prefix="salt_test_")
  33. self.image_tag = sys.version_info[0]
  34. self.run_state("docker_image.present", tag=self.image_tag, name="python")
  35. self.run_state(
  36. "docker_container.running",
  37. name=self.random_name,
  38. image="python:{0}".format(self.image_tag),
  39. entrypoint="tail -f /dev/null",
  40. )
  41. def tearDown(self):
  42. """
  43. teardown docker.call tests
  44. """
  45. self.run_state("docker_container.absent", name=self.random_name, force=True)
  46. self.run_state(
  47. "docker_image.absent",
  48. images=["python:{0}".format(self.image_tag)],
  49. force=True,
  50. )
  51. delattr(self, "random_name")
  52. delattr(self, "image_tag")
  53. @slowTest
  54. def test_docker_call(self):
  55. """
  56. check that docker.call works, and works with a container not running as root
  57. """
  58. ret = self.run_function("docker.call", [self.random_name, "test.ping"])
  59. assert ret is True
  60. @slowTest
  61. def test_docker_sls(self):
  62. """
  63. check that docker.sls works, and works with a container not running as root
  64. """
  65. ret = self.run_function("docker.apply", [self.random_name, "core"])
  66. self.assertSaltTrueReturn(ret)
  67. @slowTest
  68. def test_docker_highstate(self):
  69. """
  70. check that docker.highstate works, and works with a container not running as root
  71. """
  72. ret = self.run_function("docker.apply", [self.random_name])
  73. self.assertSaltTrueReturn(ret)