Fix incorrect result of listing templates

- When user executes 'murano env-template-list', it only returns all
  templates belong this tenant, and doesn't include public templates
  from other tenants.
- It returns all templates belong to tenant when only requests
  private templates.

Change-Id: I50f70f28827c851139f74cff3923843c3d48170b
Closes-Bug: #1542626
Closes-Bug: #1540709
This commit is contained in:
Lin Yang 2016-02-06 21:14:30 +08:00
parent 1b1a140552
commit 72cc7bf68e
3 changed files with 38 additions and 6 deletions

View File

@ -49,7 +49,7 @@ class Controller(object):
if not is_public:
filters['is_public'] = False
filters = {'tenant_id': tenant_id}
filters['tenant_id'] = tenant_id
elif is_public:
filters['is_public'] = True
@ -57,7 +57,7 @@ class Controller(object):
get_env_templates_by(filters)
else:
filters = (EnvironmentTemplate.is_public is True,
filters = (EnvironmentTemplate.is_public,
EnvironmentTemplate.tenant_id == tenant_id)
list_templates = env_temps.EnvTemplateServices.\
get_env_templates_or_by(filters)

View File

@ -173,8 +173,8 @@ class TestEnvTemplateApi(tb.ControllerTest, tb.MuranoApiTestCase):
self.assertFalse(0, len(json.loads(result.body)))
def test_list_private_env_templates(self):
"""Create an template, test list public with no
public templates.
"""Create a public template and a private template,
test list private templates.
"""
self._set_policy_rules(
{'create_env_template': '@',
@ -187,6 +187,12 @@ class TestEnvTemplateApi(tb.ControllerTest, tb.MuranoApiTestCase):
result = req.get_response(self.api)
self.assertFalse(json.loads(result.body)['is_public'])
self.expect_policy_check('create_env_template')
body = {'name': 'mytemp1', 'is_public': True}
req = self._post('/templates', json.dumps(body))
result = req.get_response(self.api)
self.assertTrue(json.loads(result.body)['is_public'])
self.expect_policy_check('list_env_templates')
req = self._get('/templates', {'is_public': False})
result = req.get_response(self.api)
@ -219,6 +225,34 @@ class TestEnvTemplateApi(tb.ControllerTest, tb.MuranoApiTestCase):
self.assertEqual(2, len(json.loads(result.body)['templates']))
def test_list_env_templates_with_different_tenant(self):
"""Create two template in two different tenants,
test list public template from another tenant.
"""
self._set_policy_rules(
{'create_env_template': '@',
'list_env_templates': '@'}
)
self.expect_policy_check('create_env_template')
body = {'name': 'mytemp', 'is_public': False}
req = self._post('/templates', json.dumps(body), tenant='first_tenant')
result = req.get_response(self.api)
self.assertFalse(json.loads(result.body)['is_public'])
self.expect_policy_check('create_env_template')
body = {'name': 'mytemp1', 'is_public': True}
req = self._post('/templates', json.dumps(body),
tenant='second_tenant')
result = req.get_response(self.api)
self.assertTrue(json.loads(result.body)['is_public'])
self.expect_policy_check('list_env_templates')
req = self._get('/templates', tenant='first_tenant')
result = req.get_response(self.api)
self.assertEqual(2, len(json.loads(result.body)['templates']))
def test_illegal_template_name_create(self):
"""Check that an illegal temp name results in an HTTPClientError."""
self._set_policy_rules(

View File

@ -14,7 +14,6 @@
# under the License.
from tempest.test import attr
from tempest_lib import decorators
from murano_tempest_tests.tests.api.application_catalog import base
from murano_tempest_tests import utils
@ -126,7 +125,6 @@ class TestEnvironmentTemplates(base.BaseApplicationCatalogTest):
template = self.alt_client.get_env_template(cloned_template['id'])
self.assertEqual(name, template['name'])
@decorators.skip_because(bug="1540709")
@attr(type='smoke')
def test_get_public_private_both_env_templates(self):
name = utils.generate_name('get_public_private_both')