# clearupscript5.py
import transaction
import pdb
from Testing.makerequest import makerequest
from zope.component.hooks import setSite
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManager import setSecurityPolicy
from Testing.makerequest import makerequest
from Products.CMFCore.tests.base.security import PermissiveSecurityPolicy
from Products.CMFCore.tests.base.security import OmnipotentUser
def spoofRequest(context):
"""
Make REQUEST variable to be available on the Zope application server.
This allows acquisition to work properly
"""
_policy=PermissiveSecurityPolicy()
_oldpolicy=setSecurityPolicy(_policy)
newSecurityManager(None, OmnipotentUser().__of__(context.acl_users))
context = makerequest(context)
import pdb
pdb.set_trace()
return context
app = spoofRequest(app)
myplone = app.myplone
setSite(myplone)
migration_tool = myplone['portal_migration']
if migration_tool is not None:
migration_tool.upgrade(myplone.REQUEST, dry_run=True)
The Traceback:
Traceback (most recent call last):
File "/opt/mig-to-plone5/py2/parts/instance-archetypes/bin/interpreter", line 297, in <module>
exec(_val)
File "<string>", line 1, in <module>
File "clearupscript5.py", line 32, in <module>
migration_tool.upgrade(myplone.REQUEST,dry_run=True)
File "<string>", line 3, in upgrade
File "/opt/mig-to-plone5/Plone5/py2/eggs/AccessControl-4.2-py2.7-linux-x86_64.egg/AccessControl/requestmethod.py", line 77, in _curried
raise Forbidden('Request must be %s' % methodsstr)
zExceptions.Forbidden: Request must be POST
What i do:
I call in my Browser the /@@plone-upgrade view and click the Button Upgrade, then the migration starts and run successfully. But if i call the my script via bin/instance-archetypes run clearupscript5.py, it fails.
How can i fake the Post Request to start the Upgrade via Commandline or is there another option availabel to automate the process? Any ideas or tips?
Why do you need to make a fake request? Can't you just import the related browser view class, initialize the browser view and call the related method on this view?.
Traceback (most recent call last):
File "/opt/mig-to-plone5/py2/parts/instance-archetypes/bin/interpreter", line 297, in <module>
exec(_val)
File "<string>", line 1, in <module>
File "clearupscript5.py", line 38, in <module>
upgrade_view = getMultiAdapter(
File "/opt/mig-to-plone5/src/Products.CMFPlone/Products/CMFPlone/browser/admin.py", line 310, in __call__
dry_run=form.get('dry_run', False),
File "<string>", line 3, in upgrade
File "/opt/mig-to-plone5/py2/eggs/AccessControl-4.2-py2.7-linux-x86_64.egg/AccessControl/requestmethod.py", line 77, in _curried
raise Forbidden('Request must be %s' % methodsstr)
zExceptions.Forbidden: Request must be POST
Thanks, for advice. I migrate from 2.5 to 5.2 with a bashscript, install the Plone Versions, Copy Data.fs, Run migration via instance script. But to start the migration_tool in the instance-script for Plone 5 ends with the Traceback above
I don't see you setting the method to POST for the request. makerequest is creating an HTTPRequest, which sets the method based on an environment variable (https://github.com/zopefoundation/Zope/blob/master/src/ZPublisher/BaseRequest.py#L387).
But makrequest itself supports setting this: environ.setdefault('REQUEST_METHOD', 'GET'). So you could pass this in the call (currently you only provide the context).
Traceback (most recent call last):
File "/opt/mig-to-plone5/py2/parts/instance-archetypes/bin/interpreter", line 297, in <module>
exec(_val)
File "<string>", line 1, in <module>
File "clearupscript5.py", line 41, in <module>
view()
File "/opt/mig-to-plone5/src/Products.CMFPlone/Products/CMFPlone/browser/admin.py", line 310, in __call__
dry_run=form.get('dry_run', False),
File "<string>", line 3, in upgrade
File "/opt/mig-to-plone5/py2/eggs/AccessControl-4.2-py2.7-linux-x86_64.egg/AccessControl/requestmethod.py", line 77, in _curried
raise Forbidden('Request must be %s' % methodsstr)
zExceptions.Forbidden: Request must be POST
I have the feeling that it is going in the wrong direction. i don't know if it's a good idea. I will create an addon with a global browserview and run curl, e.g curl --user "admin:admin" --request POST https://127.0.0.1:10580/myplone/@@automate-upgrade
There are two options: it’s either not set correctly within makerequest or overwritten at some point. I would try to set it like this (and hope it goes through or make a curl request as you mentioned):