Fuel UI
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.

test_migration_plugins_cluster_attrs_use_ids_mapping.py 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright 2015 Mirantis, 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. from copy import deepcopy
  15. from nailgun.objects import Plugin
  16. from nailgun.test.base import BaseTestCase
  17. from nailgun.utils.migration import \
  18. upgrade_6_0_to_6_1_plugins_cluster_attrs_use_ids_mapping
  19. class TestMigrationPluginsClusterAttrs(BaseTestCase):
  20. def setUp(self):
  21. super(TestMigrationPluginsClusterAttrs, self).setUp()
  22. self.cluster = self.env.create()
  23. self.plugins = [
  24. Plugin.create(self.env.get_default_plugin_metadata(
  25. name='plugin_name_1')),
  26. Plugin.create(self.env.get_default_plugin_metadata(
  27. name='plugin_name_2'))]
  28. def test_replaces_versions_with_ids(self):
  29. attrs = deepcopy(self.cluster.attributes.editable)
  30. for plugin in self.plugins:
  31. attrs[plugin.name] = {}
  32. attrs[plugin.name]['metadata'] = {
  33. 'plugin_version': plugin.version}
  34. self.cluster.attributes.editable = attrs
  35. self.db.commit()
  36. connection = self.db.connection()
  37. upgrade_6_0_to_6_1_plugins_cluster_attrs_use_ids_mapping(connection)
  38. for plugin in self.plugins:
  39. plugin_attr = self.cluster.attributes.editable[plugin.name]
  40. self.assertEqual(plugin_attr['metadata']['plugin_id'], plugin.id)
  41. self.assertNotIn('plugin_version', plugin_attr['metadata'])
  42. def test_do_not_fail_if_plugin_was_not_found(self):
  43. attrs = deepcopy(self.cluster.attributes.editable)
  44. attrs['some_plugin_name'] = {}
  45. attrs['some_plugin_name']['metadata'] = {
  46. 'plugin_version': '1111.111.111'}
  47. self.cluster.attributes.editable = attrs
  48. self.db.commit()
  49. connection = self.db.connection()
  50. upgrade_6_0_to_6_1_plugins_cluster_attrs_use_ids_mapping(connection)
  51. plugin_attr = self.cluster.attributes.editable['some_plugin_name']
  52. self.assertEqual(plugin_attr['metadata']['plugin_id'], None)
  53. self.assertNotIn('plugin_version', plugin_attr['metadata'])