Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds migration 0026 which removes a field from Distribution units
The pulp_distribution_xml_file was present in earlier versions of Pulp but is no longer used. It's not included in the mongoengine Distribution model so it fails to hydrate when it is present in the database. closes #1742 https://pulp.plan.io/issues/1743
- Loading branch information
Brian Bouterse
committed
Mar 4, 2016
1 parent
a1a3b71
commit 6f575de
Showing
5 changed files
with
56 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
plugins/pulp_rpm/plugins/migrations/0026_remove_distribution_field.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
Migration to remove the pulp_distribution_xml_file field from Distribution units, which is no | ||
longer used. | ||
""" | ||
|
||
from pulp.server.db import connection | ||
|
||
|
||
def migrate(*args, **kwargs): | ||
""" | ||
Perform the migration as described in this module's docblock. | ||
:param args: unused | ||
:type args: list | ||
:param kwargs: unused | ||
:type kwargs: dict | ||
""" | ||
db = connection.get_database() | ||
units_distribution_collection = db['units_distribution'] | ||
units_distribution_collection.update( | ||
{'pulp_distribution_xml_file': {'$exists': True}}, | ||
{'$unset': {'pulp_distribution_xml_file': True}}, | ||
multi=True | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
plugins/test/unit/plugins/migrations/test_0026_remove_distribution_field.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import unittest | ||
|
||
import mock | ||
|
||
from pulp.server.db.migrate.models import _import_all_the_way | ||
|
||
|
||
PATH_TO_MODULE = 'pulp_rpm.plugins.migrations.0026_remove_distribution_field' | ||
|
||
migration = _import_all_the_way(PATH_TO_MODULE) | ||
|
||
|
||
class TestMigrate(unittest.TestCase): | ||
""" | ||
Test migration 0026. | ||
""" | ||
|
||
@mock.patch(PATH_TO_MODULE + '.connection') | ||
def test_migration_fixed_expected_collections(self, mock_connection): | ||
mock_units_distribution = mock.Mock() | ||
mock_connection.get_database.return_value = { | ||
'units_distribution': mock_units_distribution, | ||
} | ||
|
||
migration.migrate() | ||
mock_connection.get_database.assert_called_once_with() | ||
|
||
mock_units_distribution.update.assert_called_once_with( | ||
{'pulp_distribution_xml_file': {'$exists': True}}, | ||
{'$unset': {'pulp_distribution_xml_file': True}}, | ||
multi=True | ||
) |