Ejemplo n.º 1
0
 def __init__(self, messaging):
     self._messaging = messaging
     self._strategy_context = default_context.DefaultStrategyContext()
     self._planner_manager = planner_manager.PlannerManager()
     self._planner = None
Ejemplo n.º 2
0
class TestStrategyContext(base.DbTestCase):
    def setUp(self):
        super(TestStrategyContext, self).setUp()
        obj_utils.create_test_goal(self.context, id=1, name="DUMMY")
        audit_template = obj_utils.create_test_audit_template(
            self.context, uuid=utils.generate_uuid())
        self.audit = obj_utils.create_test_audit(
            self.context, audit_template_id=audit_template.id)

    strategy_context = d_strategy_ctx.DefaultStrategyContext()

    @mock.patch.object(strategies.DummyStrategy,
                       'compute_model',
                       new_callable=mock.PropertyMock)
    @mock.patch.object(d_selector.DefaultStrategySelector, 'select')
    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)

    @mock.patch.object(manager.CollectorManager, "get_cluster_model_collector",
                       mock.Mock())
    def test_execute_force_dummy(self):
        goal = obj_utils.create_test_goal(self.context,
                                          id=50,
                                          uuid=utils.generate_uuid(),
                                          name="my_goal")

        strategy = obj_utils.create_test_strategy(self.context,
                                                  id=42,
                                                  uuid=utils.generate_uuid(),
                                                  name="dummy",
                                                  goal_id=goal.id)

        audit = obj_utils.create_test_audit(
            self.context,
            id=2,
            name='My Audit {0}'.format(2),
            goal_id=goal.id,
            strategy_id=strategy.id,
            uuid=utils.generate_uuid(),
        )

        solution = self.strategy_context.execute_strategy(audit, self.context)

        self.assertEqual(len(solution.actions), 3)

    @mock.patch.object(strategies.BasicConsolidation, "execute")
    @mock.patch.object(manager.CollectorManager, "get_cluster_model_collector",
                       mock.Mock())
    def test_execute_force_basic(self, mock_call):
        expected_strategy = "basic"
        mock_call.return_value = expected_strategy

        obj_utils.create_test_goal(self.context,
                                   id=50,
                                   uuid=utils.generate_uuid(),
                                   name="my_goal")

        strategy = obj_utils.create_test_strategy(self.context,
                                                  id=42,
                                                  uuid=utils.generate_uuid(),
                                                  name=expected_strategy)

        audit = obj_utils.create_test_audit(
            self.context,
            id=2,
            name='My Audit {0}'.format(2),
            strategy_id=strategy.id,
            uuid=utils.generate_uuid(),
        )

        solution = self.strategy_context.execute_strategy(audit, self.context)

        self.assertEqual(solution, expected_strategy)
Ejemplo n.º 3
0
 def __init__(self):
     super(AuditHandler, self).__init__()
     self._strategy_context = default_context.DefaultStrategyContext()
     self._planner_manager = planner_manager.PlannerManager()
     self._planner = None
     self.applier_client = rpcapi.ApplierAPI()
Ejemplo n.º 4
0
 def __init__(self, messaging):
     super(DefaultAuditHandler, self).__init__()
     self._messaging = messaging
     self._strategy_context = default_context.DefaultStrategyContext()
     self._planner_manager = planner_manager.PlannerManager()
     self._planner = None
Ejemplo n.º 5
0
 def __init__(self):
     super(AuditHandler, self).__init__()
     self._strategy_context = default_context.DefaultStrategyContext()
     self._planner_loader = loader.DefaultPlannerLoader()
     self.applier_client = rpcapi.ApplierAPI()