Beispiel #1
0
 def test_min_modify_time(self):
     fb = FakedBuilder(device_count=4)
     builder = fb.gen_builder(balanced=False)
     pickle.dump(builder.to_dict(),
                 open(os.path.join(self.testdir, 'account.builder'), 'wb'),
                 protocol=2)
     rmd = RingMasterServer(rms_conf={'ringmasterd': self.confdict})
     rmd.logger = MagicMock()
     self.assertFalse(rmd.min_modify_time('account'))
     t = time.time() - 8600
     os.utime(os.path.join(self.testdir, 'account.builder'), (t, t))
     self.assertTrue(rmd.min_modify_time('account'))
 def test_min_modify_time(self):
     fb = FakedBuilder(device_count=4)
     builder = fb.gen_builder(balanced=False)
     pickle.dump(builder.to_dict(),
                 open(os.path.join(self.testdir, 'account.builder'), 'wb'),
                 protocol=2)
     rmd = RingMasterServer(rms_conf={'ringmasterd': self.confdict})
     rmd.logger = MagicMock()
     self.assertFalse(rmd.min_modify_time('account'))
     t = time.time() - 8600
     os.utime(os.path.join(self.testdir, 'account.builder'), (t, t))
     self.assertTrue(rmd.min_modify_time('account'))
Beispiel #3
0
    def test_orchestration_pass(self, srs):
        srs.return_value = Mock()
        self._setup_builder_rings(count=4, balanced=False)
        rmd = RingMasterServer(rms_conf={'ringmasterd': self.confdict})
        rmd.logger = MagicMock()
        rmd.ring_requires_change = MagicMock(return_value=True)
        rmd.min_part_hours_ok = MagicMock(return_value=True)
        rmd.min_modify_time = MagicMock(return_value=True)
        rmd.dispersion_ok = MagicMock(return_value=True)
        rmd.ring_balance_ok = MagicMock(return_value=True)
        rmd.rebalance_ring = MagicMock(return_value=True)
        rmd.write_builder = MagicMock(return_value=True)
        rmd.write_ring = MagicMock(return_value=True)

        def _reset_all():
            rmd.ring_requires_change.reset_mock()
            rmd.min_part_hours_ok.reset_mock()
            rmd.min_modify_time.reset_mock()
            rmd.dispersion_ok.reset_mock()
            rmd.ring_balance_ok.reset_mock()
            rmd.rebalance_ring.reset_mock()
            rmd.write_builder.reset_mock()
            rmd.write_ring.reset_mock()
            srs.reset_mock()

        # passes with no changes
        rmd.ring_requires_change.return_value = False
        ring_changed = rmd.orchestration_pass('object')
        self.assertFalse(rmd.min_part_hours_ok.called)
        self.assertFalse(rmd.min_modify_time.called)
        self.assertFalse(rmd.dispersion_ok.called)
        self.assertFalse(rmd.ring_balance_ok.called)
        self.assertFalse(rmd.rebalance_ring.called)
        self.assertFalse(rmd.write_builder.called)
        self.assertFalse(rmd.write_ring.called)
        self.assertFalse(ring_changed)
        _reset_all()

        # change required, with min_part_hours enabled and everything ready
        rmd.ring_requires_change.return_value = True
        rmd.mph_enabled = True
        ring_changed = rmd.orchestration_pass('object')
        self.assertTrue(rmd.min_part_hours_ok.called)
        self.assertTrue(rmd.min_modify_time.called)
        self.assertTrue(rmd.dispersion_ok.called)
        self.assertTrue(rmd.ring_balance_ok.called)
        self.assertTrue(rmd.rebalance_ring.called)
        self.assertTrue(rmd.write_builder.called)
        self.assertTrue(rmd.write_ring.called)
        self.assertTrue(ring_changed)
        _reset_all()

        # change required, min_part_hours enabled and min_part_hours not ready
        rmd.ring_requires_change.return_value = True
        rmd.mph_enabled = True
        rmd.min_part_hours_ok.return_value = False
        ring_changed = rmd.orchestration_pass('object')
        self.assertTrue(rmd.min_part_hours_ok.called)
        self.assertFalse(rmd.min_modify_time.called)
        self.assertFalse(rmd.dispersion_ok.called)
        self.assertFalse(rmd.ring_balance_ok.called)
        self.assertFalse(rmd.rebalance_ring.called)
        self.assertFalse(rmd.write_builder.called)
        self.assertFalse(rmd.write_ring.called)
        self.assertFalse(ring_changed)
        rmd.min_part_hours_ok.return_value = True
        _reset_all()

        # change required, min_part_hours enabled and min_modify_time not ready
        rmd.ring_requires_change.return_value = True
        rmd.mph_enabled = True
        rmd.min_modify_time.return_value = False
        ring_changed = rmd.orchestration_pass('object')
        self.assertTrue(rmd.min_part_hours_ok.called)
        self.assertTrue(rmd.min_modify_time.called)
        self.assertFalse(rmd.dispersion_ok.called)
        self.assertFalse(rmd.ring_balance_ok.called)
        self.assertFalse(rmd.rebalance_ring.called)
        self.assertFalse(rmd.write_builder.called)
        self.assertFalse(rmd.write_ring.called)
        self.assertFalse(ring_changed)
        rmd.min_modify_time.return_value = True
        _reset_all()

        # change required, min_part_hours enabled and dispersion not ready
        rmd.ring_requires_change.return_value = True
        rmd.mph_enabled = True
        rmd.dispersion_ok.return_value = False
        ring_changed = rmd.orchestration_pass('object')
        self.assertTrue(rmd.min_part_hours_ok.called)
        self.assertTrue(rmd.min_modify_time.called)
        self.assertTrue(rmd.dispersion_ok.called)
        self.assertFalse(rmd.ring_balance_ok.called)
        self.assertFalse(rmd.rebalance_ring.called)
        self.assertFalse(rmd.write_builder.called)
        self.assertFalse(rmd.write_ring.called)
        self.assertFalse(ring_changed)
        rmd.dispersion_ok.return_value = True
        _reset_all()

        # change required, min_part_hours enabled and ring balance not ready
        rmd.ring_requires_change.return_value = True
        rmd.mph_enabled = True
        rmd.ring_balance_ok.return_value = False
        ring_changed = rmd.orchestration_pass('object')
        self.assertTrue(rmd.min_part_hours_ok.called)
        self.assertTrue(rmd.min_modify_time.called)
        self.assertTrue(rmd.dispersion_ok.called)
        self.assertTrue(rmd.ring_balance_ok.called)
        self.assertTrue(rmd.rebalance_ring.called)
        self.assertTrue(rmd.write_builder.called)
        self.assertTrue(rmd.write_ring.called)
        self.assertTrue(ring_changed)
        rmd.ring_balance_ok.return_value = True
        _reset_all()
    def test_orchestration_pass(self, srs):
        srs.return_value = Mock()
        self._setup_builder_rings(count=4, balanced=False)
        rmd = RingMasterServer(rms_conf={'ringmasterd': self.confdict})
        rmd.logger = MagicMock()
        rmd.ring_requires_change = MagicMock(return_value=True)
        rmd.min_part_hours_ok = MagicMock(return_value=True)
        rmd.min_modify_time = MagicMock(return_value=True)
        rmd.dispersion_ok = MagicMock(return_value=True)
        rmd.ring_balance_ok = MagicMock(return_value=True)
        rmd.rebalance_ring = MagicMock(return_value=True)
        rmd.write_builder = MagicMock(return_value=True)
        rmd.write_ring = MagicMock(return_value=True)

        def _reset_all():
            rmd.ring_requires_change.reset_mock()
            rmd.min_part_hours_ok.reset_mock()
            rmd.min_modify_time.reset_mock()
            rmd.dispersion_ok.reset_mock()
            rmd.ring_balance_ok.reset_mock()
            rmd.rebalance_ring.reset_mock()
            rmd.write_builder.reset_mock()
            rmd.write_ring.reset_mock()
            srs.reset_mock()

        # passes with no changes
        rmd.ring_requires_change.return_value = False
        ring_changed = rmd.orchestration_pass('object')
        self.assertFalse(rmd.min_part_hours_ok.called)
        self.assertFalse(rmd.min_modify_time.called)
        self.assertFalse(rmd.dispersion_ok.called)
        self.assertFalse(rmd.ring_balance_ok.called)
        self.assertFalse(rmd.rebalance_ring.called)
        self.assertFalse(rmd.write_builder.called)
        self.assertFalse(rmd.write_ring.called)
        self.assertFalse(ring_changed)
        _reset_all()

        # change required, with min_part_hours enabled and everything ready
        rmd.ring_requires_change.return_value = True
        rmd.mph_enabled = True
        ring_changed = rmd.orchestration_pass('object')
        self.assertTrue(rmd.min_part_hours_ok.called)
        self.assertTrue(rmd.min_modify_time.called)
        self.assertTrue(rmd.dispersion_ok.called)
        self.assertTrue(rmd.ring_balance_ok.called)
        self.assertTrue(rmd.rebalance_ring.called)
        self.assertTrue(rmd.write_builder.called)
        self.assertTrue(rmd.write_ring.called)
        self.assertTrue(ring_changed)
        _reset_all()

        # change required, min_part_hours enabled and min_part_hours not ready
        rmd.ring_requires_change.return_value = True
        rmd.mph_enabled = True
        rmd.min_part_hours_ok.return_value = False
        ring_changed = rmd.orchestration_pass('object')
        self.assertTrue(rmd.min_part_hours_ok.called)
        self.assertFalse(rmd.min_modify_time.called)
        self.assertFalse(rmd.dispersion_ok.called)
        self.assertFalse(rmd.ring_balance_ok.called)
        self.assertFalse(rmd.rebalance_ring.called)
        self.assertFalse(rmd.write_builder.called)
        self.assertFalse(rmd.write_ring.called)
        self.assertFalse(ring_changed)
        rmd.min_part_hours_ok.return_value = True
        _reset_all()

        # change required, min_part_hours enabled and min_modify_time not ready
        rmd.ring_requires_change.return_value = True
        rmd.mph_enabled = True
        rmd.min_modify_time.return_value = False
        ring_changed = rmd.orchestration_pass('object')
        self.assertTrue(rmd.min_part_hours_ok.called)
        self.assertTrue(rmd.min_modify_time.called)
        self.assertFalse(rmd.dispersion_ok.called)
        self.assertFalse(rmd.ring_balance_ok.called)
        self.assertFalse(rmd.rebalance_ring.called)
        self.assertFalse(rmd.write_builder.called)
        self.assertFalse(rmd.write_ring.called)
        self.assertFalse(ring_changed)
        rmd.min_modify_time.return_value = True
        _reset_all()

        # change required, min_part_hours enabled and dispersion not ready
        rmd.ring_requires_change.return_value = True
        rmd.mph_enabled = True
        rmd.dispersion_ok.return_value = False
        ring_changed = rmd.orchestration_pass('object')
        self.assertTrue(rmd.min_part_hours_ok.called)
        self.assertTrue(rmd.min_modify_time.called)
        self.assertTrue(rmd.dispersion_ok.called)
        self.assertFalse(rmd.ring_balance_ok.called)
        self.assertFalse(rmd.rebalance_ring.called)
        self.assertFalse(rmd.write_builder.called)
        self.assertFalse(rmd.write_ring.called)
        self.assertFalse(ring_changed)
        rmd.dispersion_ok.return_value = True
        _reset_all()

        # change required, min_part_hours enabled and ring balance not ready
        rmd.ring_requires_change.return_value = True
        rmd.mph_enabled = True
        rmd.ring_balance_ok.return_value = False
        ring_changed = rmd.orchestration_pass('object')
        self.assertTrue(rmd.min_part_hours_ok.called)
        self.assertTrue(rmd.min_modify_time.called)
        self.assertTrue(rmd.dispersion_ok.called)
        self.assertTrue(rmd.ring_balance_ok.called)
        self.assertTrue(rmd.rebalance_ring.called)
        self.assertTrue(rmd.write_builder.called)
        self.assertTrue(rmd.write_ring.called)
        self.assertTrue(ring_changed)
        rmd.ring_balance_ok.return_value = True
        _reset_all()