Debian Codegraph @

mistral_tempest_tests/tests/scenario/engine/actions/v2/test_multi_vim_authentication.py

raw
1 # Copyright 2016 - Nokia, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 import base64
15
16 from keystoneclient import service_catalog as ks_service_catalog
17 from oslo_serialization import jsonutils
18 from oslo_utils import uuidutils
19 from tempest.lib import decorators
20 from urllib.parse import urlparse
21
22 from mistral_tempest_tests.tests import base
23
24
25 class MultiVimActionsTests(base.TestCase):
26 _service = 'workflowv2'
27
28 @decorators.attr(type='openstack')
29 @decorators.idempotent_id('dadc9960-9c03-41a9-9a9d-7e97d527e6dd')
30 @decorators.skip_because(bug="1964344")
31 def test_multi_vim_support_target_headers(self):
32 client_1 = self.alt_client
33 client_2 = self.client
34
35 # Create stack with client2.
36 result = _execute_action(client_2, _get_create_stack_request())
37 stack_id = str(
38 jsonutils.loads(result['output'])['result']['stack']['id']
39 )
40
41 # List stacks with client1, and assert that there is no stack.
42 result = _execute_action(client_1, _get_list_stack_request())
43 self.assertEmpty(jsonutils.loads(result['output'])['result'])
44
45 # List stacks with client1, but with the target headers of client2,
46 # and assert the created stack is there.
47 result = _execute_action(
48 client_1,
49 _get_list_stack_request(),
50 extra_headers=_extract_target_headers_from_client(client_2)
51 )
52 self.assertEqual(
53 stack_id,
54 str(jsonutils.loads(result['output'])['result'][0]['id'])
55 )
56
57 @decorators.attr(type='openstack')
58 @decorators.idempotent_id('bc0e9b99-62b0-4d96-95c9-016a3f69b02a')
59 @decorators.skip_because(bug="1736685")
60 def test_multi_vim_support_target_headers_and_service_catalog(self):
61 client_1 = self.alt_client
62 client_2 = self.client
63
64 # List stacks with client1, but with the target headers of client2,
65 # and additionally with an invalid X-Target-Service-Catalog.
66 extra_headers = _extract_target_headers_from_client(client_2)
67
68 # Use ServiceCatalog to eliminate differences between keystone v2 and
69 # v3.
70 token_data = client_2.auth_provider.auth_data[1]
71 service_catalog = ks_service_catalog.ServiceCatalog.factory(
72 token_data
73 ).get_data()
74
75 for service in service_catalog:
76 if service['name'] == 'heat':
77 for ep in service['endpoints']:
78 if 'publicURL' in ep:
79 ep['publicURL'] = "invalid"
80 elif ep['interface'] == 'public':
81 ep['url'] = "invalid"
82 break
83 break
84
85 if 'catalog' in token_data:
86 token_data['catalog'] = service_catalog
87 else:
88 token_data['serviceCatalog'] = service_catalog
89
90 invalid_service_catalog = {
91 "X-Target-Service-Catalog": base64.b64encode(
92 jsonutils.dumps(token_data)
93 )
94 }
95 extra_headers.update(invalid_service_catalog)
96 result = _execute_action(
97 client_1,
98 _get_list_stack_request(),
99 extra_headers=extra_headers
100 )
101
102 # Assert that the invalid catalog was used.
103 self.assertIn("Invalid URL", result['output'])
104
105
106 def _extract_target_headers_from_client(client):
107 u = urlparse(client.auth_provider.auth_url)
108 v3_auth_url = '{}://{}/identity/v3/'.format(u.scheme, u.netloc)
109 return {
110 'X-Target-Auth-Token': client.token,
111 'X-Target-Auth-Uri': v3_auth_url,
112 'X-Target-Project-Id': client.tenant_id,
113 'X-Target-User-Id': client.user_id,
114 }
115
116
117 def _execute_action(client, request, extra_headers=None):
118 if extra_headers is None:
119 extra_headers = {}
120 _, result = client.create_action_execution(
121 request,
122 extra_headers=extra_headers
123 )
124
125 return result
126
127
128 def _get_create_stack_request():
129 stack_name = 'multi_vim_test_stack_{}'.format(
130 uuidutils.generate_uuid()[:8])
131
132 return {
133 'name': 'heat.stacks_create',
134 'input': {
135 'stack_name': stack_name,
136 "template": {"heat_template_version": "2013-05-23"}
137 }
138 }
139
140
141 def _get_list_stack_request():
142 return {
143 'name': 'heat.stacks_list',
144 }