def test_check_parameters(self): dummy = strategies.DummyStrategy("dummy", "Dummy strategy") fake_cluster = faker_cluster_state.FakerModelCollector() model = fake_cluster.generate_scenario_3_with_2_hypervisors() solution = dummy.execute(model) loader = default.DefaultActionLoader() for action in solution.actions: loaded_action = loader.load(action['action_type']) loaded_action.input_parameters = action['input_parameters'] loaded_action.validate_parameters()
def test_strategy_preference_override(self, m_conf, m_manager): """Test if the global preference can be overridden""" datasources = mock.Mock(datasources=['ceilometer']) self.strategy = strategies.DummyStrategy(config=datasources) m_conf.watcher_datasources.datasources = \ ['ceilometer', 'monasca', 'gnocchi'] # Access the property so that the configuration is read in order to # get the correct datasource self.strategy.datasource_backend m_manager.assert_called_once_with(config=datasources, osc=None)
def setUp(self): super(TestDummyStrategy, self).setUp() # fake cluster self.fake_cluster = faker_cluster_state.FakerModelCollector() p_model = mock.patch.object(strategies.DummyStrategy, "compute_model", new_callable=mock.PropertyMock) self.m_model = p_model.start() self.addCleanup(p_model.stop) p_audit_scope = mock.patch.object(strategies.DummyStrategy, "audit_scope", new_callable=mock.PropertyMock) self.m_audit_scope = p_audit_scope.start() self.addCleanup(p_audit_scope.stop) self.m_audit_scope.return_value = mock.Mock() self.m_model.return_value = model_root.ModelRoot() self.strategy = strategies.DummyStrategy(config=mock.Mock()) self.m_model.return_value = model_root.ModelRoot() self.strategy = strategies.DummyStrategy(config=mock.Mock())
def test_default_solution_with_no_input_parameters(self): solution = default.DefaultSolution( goal=mock.Mock(), strategy=strategies.DummyStrategy(config=mock.Mock())) solution.add_action(action_type="nop", resource_id="b199db0c-1408-4d52-b5a5-5ca14de0ff36") self.assertEqual(1, len(solution.actions)) expected_action_type = "nop" expected_parameters = { "resource_id": "b199db0c-1408-4d52-b5a5-5ca14de0ff36" } self.assertEqual(expected_action_type, solution.actions[0].get('action_type')) self.assertEqual(expected_parameters, solution.actions[0].get('input_parameters')) self.assertEqual('weight', solution.strategy.planner)
def test_execute_strategy(self, mock_call, m_model): m_model.return_value = mock.Mock() mock_call.return_value = strategies.DummyStrategy(config=mock.Mock()) solution = self.strategy_context.execute_strategy( self.audit, self.context) self.assertIsInstance(solution, default.DefaultSolution)
def test_dummy_strategy(self): dummy = strategies.DummyStrategy("dummy", "Dummy strategy") fake_cluster = faker_cluster_state.FakerModelCollector() model = fake_cluster.generate_scenario_3_with_2_hypervisors() solution = dummy.execute(model) self.assertEqual(3, len(solution.actions))
def setUp(self): super(TestBaseStrategyDatasource, self).setUp() self.strategy = strategies.DummyStrategy(config=mock.Mock( datasources=None))
def test_dummy_strategy(self): dummy = strategies.DummyStrategy(config=mock.Mock()) dummy.input_parameters = utils.Struct() dummy.input_parameters.update({'para1': 4.0, 'para2': 'Hi'}) solution = dummy.execute() self.assertEqual(3, len(solution.actions))
def setUp(self): super(TestDummyStrategy, self).setUp() self.strategy = strategies.DummyStrategy(config=mock.Mock())