Added goal filter in Watcher API
Although it was proposed via python-watcherclient, the feature was not implemented on the Watcher API. As the notion of host aggregate is currently unused in Watcher, decision was made to only implement the filtering of goal within the Watcher API whilst removing the host_aggregate filter from the Watcher client. Thus, this patchset adds this missing functionality by adding the 'goal' parameter to the API. Change-Id: I54d248f7e470249c6412650ddf50a3e3631d2a09 Related-Bug: #1510189
This commit is contained in:
@@ -207,6 +207,25 @@ class TestListAuditTemplate(api_base.FunctionalTest):
|
||||
next_marker = response['audit_templates'][-1]['uuid']
|
||||
self.assertIn(next_marker, response['next'])
|
||||
|
||||
def test_filter_by_goal(self):
|
||||
cfg.CONF.set_override('goals', {"DUMMY": "DUMMY", "BASIC": "BASIC"},
|
||||
group='watcher_goals', enforce_type=True)
|
||||
|
||||
for id_ in range(2):
|
||||
obj_utils.create_test_audit_template(
|
||||
self.context, id=id_, uuid=utils.generate_uuid(),
|
||||
name='My Audit Template {0}'.format(id_),
|
||||
goal="DUMMY")
|
||||
|
||||
for id_ in range(2, 5):
|
||||
obj_utils.create_test_audit_template(
|
||||
self.context, id=id_, uuid=utils.generate_uuid(),
|
||||
name='My Audit Template {0}'.format(id_),
|
||||
goal="BASIC")
|
||||
|
||||
response = self.get_json('/audit_templates?goal=BASIC')
|
||||
self.assertEqual(3, len(response['audit_templates']))
|
||||
|
||||
|
||||
class TestPatch(api_base.FunctionalTest):
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
|
||||
import wsme
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from watcher.api.controllers.v1 import utils
|
||||
from watcher.tests import base
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
@@ -47,3 +47,21 @@ class TestApiUtils(base.TestCase):
|
||||
self.assertRaises(wsme.exc.ClientSideError,
|
||||
utils.validate_sort_dir,
|
||||
'fake-sort')
|
||||
|
||||
def test_validate_search_filters(self):
|
||||
allowed_fields = ["allowed", "authorized"]
|
||||
|
||||
test_filters = {"allowed": 1, "authorized": 2}
|
||||
try:
|
||||
utils.validate_search_filters(test_filters, allowed_fields)
|
||||
except Exception as exc:
|
||||
self.fail(exc)
|
||||
|
||||
def test_validate_search_filters_with_invalid_key(self):
|
||||
allowed_fields = ["allowed", "authorized"]
|
||||
|
||||
test_filters = {"allowed": 1, "unauthorized": 2}
|
||||
|
||||
self.assertRaises(
|
||||
wsme.exc.ClientSideError, utils.validate_search_filters,
|
||||
test_filters, allowed_fields)
|
||||
|
||||
Reference in New Issue
Block a user