Esempio n. 1
0
    def setUp(self):
        super(TestUniformAirflow, self).setUp()
        # fake metrics
        self.fake_metrics = self.fake_datasource_cls()

        p_datasource = mock.patch.object(strategies.UniformAirflow,
                                         'datasource_backend',
                                         new_callable=mock.PropertyMock)
        self.m_datasource = p_datasource.start()
        self.addCleanup(p_datasource.stop)

        self.m_datasource.return_value = mock.Mock(
            statistic_aggregation=self.fake_metrics.mock_get_statistics,
            NAME=self.fake_metrics.NAME)
        self.strategy = strategies.UniformAirflow(config=mock.Mock(
            datasource=self.datasource))
        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({
            'threshold_airflow': 400.0,
            'threshold_inlet_t': 28.0,
            'threshold_power': 350.0,
            'period': 300
        })
        self.strategy.threshold_airflow = 400
        self.strategy.threshold_inlet_t = 28
        self.strategy.threshold_power = 350
        self._period = 300
        self.strategy.pre_execute()
Esempio n. 2
0
 def test_actuator_strategy(self):
     fake_action = {"action_type": "TEST", "input_parameters": {"a": "b"}}
     self.strategy.input_parameters = utils.Struct(
         {"actions": [fake_action]})
     solution = self.strategy.execute()
     self.assertEqual(1, len(solution.actions))
     self.assertEqual([fake_action], solution.actions)
Esempio n. 3
0
    def setUp(self):
        super(TestWorkloadBalance, self).setUp()
        # fake metrics
        self.fake_metrics = self.fake_datasource_cls()

        p_datasource = mock.patch.object(strategies.WorkloadBalance,
                                         "datasource_backend",
                                         new_callable=mock.PropertyMock)
        self.m_datasource = p_datasource.start()
        self.addCleanup(p_datasource.stop)

        self.m_datasource.return_value = mock.Mock(
            statistic_aggregation=self.fake_metrics.mock_get_statistics_wb)
        self.strategy = strategies.WorkloadBalance(config=mock.Mock(
            datasource=self.datasource))
        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({
            'metrics': 'cpu_util',
            'threshold': 25.0,
            'period': 300,
            'granularity': 300
        })
        self.strategy.threshold = 25.0
        self.strategy._period = 300
        self.strategy._meter = "cpu_util"
        self.strategy._granularity = 300
Esempio n. 4
0
    def __init__(self, config, osc=None):
        """Constructor: the signature should be identical within the subclasses

        :param config: Configuration related to this plugin
        :type config: :py:class:`~.Struct`
        :param osc: An OpenStackClients instance
        :type osc: :py:class:`~.OpenStackClients` instance
        """
        super(BaseStrategy, self).__init__(config)
        self.ctx = context.make_context()
        self._name = self.get_name()
        self._display_name = self.get_display_name()
        self._goal = self.get_goal()
        # default strategy level
        self._strategy_level = level.StrategyLevel.conservative
        self._cluster_state_collector = None
        # the solution given by the strategy
        self._solution = default.DefaultSolution(goal=self.goal, strategy=self)
        self._osc = osc
        self._collector_manager = None
        self._compute_model = None
        self._storage_model = None
        self._baremetal_model = None
        self._input_parameters = utils.Struct()
        self._audit_scope = None
        self._datasource_backend = None
Esempio n. 5
0
    def setUp(self):
        super(TestSavingEnergy, self).setUp()

        mock_node1 = mock.Mock()
        mock_node2 = mock.Mock()
        mock_node1.to_dict.return_value = {
            'uuid': '922d4762-0bc5-4b30-9cb9-48ab644dd861'
        }
        mock_node2.to_dict.return_value = {
            'uuid': '922d4762-0bc5-4b30-9cb9-48ab644dd862'
        }
        self.fake_nodes = [mock_node1, mock_node2]

        p_ironic = mock.patch.object(clients.OpenStackClients, 'ironic')
        self.m_ironic = p_ironic.start()
        self.addCleanup(p_ironic.stop)

        p_nova = mock.patch.object(clients.OpenStackClients, 'nova')
        self.m_nova = p_nova.start()
        self.addCleanup(p_nova.stop)

        self.m_ironic.node.list.return_value = self.fake_nodes

        self.m_c_model.return_value = self.fake_c_cluster.generate_scenario_1()

        self.strategy = strategies.SavingEnergy(config=mock.Mock())
        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({
            'free_used_percent': 10.0,
            'min_free_hosts_num': 1
        })
        self.strategy.free_used_percent = 10.0
        self.strategy.min_free_hosts_num = 1
        self.strategy._ironic_client = self.m_ironic
        self.strategy._nova_client = self.m_nova
Esempio n. 6
0
    def setUp(self):
        super(TestOutletTempControl, self).setUp()
        # fake metrics
        self.fake_metrics = faker_metrics_collector.FakerMetricsCollector()
        # fake cluster
        self.fake_cluster = faker_cluster_state.FakerModelCollector()

        p_model = mock.patch.object(strategies.OutletTempControl,
                                    "compute_model",
                                    new_callable=mock.PropertyMock)
        self.m_model = p_model.start()
        self.addCleanup(p_model.stop)

        p_ceilometer = mock.patch.object(strategies.OutletTempControl,
                                         "ceilometer",
                                         new_callable=mock.PropertyMock)
        self.m_ceilometer = p_ceilometer.start()
        self.addCleanup(p_ceilometer.stop)

        p_audit_scope = mock.patch.object(strategies.OutletTempControl,
                                          "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.m_ceilometer.return_value = mock.Mock(
            statistic_aggregation=self.fake_metrics.mock_get_statistics)
        self.strategy = strategies.OutletTempControl(config=mock.Mock())

        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({'threshold': 34.3})
        self.strategy.threshold = 34.3
Esempio n. 7
0
    def test_nova_cdmc_execute(self, m_nova_helper_cls):
        m_nova_helper = mock.Mock(name="nova_helper")
        m_nova_helper_cls.return_value = m_nova_helper
        m_nova_helper.get_service.return_value = mock.Mock(
            host="test_hostname")

        fake_compute_node = mock.Mock(
            id=1337,
            service={'id': 123},
            hypervisor_hostname='test_hostname',
            memory_mb=333,
            free_disk_gb=222,
            local_gb=111,
            vcpus=4,
            state='TEST_STATE',
            status='TEST_STATUS',
        )
        fake_instance = mock.Mock(
            id='ef500f7e-dac8-470f-960c-169486fce71b',
            human_id='fake_instance',
            flavor={
                'ram': 333,
                'disk': 222,
                'vcpus': 4,
                'id': 1
            },
            metadata={'hi': 'hello'},
        )
        setattr(fake_instance, 'OS-EXT-STS:vm_state', 'VM_STATE')
        m_nova_helper.get_compute_node_list.return_value = [fake_compute_node]
        # m_nova_helper.get_instances_by_node.return_value = [fake_instance]
        m_nova_helper.get_instance_list.return_value = [fake_instance]

        m_nova_helper.get_flavor.return_value = utils.Struct(**{
            'ram': 333,
            'disk': 222,
            'vcpus': 4
        })

        m_config = mock.Mock()
        m_osc = mock.Mock()

        nova_cdmc = nova.NovaClusterDataModelCollector(config=m_config,
                                                       osc=m_osc)

        model = nova_cdmc.execute()

        compute_nodes = model.get_all_compute_nodes()
        instances = model.get_all_instances()

        self.assertEqual(1, len(compute_nodes))
        self.assertEqual(1, len(instances))

        node = list(compute_nodes.values())[0]
        instance = list(instances.values())[0]

        self.assertEqual(node.uuid, 'test_hostname')
        self.assertEqual(instance.uuid, 'ef500f7e-dac8-470f-960c-169486fce71b')
Esempio n. 8
0
    def get_collectors(self):
        if self._collectors is None:
            collectors = utils.Struct()
            collector_plugins = cfg.CONF.collector.collector_plugins
            for collector_name in collector_plugins:
                collector = self.collector_loader.load(collector_name)
                collectors[collector_name] = collector
            self._collectors = collectors

        return self._collectors
Esempio n. 9
0
    def get_collectors(self):
        if self._collectors is None:
            collectors = utils.Struct()
            available_collectors = self.collector_loader.list_available()
            for collector_name in available_collectors:
                collector = self.collector_loader.load(collector_name)
                collectors[collector_name] = collector
            self._collectors = collectors

        return self._collectors
Esempio n. 10
0
    def setUp(self):
        super(TestSavingEnergy, self).setUp()

        mock_node1 = mock.Mock()
        mock_node2 = mock.Mock()
        mock_node1.to_dict.return_value = {
            'uuid': '922d4762-0bc5-4b30-9cb9-48ab644dd861'
        }
        mock_node2.to_dict.return_value = {
            'uuid': '922d4762-0bc5-4b30-9cb9-48ab644dd862'
        }
        self.fake_nodes = [mock_node1, mock_node2]

        # fake cluster
        self.fake_cluster = faker_cluster_and_metrics.FakerModelCollector()

        p_model = mock.patch.object(strategies.SavingEnergy,
                                    "compute_model",
                                    new_callable=mock.PropertyMock)
        self.m_model = p_model.start()
        self.addCleanup(p_model.stop)

        p_ironic = mock.patch.object(clients.OpenStackClients, 'ironic')
        self.m_ironic = p_ironic.start()
        self.addCleanup(p_ironic.stop)

        p_nova = mock.patch.object(clients.OpenStackClients, 'nova')
        self.m_nova = p_nova.start()
        self.addCleanup(p_nova.stop)

        p_model = mock.patch.object(strategies.SavingEnergy,
                                    "compute_model",
                                    new_callable=mock.PropertyMock)
        self.m_model = p_model.start()
        self.addCleanup(p_model.stop)

        p_audit_scope = mock.patch.object(strategies.SavingEnergy,
                                          "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_ironic.node.list.return_value = self.fake_nodes

        self.strategy = strategies.SavingEnergy(config=mock.Mock())
        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({
            'free_used_percent': 10.0,
            'min_free_hosts_num': 1
        })
        self.strategy.free_used_percent = 10.0
        self.strategy.min_free_hosts_num = 1
        self.strategy._ironic_client = self.m_ironic
        self.strategy._nova_client = self.m_nova
Esempio n. 11
0
 def get_ironic_node_by_uuid(self, node_uuid):
     """Get ironic node by node UUID"""
     try:
         node = self.ironic.node.get(utils.Struct(uuid=node_uuid))
         if not node:
             raise exception.IronicNodeNotFound(uuid=node_uuid)
     except Exception as exc:
         LOG.exception(exc)
         raise exception.IronicNodeNotFound(uuid=node_uuid)
     # We need to pass an object with an 'uuid' attribute to make it work
     return node
 def test_check_parameters(self):
     model = self.fake_c_cluster.generate_scenario_3_with_2_nodes()
     self.m_c_model.return_value = model
     self.strategy.input_parameters = utils.Struct()
     self.strategy.input_parameters.update({'param1': 4.0, 'param2': 'Hi'})
     solution = self.strategy.execute()
     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()
Esempio n. 13
0
    def setUp(self):
        super(TestUniformAirflow, self).setUp()
        # fake metrics
        self.fake_metrics = self.fake_datasource_cls()
        # fake cluster
        self.fake_cluster = faker_cluster_state.FakerModelCollector()

        p_model = mock.patch.object(strategies.UniformAirflow,
                                    "compute_model",
                                    new_callable=mock.PropertyMock)
        self.m_model = p_model.start()
        self.addCleanup(p_model.stop)

        p_datasource = mock.patch.object(strategies.UniformAirflow,
                                         'datasource_backend',
                                         new_callable=mock.PropertyMock)
        self.m_datasource = p_datasource.start()
        self.addCleanup(p_datasource.stop)

        p_audit_scope = mock.patch.object(strategies.UniformAirflow,
                                          "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.m_datasource.return_value = mock.Mock(
            statistic_aggregation=self.fake_metrics.mock_get_statistics)
        self.strategy = strategies.UniformAirflow(config=mock.Mock(
            datasource=self.datasource))
        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({
            'threshold_airflow': 400.0,
            'threshold_inlet_t': 28.0,
            'threshold_power': 350.0,
            'period': 300
        })
        self.strategy.threshold_airflow = 400
        self.strategy.threshold_inlet_t = 28
        self.strategy.threshold_power = 350
        self._period = 300
Esempio n. 14
0
    def setUp(self):
        super(TestNoisyNeighbor, self).setUp()
        # fake metrics
        self.f_metrics = self.fake_datasource_cls()

        p_datasource = mock.patch.object(strategies.NoisyNeighbor,
                                         "datasource_backend",
                                         new_callable=mock.PropertyMock)
        self.m_datasource = p_datasource.start()
        self.addCleanup(p_datasource.stop)

        self.m_datasource.return_value = mock.Mock(
            get_instance_l3_cache_usage=self.f_metrics.mock_get_statistics_nn)
        self.strategy = strategies.NoisyNeighbor(config=mock.Mock())

        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({'cache_threshold': 35})
        self.strategy.threshold = 35
        self.strategy.input_parameters.update({'period': 100})
        self.strategy.threshold = 100
Esempio n. 15
0
    def setUp(self):
        super(TestOutletTempControl, self).setUp()
        # fake metrics
        self.fake_metrics = self.fake_datasource_cls()

        p_datasource = mock.patch.object(
            strategies.OutletTempControl, 'datasource_backend',
            new_callable=mock.PropertyMock)
        self.m_datasource = p_datasource.start()
        self.addCleanup(p_datasource.stop)

        self.m_datasource.return_value = mock.Mock(
            statistic_aggregation=self.fake_metrics.mock_get_statistics,
            NAME=self.fake_metrics.NAME)
        self.strategy = strategies.OutletTempControl(
            config=mock.Mock(datasource=self.datasource))

        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({'threshold': 34.3})
        self.strategy.threshold = 34.3
Esempio n. 16
0
    def _load_plugin_config(self, name, driver_cls):
        """Load the config of the plugin"""
        config = utils.Struct()
        config_opts = driver_cls.get_config_opts()
        if not config_opts:
            return config

        group_name = self.get_entry_name(name)
        self.conf.register_opts(config_opts, group=group_name)

        # Finalise the opt import by re-checking the configuration
        # against the provided config files
        self._reload_config()

        config_group = self.conf.get(group_name)
        if not config_group:
            raise exception.LoadingError(name=name)

        config.update({name: value for name, value in config_group.items()})

        return config
    def setUp(self):
        super(TestWorkloadBalance, self).setUp()
        # fake metrics
        self.fake_metrics = self.fake_datasource_cls()
        # fake cluster
        self.fake_cluster = faker_cluster_state.FakerModelCollector()

        p_model = mock.patch.object(
            strategies.WorkloadBalance, "compute_model",
            new_callable=mock.PropertyMock)
        self.m_model = p_model.start()
        self.addCleanup(p_model.stop)

        p_datasource = mock.patch.object(
            strategies.WorkloadBalance, self.datasource,
            new_callable=mock.PropertyMock)
        self.m_datasource = p_datasource.start()
        self.addCleanup(p_datasource.stop)

        p_audit_scope = mock.patch.object(
            strategies.WorkloadBalance, "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_datasource.return_value = mock.Mock(
            statistic_aggregation=self.fake_metrics.mock_get_statistics_wb)
        self.strategy = strategies.WorkloadBalance(
            config=mock.Mock(datasource=self.datasource))
        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({'metrics': 'cpu_util',
                                               'threshold': 25.0,
                                               'period': 300})
        self.strategy.threshold = 25.0
        self.strategy._period = 300
        self.strategy._meter = "cpu_util"
Esempio n. 18
0
    def setUp(self):
        super(TestNoisyNeighbor, self).setUp()
        # fake metrics
        self.fake_metrics = ceilometer_metrics.FakeCeilometerMetrics()
        # fake cluster
        self.fake_cluster = faker_cluster_state.FakerModelCollector()

        p_model = mock.patch.object(strategies.NoisyNeighbor,
                                    "compute_model",
                                    new_callable=mock.PropertyMock)
        self.m_model = p_model.start()
        self.addCleanup(p_model.stop)

        p_ceilometer = mock.patch.object(strategies.NoisyNeighbor,
                                         "ceilometer",
                                         new_callable=mock.PropertyMock)
        self.m_ceilometer = p_ceilometer.start()
        self.addCleanup(p_ceilometer.stop)

        p_audit_scope = mock.patch.object(strategies.NoisyNeighbor,
                                          "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.m_ceilometer.return_value = mock.Mock(
            statistic_aggregation=self.fake_metrics.mock_get_statistics_nn)
        self.strategy = strategies.NoisyNeighbor(config=mock.Mock())

        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({'cache_threshold': 35})
        self.strategy.threshold = 35
        self.strategy.input_parameters.update({'period': 100})
        self.strategy.threshold = 100
    def setUp(self):
        super(TestWorkloadStabilization, self).setUp()

        # fake metrics
        self.fake_metrics = self.fake_datasource_cls()

        # fake cluster
        self.fake_cluster = faker_cluster_state.FakerModelCollector()

        self.hosts_load_assert = {
            'Node_0': {'cpu_util': 0.07, 'memory.resident': 7.0, 'vcpus': 40},
            'Node_1': {'cpu_util': 0.07, 'memory.resident': 5, 'vcpus': 40},
            'Node_2': {'cpu_util': 0.8, 'memory.resident': 29, 'vcpus': 40},
            'Node_3': {'cpu_util': 0.05, 'memory.resident': 8, 'vcpus': 40},
            'Node_4': {'cpu_util': 0.05, 'memory.resident': 4, 'vcpus': 40}}

        p_osc = mock.patch.object(
            clients, "OpenStackClients")
        self.m_osc = p_osc.start()
        self.addCleanup(p_osc.stop)

        p_model = mock.patch.object(
            strategies.WorkloadStabilization, "compute_model",
            new_callable=mock.PropertyMock)
        self.m_model = p_model.start()
        self.addCleanup(p_model.stop)

        p_datasource = mock.patch.object(
            strategies.WorkloadStabilization, "datasource_backend",
            new_callable=mock.PropertyMock)
        self.m_datasource = p_datasource.start()
        self.addCleanup(p_datasource.stop)

        p_audit_scope = mock.patch.object(
            strategies.WorkloadStabilization, "audit_scope",
            new_callable=mock.PropertyMock
        )
        self.m_audit_scope = p_audit_scope.start()
        self.addCleanup(p_audit_scope.stop)

        self.m_model.return_value = model_root.ModelRoot()
        self.m_audit_scope.return_value = mock.Mock()
        self.m_datasource.return_value = mock.Mock(
            statistic_aggregation=self.fake_metrics.mock_get_statistics)

        self.strategy = strategies.WorkloadStabilization(
            config=mock.Mock(datasource=self.datasource))
        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update(
            {'metrics': ["cpu_util", "memory.resident"],
             'thresholds': {"cpu_util": 0.2, "memory.resident": 0.2},
             'weights': {"cpu_util_weight": 1.0,
                         "memory.resident_weight": 1.0},
             'instance_metrics':
                 {"cpu_util": "compute.node.cpu.percent",
                  "memory.resident": "hardware.memory.used"},
             'host_choice': 'retry',
             'retry_count': 1,
             'periods': {"instance": 720, "node": 600},
             'aggregation_method': {"instance": "mean", "node": "mean"}})
        self.strategy.metrics = ["cpu_util", "memory.resident"]
        self.strategy.thresholds = {"cpu_util": 0.2, "memory.resident": 0.2}
        self.strategy.weights = {"cpu_util_weight": 1.0,
                                 "memory.resident_weight": 1.0}
        self.strategy.instance_metrics = {
            "cpu_util": "compute.node.cpu.percent",
            "memory.resident": "hardware.memory.used"}
        self.strategy.host_choice = 'retry'
        self.strategy.retry_count = 1
        self.strategy.periods = {"instance": 720, "node": 600}
        self.strategy.aggregation_method = {"instance": "mean", "node": "mean"}
 def test_dummy_with_scorer(self):
     dummy = strategies.DummyWithScorer(config=mock.Mock())
     dummy.input_parameters = utils.Struct()
     dummy.input_parameters.update({'param1': 4.0, 'param2': 'Hi'})
     solution = dummy.execute()
     self.assertEqual(4, len(solution.actions))
Esempio n. 21
0
 def __init__(self, stale=False):
     self._nodes = utils.Struct()
     self._instances = utils.Struct()
     self.mapping = mapping.Mapping(self)
     self.resource = utils.Struct()
     self.stale = stale
Esempio n. 22
0
    def setUp(self):
        super(TestStorageCapacityBalance, self).setUp()

        def test_fake_pool(name, free, total, allocated):
            fake_pool = mock.MagicMock()
            fake_pool.name = name
            fake_pool.pool_name = name.split('#')[1]
            fake_pool.volume_backend_name = name.split('#')[1]
            fake_pool.free_capacity_gb = free
            fake_pool.total_capacity_gb = total
            fake_pool.allocated_capacity_gb = allocated
            fake_pool.max_over_subscription_ratio = 1.0

            return fake_pool

        self.fake_pool1 = test_fake_pool('host1@IPSAN-1#pool1', '60', '100',
                                         '90')

        self.fake_pool2 = test_fake_pool('host1@IPSAN-1#pool2', '20', '100',
                                         '80')

        self.fake_pool3 = test_fake_pool('host1@IPSAN-1#local_vstorage', '20',
                                         '100', '80')
        self.fake_pools = [self.fake_pool1, self.fake_pool2, self.fake_pool3]

        def test_fake_vol(id,
                          name,
                          size,
                          status,
                          bootable,
                          migration_status=None,
                          volume_type=None):
            fake_vol = mock.MagicMock()
            fake_vol.id = id
            fake_vol.name = name
            fake_vol.size = size
            fake_vol.status = status
            fake_vol.bootable = bootable
            fake_vol.migration_status = migration_status
            fake_vol.volume_type = volume_type
            setattr(fake_vol, 'os-vol-host-attr:host', 'host1@IPSAN-1#pool2')

            return fake_vol

        self.fake_vol1 = test_fake_vol('922d4762-0bc5-4b30-9cb9-48ab644dd861',
                                       'test_volume1',
                                       4,
                                       'available',
                                       'true',
                                       'success',
                                       volume_type='type2')
        self.fake_vol2 = test_fake_vol('922d4762-0bc5-4b30-9cb9-48ab644dd862',
                                       'test_volume2', 10, 'in-use', 'false')
        self.fake_vol3 = test_fake_vol('922d4762-0bc5-4b30-9cb9-48ab644dd863',
                                       'test_volume3',
                                       4,
                                       'in-use',
                                       'true',
                                       volume_type='type2')
        self.fake_vol4 = test_fake_vol('922d4762-0bc5-4b30-9cb9-48ab644dd864',
                                       'test_volume4', 10, 'error', 'true')
        self.fake_vol5 = test_fake_vol('922d4762-0bc5-4b30-9cb9-48ab644dd865',
                                       'test_volume5', 15, 'in-use', 'true')

        self.fake_volumes = [
            self.fake_vol1, self.fake_vol2, self.fake_vol3, self.fake_vol4,
            self.fake_vol5
        ]

        def test_fake_snap(vol_id):
            fake_snap = mock.MagicMock()
            fake_snap.volume_id = vol_id

            return fake_snap

        self.fake_snap = [
            test_fake_snap('922d4762-0bc5-4b30-9cb9-48ab644dd865')
        ]

        def test_fake_volume_type(type_name, extra_specs):
            fake_type = mock.MagicMock()
            fake_type.name = type_name
            fake_type.extra_specs = extra_specs

            return fake_type

        self.fake_types = [
            test_fake_volume_type('type1', {'volume_backend_name': 'pool1'}),
            test_fake_volume_type('type2', {'volume_backend_name': 'pool2'})
        ]

        osc = clients.OpenStackClients()

        p_cinder = mock.patch.object(osc, 'cinder')
        p_cinder.start()
        self.addCleanup(p_cinder.stop)
        self.m_cinder = cinder_helper.CinderHelper(osc=osc)

        p_model = mock.patch.object(strategies.StorageCapacityBalance,
                                    "compute_model",
                                    new_callable=mock.PropertyMock)
        self.m_model = p_model.start()
        self.addCleanup(p_model.stop)

        p_audit_scope = mock.patch.object(strategies.StorageCapacityBalance,
                                          "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_cinder.get_storage_pool_list = mock.Mock(
            return_value=self.fake_pools)
        self.m_cinder.get_volume_list = mock.Mock(
            return_value=self.fake_volumes)
        self.m_cinder.get_volume_snapshots_list = mock.Mock(
            return_value=self.fake_snap)
        self.m_cinder.get_volume_type_list = mock.Mock(
            return_value=self.fake_types)
        self.strategy = strategies.StorageCapacityBalance(config=mock.Mock(),
                                                          osc=osc)
        self.strategy._cinder = self.m_cinder
        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({'volume_threshold': 80.0})
        self.strategy.volume_threshold = 80.0
    def setUp(self):
        super(TestWorkloadStabilization, self).setUp()

        # fake metrics
        self.fake_metrics = self.fake_datasource_cls()

        self.hosts_load_assert = {
            'Node_0': {
                'instance_cpu_usage': 0.07,
                'instance_ram_usage': 7.0,
                'vcpus': 40
            },
            'Node_1': {
                'instance_cpu_usage': 0.07,
                'instance_ram_usage': 5,
                'vcpus': 40
            },
            'Node_2': {
                'instance_cpu_usage': 0.8,
                'instance_ram_usage': 29,
                'vcpus': 40
            },
            'Node_3': {
                'instance_cpu_usage': 0.05,
                'instance_ram_usage': 8,
                'vcpus': 40
            },
            'Node_4': {
                'instance_cpu_usage': 0.05,
                'instance_ram_usage': 4,
                'vcpus': 40
            }
        }

        p_osc = mock.patch.object(clients, "OpenStackClients")
        self.m_osc = p_osc.start()
        self.addCleanup(p_osc.stop)

        p_datasource = mock.patch.object(strategies.WorkloadStabilization,
                                         "datasource_backend",
                                         new_callable=mock.PropertyMock)
        self.m_datasource = p_datasource.start()
        self.addCleanup(p_datasource.stop)

        self.m_datasource.return_value = mock.Mock(
            statistic_aggregation=self.fake_metrics.mock_get_statistics)

        self.strategy = strategies.WorkloadStabilization(config=mock.Mock(
            datasource=self.datasource))
        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({
            'metrics': ["instance_cpu_usage", "instance_ram_usage"],
            'thresholds': {
                "instance_cpu_usage": 0.2,
                "instance_ram_usage": 0.2
            },
            'weights': {
                "instance_cpu_usage_weight": 1.0,
                "instance_ram_usage_weight": 1.0
            },
            'instance_metrics': {
                "instance_cpu_usage": "host_cpu_usage",
                "instance_ram_usage": "host_ram_usage"
            },
            'host_choice':
            'retry',
            'retry_count':
            1,
            'periods': {
                "instance": 720,
                "compute_node": 600,
                "node": 0
            },
            'aggregation_method': {
                "instance": "mean",
                "compute_node": "mean",
                "node": ''
            }
        })
        self.strategy.metrics = ["instance_cpu_usage", "instance_ram_usage"]
        self.strategy.thresholds = {
            "instance_cpu_usage": 0.2,
            "instance_ram_usage": 0.2
        }
        self.strategy.weights = {
            "instance_cpu_usage_weight": 1.0,
            "instance_ram_usage_weight": 1.0
        }
        self.strategy.instance_metrics = {
            "instance_cpu_usage": "host_cpu_usage",
            "instance_ram_usage": "host_ram_usage"
        }
        self.strategy.host_choice = 'retry'
        self.strategy.retry_count = 1
        self.strategy.periods = {
            "instance": 720,
            "compute_node": 600,
            # node is deprecated
            "node": 0,
        }
        self.strategy.aggregation_method = {
            "instance": "mean",
            "compute_node": "mean",
            # node is deprecated
            "node": '',
        }
Esempio n. 24
0
 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))
Esempio n. 25
0
 def get_compute_node_by_id(self, node_id):
     """Get compute node by ID (*not* UUID)"""
     # We need to pass an object with an 'id' attribute to make it work
     return self.nova.hypervisors.get(utils.Struct(id=node_id))
Esempio n. 26
0
    def setUp(self):
        super(TestWorkloadStabilization, self).setUp()

        # fake metrics
        self.fake_metrics = faker_metrics_collector.FakerMetricsCollector()

        # fake cluster
        self.fake_cluster = faker_cluster_state.FakerModelCollector()

        self.hosts_load_assert = {
            'Node_0': {
                'cpu_util': 0.07,
                'memory.resident': 7.0,
                'vcpus': 40
            },
            'Node_1': {
                'cpu_util': 0.05,
                'memory.resident': 5,
                'vcpus': 40
            },
            'Node_2': {
                'cpu_util': 0.1,
                'memory.resident': 29,
                'vcpus': 40
            },
            'Node_3': {
                'cpu_util': 0.04,
                'memory.resident': 8,
                'vcpus': 40
            },
            'Node_4': {
                'cpu_util': 0.02,
                'memory.resident': 4,
                'vcpus': 40
            }
        }

        p_model = mock.patch.object(strategies.WorkloadStabilization,
                                    "compute_model",
                                    new_callable=mock.PropertyMock)
        self.m_model = p_model.start()
        self.addCleanup(p_model.stop)

        p_ceilometer = mock.patch.object(strategies.WorkloadStabilization,
                                         "ceilometer",
                                         new_callable=mock.PropertyMock)
        self.m_ceilometer = p_ceilometer.start()
        self.addCleanup(p_ceilometer.stop)

        p_audit_scope = mock.patch.object(strategies.WorkloadStabilization,
                                          "audit_scope",
                                          new_callable=mock.PropertyMock)
        self.m_audit_scope = p_audit_scope.start()
        self.addCleanup(p_audit_scope.stop)

        self.m_model.return_value = model_root.ModelRoot()
        self.m_ceilometer.return_value = mock.Mock(
            statistic_aggregation=self.fake_metrics.mock_get_statistics)
        self.m_audit_scope.return_value = mock.Mock()
        self.strategy = strategies.WorkloadStabilization(config=mock.Mock())
        self.strategy.input_parameters = utils.Struct()
        self.strategy.input_parameters.update({
            'metrics': ["cpu_util", "memory.resident"],
            'thresholds': {
                "cpu_util": 0.2,
                "memory.resident": 0.2
            },
            'weights': {
                "cpu_util_weight": 1.0,
                "memory.resident_weight": 1.0
            },
            'instance_metrics': {
                "cpu_util": "hardware.cpu.util",
                "memory.resident": "hardware.memory.used"
            },
            'host_choice':
            'retry',
            'retry_count':
            1
        })
        self.strategy.metrics = ["cpu_util", "memory.resident"]
        self.strategy.thresholds = {"cpu_util": 0.2, "memory.resident": 0.2}
        self.strategy.weights = {
            "cpu_util_weight": 1.0,
            "memory.resident_weight": 1.0
        }
        self.strategy.instance_metrics = {
            "cpu_util": "hardware.cpu.util",
            "memory.resident": "hardware.memory.used"
        }
        self.strategy.host_choice = 'retry'
        self.strategy.retry_count = 1