コード例 #1
0
ファイル: test_systemd.py プロジェクト: bsemar/IntCont
 def test_version_invalid_context(self):
     '''
     Test with invalid context data. The context value must be a dict, so
     this should raise a SaltInvocationError.
     '''
     # Test with invalid context data
     with self.assertRaises(SaltInvocationError):
         _systemd.version(99999)
コード例 #2
0
ファイル: systemd_test.py プロジェクト: bryson/salt
 def test_version_invalid_context(self):
     '''
     Test with invalid context data. The context value must be a dict, so
     this should raise a SaltInvocationError.
     '''
     # Test with invalid context data
     with self.assertRaises(SaltInvocationError):
         _systemd.version(99999)
コード例 #3
0
ファイル: test_systemd.py プロジェクト: cldeluna/salt
 def test_version_parse_problem(self, popen_mock):
     '''
     Test with invalid context data. The context value must be a dict, so
     this should raise a SaltInvocationError.
     '''
     popen_mock.return_value = Mock(communicate=lambda *args, **kwargs:
                                    ('invalid', None),
                                    pid=lambda: 12345,
                                    retcode=0)
     # Test without context dict passed
     self.assertIsNone(_systemd.version())
     # Test that context key is set when context dict is passed. A failure
     # to parse the systemctl output should not set a context key, so it
     # should not be present in the context dict.
     context = {}
     self.assertIsNone(_systemd.version(context))
     self.assertEqual(context, {})
コード例 #4
0
ファイル: test_systemd.py プロジェクト: bsemar/IntCont
 def test_version_return_from_context(self):
     '''
     Test that the context data is returned when present. To ensure we're
     getting data from the context dict, we use a non-integer value to
     differentiate it from the integer return this function normally
     produces.
     '''
     context = {'salt.utils.systemd.version': 'foo'}
     self.assertEqual(_systemd.version(context), 'foo')
コード例 #5
0
ファイル: systemd_test.py プロジェクト: bryson/salt
 def test_version_parse_problem(self, popen_mock):
     '''
     Test with invalid context data. The context value must be a dict, so
     this should raise a SaltInvocationError.
     '''
     popen_mock.return_value = Mock(
         communicate=lambda *args, **kwargs: ('invalid', None),
         pid=lambda: 12345,
         retcode=0
     )
     # Test without context dict passed
     self.assertIsNone(_systemd.version())
     # Test that context key is set when context dict is passed. A failure
     # to parse the systemctl output should not set a context key, so it
     # should not be present in the context dict.
     context = {}
     self.assertIsNone(_systemd.version(context))
     self.assertEqual(context, {})
コード例 #6
0
ファイル: systemd_test.py プロジェクト: bryson/salt
 def test_version_return_from_context(self):
     '''
     Test that the context data is returned when present. To ensure we're
     getting data from the context dict, we use a non-integer value to
     differentiate it from the integer return this function normally
     produces.
     '''
     context = {'salt.utils.systemd.version': 'foo'}
     self.assertEqual(_systemd.version(context), 'foo')
コード例 #7
0
ファイル: test_systemd.py プロジェクト: cldeluna/salt
    def test_version(self, popen_mock):
        '''
        Test that salt.utils.systemd.booted() returns True when minion is
        systemd-booted.
        '''
        _version = 231
        output = 'systemd {0}\n-SYSVINIT'.format(_version)
        popen_mock.return_value = Mock(communicate=lambda *args, **kwargs:
                                       (output, None),
                                       pid=lambda: 12345,
                                       retcode=0)

        # Test without context dict passed
        self.assertEqual(_systemd.version(), _version)
        # Test that context key is set when context dict is passed
        context = {}
        self.assertTrue(_systemd.version(context))
        self.assertEqual(context, {'salt.utils.systemd.version': _version})
コード例 #8
0
ファイル: systemd_test.py プロジェクト: bryson/salt
    def test_version(self, popen_mock):
        '''
        Test that salt.utils.systemd.booted() returns True when minion is
        systemd-booted.
        '''
        _version = 231
        output = 'systemd {0}\n-SYSVINIT'.format(_version)
        popen_mock.return_value = Mock(
            communicate=lambda *args, **kwargs: (output, None),
            pid=lambda: 12345,
            retcode=0
        )

        # Test without context dict passed
        self.assertEqual(_systemd.version(), _version)
        # Test that context key is set when context dict is passed
        context = {}
        self.assertTrue(_systemd.version(context))
        self.assertEqual(context, {'salt.utils.systemd.version': _version})
コード例 #9
0
    def test_version_generated_from_git_describe(self):
        '''
        Test with version string matching versions generated by git describe
        in systemd. This feature is used in systemd>=241.
        '''
        with patch('subprocess.Popen') as popen_mock:
            _version = 241
            output = 'systemd {0} ({0}.0-0-dist)\n-SYSVINIT'.format(_version)
            popen_mock.return_value = Mock(communicate=lambda *args, **kwargs:
                                           (output, None),
                                           pid=lambda: 12345,
                                           retcode=0)

            # Test without context dict passed
            self.assertEqual(_systemd.version(), _version)
            # Test that context key is set when context dict is passed
            context = {}
            self.assertTrue(_systemd.version(context))
            self.assertEqual(context, {'salt.utils.systemd.version': _version})
コード例 #10
0
    def test_version(self):
        """
        Test that salt.utils.systemd.booted() returns True when minion is
        systemd-booted.
        """
        with patch("subprocess.Popen") as popen_mock:
            _version = 231
            output = "systemd {0}\n-SYSVINIT".format(_version)
            popen_mock.return_value = Mock(
                communicate=lambda *args, **kwargs: (output, None),
                pid=lambda: 12345,
                retcode=0,
            )

            # Test without context dict passed
            self.assertEqual(_systemd.version(), _version)
            # Test that context key is set when context dict is passed
            context = {}
            self.assertTrue(_systemd.version(context))
            self.assertEqual(context, {"salt.utils.systemd.version": _version})