Пример #1
0
    def test_build_model_from_xml(self):
        fake_cluster = faker_cluster_state.FakerStorageModelCollector()

        expected_model = fake_cluster.generate_scenario_1()
        struct_str = self.load_data('storage_scenario_1.xml')

        model = model_root.StorageModelRoot.from_xml(struct_str)
        self.assertEqual(expected_model.to_string(), model.to_string())
Пример #2
0
    def test_model_structure(self):
        fake_cluster = faker_cluster_state.FakerStorageModelCollector()
        model1 = fake_cluster.build_scenario_1()

        self.assertEqual(2, len(model1.get_all_storage_nodes()))
        self.assertEqual(9, len(model1.get_all_volumes()))
        self.assertEqual(12, len(model1.edges()))

        expected_struct_str = self.load_data('storage_scenario_1.xml')
        model2 = model_root.StorageModelRoot.from_xml(expected_struct_str)
        self.assertTrue(
            model_root.StorageModelRoot.is_isomorphic(model2, model1))
Пример #3
0
class FakeStorageManager(FakeManager):

    fake_cdmc = faker_cluster_state.FakerStorageModelCollector()

    @property
    def notification_endpoints(self):
        return [
            cnotification.CapacityNotificationEndpoint(self.fake_cdmc),
            cnotification.VolumeCreateEnd(self.fake_cdmc),
            cnotification.VolumeUpdateEnd(self.fake_cdmc),
            cnotification.VolumeDeleteEnd(self.fake_cdmc),
            cnotification.VolumeAttachEnd(self.fake_cdmc),
            cnotification.VolumeDetachEnd(self.fake_cdmc),
            cnotification.VolumeResizeEnd(self.fake_cdmc),
        ]
Пример #4
0
    def setUp(self):
        super(TestZoneMigration, self).setUp()
        # fake compute cluster
        self.fake_c_cluster = faker_cluster_state.FakerModelCollector()

        # fake storage cluster
        self.fake_s_cluster = faker_cluster_state.FakerStorageModelCollector()

        p_c_model = mock.patch.object(
            strategies.ZoneMigration, "compute_model",
            new_callable=mock.PropertyMock)
        self.m_c_model = p_c_model.start()
        self.addCleanup(p_c_model.stop)

        p_s_model = mock.patch.object(
            strategies.ZoneMigration, "storage_model",
            new_callable=mock.PropertyMock)
        self.m_s_model = p_s_model.start()
        self.addCleanup(p_s_model.stop)

        p_migrate_compute_nodes = mock.patch.object(
            strategies.ZoneMigration, "migrate_compute_nodes",
            new_callable=mock.PropertyMock)
        self.m_migrate_compute_nodes = p_migrate_compute_nodes.start()
        self.addCleanup(p_migrate_compute_nodes.stop)

        p_migrate_storage_pools = mock.patch.object(
            strategies.ZoneMigration, "migrate_storage_pools",
            new_callable=mock.PropertyMock)
        self.m_migrate_storage_pools = p_migrate_storage_pools.start()
        self.addCleanup(p_migrate_storage_pools.stop)

        p_parallel_total = mock.patch.object(
            strategies.ZoneMigration, "parallel_total",
            new_callable=mock.PropertyMock)
        self.m_parallel_total = p_parallel_total.start()
        self.addCleanup(p_parallel_total.stop)

        p_parallel_per_node = mock.patch.object(
            strategies.ZoneMigration, "parallel_per_node",
            new_callable=mock.PropertyMock)
        self.m_parallel_per_node = p_parallel_per_node.start()
        self.addCleanup(p_parallel_per_node.stop)

        p_parallel_per_pool = mock.patch.object(
            strategies.ZoneMigration, "parallel_per_pool",
            new_callable=mock.PropertyMock)
        self.m_parallel_per_pool = p_parallel_per_pool.start()
        self.addCleanup(p_parallel_per_pool.stop)

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

        p_priority = mock.patch.object(
            strategies.ZoneMigration, "priority",
            new_callable=mock.PropertyMock
        )
        self.m_priority = p_priority.start()
        self.addCleanup(p_priority.stop)

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

        model = self.fake_s_cluster.generate_scenario_1()
        self.m_s_model.return_value = model

        self.m_parallel_total.return_value = 6
        self.m_parallel_per_node.return_value = 2
        self.m_parallel_per_pool.return_value = 2
        self.m_audit_scope.return_value = mock.Mock()
        self.m_migrate_compute_nodes.return_value = [
            {"src_node": "src1", "dst_node": "dst1"},
            {"src_node": "src2", "dst_node": "dst2"}
        ]
        self.m_migrate_storage_pools.return_value = [
            {"src_pool": "src1@back1#pool1", "dst_pool": "dst1@back1#pool1",
             "src_type": "type1", "dst_type": "type1"},
            {"src_pool": "src2@back1#pool1", "dst_pool": "dst2@back2#pool1",
             "src_type": "type2", "dst_type": "type3"}
        ]
        self.m_audit_scope.return_value = mock.Mock()

        self.strategy = strategies.ZoneMigration(
            config=mock.Mock())

        self.m_osc_cls = mock.Mock()
        self.m_osc = mock.Mock(spec=clients.OpenStackClients)
        self.m_osc_cls.return_value = self.m_osc
        m_openstack_clients = mock.patch.object(
            clients, "OpenStackClients", self.m_osc_cls)
        m_openstack_clients.start()
        self.addCleanup(m_openstack_clients.stop)

        self.m_n_helper_cls = mock.Mock()
        self.m_n_helper = mock.Mock(spec=nova_helper.NovaHelper)
        self.m_n_helper_cls.return_value = self.m_n_helper
        m_nova_helper = mock.patch.object(
            nova_helper, "NovaHelper", self.m_n_helper_cls)
        m_nova_helper.start()
        self.addCleanup(m_nova_helper.stop)

        self.m_c_helper_cls = mock.Mock()
        self.m_c_helper = mock.Mock(spec=cinder_helper.CinderHelper)
        self.m_c_helper_cls.return_value = self.m_c_helper
        m_cinder_helper = mock.patch.object(
            cinder_helper, "CinderHelper", self.m_c_helper_cls)
        m_cinder_helper.start()
        self.addCleanup(m_cinder_helper.stop)
Пример #5
0
 def setUp(self):
     super(TestStorageScope, self).setUp()
     self.fake_cluster = faker_cluster_state.FakerStorageModelCollector()
Пример #6
0
 def setUp(self):
     super(TestCinderNotifications, self).setUp()
     # fake cluster
     self.fake_cdmc = faker_cluster_state.FakerStorageModelCollector()
    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'})
        ]

        self.fake_c_cluster = faker_cluster_state.FakerStorageModelCollector()

        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)

        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)

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

        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