Exemplo n.º 1
0
 def test_ring_requires_change(self):
     fb = FakedBuilder(device_count=4)
     builder = fb.gen_builder(balanced=False)
     builder.devs_changed = False
     rmd = RingMasterServer(rms_conf={'ringmasterd': self.confdict})
     rmd.ring_balance_ok = MagicMock(return_value=True)
     rmd.logger = MagicMock()
     # test no change, with no target_weight
     self.assertFalse(rmd.ring_requires_change(builder))
     # test no change, with target_weight present but equal
     builder.devs[0]['target_weight'] = 100.0
     self.assertFalse(rmd.ring_requires_change(builder))
     # test with change
     builder.devs[0]['target_weight'] = 42.0
     self.assertTrue(rmd.ring_requires_change(builder))
     # test brand new ring (i.e. newly added devs)
     builder = fb.gen_builder(balanced=False)
     self.assertTrue(rmd.ring_requires_change(builder))
     # test brand new ring bad balance
     builder.devs_changed = False
     rmd.ring_balance_ok = MagicMock(return_value=False)
     self.assertTrue(rmd.ring_requires_change(builder))
 def test_ring_requires_change(self):
     fb = FakedBuilder(device_count=4)
     builder = fb.gen_builder(balanced=False)
     builder.devs_changed = False
     rmd = RingMasterServer(rms_conf={'ringmasterd': self.confdict})
     rmd.ring_balance_ok = MagicMock(return_value=True)
     rmd.logger = MagicMock()
     # test no change, with no target_weight
     self.assertFalse(rmd.ring_requires_change(builder))
     # test no change, with target_weight present but equal
     builder.devs[0]['target_weight'] = 100.0
     self.assertFalse(rmd.ring_requires_change(builder))
     # test with change
     builder.devs[0]['target_weight'] = 42.0
     self.assertTrue(rmd.ring_requires_change(builder))
     # test brand new ring (i.e. newly added devs)
     builder = fb.gen_builder(balanced=False)
     self.assertTrue(rmd.ring_requires_change(builder))
     # test brand new ring bad balance
     builder.devs_changed = False
     rmd.ring_balance_ok = MagicMock(return_value=False)
     self.assertTrue(rmd.ring_requires_change(builder))
Exemplo n.º 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()