def test_get_disabled(self): ''' Test to return a list of all disabled services ''' cmd_mock = MagicMock(return_value=_LIST_UNIT_FILES) # 'foo' should collide with the systemd services (as returned by # sd_mock) and thus not be returned by _get_sysv_services(). It doesn't # matter that it's not part of the _LIST_UNIT_FILES output, we just # want to ensure that 'foo' isn't identified as a disabled initscript # even though below we are mocking it to show as not enabled (since # only 'baz' will be considered an enabled sysv service). 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_disabled(), ['bar', 'service2', 'timer2.timer'])
def test_get_disabled(self): ''' Test to return a list of all disabled services ''' cmd_mock = MagicMock(return_value=_LIST_UNIT_FILES) # 'foo' should collide with the systemd services (as returned by # sd_mock) and thus not be returned by _get_sysv_services(). It doesn't # matter that it's not part of the _LIST_UNIT_FILES output, we just # want to ensure that 'foo' isn't identified as a disabled initscript # even though below we are mocking it to show as not enabled (since # only 'baz' will be considered an enabled sysv service). 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_disabled(), ['bar', 'service2', 'timer2.timer'] )
def test_get_disabled(self): ''' Test to return a list of all disabled services ''' mock = MagicMock(return_value={"a": "enabled", "b": "enabled", "c": "disabled"}) with patch.object(systemd, '_get_all_unit_files', mock): mock = MagicMock(return_value={}) with patch.object(systemd, '_get_all_legacy_init_scripts', mock): self.assertListEqual(systemd.get_disabled(), ["c"])
def test_get_disabled(self): ''' Test to return a list of all disabled services ''' mock = MagicMock(return_value={'a': 'enabled', 'b': 'enabled', 'c': 'disabled'}) with patch.object(systemd, '_get_all_unit_files', mock): mock = MagicMock(return_value={}) with patch.object(systemd, '_get_all_legacy_init_scripts', mock): self.assertListEqual(systemd.get_disabled(), ['c'])
def test_get_disabled(self): ''' Test to return a list of all disabled services ''' mock = MagicMock(return_value={ 'a': 'enabled', 'b': 'enabled', 'c': 'disabled' }) with patch.object(systemd, '_get_all_unit_files', mock): mock = MagicMock(return_value={}) with patch.object(systemd, '_get_all_legacy_init_scripts', mock): self.assertListEqual(systemd.get_disabled(), ['c'])