コード例 #1
0
    def test_get_enabled(self):
        '''
            Test to return a list of all enabled services
        '''
        def sysv(name):
            if name in ['d', 'e']:
                return True
            return False

        def sysve(name):
            if name in ['e']:
                return True
            return False

        mock = MagicMock(return_value={"a": "enabled", "b": "enabled",
                                       "c": "disabled"})
        lmock = MagicMock(return_value={"d": "disabled",
                                        "a": "disabled",
                                        "b": "disabled",
                                        "e": "disabled"})
        with patch.object(systemd, "_sysv_is_disabled", sysve):
            with patch.object(systemd, "_service_is_sysv", sysv):
                with patch.object(systemd, '_get_all_unit_files', mock):
                    with patch.object(systemd, '_get_all_units', lmock):
                        self.assertListEqual(
                            systemd.get_enabled(), ["a", "b", "d"])
コード例 #2
0
ファイル: systemd_test.py プロジェクト: bryson/salt
    def test_get_enabled(self):
        '''
        Test to return a list of all enabled services
        '''
        cmd_mock = MagicMock(return_value=_LIST_UNIT_FILES)
        listdir_mock = MagicMock(return_value=['foo', 'bar', 'baz', 'README'])
        sd_mock = MagicMock(
            return_value=set(
                [x.replace('.service', '') for x in _SYSTEMCTL_STATUS]
            )
        )
        access_mock = MagicMock(
            side_effect=lambda x, y: x != os.path.join(
                systemd.INITSCRIPT_PATH,
                'README'
            )
        )
        sysv_enabled_mock = MagicMock(side_effect=lambda x: x == 'baz')

        with patch.dict(systemd.__salt__, {'cmd.run': cmd_mock}):
            with patch.object(os, 'listdir', listdir_mock):
                with patch.object(systemd, '_get_systemd_services', sd_mock):
                    with patch.object(os, 'access', side_effect=access_mock):
                        with patch.object(systemd, '_sysv_enabled',
                                          sysv_enabled_mock):
                            self.assertListEqual(
                                systemd.get_enabled(),
                                ['baz', 'service1', 'timer1.timer']
                            )
コード例 #3
0
ファイル: test_systemd.py プロジェクト: jgleissner/salt-2
    def test_get_enabled(self):
        '''
        Test to return a list of all enabled services
        '''
        cmd_mock = MagicMock(return_value=_LIST_UNIT_FILES)
        listdir_mock = MagicMock(return_value=['foo', 'bar', 'baz', 'README'])
        sd_mock = MagicMock(
            return_value=set(
                [x.replace('.service', '') for x in _SYSTEMCTL_STATUS]
            )
        )
        access_mock = MagicMock(
            side_effect=lambda x, y: x != os.path.join(
                systemd.INITSCRIPT_PATH,
                'README'
            )
        )
        sysv_enabled_mock = MagicMock(side_effect=lambda x: x == 'baz')

        with patch.dict(systemd.__salt__, {'cmd.run': cmd_mock}):
            with patch.object(os, 'listdir', listdir_mock):
                with patch.object(systemd, '_get_systemd_services', sd_mock):
                    with patch.object(os, 'access', side_effect=access_mock):
                        with patch.object(systemd, '_sysv_enabled',
                                          sysv_enabled_mock):
                            self.assertListEqual(
                                systemd.get_enabled(),
                                ['baz', 'service1', 'timer1.timer']
                            )
コード例 #4
0
ファイル: systemd_test.py プロジェクト: xiaofan-china/salt
 def test_get_enabled(self):
     '''
         Test to return a list of all enabled services
     '''
     mock = MagicMock(return_value={
         "a": "enabled",
         "b": "enabled",
         "c": "disabled"
     })
     with patch.object(systemd, '_get_all_unit_files', mock):
         self.assertListEqual(systemd.get_enabled(), ["a", "b"])
コード例 #5
0
ファイル: systemd_test.py プロジェクト: HowardMei/saltstack
    def test_get_enabled(self):
        '''
        Test to return a list of all enabled services
        '''
        _service_is_sysv = lambda x: True if x in ('d', 'e') else False
        _sysv_is_enabled = lambda x: False if x in ('e',) else True

        unit_files = MagicMock(return_value={'a': 'enabled',
                                             'b': 'enabled',
                                             'c': 'disabled'})
        all_units = MagicMock(return_value={'a': 'disabled',
                                            'b': 'disabled',
                                            'd': 'disabled',
                                            'e': 'disabled'})
        with patch.object(systemd, '_sysv_is_enabled', _sysv_is_enabled):
            with patch.object(systemd, '_service_is_sysv', _service_is_sysv):
                with patch.object(systemd, '_get_all_unit_files', unit_files):
                    with patch.object(systemd, '_get_all_units', all_units):
                        self.assertListEqual(
                            systemd.get_enabled(), ['a', 'b', 'd'])
コード例 #6
0
    def test_get_enabled(self):
        '''
        Test to return a list of all enabled services
        '''
        _service_is_sysv = lambda x: True if x in ('d', 'e') else False
        _sysv_is_enabled = lambda x: False if x in ('e', ) else True

        unit_files = MagicMock(return_value={
            'a': 'enabled',
            'b': 'enabled',
            'c': 'disabled'
        })
        all_units = MagicMock(return_value={
            'a': 'disabled',
            'b': 'disabled',
            'd': 'disabled',
            'e': 'disabled'
        })
        with patch.object(systemd, '_sysv_is_enabled', _sysv_is_enabled):
            with patch.object(systemd, '_service_is_sysv', _service_is_sysv):
                with patch.object(systemd, '_get_all_unit_files', unit_files):
                    with patch.object(systemd, '_get_all_units', all_units):
                        self.assertListEqual(systemd.get_enabled(),
                                             ['a', 'b', 'd'])