Esempio n. 1
0
    def setUp(self):
        super(TestVMWorkloadConsolidation, self).setUp()

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

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

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

        self.m_datasource.return_value = mock.Mock(
            get_instance_cpu_usage=(self.fake_metrics.get_instance_cpu_util),
            get_instance_memory_usage=(
                self.fake_metrics.get_instance_ram_util),
            get_instance_root_disk_allocated=(
                self.fake_metrics.get_instance_disk_root_size),
        )
        self.strategy = strategies.VMWorkloadConsolidation(config=mock.Mock(
            datasources=self.datasource))
    def setUp(self):
        super(TestVMWorkloadConsolidation, self).setUp()

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

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

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

        p_audit_scope = mock.patch.object(strategies.VMWorkloadConsolidation,
                                          "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()

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

        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.VMWorkloadConsolidation(config=mock.Mock(
            datasource=self.datasource))
Esempio n. 3
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