Exemple #1
0
    def __init__(self, goal_name, strategy_name=None, osc=None):
        """Default strategy selector

        :param goal_name: Name of the goal
        :param strategy_name: Name of the strategy
        :param osc: an OpenStackClients instance
        """
        super(DefaultStrategySelector, self).__init__()
        self.goal_name = goal_name
        self.strategy_name = strategy_name
        self.osc = osc
        self.strategy_loader = default.DefaultStrategyLoader()
Exemple #2
0
class TestLoadStrategiesWithDefaultStrategyLoader(base.TestCase):

    strategy_loader = default_loading.DefaultStrategyLoader()

    scenarios = [(strategy_name, {
        "strategy_name": strategy_name,
        "strategy_cls": strategy_cls
    }) for strategy_name, strategy_cls in
                 strategy_loader.list_available().items()]

    def test_load_strategies(self):
        strategy = self.strategy_loader.load(self.strategy_name)
        self.assertIsNotNone(strategy)
        self.assertEqual(self.strategy_name, strategy.name)
Exemple #3
0
 def get_strategy_info(self, context, strategy_name):
     strategy = loading.DefaultStrategyLoader().load(strategy_name)
     try:
         is_datasources = getattr(strategy.config, 'datasources', None)
         if is_datasources:
             datasource = getattr(strategy, 'datasource_backend')
         else:
             datasource = getattr(strategy, strategy.config.datasource)
     except (AttributeError, IndexError):
         datasource = []
     available_datasource = self._get_datasource_status(
         strategy, datasource)
     available_metrics = self._collect_metrics(strategy, datasource)
     available_cdm = self._get_cdm(strategy)
     return [available_datasource, available_metrics, available_cdm]
Exemple #4
0
    def _discover(self):
        strategies_map = {}
        goals_map = {}
        scoringengines_map = {}
        discovered_map = {
            "goals": goals_map,
            "strategies": strategies_map,
            "scoringengines": scoringengines_map
        }
        goal_loader = default.DefaultGoalLoader()
        implemented_goals = goal_loader.list_available()

        strategy_loader = default.DefaultStrategyLoader()
        implemented_strategies = strategy_loader.list_available()

        for goal_cls in implemented_goals.values():
            goals_map[goal_cls.get_name()] = GoalMapping(
                name=goal_cls.get_name(),
                display_name=goal_cls.get_translatable_display_name(),
                efficacy_specification=tuple(
                    IndicatorSpec(**indicator.to_dict())
                    for indicator in goal_cls.get_efficacy_specification().
                    get_indicators_specifications()))

        for strategy_cls in implemented_strategies.values():
            strategies_map[strategy_cls.get_name()] = StrategyMapping(
                name=strategy_cls.get_name(),
                goal_name=strategy_cls.get_goal_name(),
                display_name=strategy_cls.get_translatable_display_name(),
                parameters_spec=str(strategy_cls.get_schema()))

        for se in scoring_factory.get_scoring_engine_list():
            scoringengines_map[se.get_name()] = ScoringEngineMapping(
                name=se.get_name(),
                description=se.get_description(),
                metainfo=se.get_metainfo())

        return discovered_map
Exemple #5
0
 def test_load_dummy_strategy(self):
     strategy_loader = default_loading.DefaultStrategyLoader()
     loaded_strategy = strategy_loader.load("dummy")
     self.assertIsInstance(loaded_strategy, dummy_strategy.DummyStrategy)
Exemple #6
0
 def setUp(self):
     super(TestDefaultStrategyLoader, self).setUp()
     self.strategy_loader = default_loading.DefaultStrategyLoader()