Beispiel #1
0
    def test_get_state_quarantine_sticky(self):
        # A crash in get_dimensions() causes sticky quarantine in get_state.
        from config import bot_config
        obj = self.make_bot()

        def get_dimensions(botobj):
            self.assertEqual(obj, botobj)
            return 'invalid'

        self.mock(bot_config, 'get_dimensions', get_dimensions)

        def get_dimensions_os():
            return {u'os': [u'safe']}

        self.mock(os_utilities, 'get_dimensions', get_dimensions_os)

        def get_state(botobj):
            self.assertEqual(obj, botobj)
            return {'yo': 'dawh'}

        self.mock(bot_config, 'get_state', get_state)

        expected = {
            u'os': [u'safe'],
            u'quarantined': [u'1'],
            u'server_version': [u'version1'],
        }
        self.assertEqual(expected, bot_main._get_dimensions(obj))
        expected = {
            'quarantined': "get_dimensions(): expected a dict, got 'invalid'",
            'sleep_streak': 0.1,
            'yo': 'dawh',
        }
        self.assertEqual(expected, bot_main._get_state(obj, 0.1))
 def test_get_state(self):
   from config import bot_config
   obj = self.make_bot()
   def get_state(botobj):
     self.assertEqual(obj, botobj)
     return {'yo': 'dawh'}
   self.mock(bot_config, 'get_state', get_state)
   expected = {'sleep_streak': 0.1, 'yo': 'dawh'}
   self.assertEqual(expected, bot_main._get_state(obj, 0.1))
Beispiel #3
0
    def test_get_state_quarantine(self):
        botobj = bot_main.get_bot(bot_main.get_config())
        root = u'c:\\' if sys.platform == 'win32' else u'/'

        def get_state(_):
            return {
                u'disks': {
                    root: {
                        u'free_mb': 0.1,
                        u'size_mb': 1000,
                    },
                    botobj.base_dir: {
                        u'free_mb': 0.1,
                        u'size_mb': 1000,
                    },
                },
            }

        # This uses the default get_settings() values. The threshold used is
        # dependent on these values. This affects the error message below.
        # 'size' == 4096Mb
        # 'max_percent' == 15% * 1000Mb = 150Mb
        # 'min_percent' == 5% of 1000Mb == 50Mb
        # 'max_percent' is chosen.
        from config import bot_config
        self.mock(bot_config, 'get_state', get_state)
        expected = {
            u'disks': {
                u'c:\\' if sys.platform == 'win32' else u'/': {
                    u'free_mb': 0.1,
                    u'size_mb': 1000,
                },
                botobj.base_dir: {
                    u'free_mb': 0.1,
                    u'size_mb': 1000,
                },
            },
            u'quarantined':
            (u'Not enough free disk space on %s. 0.1mib < 100.0mib\n'
             u'Not enough free disk space on %s. 0.1mib < 150.0mib') %
            (root, botobj.base_dir),
            u'sleep_streak':
            1,
        }
        self.assertEqual(expected, bot_main._get_state(botobj, 1))