Ejemplo n.º 1
0
    def test_clean_up_another_fs(self, mock_stat, mock_image_service,
                                 mock_statvfs, mock_instance_cache,
                                 mock_tftp_cache):
        # Not enough space, instance cache on another partition
        mock_stat.side_effect = [mock.Mock(st_dev=1),
                                 mock.Mock(st_dev=2),
                                 mock.Mock(st_dev=1)]
        mock_show = mock_image_service.return_value.show
        mock_show.return_value = dict(size=42)
        mock_statvfs.side_effect = [
            mock.Mock(f_frsize=1, f_bavail=1),
            mock.Mock(f_frsize=1, f_bavail=1024)
        ]

        cache = mock.Mock(master_dir='master_dir')
        pxe._fetch_images(None, cache, [('uuid', 'path')])

        mock_show.assert_called_once_with('uuid')
        mock_statvfs.assert_called_with('master_dir')
        self.assertEqual(2, mock_statvfs.call_count)
        cache.fetch_image.assert_called_once_with('uuid', 'path', ctx=None)
        mock_tftp_cache.return_value.clean_up.assert_called_once_with(
            amount=(42 * 2 - 1))
        self.assertFalse(mock_instance_cache.return_value.clean_up.called)
        self.assertEqual(3, mock_stat.call_count)
Ejemplo n.º 2
0
    def test_clean_up_another_fs(self, mock_stat, mock_image_service,
                                 mock_statvfs, mock_instance_cache,
                                 mock_tftp_cache):
        # Not enough space, instance cache on another partition
        mock_stat.side_effect = [mock.Mock(st_dev=1),
                                 mock.Mock(st_dev=2),
                                 mock.Mock(st_dev=1)]
        mock_show = mock_image_service.return_value.show
        mock_show.return_value = dict(size=42)
        mock_statvfs.side_effect = [
            mock.Mock(f_frsize=1, f_bavail=1),
            mock.Mock(f_frsize=1, f_bavail=1024)
        ]

        cache = mock.Mock(master_dir='master_dir')
        pxe._fetch_images(None, cache, [('uuid', 'path')])

        mock_show.assert_called_once_with('uuid')
        mock_statvfs.assert_called_with('master_dir')
        self.assertEqual(2, mock_statvfs.call_count)
        cache.fetch_image.assert_called_once_with('uuid', 'path', ctx=None)
        mock_tftp_cache.return_value.clean_up.assert_called_once_with(
            amount=(42 * 2 - 1))
        self.assertFalse(mock_instance_cache.return_value.clean_up.called)
        self.assertEqual(3, mock_stat.call_count)
Ejemplo n.º 3
0
    def test_no_clean_up(self, mock_image_service, mock_statvfs, mock_instance_cache, mock_tftp_cache):
        # Enough space found - no clean up
        mock_show = mock_image_service.return_value.show
        mock_show.return_value = dict(size=42)
        mock_statvfs.return_value = mock.Mock(f_frsize=1, f_bavail=1024)

        cache = mock.Mock(master_dir="master_dir")
        pxe._fetch_images(None, cache, [("uuid", "path")])

        mock_show.assert_called_once_with("uuid")
        mock_statvfs.assert_called_once_with("master_dir")
        cache.fetch_image.assert_called_once_with("uuid", "path", ctx=None)
        self.assertFalse(mock_instance_cache.return_value.clean_up.called)
        self.assertFalse(mock_tftp_cache.return_value.clean_up.called)
Ejemplo n.º 4
0
    def test_no_clean_up(self, mock_image_service, mock_statvfs,
                         mock_instance_cache, mock_tftp_cache):
        # Enough space found - no clean up
        mock_show = mock_image_service.return_value.show
        mock_show.return_value = dict(size=42)
        mock_statvfs.return_value = mock.Mock(f_frsize=1, f_bavail=1024)

        cache = mock.Mock(master_dir='master_dir')
        pxe._fetch_images(None, cache, [('uuid', 'path')])

        mock_show.assert_called_once_with('uuid')
        mock_statvfs.assert_called_once_with('master_dir')
        cache.fetch_image.assert_called_once_with('uuid', 'path', ctx=None)
        self.assertFalse(mock_instance_cache.return_value.clean_up.called)
        self.assertFalse(mock_tftp_cache.return_value.clean_up.called)
Ejemplo n.º 5
0
    def test_one_clean_up(self, mock_stat, mock_image_service, mock_statvfs, mock_instance_cache, mock_tftp_cache):
        # Not enough space, instance cache clean up is enough
        mock_stat.return_value.st_dev = 1
        mock_show = mock_image_service.return_value.show
        mock_show.return_value = dict(size=42)
        mock_statvfs.side_effect = [mock.Mock(f_frsize=1, f_bavail=1), mock.Mock(f_frsize=1, f_bavail=1024)]

        cache = mock.Mock(master_dir="master_dir")
        pxe._fetch_images(None, cache, [("uuid", "path")])

        mock_show.assert_called_once_with("uuid")
        mock_statvfs.assert_called_with("master_dir")
        self.assertEqual(2, mock_statvfs.call_count)
        cache.fetch_image.assert_called_once_with("uuid", "path", ctx=None)
        mock_instance_cache.return_value.clean_up.assert_called_once_with()
        self.assertFalse(mock_tftp_cache.return_value.clean_up.called)
        self.assertEqual(3, mock_stat.call_count)
Ejemplo n.º 6
0
    def test_both_clean_up(self, mock_stat, mock_image_service, mock_statvfs, mock_instance_cache, mock_tftp_cache):
        # Not enough space, clean up of both caches required
        mock_stat.return_value.st_dev = 1
        mock_show = mock_image_service.return_value.show
        mock_show.return_value = dict(size=42)
        mock_statvfs.side_effect = [
            mock.Mock(f_frsize=1, f_bavail=1),
            mock.Mock(f_frsize=1, f_bavail=2),
            mock.Mock(f_frsize=1, f_bavail=1024),
        ]

        cache = mock.Mock(master_dir="master_dir")
        pxe._fetch_images(None, cache, [("uuid", "path")])

        mock_show.assert_called_once_with("uuid")
        mock_statvfs.assert_called_with("master_dir")
        self.assertEqual(3, mock_statvfs.call_count)
        cache.fetch_image.assert_called_once_with("uuid", "path", ctx=None)
        mock_instance_cache.return_value.clean_up.assert_called_once_with(amount=(42 * 2 - 1))
        mock_tftp_cache.return_value.clean_up.assert_called_once_with(amount=(42 * 2 - 2))
        self.assertEqual(3, mock_stat.call_count)
Ejemplo n.º 7
0
    def test_both_clean_up(self, mock_stat, mock_image_service, mock_statvfs,
                           mock_instance_cache, mock_tftp_cache):
        # Not enough space, clean up of both caches required
        mock_stat.return_value.st_dev = 1
        mock_show = mock_image_service.return_value.show
        mock_show.return_value = dict(size=42)
        mock_statvfs.side_effect = [
            mock.Mock(f_frsize=1, f_bavail=1),
            mock.Mock(f_frsize=1, f_bavail=2),
            mock.Mock(f_frsize=1, f_bavail=1024)
        ]

        cache = mock.Mock(master_dir='master_dir')
        pxe._fetch_images(None, cache, [('uuid', 'path')])

        mock_show.assert_called_once_with('uuid')
        mock_statvfs.assert_called_with('master_dir')
        self.assertEqual(3, mock_statvfs.call_count)
        cache.fetch_image.assert_called_once_with('uuid', 'path', ctx=None)
        mock_instance_cache.return_value.clean_up.assert_called_once_with(
            amount=(42 * 2 - 1))
        mock_tftp_cache.return_value.clean_up.assert_called_once_with(
            amount=(42 * 2 - 2))
        self.assertEqual(3, mock_stat.call_count)