kolla/tests/test_set_config.py
Steven Dake 025d57f820 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
2016-05-02 06:12:50 -07:00

67 lines
2.5 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import imp
import json
import mock
import os.path
import sys
from oslotest import base
# nasty: to import set_config (not a part of the kolla package)
this_dir = os.path.dirname(sys.modules[__name__].__file__)
set_configs_file = os.path.abspath(
os.path.join(this_dir, '..',
'docker', 'base', 'set_configs.py'))
set_configs = imp.load_source('set_configs', set_configs_file)
class LoadFromFile(base.BaseTestCase):
def test_load_ok(self):
in_config = json.dumps({'command': '/bin/true',
'config_files': {}})
mo = mock.mock_open(read_data=in_config)
with mock.patch.object(set_configs, 'open', mo):
config = set_configs.load_config()
set_configs.copy_config(config)
self.assertEqual([
mock.call('/var/lib/kolla/config_files/config.json'),
mock.call().__enter__(),
mock.call().read(),
mock.call().__exit__(None, None, None),
mock.call('/run_command', 'w+'),
mock.call().__enter__(),
mock.call().write(u'/bin/true'),
mock.call().__exit__(None, None, None)], mo.mock_calls)
class LoadFromEnv(base.BaseTestCase):
def test_load_ok(self):
in_config = json.dumps({'command': '/bin/true',
'config_files': {}})
mo = mock.mock_open()
with mock.patch.object(set_configs, 'open', mo):
with mock.patch.dict('os.environ', {'KOLLA_CONFIG': in_config}):
config = set_configs.load_config()
set_configs.copy_config(config)
self.assertEqual([mock.call('/run_command', 'w+'),
mock.call().__enter__(),
mock.call().write(u'/bin/true'),
mock.call().__exit__(None, None, None)],
mo.mock_calls)