def test_booted_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.booted(99999)
def test_booted_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.booted(99999)
def test_not_booted(self): ''' Test that salt.utils.systemd.booted() returns False when minion is not systemd-booted. ''' # Ensure that os.stat raises an exception even if test is being run on # a systemd-booted host. with patch('os.stat', side_effect=_not_booted_effect): # Test without context dict passed self.assertFalse(_systemd.booted()) # Test that context key is set when context dict is passed context = {} self.assertFalse(_systemd.booted(context)) self.assertEqual(context, {'salt.utils.systemd.booted': False})
def test_not_booted(self): ''' Test that salt.utils.systemd.booted() returns False when minion is not systemd-booted. ''' # Ensure that os.stat raises an exception even if test is being run on # a systemd-booted host. with patch('os.stat', side_effect=_not_booted_effect): # Test without context dict passed self.assertFalse(_systemd.booted()) # Test that context key is set when context dict is passed context = {} self.assertFalse(_systemd.booted(context)) self.assertEqual(context, {'salt.utils.systemd.booted': False})
def test_booted(self): ''' Test that salt.utils.systemd.booted() returns True when minion is systemd-booted. ''' # Ensure that os.stat returns True. os.stat doesn't return a bool # normally, but the code is doing a simple truth check on the return # data, so it is sufficient enough to mock it as True for these tests. with patch('os.stat', side_effect=_booted_effect): # Test without context dict passed self.assertTrue(_systemd.booted()) # Test that context key is set when context dict is passed context = {} self.assertTrue(_systemd.booted(context)) self.assertEqual(context, {'salt.utils.systemd.booted': True})
def test_booted(self): ''' Test that salt.utils.systemd.booted() returns True when minion is systemd-booted. ''' # Ensure that os.stat returns True. os.stat doesn't return a bool # normally, but the code is doing a simple truth check on the return # data, so it is sufficient enough to mock it as True for these tests. with patch('os.stat', side_effect=_booted_effect): # Test without context dict passed self.assertTrue(_systemd.booted()) # Test that context key is set when context dict is passed context = {} self.assertTrue(_systemd.booted(context)) self.assertEqual(context, {'salt.utils.systemd.booted': True})
def test_booted_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-boolean value to differentiate it from the True/False return this function normally produces. ''' context = {'salt.utils.systemd.booted': 'foo'} self.assertEqual(_systemd.booted(context), 'foo')
def test_booted_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-boolean value to differentiate it from the True/False return this function normally produces. ''' context = {'salt.utils.systemd.booted': 'foo'} self.assertEqual(_systemd.booted(context), 'foo')
def _get_systemd_only(func, kwargs): if not hasattr(_get_systemd_only, "HAS_SYSTEMD"): setattr(_get_systemd_only, "HAS_SYSTEMD", booted()) ret = {} warnings = [] valid_args = _argspec(func).args for systemd_arg in SYSTEMD_ONLY: if systemd_arg in kwargs and systemd_arg in valid_args: if _get_systemd_only.HAS_SYSTEMD: ret[systemd_arg] = kwargs[systemd_arg] else: warnings.append("The '{}' argument is not supported by this " "platform".format(systemd_arg)) return ret, warnings