Fix cron-triggers and openstack actions

* Fixed deleting cron-trigger-trust
   (only trustor can delete trust)
 * Fixed retrieving keystone service catalog
   (otherwise we always get UnauthorizedException
   from utils/openstack/keystone.py:210, need
   just request service catalog)

Change-Id: Ibb044788a6fb6727a48af0371096972561ef9e8d
This commit is contained in:
Nikolay Mahotkin 2017-07-27 12:19:20 +03:00
parent 7fad3e7b18
commit e0f2fb7ac4
3 changed files with 9 additions and 11 deletions

View File

@ -85,15 +85,7 @@ def delete_trust(trust_id):
if not trust_id:
return
ctx = auth_ctx.ctx()
# If this trust is already in the context then it means that
# context already has trust scoped token from exactly this trust_id.
# So we don't need request the token from the trust one more time.
if ctx.is_trust_scoped and ctx.trust_id == trust_id:
keystone_client = keystone.client()
else:
keystone_client = keystone.client_for_trusts(trust_id)
keystone_client = keystone.client_for_trusts(trust_id)
try:
keystone_client.trusts.delete(trust_id)

View File

@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from mistral import context as auth_context
from mistral import exceptions
from mistral.tests.unit import base
@ -44,7 +46,10 @@ class KeystoneUtilsTest(base.BaseTest):
keystone.format_url(url_template, self.values)
)
def test_get_endpoint_for_project_noauth(self):
@mock.patch.object(keystone, 'client')
def test_get_endpoint_for_project_noauth(self, client):
client().tokens.get_token_data.return_value = {'token': None}
# service_catalog is not set by default.
auth_context.set_ctx(base.get_context())
self.addCleanup(auth_context.set_ctx, None)

View File

@ -200,7 +200,8 @@ def obtain_service_catalog(ctx):
response = ctx.service_catalog
# Target service catalog may not be passed via API.
if not response and ctx.is_target:
# If we don't have the catalog yet, it should be requested.
if not response:
response = client().tokens.get_token_data(
token,
include_catalog=True