Trying to perform these operations fails with the stacktrace below:
curl -X POST -H 'content-type:application/json' -H 'X-Project-Id:12345' -d '{}' http://localhost:9311/v1/secrets
curl -X PUT -H 'content-type:application/octet-stream' -H 'content-encoding:base64' -H 'X-Project-Id:12345' -d 'bXktc2VjcmV0LWhlcmU=' http://localhost:9311/v1/secrets/<UUID>
----
Stacktrace:
2014-09-25 16:32:17.308 704 ERROR barbican.api.controllers [-] Secret update failure seen - please contact site administrator.
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers Traceback (most recent call last):
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/api/controllers/__init__.py", line 96, in handler
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers return fn(inst, *args, **kwargs)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/api/controllers/__init__.py", line 82, in enforcer
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers return fn(inst, *args, **kwargs)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/api/controllers/__init__.py", line 130, in content_types_enforcer
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers return fn(inst, *args, **kwargs)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/api/controllers/secrets.py", line 171, in on_put
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers transport_key_id=transport_key_id)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/plugin/resources.py", line 125, in store_secret
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers _save_secret(secret_model, tenant_model, repos)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/plugin/resources.py", line 365, in _save_secret
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers repos.secret_repo.save(secret_model)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/model/repositories.py", line 386, in save
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers entity.save(session=session)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/model/models.py", line 111, in save
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers session.add(self)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/.virtualenvs/Barbican/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1492, in add
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers self._save_or_update_state(state)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/.virtualenvs/Barbican/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1504, in _save_or_update_state
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers self._save_or_update_impl(state)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/.virtualenvs/Barbican/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1761, in _save_or_update_impl
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers self._update_impl(state)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/.virtualenvs/Barbican/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1755, in _update_impl
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers self._attach(state)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/.virtualenvs/Barbican/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1849, in _attach
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers state.session_id, self.hash_key))
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers InvalidRequestError: Object '<Secret at 0x7f662af1b450>' is already attached to session '90' (this is '94')
Reviewed: https:/ /review. openstack. org/124274 /git.openstack. org/cgit/ openstack/ barbican/ commit/ ?id=6b384e08305 9247ae29062f524 b6c32a500d822b
Committed: https:/
Submitter: Jenkins
Branch: master
commit 6b384e083059247 ae29062f524b6c3 2a500d822b
Author: jfwood <email address hidden>
Date: Fri Sep 26 00:17:03 2014 -0500
Fix error in two-step secret PUT with base64
An attempt to PUT base64-encoded binary data as the 2nd step in storing
a secret resulted in a SQLAlchemy 'already attached in another session'
error with the secret model. This CR moves to the SQLAlchemy scoped
session which ensures one session per thread. This CR also adds a
simple 'smoke test' script that was used to exercise the API during the
development of this CR, and could be helpful for others looking for a
simple way to test and evaluate their local Barbican API instances.
Closes-Bug: #1374270 12d82a285a71e2f 1b5c2483ea0
Change-Id: Ie50e5f03be7b9b