diff --git a/watcherclient/tests/v1/test_audit_template.py b/watcherclient/tests/v1/test_audit_template.py index f2afe86..bd07025 100644 --- a/watcherclient/tests/v1/test_audit_template.py +++ b/watcherclient/tests/v1/test_audit_template.py @@ -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) diff --git a/watcherclient/tests/v1/test_audit_template_shell.py b/watcherclient/tests/v1/test_audit_template_shell.py index 7b842d4..6ee8da8 100644 --- a/watcherclient/tests/v1/test_audit_template_shell.py +++ b/watcherclient/tests/v1/test_audit_template_shell.py @@ -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)) diff --git a/watcherclient/tests/v1/test_strategy.py b/watcherclient/tests/v1/test_strategy.py index 6137e23..9f1c6fe 100644 --- a/watcherclient/tests/v1/test_strategy.py +++ b/watcherclient/tests/v1/test_strategy.py @@ -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) diff --git a/watcherclient/v1/audit_template.py b/watcherclient/v1/audit_template.py index f3c1eda..9b17141 100644 --- a/watcherclient/v1/audit_template.py +++ b/watcherclient/v1/audit_template.py @@ -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: diff --git a/watcherclient/v1/audit_template_shell.py b/watcherclient/v1/audit_template_shell.py index 946306b..f4354e2 100644 --- a/watcherclient/v1/audit_template_shell.py +++ b/watcherclient/v1/audit_template_shell.py @@ -46,9 +46,13 @@ def do_audit_template_show(cc, args): default=False, help="Show detailed information about audit templates.") @cliutils.arg( - '--goal', - metavar='', - help='Name the goal used for filtering.') + '--goal-uuid', + metavar='', + help='UUID the goal used for filtering.') +@cliutils.arg( + '--strategy-uuid', + metavar='', + help='UUID the strategy used for filtering.') @cliutils.arg( '--limit', metavar='', @@ -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='', help='Name for this audit template.') @cliutils.arg( - 'goal', - metavar='', - help='Goal Type associated to this audit template.') + 'goal_uuid', + metavar='', + help='Goal ID associated to this audit template.') +@cliutils.arg( + '-s', '--strategy-uuid', + dest='strategy_uuid', + metavar='', + help='Strategy ID associated to this audit template.') @cliutils.arg( '-d', '--description', metavar='', @@ -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') diff --git a/watcherclient/v1/metric_collector_shell.py b/watcherclient/v1/metric_collector_shell.py index 6d0061a..cd37fc6 100644 --- a/watcherclient/v1/metric_collector_shell.py +++ b/watcherclient/v1/metric_collector_shell.py @@ -93,7 +93,7 @@ def do_metric_collector_list(cc, args): @cliutils.arg( '-e', '--endpoint-url', required=True, - metavar='', + metavar='', help='URL towards which publish metric data.') def do_metric_collector_create(cc, args): """Create a new metric collector.""" diff --git a/watcherclient/v1/resource_fields.py b/watcherclient/v1/resource_fields.py index a14501b..a8f00f1 100644 --- a/watcherclient/v1/resource_fields.py +++ b/watcherclient/v1/resource_fields.py @@ -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']