Merge "Remove dependencies on kazoo and friends"
This commit is contained in:
commit
86a99c4634
@ -155,9 +155,6 @@ RUN yum -y install \
|
|||||||
sudo \
|
sudo \
|
||||||
which \
|
which \
|
||||||
python \
|
python \
|
||||||
python-jinja2 \
|
|
||||||
python-kazoo \
|
|
||||||
python-six \
|
|
||||||
lvm2 \
|
lvm2 \
|
||||||
scsi-target-utils \
|
scsi-target-utils \
|
||||||
iscsi-initiator-utils \
|
iscsi-initiator-utils \
|
||||||
@ -171,9 +168,6 @@ RUN yum -y install \
|
|||||||
# Update packages
|
# Update packages
|
||||||
RUN yum -y install \
|
RUN yum -y install \
|
||||||
curl \
|
curl \
|
||||||
python-jinja2 \
|
|
||||||
python-kazoo \
|
|
||||||
python-six \
|
|
||||||
sudo \
|
sudo \
|
||||||
tar \
|
tar \
|
||||||
which \
|
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 \
|
&& apt-get install -y --no-install-recommends \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
python \
|
python \
|
||||||
python-jinja2 \
|
|
||||||
python-kazoo \
|
|
||||||
python-six \
|
|
||||||
curl \
|
curl \
|
||||||
open-iscsi \
|
open-iscsi \
|
||||||
tgt \
|
tgt \
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import contextlib
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -21,10 +20,6 @@ import pwd
|
|||||||
import shutil
|
import shutil
|
||||||
import sys
|
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.
|
# TODO(rhallisey): add docstring.
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
@ -50,10 +45,6 @@ def validate_config(config):
|
|||||||
def validate_source(data):
|
def validate_source(data):
|
||||||
source = data.get('source')
|
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 not exists:
|
||||||
@ -67,61 +58,6 @@ def validate_source(data):
|
|||||||
return True
|
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):
|
def copy_files(data):
|
||||||
dest = data.get('dest')
|
dest = data.get('dest')
|
||||||
source = data.get('source')
|
source = data.get('source')
|
||||||
@ -133,11 +69,6 @@ def copy_files(data):
|
|||||||
else:
|
else:
|
||||||
os.remove(dest)
|
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):
|
if os.path.isdir(source):
|
||||||
source_path = source
|
source_path = source
|
||||||
dest_path = dest
|
dest_path = dest
|
||||||
|
@ -14,8 +14,7 @@ RUN yum -y install \
|
|||||||
openssl-devel \
|
openssl-devel \
|
||||||
python-devel \
|
python-devel \
|
||||||
openssh-clients \
|
openssh-clients \
|
||||||
&& yum clean all \
|
&& yum clean all
|
||||||
&& rpm -e --nodeps pytz
|
|
||||||
|
|
||||||
{% elif base_distro in ['ubuntu', 'debian'] %}
|
{% elif base_distro in ['ubuntu', 'debian'] %}
|
||||||
|
|
||||||
|
@ -15,11 +15,8 @@ import json
|
|||||||
import mock
|
import mock
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
|
|
||||||
from oslotest import base
|
from oslotest import base
|
||||||
import testscenarios
|
|
||||||
from zake import fake_client
|
|
||||||
|
|
||||||
# nasty: to import set_config (not a part of the kolla package)
|
# nasty: to import set_config (not a part of the kolla package)
|
||||||
this_dir = os.path.dirname(sys.modules[__name__].__file__)
|
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().write(u'/bin/true'),
|
||||||
mock.call().__exit__(None, None, None)],
|
mock.call().__exit__(None, None, None)],
|
||||||
mo.mock_calls)
|
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'))
|
|
||||||
|
Loading…
Reference in New Issue
Block a user