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:
Vincent Francoise
2016-04-20 18:13:11 +02:00
committed by David TARDIVEL
parent c5a5b7dad7
commit d2c22f0353
7 changed files with 108 additions and 46 deletions

View File

@@ -31,7 +31,8 @@ AUDIT_TMPL1 = {
'description': 'Audit Template 1 description', 'description': 'Audit Template 1 description',
'host_aggregate': 5, 'host_aggregate': 5,
'extra': {'automatic': False}, 'extra': {'automatic': False},
'goal': 'MINIMIZE_LICENSING_COST' 'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f',
'strategy_uuid': 'bbe6b966-f98e-439b-a01a-17b9b3b8478b',
} }
AUDIT_TMPL2 = { AUDIT_TMPL2 = {
@@ -41,7 +42,8 @@ AUDIT_TMPL2 = {
'description': 'Audit Template 2 description', 'description': 'Audit Template 2 description',
'host_aggregate': 8, 'host_aggregate': 8,
'extra': {'automatic': True}, 'extra': {'automatic': True},
'goal': 'BASIC_CONSOLIDATION' 'goal_uuid': 'e75ee410-b32b-465f-88b5-4397705f9473',
'strategy_uuid': 'ae99a4a4-acbc-4c67-abe1-e37128fac45d',
} }
AUDIT_TMPL3 = { AUDIT_TMPL3 = {
@@ -51,7 +53,7 @@ AUDIT_TMPL3 = {
'description': 'Audit Template 3 description', 'description': 'Audit Template 3 description',
'host_aggregate': 7, 'host_aggregate': 7,
'extra': {'automatic': True}, 'extra': {'automatic': True},
'goal': 'MINIMIZE_LICENSING_COST' 'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f',
} }
CREATE_AUDIT_TEMPLATE = copy.deepcopy(AUDIT_TMPL1) CREATE_AUDIT_TEMPLATE = copy.deepcopy(AUDIT_TMPL1)
@@ -125,14 +127,14 @@ fake_responses = {
{"audit_templates": [AUDIT_TMPL1]}, {"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': ( 'GET': (
{}, {},
{"audit_templates": [AUDIT_TMPL1, AUDIT_TMPL3]}, {"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': ( 'GET': (
{}, {},
@@ -176,8 +178,18 @@ fake_responses_sorting = {
}, },
} }
fake_responses_filter_by_goal = { fake_responses_filter_by_goal_uuid = {
'/v1/audit_templates/?goal=BASIC_CONSOLIDATION': '/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': ( 'GET': (
{}, {},
@@ -203,7 +215,7 @@ class AuditTemplateManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls) self.assertEqual(expect, self.api.calls)
self.assertEqual(1, len(audit_templates)) 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']) audit_templates = self.mgr.list(name=AUDIT_TMPL1['name'])
expect = [ expect = [
('GET', '/v1/audit_templates/?name=%s' % AUDIT_TMPL1['name'], ('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(expect, self.api.calls)
self.assertEqual(1, len(audit_templates)) self.assertEqual(1, len(audit_templates))
def test_audit_templates_list_by_goal(self): def test_audit_templates_list_filter_by_goal_uuid(self):
self.api = utils.FakeAPI(fake_responses_filter_by_goal) self.api = utils.FakeAPI(fake_responses_filter_by_goal_uuid)
self.mgr = watcherclient.v1.audit_template.AuditTemplateManager( self.mgr = watcherclient.v1.audit_template.AuditTemplateManager(
self.api) self.api)
audit_templates = self.mgr.list(goal="BASIC_CONSOLIDATION") audit_templates = self.mgr.list(
goal_uuid="e75ee410-b32b-465f-88b5-4397705f9473")
expect = [ 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), {}, None),
] ]
self.assertEqual(expect, self.api.calls) self.assertEqual(expect, self.api.calls)
@@ -300,9 +329,10 @@ class AuditTemplateManagerTest(testtools.TestCase):
audit_template.description) audit_template.description)
self.assertEqual(AUDIT_TMPL1['host_aggregate'], self.assertEqual(AUDIT_TMPL1['host_aggregate'],
audit_template.host_aggregate) audit_template.host_aggregate)
self.assertEqual(AUDIT_TMPL1['goal'], audit_template.goal) self.assertEqual(AUDIT_TMPL1['goal_uuid'], audit_template.goal_uuid)
self.assertEqual(AUDIT_TMPL1['extra'], self.assertEqual(AUDIT_TMPL1['strategy_uuid'],
audit_template.extra) audit_template.strategy_uuid)
self.assertEqual(AUDIT_TMPL1['extra'], audit_template.extra)
def test_audit_templates_show_by_name(self): def test_audit_templates_show_by_name(self):
audit_template = self.mgr.get(urlparse.quote(AUDIT_TMPL1['name'])) audit_template = self.mgr.get(urlparse.quote(AUDIT_TMPL1['name']))
@@ -319,9 +349,10 @@ class AuditTemplateManagerTest(testtools.TestCase):
audit_template.description) audit_template.description)
self.assertEqual(AUDIT_TMPL1['host_aggregate'], self.assertEqual(AUDIT_TMPL1['host_aggregate'],
audit_template.host_aggregate) audit_template.host_aggregate)
self.assertEqual(AUDIT_TMPL1['goal'], audit_template.goal) self.assertEqual(AUDIT_TMPL1['goal_uuid'], audit_template.goal_uuid)
self.assertEqual(AUDIT_TMPL1['extra'], self.assertEqual(AUDIT_TMPL1['strategy_uuid'],
audit_template.extra) audit_template.strategy_uuid)
self.assertEqual(AUDIT_TMPL1['extra'], audit_template.extra)
def test_create(self): def test_create(self):
audit_template = self.mgr.create(**CREATE_AUDIT_TEMPLATE) audit_template = self.mgr.create(**CREATE_AUDIT_TEMPLATE)

View File

@@ -32,7 +32,7 @@ class AuditTemplateShellTest(utils.BaseTestCase):
exp = [ exp = [
'uuid', 'created_at', 'updated_at', 'deleted_at', 'uuid', 'created_at', 'updated_at', 'deleted_at',
'description', 'host_aggregate', 'name', 'description', 'host_aggregate', 'name',
'extra', 'goal'] 'extra', 'goal_uuid', 'strategy_uuid']
act = actual.keys() act = actual.keys()
self.assertEqual(sorted(exp), sorted(act)) self.assertEqual(sorted(exp), sorted(act))

View File

@@ -23,15 +23,17 @@ from watcherclient.tests import utils
import watcherclient.v1.strategy import watcherclient.v1.strategy
STRATEGY1 = { STRATEGY1 = {
'id': "basic", 'uuid': '2cf86250-d309-4b81-818e-1537f3dba6e5',
'name': 'basic',
'display_name': 'Basic consolidation', 'display_name': 'Basic consolidation',
'strategy_id': "SERVER_CONSOLIDATION", 'strategy_id': 'SERVER_CONSOLIDATION',
} }
STRATEGY2 = { STRATEGY2 = {
'id': "dummy", 'uuid': 'b20bb987-ea8f-457a-a4ea-ab3ffdfeff8b',
'name': 'dummy',
'display_name': 'Dummy', 'display_name': 'Dummy',
'strategy_id': "DUMMY", 'strategy_id': 'DUMMY',
} }
fake_responses = { fake_responses = {
@@ -49,7 +51,14 @@ fake_responses = {
{"strategies": [STRATEGY1]}, {"strategies": [STRATEGY1]},
) )
}, },
'/v1/strategies/%s' % STRATEGY1['id']: '/v1/strategies/%s' % STRATEGY1['uuid']:
{
'GET': (
{},
STRATEGY1,
),
},
'/v1/strategies/%s' % STRATEGY1['name']:
{ {
'GET': ( 'GET': (
{}, {},
@@ -159,9 +168,17 @@ class StrategyManagerTest(testtools.TestCase):
self.assertEqual(2, len(strategies)) self.assertEqual(2, len(strategies))
def test_strategies_show(self): def test_strategies_show(self):
strategy = self.mgr.get(STRATEGY1['id']) strategy = self.mgr.get(STRATEGY1['uuid'])
expect = [ expect = [
('GET', '/v1/strategies/%s' % STRATEGY1['id'], {}, None), ('GET', '/v1/strategies/%s' % STRATEGY1['uuid'], {}, None),
] ]
self.assertEqual(expect, self.api.calls) 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)

View File

@@ -19,7 +19,7 @@ from watcherclient.common import utils
from watcherclient import exceptions as exc from watcherclient import exceptions as exc
CREATION_ATTRIBUTES = ['host_aggregate', 'description', 'name', CREATION_ATTRIBUTES = ['host_aggregate', 'description', 'name',
'extra', 'goal'] 'extra', 'goal_uuid', 'strategy_uuid']
class AuditTemplate(base.Resource): class AuditTemplate(base.Resource):
@@ -31,11 +31,11 @@ class AuditTemplateManager(base.Manager):
resource_class = AuditTemplate resource_class = AuditTemplate
@staticmethod @staticmethod
def _path(id=None): def _path(id_=None):
return '/v1/audit_templates/%s' % id if id else '/v1/audit_templates' return '/v1/audit_templates/%s' % id_ if id_ else '/v1/audit_templates'
def list(self, name=None, goal=None, limit=None, sort_key=None, def list(self, name=None, goal_uuid=None, strategy_uuid=None, limit=None,
sort_dir=None, detail=False): sort_key=None, sort_dir=None, detail=False):
"""Retrieve a list of audit template. """Retrieve a list of audit template.
:param name: Name of the 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) filters = utils.common_filters(limit, sort_key, sort_dir)
if name is not None: if name is not None:
filters.append('name=%s' % name) filters.append('name=%s' % name)
if goal is not None: if goal_uuid is not None:
filters.append("goal=%s" % goal) filters.append("goal_uuid=%s" % goal_uuid)
if strategy_uuid is not None:
filters.append("strategy_uuid=%s" % strategy_uuid)
path = '' path = ''
if detail: if detail:

View File

@@ -46,9 +46,13 @@ def do_audit_template_show(cc, args):
default=False, default=False,
help="Show detailed information about audit templates.") help="Show detailed information about audit templates.")
@cliutils.arg( @cliutils.arg(
'--goal', '--goal-uuid',
metavar='<goal>', metavar='<goal-uuid>',
help='Name the goal used for filtering.') help='UUID the goal used for filtering.')
@cliutils.arg(
'--strategy-uuid',
metavar='<strategy-uuid>',
help='UUID the strategy used for filtering.')
@cliutils.arg( @cliutils.arg(
'--limit', '--limit',
metavar='<limit>', metavar='<limit>',
@@ -69,8 +73,10 @@ def do_audit_template_list(cc, args):
"""List the audit templates.""" """List the audit templates."""
params = {} params = {}
if args.goal is not None: if args.goal_uuid is not None:
params['goal'] = args.goal params['goal_uuid'] = args.goal_uuid
if args.strategy_uuid is not None:
params['strategy_uuid'] = args.strategy_uuid
if args.detail: if args.detail:
fields = res_fields.AUDIT_TEMPLATE_FIELDS fields = res_fields.AUDIT_TEMPLATE_FIELDS
field_labels = res_fields.AUDIT_TEMPLATE_FIELD_LABELS field_labels = res_fields.AUDIT_TEMPLATE_FIELD_LABELS
@@ -93,9 +99,14 @@ def do_audit_template_list(cc, args):
metavar='<name>', metavar='<name>',
help='Name for this audit template.') help='Name for this audit template.')
@cliutils.arg( @cliutils.arg(
'goal', 'goal_uuid',
metavar='<goal>', metavar='<goal-uuid>',
help='Goal Type associated to this audit template.') 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( @cliutils.arg(
'-d', '--description', '-d', '--description',
metavar='<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.') help='Name or ID of the host aggregate targeted by this audit template.')
def do_audit_template_create(cc, args): def do_audit_template_create(cc, args):
"""Create a new audit template.""" """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() fields = dict((k, v) for (k, v) in vars(args).items()
if k in field_list and not (v is None)) if k in field_list and not (v is None))
fields = utils.args_array_to_dict(fields, 'extra') fields = utils.args_array_to_dict(fields, 'extra')

View File

@@ -93,7 +93,7 @@ def do_metric_collector_list(cc, args):
@cliutils.arg( @cliutils.arg(
'-e', '--endpoint-url', '-e', '--endpoint-url',
required=True, required=True,
metavar='<goal>', metavar='<endpoint-url>',
help='URL towards which publish metric data.') help='URL towards which publish metric data.')
def do_metric_collector_create(cc, args): def do_metric_collector_create(cc, args):
"""Create a new metric collector.""" """Create a new metric collector."""

View File

@@ -20,12 +20,12 @@
AUDIT_TEMPLATE_FIELDS = [ AUDIT_TEMPLATE_FIELDS = [
'uuid', 'created_at', 'updated_at', 'deleted_at', 'uuid', 'created_at', 'updated_at', 'deleted_at',
'description', 'host_aggregate', 'name', 'description', 'host_aggregate', 'name',
'extra', 'goal'] 'extra', 'goal_uuid', 'strategy_uuid']
AUDIT_TEMPLATE_FIELD_LABELS = [ AUDIT_TEMPLATE_FIELD_LABELS = [
'UUID', 'Created At', 'Updated At', 'Deleted At', 'UUID', 'Created At', 'Updated At', 'Deleted At',
'Description', 'Host Aggregate ID or Name', 'Name', 'Description', 'Host Aggregate ID or Name', 'Name',
'Extra', 'Goal Type'] 'Extra', 'Goal UUID', 'Strategy UUID']
AUDIT_TEMPLATE_SHORT_LIST_FIELDS = ['uuid', 'name'] AUDIT_TEMPLATE_SHORT_LIST_FIELDS = ['uuid', 'name']