From 7556d19638680f695a929ace39fb38e48cbc5120 Mon Sep 17 00:00:00 2001 From: Hidekazu Nakamura Date: Tue, 15 May 2018 20:30:31 +0900 Subject: [PATCH] Add Cinder Cluster Data Model Collector test case This patch adds Cinder Data Model Collector test case. Change-Id: Ifaf7cd4a962da287f740a12e4c382a1ca92750d6 --- .../cluster/test_cinder_cdmc.py | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 watcher/tests/decision_engine/cluster/test_cinder_cdmc.py diff --git a/watcher/tests/decision_engine/cluster/test_cinder_cdmc.py b/watcher/tests/decision_engine/cluster/test_cinder_cdmc.py new file mode 100644 index 000000000..9c275319b --- /dev/null +++ b/watcher/tests/decision_engine/cluster/test_cinder_cdmc.py @@ -0,0 +1,103 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import mock + +from watcher.common import cinder_helper +from watcher.decision_engine.model.collector import cinder +from watcher.tests import base +from watcher.tests import conf_fixture + + +class TestCinderClusterDataModelCollector(base.TestCase): + + def setUp(self): + super(TestCinderClusterDataModelCollector, self).setUp() + self.useFixture(conf_fixture.ConfReloadFixture()) + + @mock.patch('keystoneclient.v3.client.Client', mock.Mock()) + @mock.patch.object(cinder_helper, 'CinderHelper') + def test_cinder_cdmc_execute(self, m_cinder_helper_cls): + + m_cinder_helper = mock.Mock(name="cinder_helper") + m_cinder_helper_cls.return_value = m_cinder_helper + + fake_storage_node = mock.Mock( + host='host@backend', + zone='zone', + status='enabled', + state='up', + volume_type=['fake_type'] + ) + + fake_storage_pool = mock.Mock( + total_volumes=1, + total_capacity_gb=30, + free_capacity_gb=20, + provisioned_capacity_gb=10, + allocated_capacity_gb=10, + virtual_free=20 + ) + setattr(fake_storage_pool, 'name', 'host@backend#pool') + + fake_volume = mock.Mock( + id=1, + size=1, + status='in-use', + attachments=[{"server_id": "server_id", + "attachment_id": "attachment_id"}], + multiattach='false', + snapshot_id='', + metadata='{"key": "value"}', + bootable='false' + ) + setattr(fake_volume, 'name', 'name') + setattr(fake_volume, 'os-vol-tenant-attr:tenant_id', 'project_id') + setattr(fake_volume, 'os-vol-host-attr:host', 'host@backend#pool') + + # storage node list + m_cinder_helper.get_storage_node_list.return_value = [ + fake_storage_node] + m_cinder_helper.get_volume_type_by_backendname.return_value = [ + 'fake_type'] + + # storage pool list + m_cinder_helper.get_storage_pool_list.return_value = [ + fake_storage_pool] + # volume list + m_cinder_helper.get_volume_list.return_value = [fake_volume] + + m_config = mock.Mock() + m_osc = mock.Mock() + + cinder_cdmc = cinder.CinderClusterDataModelCollector( + config=m_config, osc=m_osc) + + model = cinder_cdmc.execute() + + storage_nodes = model.get_all_storage_nodes() + storage_node = list(storage_nodes.values())[0] + + storage_pools = model.get_node_pools(storage_node) + storage_pool = storage_pools[0] + + volumes = model.get_pool_volumes(storage_pool) + volume = volumes[0] + + self.assertEqual(1, len(storage_nodes)) + self.assertEqual(1, len(storage_pools)) + self.assertEqual(1, len(volumes)) + + self.assertEqual(storage_node.host, 'host@backend') + self.assertEqual(storage_pool.name, 'host@backend#pool') + self.assertEqual(volume.uuid, '1')