def test_userpass_mech_domain_unused(self): mock_sc = MagicMock() with patch('salt.utils.vmware.SmartConnect', mock_sc): salt.utils.vmware._get_service_instance( host='fake_host.fqdn', username='******', password='******', protocol='fake_protocol', port=1, mechanism='userpass', principal='fake principal', domain='fake_domain') mock_sc.assert_called_once_with( host='fake_host.fqdn', user='******', pwd='fake_password', protocol='fake_protocol', port=1, b64token=None, mechanism='userpass') mock_sc.reset_mock() salt.utils.vmware._get_service_instance( host='fake_host.fqdn', username='******', password='******', protocol='fake_protocol', port=1, mechanism='userpass', principal='fake principal', domain='fake_domain') mock_sc.assert_called_once_with( host='fake_host.fqdn', user='******', pwd='fake_password', protocol='fake_protocol', port=1, b64token=None, mechanism='userpass')
def test_disable(self): """ Test for Disable the named service to start at boot """ rc_update_mock = MagicMock(return_value=0) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.disable('name')) rc_update_mock.assert_called_once_with('rc-update delete name', python_shell=False) rc_update_mock.reset_mock() # disable service service_name = 'name' runlevels = ['l1'] level_list_mock = MagicMock( return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.disable('name', runlevels='l1')) rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False) rc_update_mock.reset_mock() # same as above with list runlevels = ['l1'] level_list_mock = MagicMock( return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue( gentoo_service.disable('name', runlevels=['l1'])) rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False) rc_update_mock.reset_mock() # remove from 'l1', and leave at 'l2' runlevels = ['l1', 'l2'] level_list_mock = MagicMock( return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue( gentoo_service.disable('name', runlevels=['l1'])) rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False) rc_update_mock.reset_mock() # remove from non-enabled level runlevels = ['l2'] level_list_mock = MagicMock( return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue( gentoo_service.disable('name', runlevels=['l1'])) self.assertTrue(rc_update_mock.call_count == 0) rc_update_mock.reset_mock() # remove from 'l1' and 'l3', leave at 'l2' runlevels = ['l1', 'l2', 'l3'] level_list_mock = MagicMock( return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue( gentoo_service.disable('name', runlevels=['l1', 'l3'])) rc_update_mock.assert_called_once_with('rc-update delete name l1 l3', python_shell=False) rc_update_mock.reset_mock() # rc-update failed rc_update_mock = MagicMock(return_value=1) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertFalse(gentoo_service.disable('name')) rc_update_mock.assert_called_once_with('rc-update delete name', python_shell=False) rc_update_mock.reset_mock() # move service delete failed runlevels = ['l1'] level_list_mock = MagicMock( return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertFalse(gentoo_service.disable('name', runlevels='l1')) rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False) rc_update_mock.reset_mock() # move service delete succeeds. add fails runlevels = ['l1', 'l2', 'l3'] level_list_mock = MagicMock( return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertFalse( gentoo_service.disable('name', runlevels=['l1', 'l3'])) rc_update_mock.assert_called_once_with('rc-update delete name l1 l3', python_shell=False) rc_update_mock.reset_mock()
def test_disable(self): """ Test for Disable the named service to start at boot """ rc_update_mock = MagicMock(return_value=0) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.disable('name')) rc_update_mock.assert_called_once_with('rc-update delete name', python_shell=False) rc_update_mock.reset_mock() # disable service service_name = 'name' runlevels = ['l1'] level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.disable('name', runlevels='l1')) rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False) rc_update_mock.reset_mock() # same as above with list runlevels = ['l1'] level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.disable('name', runlevels=['l1'])) rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False) rc_update_mock.reset_mock() # remove from 'l1', and leave at 'l2' runlevels = ['l1', 'l2'] level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.disable('name', runlevels=['l1'])) rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False) rc_update_mock.reset_mock() # remove from non-enabled level runlevels = ['l2'] level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.disable('name', runlevels=['l1'])) rc_update_mock.assert_not_called() rc_update_mock.reset_mock() # remove from 'l1' and 'l3', leave at 'l2' runlevels = ['l1', 'l2', 'l3'] level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.disable('name', runlevels=['l1', 'l3'])) rc_update_mock.assert_called_once_with('rc-update delete name l1 l3', python_shell=False) rc_update_mock.reset_mock() # rc-update failed rc_update_mock = MagicMock(return_value=1) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertFalse(gentoo_service.disable('name')) rc_update_mock.assert_called_once_with('rc-update delete name', python_shell=False) rc_update_mock.reset_mock() # move service delete failed runlevels = ['l1'] level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertFalse(gentoo_service.disable('name', runlevels='l1')) rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False) rc_update_mock.reset_mock() # move service delete succeeds. add fails runlevels = ['l1', 'l2', 'l3'] level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertFalse(gentoo_service.disable('name', runlevels=['l1', 'l3'])) rc_update_mock.assert_called_once_with('rc-update delete name l1 l3', python_shell=False) rc_update_mock.reset_mock()
def test_enable(self): """ Test for Enable the named service to start at boot """ rc_update_mock = MagicMock(return_value=0) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name')) rc_update_mock.assert_called_once_with('rc-update add name', python_shell=False) rc_update_mock.reset_mock() # move service from 'l1' to 'l2' runlevel service_name = 'name' runlevels = ['l1'] level_list_mock = MagicMock( return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name', runlevels='l2')) rc_update_mock.assert_has_calls([ call('rc-update delete name l1', python_shell=False), call('rc-update add name l2', python_shell=False) ]) rc_update_mock.reset_mock() # requested levels are the same as the current ones with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name', runlevels='l1')) self.assertTrue(rc_update_mock.call_count == 0) rc_update_mock.reset_mock() # same as above with the list instead of the string with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name', runlevels=['l1'])) self.assertTrue(rc_update_mock.call_count == 0) rc_update_mock.reset_mock() # add service to 'l2' runlevel with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue( gentoo_service.enable('name', runlevels=['l2', 'l1'])) rc_update_mock.assert_called_once_with('rc-update add name l2', python_shell=False) rc_update_mock.reset_mock() # remove service from 'l1' runlevel runlevels = ['l1', 'l2'] level_list_mock = MagicMock( return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name', runlevels=['l2'])) rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False) rc_update_mock.reset_mock() # move service from 'l2' add to 'l3', leaving at l1 with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue( gentoo_service.enable('name', runlevels=['l1', 'l3'])) rc_update_mock.assert_has_calls([ call('rc-update delete name l2', python_shell=False), call('rc-update add name l3', python_shell=False) ]) rc_update_mock.reset_mock() # remove from l1, l3, and add to l2, l4, and leave at l5 runlevels = ['l1', 'l3', 'l5'] level_list_mock = MagicMock( return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue( gentoo_service.enable('name', runlevels=['l2', 'l4', 'l5'])) rc_update_mock.assert_has_calls([ call('rc-update delete name l1 l3', python_shell=False), call('rc-update add name l2 l4', python_shell=False) ]) rc_update_mock.reset_mock() # rc-update failed rc_update_mock = MagicMock(return_value=1) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertFalse(gentoo_service.enable('name')) rc_update_mock.assert_called_once_with('rc-update add name', python_shell=False) rc_update_mock.reset_mock() # move service delete failed runlevels = ['l1'] level_list_mock = MagicMock( return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertFalse(gentoo_service.enable('name', runlevels='l2')) rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False) rc_update_mock.reset_mock() # move service delete succeeds. add fails rc_update_mock = MagicMock() rc_update_mock.side_effect = [0, 1] with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertFalse(gentoo_service.enable('name', runlevels='l2')) rc_update_mock.assert_has_calls([ call('rc-update delete name l1', python_shell=False), call('rc-update add name l2', python_shell=False) ]) rc_update_mock.reset_mock()
def test_enable(self): """ Test for Enable the named service to start at boot """ rc_update_mock = MagicMock(return_value=0) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name')) rc_update_mock.assert_called_once_with('rc-update add name', python_shell=False) rc_update_mock.reset_mock() # move service from 'l1' to 'l2' runlevel service_name = 'name' runlevels = ['l1'] level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name', runlevels='l2')) rc_update_mock.assert_has_calls([call('rc-update delete name l1', python_shell=False), call('rc-update add name l2', python_shell=False)]) rc_update_mock.reset_mock() # requested levels are the same as the current ones with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name', runlevels='l1')) rc_update_mock.assert_not_called() rc_update_mock.reset_mock() # same as above with the list instead of the string with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name', runlevels=['l1'])) rc_update_mock.assert_not_called() rc_update_mock.reset_mock() # add service to 'l2' runlevel with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name', runlevels=['l2', 'l1'])) rc_update_mock.assert_called_once_with('rc-update add name l2', python_shell=False) rc_update_mock.reset_mock() # remove service from 'l1' runlevel runlevels = ['l1', 'l2'] level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name', runlevels=['l2'])) rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False) rc_update_mock.reset_mock() # move service from 'l2' add to 'l3', leaving at l1 with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name', runlevels=['l1', 'l3'])) rc_update_mock.assert_has_calls([call('rc-update delete name l2', python_shell=False), call('rc-update add name l3', python_shell=False)]) rc_update_mock.reset_mock() # remove from l1, l3, and add to l2, l4, and leave at l5 runlevels = ['l1', 'l3', 'l5'] level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name', runlevels=['l2', 'l4', 'l5'])) rc_update_mock.assert_has_calls([call('rc-update delete name l1 l3', python_shell=False), call('rc-update add name l2 l4', python_shell=False)]) rc_update_mock.reset_mock() # rc-update failed rc_update_mock = MagicMock(return_value=1) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertFalse(gentoo_service.enable('name')) rc_update_mock.assert_called_once_with('rc-update add name', python_shell=False) rc_update_mock.reset_mock() # move service delete failed runlevels = ['l1'] level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels})) with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertFalse(gentoo_service.enable('name', runlevels='l2')) rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False) rc_update_mock.reset_mock() # move service delete succeeds. add fails rc_update_mock = MagicMock() rc_update_mock.side_effect = [0, 1] with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}): with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertFalse(gentoo_service.enable('name', runlevels='l2')) rc_update_mock.assert_has_calls([call('rc-update delete name l1', python_shell=False), call('rc-update add name l2', python_shell=False)]) rc_update_mock.reset_mock()