Esempio n. 1
0
    def test_persist_no_conf_success(self):
        '''
        Tests successful add of config file when previously not one
        '''
        asn_cmd = {'pid': 1337, 'retcode': 0, 'stderr': '',
               'stdout': 'net.ipv4.ip_forward = 1'}
        mock_asn_cmd = MagicMock(return_value=asn_cmd)

        sys_cmd = 'systemd 208\n+PAM +LIBWRAP'
        mock_sys_cmd = MagicMock(return_value=sys_cmd)

        with patch('salt.utils.fopen', mock_open()) as m_open:
            with patch.dict(linux_sysctl.__salt__,
                            {'cmd.run_stdout': mock_sys_cmd,
                             'cmd.run_all': mock_asn_cmd}):
                with patch.dict(systemd.__context__,
                                {'salt.utils.systemd.booted': True}):
                    linux_sysctl.persist('net.ipv4.ip_forward', 1)
                    helper_open = m_open()
                    helper_open.write.assert_called_once_with(
                        '#\n# Kernel sysctl configuration\n#\n')
Esempio n. 2
0
    def test_persist_read_conf_success(self):
        '''
        Tests sysctl.conf read success
        '''
        asn_cmd = {'pid': 1337, 'retcode': 0, 'stderr': '',
               'stdout': 'net.ipv4.ip_forward = 1'}
        mock_asn_cmd = MagicMock(return_value=asn_cmd)

        sys_cmd = 'systemd 208\n+PAM +LIBWRAP'
        mock_sys_cmd = MagicMock(return_value=sys_cmd)

        with patch('salt.utils.fopen', mock_open()):
            with patch.dict(linux_sysctl.__salt__,
                            {'cmd.run_stdout': mock_sys_cmd,
                             'cmd.run_all': mock_asn_cmd}):
                with patch.dict(systemd.__context__,
                                {'salt.utils.systemd.booted': True}):
                    self.assertEqual(linux_sysctl.persist(
                                     'net.ipv4.ip_forward', 1), 'Updated')