salt/tests/unit/conf_test.py
Nicole Thomas 7cdbc546f1 Back-port #36062 to 2015.8 (#36118)
* Comment all lines in the minion config file

* Add unit tests to check for all files in conf/ to be commented out

* Make sure cont/cloud.profiles file is commented out

Matches the cloud.providers file format and other sample config files.

* Add unit tests for sample files in cloud.profiles.d, cloud.providers.d,
and cloud.maps.d

* Make sure all sample config files in cloud.maps.d are commented out

* Make sure all sample config files in cloud.profiles.d are commented out
2016-09-07 16:01:34 -06:00

195 lines
6.8 KiB
Python

# -*- coding: utf-8 -*-
'''
Unit tests for the files in the salt/conf directory.
'''
# Import Python libs
from __future__ import absolute_import
import os
# Import Salt Testing libs
from salttesting import skipIf, TestCase
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import (
NO_MOCK,
NO_MOCK_REASON,
)
ensure_in_syspath('../')
# Import Salt libs
import salt.config
SAMPLE_CONF_DIR = os.path.dirname(os.path.realpath(__file__)).split('tests')[0] + 'conf/'
@skipIf(NO_MOCK, NO_MOCK_REASON)
class ConfTest(TestCase):
'''
Validate files in the salt/conf directory.
'''
def test_conf_master_sample_is_commented(self):
'''
The sample config file located in salt/conf/master must be completely
commented out. This test checks for any lines that are not commented or blank.
'''
master_config = SAMPLE_CONF_DIR + 'master'
ret = salt.config._read_conf_file(master_config)
self.assertEqual(
ret,
{},
'Sample config file \'{0}\' must be commented out.'.format(
master_config
)
)
def test_conf_minion_sample_is_commented(self):
'''
The sample config file located in salt/conf/minion must be completely
commented out. This test checks for any lines that are not commented or blank.
'''
minion_config = SAMPLE_CONF_DIR + 'minion'
ret = salt.config._read_conf_file(minion_config)
self.assertEqual(
ret,
{},
'Sample config file \'{0}\' must be commented out.'.format(
minion_config
)
)
def test_conf_cloud_sample_is_commented(self):
'''
The sample config file located in salt/conf/cloud must be completely
commented out. This test checks for any lines that are not commented or blank.
'''
cloud_config = SAMPLE_CONF_DIR + 'cloud'
ret = salt.config._read_conf_file(cloud_config)
self.assertEqual(
ret,
{},
'Sample config file \'{0}\' must be commented out.'.format(
cloud_config
)
)
def test_conf_cloud_profiles_sample_is_commented(self):
'''
The sample config file located in salt/conf/cloud.profiles must be completely
commented out. This test checks for any lines that are not commented or blank.
'''
cloud_profiles_config = SAMPLE_CONF_DIR + 'cloud.profiles'
ret = salt.config._read_conf_file(cloud_profiles_config)
self.assertEqual(
ret,
{},
'Sample config file \'{0}\' must be commented out.'.format(
cloud_profiles_config
)
)
def test_conf_cloud_providers_sample_is_commented(self):
'''
The sample config file located in salt/conf/cloud.providers must be completely
commented out. This test checks for any lines that are not commented or blank.
'''
cloud_providers_config = SAMPLE_CONF_DIR + 'cloud.providers'
ret = salt.config._read_conf_file(cloud_providers_config)
self.assertEqual(
ret,
{},
'Sample config file \'{0}\' must be commented out.'.format(
cloud_providers_config
)
)
def test_conf_proxy_sample_is_commented(self):
'''
The sample config file located in salt/conf/proxy must be completely
commented out. This test checks for any lines that are not commented or blank.
'''
proxy_config = SAMPLE_CONF_DIR + 'proxy'
ret = salt.config._read_conf_file(proxy_config)
self.assertEqual(
ret,
{},
'Sample config file \'{0}\' must be commented out.'.format(
proxy_config
)
)
def test_conf_roster_sample_is_commented(self):
'''
The sample config file located in salt/conf/roster must be completely
commented out. This test checks for any lines that are not commented or blank.
'''
roster_config = SAMPLE_CONF_DIR + 'roster'
ret = salt.config._read_conf_file(roster_config)
self.assertEqual(
ret,
{},
'Sample config file \'{0}\' must be commented out.'.format(
roster_config
)
)
def test_conf_cloud_profiles_d_files_are_commented(self):
'''
All cloud profile sample configs in salt/conf/cloud.profiles.d/* must be completely
commented out. This test loops through all of the files in that directory to check
for any lines that are not commented or blank.
'''
cloud_sample_files = os.listdir(SAMPLE_CONF_DIR + 'cloud.profiles.d/')
for conf_file in cloud_sample_files:
profile_conf = SAMPLE_CONF_DIR + 'cloud.profiles.d/' + conf_file
ret = salt.config._read_conf_file(profile_conf)
self.assertEqual(
ret,
{},
'Sample config file \'{0}\' must be commented out.'.format(
conf_file
)
)
def test_conf_cloud_providers_d_files_are_commented(self):
'''
All cloud profile sample configs in salt/conf/cloud.providers.d/* must be completely
commented out. This test loops through all of the files in that directory to check
for any lines that are not commented or blank.
'''
cloud_sample_files = os.listdir(SAMPLE_CONF_DIR + 'cloud.providers.d/')
for conf_file in cloud_sample_files:
provider_conf = SAMPLE_CONF_DIR + 'cloud.providers.d/' + conf_file
ret = salt.config._read_conf_file(provider_conf)
self.assertEqual(
ret,
{},
'Sample config file \'{0}\' must be commented out.'.format(
conf_file
)
)
def test_conf_cloud_maps_d_files_are_commented(self):
'''
All cloud profile sample configs in salt/conf/cloud.maps.d/* must be completely
commented out. This test loops through all of the files in that directory to check
for any lines that are not commented or blank.
'''
cloud_sample_files = os.listdir(SAMPLE_CONF_DIR + 'cloud.maps.d/')
for conf_file in cloud_sample_files:
map_conf = SAMPLE_CONF_DIR + 'cloud.maps.d/' + conf_file
ret = salt.config._read_conf_file(map_conf)
self.assertEqual(
ret,
{},
'Sample config file \'{0}\' must be commented out.'.format(
conf_file
)
)
if __name__ == '__main__':
from integration import run_tests
run_tests(ConfTest, needs_daemon=False)