OpenStack Block Storage (Cinder)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.8KB

  1. # Copyright 2020 Red Hat, Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. """Tests for code that makes assumptions about ORM relationships."""
  15. from sqlalchemy_utils import functions as saf
  16. from cinder.db.sqlalchemy import api as db_api
  17. from cinder.db.sqlalchemy import models
  18. from cinder import test
  19. class VolumeRelationshipsTestCase(test.TestCase):
  20. """Test cases for Volume ORM model relationshps."""
  21. def test_volume_dependent_models_list(self):
  22. """Make sure the volume dependent tables list is accurate."""
  23. # Addresses LP Bug #1542169
  24. volume_declarative_base = saf.get_declarative_base(models.Volume)
  25. volume_fks = saf.get_referencing_foreign_keys(models.Volume)
  26. dependent_tables = []
  27. for table, fks in saf.group_foreign_keys(volume_fks):
  28. dependent_tables.append(table)
  29. found_dependent_models = []
  30. for table in dependent_tables:
  31. found_dependent_models.append(saf.get_class_by_table(
  32. volume_declarative_base, table))
  33. self.assertEqual(len(found_dependent_models),
  34. len(db_api.VOLUME_DEPENDENT_MODELS))
  35. for model in found_dependent_models:
  36. self.assertIn(model, db_api.VOLUME_DEPENDENT_MODELS)