test_etcd_db.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. """
  2. Integration tests for the etcd modules
  3. """
  4. import inspect
  5. import logging
  6. import salt.utils.path
  7. from tests.support.case import ModuleCase, ShellCase
  8. from tests.support.helpers import slowTest
  9. from tests.support.unit import skipIf
  10. log = logging.getLogger(__name__)
  11. @skipIf(not salt.utils.path.which("dockerd"), "Docker not installed")
  12. class EtcdTestCase(ModuleCase, ShellCase):
  13. """
  14. Test etcd module
  15. """
  16. count = 0
  17. def setUp(self):
  18. """
  19. SetUp etcd container
  20. """
  21. if EtcdTestCase.count == 0:
  22. self.run_state("docker_image.present", name="bitnami/etcd", tag="latest")
  23. self.run_state(
  24. "docker_container.running",
  25. name="etcd",
  26. image="bitnami/etcd:latest",
  27. port_bindings="2379:2379",
  28. environment={
  29. "ALLOW_NONE_AUTHENTICATION": "yes",
  30. "ETCD_ENABLE_V2": "true",
  31. },
  32. cap_add="IPC_LOCK",
  33. )
  34. EtcdTestCase.count += 1
  35. def tearDown(self):
  36. """
  37. TearDown etcd container
  38. """
  39. def count_tests(funcobj):
  40. return (
  41. inspect.ismethod(funcobj)
  42. or inspect.isfunction(funcobj)
  43. and funcobj.__name__.startswith("test_")
  44. )
  45. numtests = len(inspect.getmembers(EtcdTestCase, predicate=count_tests))
  46. if EtcdTestCase.count >= numtests:
  47. self.run_state("docker_container.stopped", name="etcd")
  48. self.run_state("docker_container.absent", name="etcd")
  49. self.run_state("docker_image.absent", name="bitnami/etcd", force=True)
  50. @slowTest
  51. def test_sdb(self):
  52. set_output = self.run_function(
  53. "sdb.set", uri="sdb://sdbetcd/secret/test/test_sdb/foo", value="bar"
  54. )
  55. self.assertEqual(set_output, "bar")
  56. get_output = self.run_function(
  57. "sdb.get", arg=["sdb://sdbetcd/secret/test/test_sdb/foo"]
  58. )
  59. self.assertEqual(get_output, "bar")
  60. @slowTest
  61. def test_sdb_runner(self):
  62. set_output = self.run_run(
  63. "sdb.set sdb://sdbetcd/secret/test/test_sdb_runner/foo bar"
  64. )
  65. self.assertEqual(set_output, ["bar"])
  66. get_output = self.run_run(
  67. "sdb.get sdb://sdbetcd/secret/test/test_sdb_runner/foo"
  68. )
  69. self.assertEqual(get_output, ["bar"])
  70. @slowTest
  71. def test_config(self):
  72. set_output = self.run_function(
  73. "sdb.set", uri="sdb://sdbetcd/secret/test/test_pillar_sdb/foo", value="bar"
  74. )
  75. self.assertEqual(set_output, "bar")
  76. get_output = self.run_function("config.get", arg=["test_etcd_pillar_sdb"])
  77. self.assertEqual(get_output, "bar")