-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from pulp/mhrivnak-1004049
1004049 - added a migration for errata that have the old "from_str" key
- Loading branch information
Showing
2 changed files
with
200 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright © 2013 Red Hat, Inc. | ||
# | ||
# This software is licensed to you under the GNU General Public | ||
# License as published by the Free Software Foundation; either version | ||
# 2 of the License (GPLv2) or (at your option) any later version. | ||
# There is NO WARRANTY for this software, express or implied, | ||
# including the implied warranties of MERCHANTABILITY, | ||
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should | ||
# have received a copy of GPLv2 along with this software; if not, see | ||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
|
||
from pulp.server.db.connection import get_collection | ||
|
||
|
||
def migrate(*args, **kwargs): | ||
""" | ||
Migrate existing errata to have the key "from" instead of "from_str" | ||
""" | ||
errata_collection = get_collection('units_errata') | ||
rename_query = {'$rename': {'from_str': 'from'}} | ||
errata_collection.update({}, rename_query, safe=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright © 2013 Red Hat, Inc. | ||
# | ||
# This software is licensed to you under the GNU General Public | ||
# License as published by the Free Software Foundation; either version | ||
# 2 of the License (GPLv2) or (at your option) any later version. | ||
# There is NO WARRANTY for this software, express or implied, | ||
# including the implied warranties of MERCHANTABILITY, | ||
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should | ||
# have received a copy of GPLv2 along with this software; if not, see | ||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
|
||
import json | ||
|
||
from pulp.server.db.connection import get_collection | ||
from pulp.server.db.migrate.models import _import_all_the_way | ||
|
||
import rpm_support_base | ||
|
||
|
||
class TestMigrateErrataFromStr(rpm_support_base.PulpRPMTests): | ||
""" | ||
Test migration #0013. | ||
""" | ||
def setUp(self): | ||
super(TestMigrateErrataFromStr, self).setUp() | ||
|
||
self.collection = get_collection('units_errata') | ||
|
||
errata = [ | ||
json.loads(ERRATA_OLD), | ||
json.loads(ERRATA_NEW), | ||
] | ||
|
||
for erratum in errata: | ||
self.collection.save(erratum, safe=True) | ||
|
||
def tearDown(self): | ||
super(TestMigrateErrataFromStr, self).tearDown() | ||
|
||
self.collection.remove(safe=True) | ||
|
||
def test_migrate(self): | ||
migration = _import_all_the_way('pulp_rpm.migrations.0013_errata_from_str') | ||
|
||
# Run the migration | ||
migration.migrate() | ||
|
||
# Verify that this one's "from_str" got changed to "from" | ||
old = self.collection.find_one({'id': 'RHEA-2012:0003'}) | ||
self.assertEqual(old.get('from', None), 'errata@redhat.com') | ||
self.assertFalse('from_str' in old) | ||
|
||
# Verify that this one's "from" is still "from" | ||
new = self.collection.find_one({'id': 'RHEA-2012:0004'}) | ||
self.assertEqual(new.get('from', None), 'errata@redhat.com') | ||
self.assertFalse('from_str' in new) | ||
|
||
|
||
ERRATA_OLD = """{ | ||
"status" : "stable", | ||
"updated" : "", | ||
"description" : "Bird_Erratum", | ||
"issued" : "2012-01-27 16:08:08", | ||
"pushcount" : 1, | ||
"references" : [ ], | ||
"_content_type_id" : "erratum", | ||
"id" : "RHEA-2012:0003", | ||
"from_str" : "errata@redhat.com", | ||
"_storage_path" : null, | ||
"reboot_suggested" : false, | ||
"severity" : "", | ||
"rights" : "", | ||
"_ns" : "units_erratum", | ||
"title" : "Bird_Erratum", | ||
"solution" : "", | ||
"summary" : "", | ||
"version" : "1", | ||
"release" : "1", | ||
"type" : "security", | ||
"pkglist" : [ | ||
{ | ||
"packages" : [ | ||
{ | ||
"src" : "http://www.fedoraproject.org", | ||
"name" : "crow", | ||
"filename" : "crow-0.8-1.noarch.rpm", | ||
"epoch" : null, | ||
"version" : "0.8", | ||
"release" : "1", | ||
"arch" : "noarch" | ||
}, | ||
{ | ||
"src" : "http://www.fedoraproject.org", | ||
"name" : "stork", | ||
"filename" : "stork-0.12-2.noarch.rpm", | ||
"epoch" : null, | ||
"version" : "0.12", | ||
"release" : "2", | ||
"arch" : "noarch" | ||
}, | ||
{ | ||
"src" : "http://www.fedoraproject.org", | ||
"name" : "duck", | ||
"filename" : "duck-0.6-1.noarch.rpm", | ||
"epoch" : null, | ||
"version" : "0.6", | ||
"release" : "1", | ||
"arch" : "noarch" | ||
} | ||
], | ||
"name" : "1", | ||
"short" : "" | ||
} | ||
] | ||
}""" | ||
|
||
|
||
ERRATA_NEW = """{ | ||
"status" : "stable", | ||
"updated" : "", | ||
"description" : "Fish_Erratum", | ||
"issued" : "2012-01-27 16:08:18", | ||
"pushcount" : 1, | ||
"references" : [ ], | ||
"_content_type_id" : "erratum", | ||
"id" : "RHEA-2012:0004", | ||
"from" : "errata@redhat.com", | ||
"_storage_path" : null, | ||
"reboot_suggested" : false, | ||
"severity" : "", | ||
"rights" : "", | ||
"_ns" : "units_erratum", | ||
"title" : "Fish_Erratum", | ||
"solution" : "", | ||
"summary" : "", | ||
"version" : "1", | ||
"release" : "1", | ||
"type" : "security", | ||
"pkglist" : [ | ||
{ | ||
"packages" : [ | ||
{ | ||
"src" : "http://www.fedoraproject.org", | ||
"name" : "crow", | ||
"filename" : "crow-0.8-2.noarch.rpm", | ||
"epoch" : null, | ||
"version" : "0.8", | ||
"release" : "1", | ||
"arch" : "noarch" | ||
}, | ||
{ | ||
"src" : "http://www.fedoraproject.org", | ||
"name" : "stork", | ||
"filename" : "stork-0.12-3.noarch.rpm", | ||
"epoch" : null, | ||
"version" : "0.12", | ||
"release" : "2", | ||
"arch" : "noarch" | ||
}, | ||
{ | ||
"src" : "http://www.fedoraproject.org", | ||
"name" : "duck", | ||
"filename" : "duck-0.6-2.noarch.rpm", | ||
"epoch" : null, | ||
"version" : "0.6", | ||
"release" : "1", | ||
"arch" : "noarch" | ||
} | ||
], | ||
"name" : "1", | ||
"short" : "" | ||
} | ||
] | ||
}""" | ||
|