mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
3273bbdab7
Conflicts: - doc/ref/configuration/master.rst - doc/ref/modules/all/index.rst - doc/topics/grains/index.rst - doc/topics/releases/2016.3.4.rst - doc/topics/spm/spm_formula.rst - doc/topics/tutorials/cron.rst - doc/topics/tutorials/index.rst - doc/topics/tutorials/stormpath.rst - salt/engines/slack.py - salt/log/handlers/fluent_mod.py - salt/modules/cyg.py - salt/modules/junos.py - salt/modules/namecheap_dns.py - salt/modules/namecheap_domains.py - salt/modules/namecheap_ns.py - salt/modules/namecheap_ssl.py - salt/modules/namecheap_users.py - salt/modules/reg.py - salt/modules/tomcat.py - salt/modules/vault.py - salt/modules/win_file.py - salt/modules/zpool.py - salt/output/highstate.py - salt/renderers/pass.py - salt/runners/cache.py - salt/states/boto_apigateway.py - salt/states/boto_iam.py - salt/states/boto_route53.py - salt/states/msteams.py - salt/states/reg.py - salt/states/win_iis.py - tests/integration/modules/test_cmdmod.py - tests/integration/states/test_user.py - tests/support/helpers.py - tests/unit/cloud/clouds/test_openstack.py - tests/unit/fileserver/test_gitfs.py - tests/unit/modules/test_junos.py - tests/unit/pillar/test_git.py - tests/unit/states/test_win_path.py - tests/unit/test_pillar.py - tests/unit/utils/test_format_call.py - tests/unit/utils/test_utils.py - tests/unit/utils/test_warnings.py
178 lines
5.8 KiB
Python
178 lines
5.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
'''
|
|
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
|
|
'''
|
|
# Import Python libs
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
# Import Salt Testing Libs
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
|
from tests.support.unit import skipIf, TestCase
|
|
from tests.support.mock import (
|
|
NO_MOCK,
|
|
NO_MOCK_REASON,
|
|
MagicMock,
|
|
patch)
|
|
|
|
# Import Salt Libs
|
|
import salt.modules.smf as smf
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
|
class SmfTestCase(TestCase, LoaderModuleMockMixin):
|
|
'''
|
|
Test cases for salt.modules.smf
|
|
'''
|
|
def setup_loader_modules(self):
|
|
return {smf: {}}
|
|
|
|
def test_get_running(self):
|
|
'''
|
|
Test to return the running services
|
|
'''
|
|
with patch.dict(smf.__salt__, {'cmd.run':
|
|
MagicMock(return_value='A online\n')}):
|
|
self.assertEqual(smf.get_running(), ['A'])
|
|
|
|
def test_get_stopped(self):
|
|
'''
|
|
Test to return the stopped services
|
|
'''
|
|
with patch.dict(smf.__salt__,
|
|
{'cmd.run': MagicMock(return_value='A\n')}):
|
|
self.assertListEqual(smf.get_stopped(), ['A'])
|
|
|
|
def test_available(self):
|
|
'''
|
|
Test to returns ``True`` if the specified service is available,
|
|
otherwise returns ``False``.
|
|
'''
|
|
with patch.dict(smf.__salt__, {'cmd.run': MagicMock(return_value='A')}):
|
|
with patch.object(smf, 'get_all', return_value=('A')):
|
|
self.assertTrue(smf.available('A'))
|
|
|
|
def test_missing(self):
|
|
'''
|
|
The inverse of service.available.
|
|
Returns ``True`` if the specified service is not available, otherwise
|
|
returns ``False``.
|
|
'''
|
|
with patch.dict(smf.__salt__, {'cmd.run': MagicMock(return_value='A')}):
|
|
with patch.object(smf, 'get_all', return_value=('A')):
|
|
self.assertFalse(smf.missing('A'))
|
|
|
|
def test_get_all(self):
|
|
'''
|
|
Test to return all installed services
|
|
'''
|
|
with patch.dict(smf.__salt__,
|
|
{'cmd.run': MagicMock(return_value='A\n')}):
|
|
self.assertListEqual(smf.get_all(), ['A'])
|
|
|
|
def test_start(self):
|
|
'''
|
|
Test to start the specified service
|
|
'''
|
|
with patch.dict(smf.__salt__,
|
|
{'cmd.retcode': MagicMock(side_effect=[False, 3, None,
|
|
False, 4])}):
|
|
self.assertTrue(smf.start('name'))
|
|
|
|
self.assertTrue(smf.start('name'))
|
|
|
|
self.assertFalse(smf.start('name'))
|
|
|
|
def test_stop(self):
|
|
'''
|
|
Test to stop the specified service
|
|
'''
|
|
with patch.dict(smf.__salt__,
|
|
{'cmd.retcode': MagicMock(return_value=False)}):
|
|
self.assertTrue(smf.stop('name'))
|
|
|
|
def test_restart(self):
|
|
'''
|
|
Test to restart the named service
|
|
'''
|
|
with patch.dict(smf.__salt__,
|
|
{'cmd.retcode': MagicMock(side_effect=[False, True])}):
|
|
|
|
with patch.object(smf, 'start', return_value='A'):
|
|
self.assertEqual(smf.restart('name'), 'A')
|
|
|
|
self.assertFalse(smf.restart('name'))
|
|
|
|
def test_reload_(self):
|
|
'''
|
|
Test to reload the named service
|
|
'''
|
|
with patch.dict(smf.__salt__,
|
|
{'cmd.retcode': MagicMock(side_effect=[False, True])}):
|
|
|
|
with patch.object(smf, 'start', return_value='A'):
|
|
self.assertEqual(smf.reload_('name'), 'A')
|
|
|
|
self.assertFalse(smf.reload_('name'))
|
|
|
|
def test_status(self):
|
|
'''
|
|
Test to return the status for a service, returns a bool whether the
|
|
service is running.
|
|
'''
|
|
with patch.dict(smf.__salt__,
|
|
{'cmd.run': MagicMock(side_effect=['online',
|
|
'online1'])}):
|
|
self.assertTrue(smf.status('name'))
|
|
|
|
self.assertFalse(smf.status('name'))
|
|
|
|
def test_enable(self):
|
|
'''
|
|
Test to enable the named service to start at boot
|
|
'''
|
|
with patch.dict(smf.__salt__,
|
|
{'cmd.retcode': MagicMock(return_value=False)}):
|
|
self.assertTrue(smf.enable('name'))
|
|
|
|
def test_disable(self):
|
|
'''
|
|
Test to disable the named service to start at boot
|
|
'''
|
|
with patch.dict(smf.__salt__,
|
|
{'cmd.retcode': MagicMock(return_value=False)}):
|
|
self.assertTrue(smf.disable('name'))
|
|
|
|
def test_enabled(self):
|
|
'''
|
|
Test to check to see if the named service is enabled to start on boot
|
|
'''
|
|
with patch.dict(smf.__salt__,
|
|
{'cmd.run': MagicMock(side_effect=['fmri',
|
|
'A B true',
|
|
'fmri',
|
|
'A B false'])}):
|
|
self.assertTrue(smf.enabled('name'))
|
|
|
|
self.assertFalse(smf.enabled('name'))
|
|
|
|
def test_disabled(self):
|
|
'''
|
|
Test to check to see if the named service is disabled to start on boot
|
|
'''
|
|
with patch.object(smf, 'enabled', return_value=False):
|
|
self.assertTrue(smf.disabled('name'))
|
|
|
|
def test_get_enabled(self):
|
|
'''
|
|
Test to return the enabled services
|
|
'''
|
|
with patch.object(smf, '_get_enabled_disabled', return_value=True):
|
|
self.assertTrue(smf.get_enabled())
|
|
|
|
def test_get_disabled(self):
|
|
'''
|
|
Test to return the disabled services
|
|
'''
|
|
with patch.object(smf, '_get_enabled_disabled', return_value=True):
|
|
self.assertTrue(smf.get_disabled())
|