kolla-ansible/tests/test_set_config.py
Angus Salkeld 1af722eb49 Add a test case for load_config
This is just a basic test to make sure loading from file works.

Change-Id: I074f36023ac4198c436fcee1668d32f9d1f0e61b
2015-11-10 13:37:51 +10:00

48 lines
1.7 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):
set_configs.load_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)