Jelajahi Sumber

Add more `unit tests` for `check_changed_storage_mappings` method

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu 8 bulan lalu
induk
melakukan
d4ced9fa83
1 mengubah file dengan 128 tambahan dan 0 penghapusan
  1. 128 0
      coriolis/tests/providers/test_provider_utils.py

+ 128 - 0
coriolis/tests/providers/test_provider_utils.py

@@ -129,3 +129,131 @@ class ProviderUtilsTestCase(test_base.CoriolisBaseTestCase):
             provider_utils.check_changed_storage_mappings,
             volumes_info, old_storage_mappings,
             new_storage_mappings)
+
+    def test_check_changed_storage_mappings_adding_new_mappings_allowed(self):
+        volumes_info = [{'volume_id': '1'}]
+        old_storage_mappings = {
+            'backend_mappings': [
+                {'source': 'backend1', 'destination': 'dest1'}
+            ],
+            'disk_mappings': [
+                {'disk_id': '1', 'destination': 'dest1'}
+            ]
+        }
+        new_storage_mappings = {
+            'backend_mappings': [
+                {'source': 'backend1', 'destination': 'dest1'},
+                {'source': 'backend2', 'destination': 'dest2'}
+            ],
+            'disk_mappings': [
+                {'disk_id': '1', 'destination': 'dest1'},
+                {'disk_id': '2', 'destination': 'dest2'}
+            ]
+        }
+        self.assertIsNone(provider_utils.check_changed_storage_mappings(
+            volumes_info, old_storage_mappings, new_storage_mappings))
+
+    def test_check_changed_storage_mappings_backend_mappings_changed(self):
+        volumes_info = [{'volume_id': '1'}]
+        old_storage_mappings = {
+            'backend_mappings': [
+                {'source': 'backend1', 'destination': 'dest1'}
+            ],
+            'disk_mappings': [
+                {'disk_id': '1', 'destination': 'dest1'}
+            ]
+        }
+        new_storage_mappings = {
+            'backend_mappings': [
+                {'source': 'backend1', 'destination': 'dest2'}
+            ],
+            'disk_mappings': [
+                {'disk_id': '1', 'destination': 'dest1'}
+            ]
+        }
+        self.assertRaises(
+            exception.CoriolisException,
+            provider_utils.check_changed_storage_mappings,
+            volumes_info, old_storage_mappings,
+            new_storage_mappings)
+
+    def test_check_changed_storage_mappings_missing_backend_mapping(self):
+        volumes_info = [{'volume_id': '1'}]
+        old_storage_mappings = {
+            'backend_mappings': [
+                {'source': 'backend1', 'destination': 'dest1'},
+                {'source': 'backend2', 'destination': 'dest2'}
+            ],
+            'disk_mappings': [
+                {'disk_id': '1', 'destination': 'dest1'}
+            ]
+        }
+        new_storage_mappings = {
+            'backend_mappings': [
+                {'source': 'backend1', 'destination': 'dest1'}
+            ],
+            'disk_mappings': [
+                {'disk_id': '1', 'destination': 'dest1'}
+            ]
+        }
+        self.assertRaises(
+            exception.CoriolisException,
+            provider_utils.check_changed_storage_mappings,
+            volumes_info, old_storage_mappings,
+            new_storage_mappings)
+
+    def test_check_changed_storage_mappings_missing_disk_mapping(self):
+        volumes_info = [{'volume_id': '1'}]
+        old_storage_mappings = {
+            'backend_mappings': [
+                {'source': 'backend1', 'destination': 'dest1'}
+            ],
+            'disk_mappings': [
+                {'disk_id': '1', 'destination': 'dest1'},
+                {'disk_id': '2', 'destination': 'dest2'}
+            ]
+        }
+        new_storage_mappings = {
+            'backend_mappings': [
+                {'source': 'backend1', 'destination': 'dest1'}
+            ],
+            'disk_mappings': [
+                {'disk_id': '1', 'destination': 'dest1'}
+            ]
+        }
+        self.assertRaises(
+            exception.CoriolisException,
+            provider_utils.check_changed_storage_mappings,
+            volumes_info, old_storage_mappings,
+            new_storage_mappings)
+
+    def test_check_changed_storage_mappings_empty_old_mappings(self):
+        volumes_info = [{'volume_id': '1'}]
+        old_storage_mappings = {}
+        new_storage_mappings = {
+            'backend_mappings': [
+                {'source': 'backend1', 'destination': 'dest1'}
+            ],
+            'disk_mappings': [
+                {'disk_id': '1', 'destination': 'dest1'}
+            ]
+        }
+        self.assertIsNone(provider_utils.check_changed_storage_mappings(
+            volumes_info, old_storage_mappings, new_storage_mappings))
+
+    def test_check_changed_storage_mappings_empty_new_mappings(self):
+        volumes_info = [{'volume_id': '1'}]
+        old_storage_mappings = {
+            'backend_mappings': [
+                {'source': 'backend1', 'destination': 'dest1'}
+            ],
+            'disk_mappings': [
+                {'disk_id': '1', 'destination': 'dest1'}
+            ]
+        }
+        new_storage_mappings = {}
+        self.assertRaises(
+            exception.CoriolisException,
+            provider_utils.check_changed_storage_mappings,
+            volumes_info, old_storage_mappings,
+            new_storage_mappings)