diff options
| author | Angus Salkeld <asalkeld@mirantis.com> | 2015-11-19 15:35:22 +1000 |
|---|---|---|
| committer | Michal Rostecki <mrostecki@mirantis.com> | 2015-12-02 10:25:43 +0100 |
| commit | 27c0ae06241e18f6639311aba65657b4ef83cf26 (patch) | |
| tree | 9194e563eeb658eb1c05b7373394fa7a7f0eb182 /tests/test_set_config.py | |
| parent | 917b4df01ea342b4bb43d12399322caab53d482a (diff) | |
| download | kolla-27c0ae06241e18f6639311aba65657b4ef83cf26.tar.gz kolla-27c0ae06241e18f6639311aba65657b4ef83cf26.zip | |
Add support for copying files from a "zk://" source
Co-Authored-By: Michal Rostecki <mrostecki@mirantis.com>
Implements: blueprint zookeeper
Change-Id: I176f063d3802716846b921e210c1569d28bd90d8
Diffstat (limited to 'tests/test_set_config.py')
| -rw-r--r-- | tests/test_set_config.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/test_set_config.py b/tests/test_set_config.py index 1e8ac9ce6..7092895c5 100644 --- a/tests/test_set_config.py +++ b/tests/test_set_config.py @@ -15,8 +15,11 @@ import json import mock import os.path import sys +import tempfile from oslotest import base +import testscenarios +from zake import fake_client # nasty: to import set_config (not a part of the kolla package) this_dir = os.path.dirname(sys.modules[__name__].__file__) @@ -62,3 +65,58 @@ class LoadFromEnv(base.BaseTestCase): mock.call().write(u'/bin/true'), mock.call().__exit__(None, None, None)], mo.mock_calls) + + +class ZkCopyTest(testscenarios.WithScenarios, base.BaseTestCase): + + scenarios = [ + ('1', dict(in_paths=['a.conf'], + in_subtree='/', + expect_paths=[['a.conf']])), + ('2', dict(in_paths=['/a/b/c.x', '/a/b/foo.x', '/a/no.x'], + in_subtree='/a/b', + expect_paths=[['c.x'], ['foo.x']])), + ('3', dict(in_paths=['/a/b/c.x', '/a/z/foo.x'], + in_subtree='/', + expect_paths=[['a', 'b', 'c.x'], ['a', 'z', 'foo.x']])), + ] + + def setUp(self): + super(ZkCopyTest, self).setUp() + self.client = fake_client.FakeClient() + self.client.start() + self.addCleanup(self.client.stop) + self.addCleanup(self.client.close) + + def test_cp_tree(self): + # Note: oslotest.base cleans up all tempfiles as follows: + # self.useFixture(fixtures.NestedTempfile()) + # so we don't have to. + temp_dir = tempfile.mkdtemp() + + for path in self.in_paths: + self.client.create(path, 'one', makepath=True) + set_configs.zk_copy_tree(self.client, self.in_subtree, temp_dir) + for expect in self.expect_paths: + expect.insert(0, temp_dir) + expect_path = os.path.join(*expect) + self.assertTrue(os.path.exists(expect_path)) + + +class ZkExistsTest(base.BaseTestCase): + def setUp(self): + super(ZkExistsTest, self).setUp() + self.client = fake_client.FakeClient() + self.client.start() + self.addCleanup(self.client.stop) + self.addCleanup(self.client.close) + + def test_path_exists_no(self): + self.client.create('/test/path/thing', 'one', makepath=True) + self.assertFalse(set_configs.zk_path_exists(self.client, + '/test/missing/thing')) + + def test_path_exists_yes(self): + self.client.create('/test/path/thing', 'one', makepath=True) + self.assertTrue(set_configs.zk_path_exists(self.client, + '/test/path/thing')) |
