From 025d57f82005a4ea92950f9b4d717c88f647d15f Mon Sep 17 00:00:00 2001
From: Steven Dake <stdake@cisco.com>
Date: Sun, 1 May 2016 14:00:54 -0400
Subject: [PATCH] Remove dependencies on kazoo and friends

Since kolla-mesos has been retired, there is no need in the code
base to keep the zookeeper implementation.  As a result, just remove
it.  If we were to keep it we need virtualenvs for that part of the
code base which installs the python dependencies related to it
for from-binary installs.

This just simplifies the implementation tremendously and culls dead
code.

Change-Id: Ieda226e652d67f5b5667112f4f2556f3171366d3
Closes-Bug: #1577194
---
 docker/base/Dockerfile.j2          |  9 ----
 docker/base/set_configs.py         | 71 +-----------------------------
 docker/kolla-toolbox/Dockerfile.j2 |  3 +-
 tests/test_set_config.py           | 58 ------------------------
 4 files changed, 2 insertions(+), 139 deletions(-)

diff --git a/docker/base/Dockerfile.j2 b/docker/base/Dockerfile.j2
index ba5759bf65..22181ff9cb 100644
--- a/docker/base/Dockerfile.j2
+++ b/docker/base/Dockerfile.j2
@@ -155,9 +155,6 @@ RUN yum -y install \
         sudo \
         which \
         python \
-        python-jinja2 \
-        python-kazoo \
-        python-six \
         lvm2 \
         scsi-target-utils \
         iscsi-initiator-utils \
@@ -171,9 +168,6 @@ RUN yum -y install \
 # Update packages
 RUN yum -y install \
         curl \
-        python-jinja2 \
-        python-kazoo \
-        python-six \
         sudo \
         tar \
         which \
@@ -207,9 +201,6 @@ RUN apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 199369E540
     && apt-get install -y --no-install-recommends \
         ca-certificates \
         python \
-        python-jinja2 \
-        python-kazoo \
-        python-six \
         curl \
         open-iscsi \
         tgt \
diff --git a/docker/base/set_configs.py b/docker/base/set_configs.py
index dc0a7e4a53..fd22a31558 100644
--- a/docker/base/set_configs.py
+++ b/docker/base/set_configs.py
@@ -13,7 +13,6 @@
 # limitations under the License.
 
 import argparse
-import contextlib
 import json
 import logging
 import os
@@ -21,10 +20,6 @@ import pwd
 import shutil
 import sys
 
-from kazoo import client as kz_client
-from kazoo import exceptions as kz_exceptions
-from six.moves.urllib import parse
-
 
 # TODO(rhallisey): add docstring.
 logging.basicConfig()
@@ -50,11 +45,7 @@ def validate_config(config):
 def validate_source(data):
     source = data.get('source')
 
-    if is_zk_transport(source):
-        with zk_connection(source) as zk:
-            exists = zk_path_exists(zk, source)
-    else:
-        exists = os.path.exists(source)
+    exists = os.path.exists(source)
 
     if not exists:
         if data.get('optional'):
@@ -67,61 +58,6 @@ def validate_source(data):
     return True
 
 
-def is_zk_transport(path):
-    return path.startswith('zk://') or \
-        os.environ.get("KOLLA_ZK_HOSTS") is not None
-
-
-@contextlib.contextmanager
-def zk_connection(url):
-    # support an environment and url
-    # if url, it should be like this:
-    # zk://<address>:<port>/<path>
-
-    zk_hosts = os.environ.get("KOLLA_ZK_HOSTS")
-    if zk_hosts is None:
-        components = parse.urlparse(url)
-        zk_hosts = components.netloc
-    zk = kz_client.KazooClient(hosts=zk_hosts)
-    zk.start()
-    try:
-        yield zk
-    finally:
-        zk.stop()
-
-
-def zk_path_exists(zk, path):
-    try:
-        components = parse.urlparse(path)
-        zk.get(components.path)
-        return True
-    except kz_exceptions.NoNodeError:
-        return False
-
-
-def zk_copy_tree(zk, src, dest):
-    """Recursively copy contents of url_source into dest."""
-    data, stat = zk.get(src)
-
-    if data:
-        dest_path = os.path.dirname(dest)
-        if not os.path.exists(dest_path):
-            LOG.info("Creating dest parent directory: %s", dest_path)
-            os.makedirs(dest_path)
-
-        LOG.info("Copying %s to %s", src, dest)
-        with open(dest, 'w') as df:
-            df.write(data.decode("utf-8"))
-
-    try:
-        children = zk.get_children(src)
-    except kz_exceptions.NoNodeError:
-        return
-    for child in children:
-        zk_copy_tree(zk, os.path.join(src, child),
-                     os.path.join(dest, child))
-
-
 def copy_files(data):
     dest = data.get('dest')
     source = data.get('source')
@@ -133,11 +69,6 @@ def copy_files(data):
         else:
             os.remove(dest)
 
-    if is_zk_transport(source):
-        with zk_connection(source) as zk:
-            components = parse.urlparse(source)
-            return zk_copy_tree(zk, components.path, dest)
-
     if os.path.isdir(source):
         source_path = source
         dest_path = dest
diff --git a/docker/kolla-toolbox/Dockerfile.j2 b/docker/kolla-toolbox/Dockerfile.j2
index 8916bdc333..c206610b28 100644
--- a/docker/kolla-toolbox/Dockerfile.j2
+++ b/docker/kolla-toolbox/Dockerfile.j2
@@ -14,8 +14,7 @@ RUN yum -y install \
         openssl-devel \
         python-devel \
         openssh-clients \
-    && yum clean all \
-    && rpm -e --nodeps pytz
+    && yum clean all
 
 {% elif base_distro in ['ubuntu', 'debian'] %}
 
diff --git a/tests/test_set_config.py b/tests/test_set_config.py
index 03975d1568..3e946c7979 100644
--- a/tests/test_set_config.py
+++ b/tests/test_set_config.py
@@ -15,11 +15,8 @@ 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__)
@@ -67,58 +64,3 @@ 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, b'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', b'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', b'one', makepath=True)
-        self.assertTrue(set_configs.zk_path_exists(self.client,
-                                                   '/test/path/thing'))