Support for refactored /audit_templates endpoint
In this changeset, I updated the Watcher CLI to support the new goal_uuid and strategy_uuid fields that were introduced. Partially Implements: blueprint get-goal-from-strategy Change-Id: I27b239361dd7df7e18d996e31da64d9477d172cc
This commit is contained in:

committed by
David TARDIVEL

parent
c5a5b7dad7
commit
d2c22f0353
@@ -31,7 +31,8 @@ AUDIT_TMPL1 = {
|
||||
'description': 'Audit Template 1 description',
|
||||
'host_aggregate': 5,
|
||||
'extra': {'automatic': False},
|
||||
'goal': 'MINIMIZE_LICENSING_COST'
|
||||
'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f',
|
||||
'strategy_uuid': 'bbe6b966-f98e-439b-a01a-17b9b3b8478b',
|
||||
}
|
||||
|
||||
AUDIT_TMPL2 = {
|
||||
@@ -41,7 +42,8 @@ AUDIT_TMPL2 = {
|
||||
'description': 'Audit Template 2 description',
|
||||
'host_aggregate': 8,
|
||||
'extra': {'automatic': True},
|
||||
'goal': 'BASIC_CONSOLIDATION'
|
||||
'goal_uuid': 'e75ee410-b32b-465f-88b5-4397705f9473',
|
||||
'strategy_uuid': 'ae99a4a4-acbc-4c67-abe1-e37128fac45d',
|
||||
}
|
||||
|
||||
AUDIT_TMPL3 = {
|
||||
@@ -51,7 +53,7 @@ AUDIT_TMPL3 = {
|
||||
'description': 'Audit Template 3 description',
|
||||
'host_aggregate': 7,
|
||||
'extra': {'automatic': True},
|
||||
'goal': 'MINIMIZE_LICENSING_COST'
|
||||
'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f',
|
||||
}
|
||||
|
||||
CREATE_AUDIT_TEMPLATE = copy.deepcopy(AUDIT_TMPL1)
|
||||
@@ -125,14 +127,14 @@ fake_responses = {
|
||||
{"audit_templates": [AUDIT_TMPL1]},
|
||||
),
|
||||
},
|
||||
'/v1/audit_templates/detail?goal=%s' % AUDIT_TMPL1['goal']:
|
||||
'/v1/audit_templates/detail?goal_uuid=%s' % AUDIT_TMPL1['goal_uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"audit_templates": [AUDIT_TMPL1, AUDIT_TMPL3]},
|
||||
),
|
||||
},
|
||||
'/v1/audit_templates/?goal=%s' % AUDIT_TMPL1['goal']:
|
||||
'/v1/audit_templates/?goal_uuid=%s' % AUDIT_TMPL1['goal_uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
@@ -176,8 +178,18 @@ fake_responses_sorting = {
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_filter_by_goal = {
|
||||
'/v1/audit_templates/?goal=BASIC_CONSOLIDATION':
|
||||
fake_responses_filter_by_goal_uuid = {
|
||||
'/v1/audit_templates/?goal_uuid=e75ee410-b32b-465f-88b5-4397705f9473':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"audit_templates": [AUDIT_TMPL2]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_filter_by_strategy_uuid = {
|
||||
'/v1/audit_templates/?strategy_uuid=ae99a4a4-acbc-4c67-abe1-e37128fac45d':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
@@ -203,7 +215,7 @@ class AuditTemplateManagerTest(testtools.TestCase):
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(audit_templates))
|
||||
|
||||
def test_audit_templates_list_by_name(self):
|
||||
def test_audit_templates_list_filter_by_name(self):
|
||||
audit_templates = self.mgr.list(name=AUDIT_TMPL1['name'])
|
||||
expect = [
|
||||
('GET', '/v1/audit_templates/?name=%s' % AUDIT_TMPL1['name'],
|
||||
@@ -212,13 +224,30 @@ class AuditTemplateManagerTest(testtools.TestCase):
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(audit_templates))
|
||||
|
||||
def test_audit_templates_list_by_goal(self):
|
||||
self.api = utils.FakeAPI(fake_responses_filter_by_goal)
|
||||
def test_audit_templates_list_filter_by_goal_uuid(self):
|
||||
self.api = utils.FakeAPI(fake_responses_filter_by_goal_uuid)
|
||||
self.mgr = watcherclient.v1.audit_template.AuditTemplateManager(
|
||||
self.api)
|
||||
audit_templates = self.mgr.list(goal="BASIC_CONSOLIDATION")
|
||||
audit_templates = self.mgr.list(
|
||||
goal_uuid="e75ee410-b32b-465f-88b5-4397705f9473")
|
||||
expect = [
|
||||
('GET', '/v1/audit_templates/?goal=%s' % AUDIT_TMPL2['goal'],
|
||||
('GET',
|
||||
'/v1/audit_templates/?goal_uuid=%s' % AUDIT_TMPL2['goal_uuid'],
|
||||
{}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(audit_templates))
|
||||
|
||||
def test_audit_templates_list_filter_by_strategy_uuid(self):
|
||||
self.api = utils.FakeAPI(fake_responses_filter_by_strategy_uuid)
|
||||
self.mgr = watcherclient.v1.audit_template.AuditTemplateManager(
|
||||
self.api)
|
||||
audit_templates = self.mgr.list(
|
||||
strategy_uuid="ae99a4a4-acbc-4c67-abe1-e37128fac45d")
|
||||
expect = [
|
||||
('GET',
|
||||
'/v1/audit_templates/?strategy_uuid=%s' % (
|
||||
AUDIT_TMPL2['strategy_uuid']),
|
||||
{}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
@@ -300,9 +329,10 @@ class AuditTemplateManagerTest(testtools.TestCase):
|
||||
audit_template.description)
|
||||
self.assertEqual(AUDIT_TMPL1['host_aggregate'],
|
||||
audit_template.host_aggregate)
|
||||
self.assertEqual(AUDIT_TMPL1['goal'], audit_template.goal)
|
||||
self.assertEqual(AUDIT_TMPL1['extra'],
|
||||
audit_template.extra)
|
||||
self.assertEqual(AUDIT_TMPL1['goal_uuid'], audit_template.goal_uuid)
|
||||
self.assertEqual(AUDIT_TMPL1['strategy_uuid'],
|
||||
audit_template.strategy_uuid)
|
||||
self.assertEqual(AUDIT_TMPL1['extra'], audit_template.extra)
|
||||
|
||||
def test_audit_templates_show_by_name(self):
|
||||
audit_template = self.mgr.get(urlparse.quote(AUDIT_TMPL1['name']))
|
||||
@@ -319,9 +349,10 @@ class AuditTemplateManagerTest(testtools.TestCase):
|
||||
audit_template.description)
|
||||
self.assertEqual(AUDIT_TMPL1['host_aggregate'],
|
||||
audit_template.host_aggregate)
|
||||
self.assertEqual(AUDIT_TMPL1['goal'], audit_template.goal)
|
||||
self.assertEqual(AUDIT_TMPL1['extra'],
|
||||
audit_template.extra)
|
||||
self.assertEqual(AUDIT_TMPL1['goal_uuid'], audit_template.goal_uuid)
|
||||
self.assertEqual(AUDIT_TMPL1['strategy_uuid'],
|
||||
audit_template.strategy_uuid)
|
||||
self.assertEqual(AUDIT_TMPL1['extra'], audit_template.extra)
|
||||
|
||||
def test_create(self):
|
||||
audit_template = self.mgr.create(**CREATE_AUDIT_TEMPLATE)
|
||||
|
@@ -32,7 +32,7 @@ class AuditTemplateShellTest(utils.BaseTestCase):
|
||||
exp = [
|
||||
'uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
'description', 'host_aggregate', 'name',
|
||||
'extra', 'goal']
|
||||
'extra', 'goal_uuid', 'strategy_uuid']
|
||||
act = actual.keys()
|
||||
self.assertEqual(sorted(exp), sorted(act))
|
||||
|
||||
|
@@ -23,15 +23,17 @@ from watcherclient.tests import utils
|
||||
import watcherclient.v1.strategy
|
||||
|
||||
STRATEGY1 = {
|
||||
'id': "basic",
|
||||
'uuid': '2cf86250-d309-4b81-818e-1537f3dba6e5',
|
||||
'name': 'basic',
|
||||
'display_name': 'Basic consolidation',
|
||||
'strategy_id': "SERVER_CONSOLIDATION",
|
||||
'strategy_id': 'SERVER_CONSOLIDATION',
|
||||
}
|
||||
|
||||
STRATEGY2 = {
|
||||
'id': "dummy",
|
||||
'uuid': 'b20bb987-ea8f-457a-a4ea-ab3ffdfeff8b',
|
||||
'name': 'dummy',
|
||||
'display_name': 'Dummy',
|
||||
'strategy_id': "DUMMY",
|
||||
'strategy_id': 'DUMMY',
|
||||
}
|
||||
|
||||
fake_responses = {
|
||||
@@ -49,7 +51,14 @@ fake_responses = {
|
||||
{"strategies": [STRATEGY1]},
|
||||
)
|
||||
},
|
||||
'/v1/strategies/%s' % STRATEGY1['id']:
|
||||
'/v1/strategies/%s' % STRATEGY1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
STRATEGY1,
|
||||
),
|
||||
},
|
||||
'/v1/strategies/%s' % STRATEGY1['name']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
@@ -159,9 +168,17 @@ class StrategyManagerTest(testtools.TestCase):
|
||||
self.assertEqual(2, len(strategies))
|
||||
|
||||
def test_strategies_show(self):
|
||||
strategy = self.mgr.get(STRATEGY1['id'])
|
||||
strategy = self.mgr.get(STRATEGY1['uuid'])
|
||||
expect = [
|
||||
('GET', '/v1/strategies/%s' % STRATEGY1['id'], {}, None),
|
||||
('GET', '/v1/strategies/%s' % STRATEGY1['uuid'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(STRATEGY1['id'], strategy.id)
|
||||
self.assertEqual(STRATEGY1['uuid'], strategy.uuid)
|
||||
|
||||
def test_strategies_show_by_name(self):
|
||||
strategy = self.mgr.get(STRATEGY1['name'])
|
||||
expect = [
|
||||
('GET', '/v1/strategies/%s' % STRATEGY1['name'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(STRATEGY1['name'], strategy.name)
|
||||
|
@@ -19,7 +19,7 @@ from watcherclient.common import utils
|
||||
from watcherclient import exceptions as exc
|
||||
|
||||
CREATION_ATTRIBUTES = ['host_aggregate', 'description', 'name',
|
||||
'extra', 'goal']
|
||||
'extra', 'goal_uuid', 'strategy_uuid']
|
||||
|
||||
|
||||
class AuditTemplate(base.Resource):
|
||||
@@ -31,11 +31,11 @@ class AuditTemplateManager(base.Manager):
|
||||
resource_class = AuditTemplate
|
||||
|
||||
@staticmethod
|
||||
def _path(id=None):
|
||||
return '/v1/audit_templates/%s' % id if id else '/v1/audit_templates'
|
||||
def _path(id_=None):
|
||||
return '/v1/audit_templates/%s' % id_ if id_ else '/v1/audit_templates'
|
||||
|
||||
def list(self, name=None, goal=None, limit=None, sort_key=None,
|
||||
sort_dir=None, detail=False):
|
||||
def list(self, name=None, goal_uuid=None, strategy_uuid=None, limit=None,
|
||||
sort_key=None, sort_dir=None, detail=False):
|
||||
"""Retrieve a list of audit template.
|
||||
|
||||
:param name: Name of the audit template
|
||||
@@ -65,8 +65,10 @@ class AuditTemplateManager(base.Manager):
|
||||
filters = utils.common_filters(limit, sort_key, sort_dir)
|
||||
if name is not None:
|
||||
filters.append('name=%s' % name)
|
||||
if goal is not None:
|
||||
filters.append("goal=%s" % goal)
|
||||
if goal_uuid is not None:
|
||||
filters.append("goal_uuid=%s" % goal_uuid)
|
||||
if strategy_uuid is not None:
|
||||
filters.append("strategy_uuid=%s" % strategy_uuid)
|
||||
|
||||
path = ''
|
||||
if detail:
|
||||
|
@@ -46,9 +46,13 @@ def do_audit_template_show(cc, args):
|
||||
default=False,
|
||||
help="Show detailed information about audit templates.")
|
||||
@cliutils.arg(
|
||||
'--goal',
|
||||
metavar='<goal>',
|
||||
help='Name the goal used for filtering.')
|
||||
'--goal-uuid',
|
||||
metavar='<goal-uuid>',
|
||||
help='UUID the goal used for filtering.')
|
||||
@cliutils.arg(
|
||||
'--strategy-uuid',
|
||||
metavar='<strategy-uuid>',
|
||||
help='UUID the strategy used for filtering.')
|
||||
@cliutils.arg(
|
||||
'--limit',
|
||||
metavar='<limit>',
|
||||
@@ -69,8 +73,10 @@ def do_audit_template_list(cc, args):
|
||||
"""List the audit templates."""
|
||||
params = {}
|
||||
|
||||
if args.goal is not None:
|
||||
params['goal'] = args.goal
|
||||
if args.goal_uuid is not None:
|
||||
params['goal_uuid'] = args.goal_uuid
|
||||
if args.strategy_uuid is not None:
|
||||
params['strategy_uuid'] = args.strategy_uuid
|
||||
if args.detail:
|
||||
fields = res_fields.AUDIT_TEMPLATE_FIELDS
|
||||
field_labels = res_fields.AUDIT_TEMPLATE_FIELD_LABELS
|
||||
@@ -93,9 +99,14 @@ def do_audit_template_list(cc, args):
|
||||
metavar='<name>',
|
||||
help='Name for this audit template.')
|
||||
@cliutils.arg(
|
||||
'goal',
|
||||
metavar='<goal>',
|
||||
help='Goal Type associated to this audit template.')
|
||||
'goal_uuid',
|
||||
metavar='<goal-uuid>',
|
||||
help='Goal ID associated to this audit template.')
|
||||
@cliutils.arg(
|
||||
'-s', '--strategy-uuid',
|
||||
dest='strategy_uuid',
|
||||
metavar='<strategy-uuid>',
|
||||
help='Strategy ID associated to this audit template.')
|
||||
@cliutils.arg(
|
||||
'-d', '--description',
|
||||
metavar='<description>',
|
||||
@@ -113,7 +124,8 @@ def do_audit_template_list(cc, args):
|
||||
help='Name or ID of the host aggregate targeted by this audit template.')
|
||||
def do_audit_template_create(cc, args):
|
||||
"""Create a new audit template."""
|
||||
field_list = ['host_aggregate', 'description', 'name', 'extra', 'goal']
|
||||
field_list = ['host_aggregate', 'description', 'name', 'extra',
|
||||
'goal_uuid', 'strategy_uuid']
|
||||
fields = dict((k, v) for (k, v) in vars(args).items()
|
||||
if k in field_list and not (v is None))
|
||||
fields = utils.args_array_to_dict(fields, 'extra')
|
||||
|
@@ -93,7 +93,7 @@ def do_metric_collector_list(cc, args):
|
||||
@cliutils.arg(
|
||||
'-e', '--endpoint-url',
|
||||
required=True,
|
||||
metavar='<goal>',
|
||||
metavar='<endpoint-url>',
|
||||
help='URL towards which publish metric data.')
|
||||
def do_metric_collector_create(cc, args):
|
||||
"""Create a new metric collector."""
|
||||
|
@@ -20,12 +20,12 @@
|
||||
AUDIT_TEMPLATE_FIELDS = [
|
||||
'uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
'description', 'host_aggregate', 'name',
|
||||
'extra', 'goal']
|
||||
'extra', 'goal_uuid', 'strategy_uuid']
|
||||
|
||||
AUDIT_TEMPLATE_FIELD_LABELS = [
|
||||
'UUID', 'Created At', 'Updated At', 'Deleted At',
|
||||
'Description', 'Host Aggregate ID or Name', 'Name',
|
||||
'Extra', 'Goal Type']
|
||||
'Extra', 'Goal UUID', 'Strategy UUID']
|
||||
|
||||
AUDIT_TEMPLATE_SHORT_LIST_FIELDS = ['uuid', 'name']
|
||||
|
||||
|
Reference in New Issue
Block a user