def add_upgrade_step(self, name, handler, destination): step = UpgradeStep(u'Upgrade %s' % name, self.policy_profile, str(destination - 1), str(destination), None, handler, checker=None, sortkey=0) if destination in self.upgrades: # pragma: no cover raise ValueError('Duplicate upgrade step to destination %s' % destination) self.upgrades.append(destination) _registerUpgradeStep(step)
def upgrade_step_directory_action(profile, dottedname, path, soft_dependencies): start_version = find_start_version(profile) scanner = Scanner(dottedname, path) if profile not in _profile_registry.listProfiles(): raise UpgradeStepConfigurationError( 'The profile "{0}" needs to be registered before registering its' ' upgrade step directory.'.format(profile)) profileinfo = _profile_registry.getProfileInfo(profile) if profileinfo.get('version', None) is not None: raise UpgradeStepConfigurationError( 'Registering an upgrades directory for "{0}" requires this profile' ' to not define a version in its metadata.xml.' ' The version is automatically set to the latest upgrade.'.format( profile)) _package, profilename = profile.split(':', 1) last_version = ''.join(find_start_version(profile)) for upgrade_info in scanner.scan(): upgrade_profile_name = '{0}-upgrade-{1}'.format( profilename, upgrade_info['target-version']) upgrade_handler = wrap_upgrade_step( handler=upgrade_info['callable'], upgrade_profile='profile-{0}:{1}'.format(dottedname, upgrade_profile_name), base_profile=profile, target_version=upgrade_info['target-version']) step = UpgradeStep(upgrade_info['title'], profile, upgrade_info['source-version'] or start_version, upgrade_info['target-version'], '', upgrade_handler) _registerUpgradeStep(step) _profile_registry.registerProfile( name=upgrade_profile_name, title='Upgrade {0} to {1}: {2}'.format( profile, upgrade_info['target-version'], upgrade_info['title']), description='', path=upgrade_info['path'], product=dottedname, profile_type=EXTENSION, for_=IMigratingPloneSiteRoot) last_version = upgrade_info['target-version'] profile = GlobalRegistryStorage(IProfile).get(profile) profile['version'] = last_version profile['ftw.upgrade:dependencies'] = soft_dependencies
def test_profileVersioning(self): site = self._makeSite() site.setup_tool = self._makeOne('setup_tool') tool = site.setup_tool profile_id = 'dummy_profile' product_name = 'GenericSetup' directory = os.path.split(__file__)[0] path = os.path.join(directory, 'versioned_profile') # register profile orig_profile_reg = (profile_registry._profile_info.copy(), profile_registry._profile_ids[:]) profile_registry.registerProfile(profile_id, 'Dummy Profile', 'This is a dummy profile', path, product=product_name) # register upgrade step from Products.GenericSetup.upgrade import _upgrade_registry orig_upgrade_registry = copy.copy(_upgrade_registry._registry) step = UpgradeStep("Upgrade", "GenericSetup:dummy_profile", '*', '1.1', '', dummy_upgrade_handler, None, "1") _registerUpgradeStep(step) # test initial states profile_id = ':'.join((product_name, profile_id)) self.assertEqual(tool.getVersionForProfile(profile_id), '1.1') self.assertEqual(tool.getLastVersionForProfile(profile_id), 'unknown') # run upgrade steps request = site.REQUEST request.form['profile_id'] = profile_id steps = listUpgradeSteps(tool, profile_id, '1.0') step_id = steps[0]['id'] request.form['upgrades'] = [step_id] tool.manage_doUpgrades() self.assertEqual(tool.getLastVersionForProfile(profile_id), ('1', '1')) # reset ugprade registry _upgrade_registry._registry = orig_upgrade_registry # reset profile registry (profile_registry._profile_info, profile_registry._profile_ids) = orig_profile_reg
def afterSetUp(self): from Products.GenericSetup.upgrade import _registerUpgradeStep from Products.GenericSetup.upgrade import UpgradeStep self.migration = getToolByName(self.portal, "portal_migration") self.setup = getToolByName(self.portal, "portal_setup") def failing_upgrade(context): raise AssertionError('Too new upgrade should not be run!') # Register a too new upgrade. fs_version = self.migration.getFileSystemVersion() new_version = unicode(int(fs_version) + 1) new_step = UpgradeStep('Too new upgrade', _DEFAULT_PROFILE, fs_version, new_version, '', failing_upgrade, None, '1') self.step_id = new_step.id _registerUpgradeStep(new_step)
def _registerUpgradeProfile(name, title, description, directory, product, provides, for_, profile, source, destination, handler, sortkey, checker): import_profile = "%s:%s" % (product, name) if import_profile not in _profile_registry.listProfiles(): _profile_registry.registerProfile(name, title, description, directory, product, provides, for_) if handler: step = UpgradeStep(title, profile, source, destination, description, handler, checker, sortkey) else: step = UpgradeDepends(title, profile, source, destination, description, import_profile=import_profile, checker=checker, sortkey=sortkey, run_deps=False) _registerUpgradeStep(step)