From 911cf21b74a446e71eb4f08ce9a7a9c6b4d6159b Mon Sep 17 00:00:00 2001 From: Hang Liu Date: Fri, 2 Jan 2015 21:41:18 +0800 Subject: [PATCH] Fix some minimal errors. --- senlin/db/sqlalchemy/api.py | 2 +- senlin/tests/db/shared.py | 17 ++++------------- senlin/tests/db/test_action_api.py | 23 ++++++++++++++--------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/senlin/db/sqlalchemy/api.py b/senlin/db/sqlalchemy/api.py index 0ca7bdb8d..628a31aca 100644 --- a/senlin/db/sqlalchemy/api.py +++ b/senlin/db/sqlalchemy/api.py @@ -746,7 +746,7 @@ def _action_dependency_add(context, action_id, field, adds): d['l'] = add_list; else: d = action[field] - d['l'] = list(set(d['l']) + set(add_list)) + d['l'] = list(set(d['l']).union(set(add_list))) action[field] = d if field == 'depends_on': diff --git a/senlin/tests/db/shared.py b/senlin/tests/db/shared.py index ff73e9227..af28f9f0a 100644 --- a/senlin/tests/db/shared.py +++ b/senlin/tests/db/shared.py @@ -72,15 +72,6 @@ def create_policy(context, policy=sample_policy, **kwargs): data.update(kwargs) return db_api.policy_create(context, data) -def create_action(context, action=sample_action, **kwargs): - data = parser.parse_action(action) - #values = { - # 'depends_on': json.loads('{"l" : "[1, 2]"}'), - # 'depended_by': json.loads('{"l" : "[4, 5]"}'), - #} - #data.update(values) - data.update(kwargs) - return db_api.action_create(context, data) def create_cluster(ctx, profile, **kwargs): values = { @@ -147,12 +138,12 @@ def create_action(ctx, **kwargs): 'target': kwargs.get('target'), 'action': kwargs.get('action'), 'cause': 'Reason for action', - 'owner': kwarge.get('owner'), + 'owner': kwargs.get('owner'), 'interval': -1, 'inputs': {'key': 'value'}, - 'outputs': {'result': 'value'} - 'depends_on': [], - 'depended_on': [] + 'outputs': {'result': 'value'}, + 'depends_on': {'l': []}, + 'depended_by': {'l': []} } values.update(kwargs) return db_api.action_create(ctx, values) diff --git a/senlin/tests/db/test_action_api.py b/senlin/tests/db/test_action_api.py index 4a748395d..a0bd76809 100644 --- a/senlin/tests/db/test_action_api.py +++ b/senlin/tests/db/test_action_api.py @@ -18,6 +18,11 @@ from senlin.tests.common import utils from senlin.tests.db import shared from senlin.openstack.common import log as logging +def _create_action(context, action=shared.sample_action, **kwargs): + data = parser.parse_action(action) + data.update(kwargs) + return db_api.action_create(context, data) + class DBAPIActionTest(base.SenlinTestCase): def setUp(self): @@ -43,7 +48,7 @@ class DBAPIActionTest(base.SenlinTestCase): def test_action_get(self): data = parser.parse_action(shared.sample_action) - action = shared.create_action(self.ctx) + action = _create_action(self.ctx) retobj = db_api.action_get(self.ctx, action.id) self.assertIsNotNone(retobj) @@ -67,7 +72,7 @@ class DBAPIActionTest(base.SenlinTestCase): ] for spec in specs: - shared.create_action(self.ctx, + _create_action(self.ctx, action=shared.sample_action, **spec) @@ -84,7 +89,7 @@ class DBAPIActionTest(base.SenlinTestCase): ] for spec in specs: - shared.create_action(self.ctx, + _create_action(self.ctx, action=shared.sample_action, **spec) @@ -104,7 +109,7 @@ class DBAPIActionTest(base.SenlinTestCase): ] for spec in specs: - shared.create_action(self.ctx, + _create_action(self.ctx, action=shared.sample_action, **spec) @@ -122,7 +127,7 @@ class DBAPIActionTest(base.SenlinTestCase): ] for spec in specs: - shared.create_action(self.ctx, + _create_action(self.ctx, action=shared.sample_action, **spec) @@ -143,7 +148,7 @@ class DBAPIActionTest(base.SenlinTestCase): id_of = {} for spec in specs: - action = shared.create_action(self.ctx, + action = _create_action(self.ctx, action=shared.sample_action, **spec) id_of[spec['name']] = action.id @@ -184,7 +189,7 @@ class DBAPIActionTest(base.SenlinTestCase): id_of = {} for spec in specs: - action = shared.create_action(self.ctx, + action = _create_action(self.ctx, action=shared.sample_action, **spec) id_of[spec['name']] = action.id @@ -281,7 +286,7 @@ class DBAPIActionTest(base.SenlinTestCase): def test_action_start_work_on(self): - action = shared.create_action(self.ctx) + action = _create_action(self.ctx) action = db_api.action_start_work_on(self.ctx, action.id, 'worker1') @@ -290,7 +295,7 @@ class DBAPIActionTest(base.SenlinTestCase): def test_action_delete(self): - action = shared.create_action(self.ctx) + action = _create_action(self.ctx) self.assertIsNotNone(action) action_id = action.id db_api.action_delete(self.ctx, action.id)