Пример #1
0
def test_downgrade():
    patchrepo = PatchRepository()
    patch1 = Patch('patch1', depends_on_names=[('patch2', False)])
    patch2 = Patch('patch2', depends_on_names=[('patch3', False),
            ('patch4', False)])
    patch3 = Patch('patch3', depends_on_names=[('patch4', False),
            ('patch5', False)])
    patch4 = Patch('patch4', depends_on_names=[])
    patch5 = Patch('patch5', depends_on_names=[])
    patchrepo.add_patches(patch1, patch2, patch3, patch4, patch5)
    patchrepo.resolve_dependencies()

    applied_patches = [patch1, patch2, patch3, patch4, patch5]
    plan = generate_downgrade_plan(applied_patches=applied_patches,
            to_be_removed_patches=[patch1])
    eq_(plan, [patch1])

    plan = generate_downgrade_plan(applied_patches=applied_patches,
            to_be_removed_patches=[patch3])
    eq_(plan, [patch1, patch2, patch3])

    plan = generate_downgrade_plan(applied_patches=applied_patches,
            to_be_removed_patches=[patch5])
    eq_(plan, [patch1, patch2, patch3, patch5])

    plan = generate_downgrade_plan(applied_patches=applied_patches,
            to_be_removed_patches=[patch5, patch4])
    assert plan == [patch1, patch2, patch3, patch4, patch5] or \
            plan == [patch1, patch2, patch3, patch5, patch4]
Пример #2
0
 def downgrade_patches(self, patches, execute_sql=True):
     dbrepo = self._get_repo()
     applied_patches = self.applied_patches
     plan = generate_downgrade_plan(applied_patches=applied_patches,
             to_be_removed_patches=patches)
     for patch in plan:
         print "removing patch '%s'" % patch.name
         dbpatch = self.sess.query(AppliedPatch)\
                 .filter_by(repository_id=dbrepo.repository_id,
                         patch_name=patch.name)\
                 .one()
         self.sess.delete(dbpatch)
         if patch.downgrade_sql is not None and execute_sql:
             for patch_name in patch.missing_deps:
                 print " (ignoring optional missing patch '%s')" % patch_name
             with _TranslateErrors("patch downgrade failed '%s'" % (
                     patch.name)):
                 execute_script(self.sess, patch.downgrade_sql)
     return plan