summaryrefslogtreecommitdiff
path: root/trove/tests/unittests/taskmanager/test_models.py
diff options
context:
space:
mode:
authorZhao Chao <zhaochao1984@gmail.com>2018-02-07 15:37:30 +0800
committerZhao Chao <zhaochao1984@gmail.com>2018-02-07 17:05:54 +0800
commit3b726f3013b0ba2a9f86b5b65278fadb981335cf (patch)
treed473f5fef94c8e614ff951033eaac3173257783a /trove/tests/unittests/taskmanager/test_models.py
parentcdc7b37cae31e8e0206ff67eea7a3e5f3e26ae7b (diff)
downloadtrove-3b726f3013b0ba2a9f86b5b65278fadb981335cf.tar.gz
report_root should always use context.user
The RootHistory intends to record by whom and when the root user of the underlying datastore backend was enabled. So the "user" column should always be set to the context user, not the actual root user in the database. But report_root(and report_root_enabled in taskmanager.models) use the database user instead, this is not correct, This patch will fix. Also remove the "user" argument from Root.create() and HistoryRoot.create() because the context is already passed in as an argument when these methods are called. Closes-Bug: #1546372 Change-Id: I3b4c8ee56c7e0876fb384f0c5841d2d391bd555d Signed-off-by: Zhao Chao <zhaochao1984@gmail.com>
Diffstat (limited to 'trove/tests/unittests/taskmanager/test_models.py')
-rw-r--r--trove/tests/unittests/taskmanager/test_models.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/trove/tests/unittests/taskmanager/test_models.py b/trove/tests/unittests/taskmanager/test_models.py
index 3c620de2..d85a5275 100644
--- a/trove/tests/unittests/taskmanager/test_models.py
+++ b/trove/tests/unittests/taskmanager/test_models.py
@@ -1084,17 +1084,20 @@ class RootReportTest(trove_testtools.TestCase):
super(RootReportTest, self).tearDown()
def test_report_root_first_time(self):
+ context = Mock()
+ context.user = utils.generate_uuid()
report = mysql_models.RootHistory.create(
- None, utils.generate_uuid(), 'root')
+ context, utils.generate_uuid())
self.assertIsNotNone(report)
def test_report_root_double_create(self):
+ context = Mock()
+ context.user = utils.generate_uuid()
uuid = utils.generate_uuid()
- history = mysql_models.RootHistory(uuid, 'root').save()
+ history = mysql_models.RootHistory(uuid, context.user).save()
with patch.object(mysql_models.RootHistory, 'load',
Mock(return_value=history)):
- report = mysql_models.RootHistory.create(
- None, uuid, 'root')
+ report = mysql_models.RootHistory.create(context, uuid)
self.assertTrue(mysql_models.RootHistory.load.called)
self.assertEqual(history.user, report.user)
self.assertEqual(history.id, report.id)
@@ -1106,17 +1109,17 @@ class ClusterRootTest(trove_testtools.TestCase):
@patch.object(common_models.Root, "create")
def test_cluster_root_create(self, root_create, root_history_create):
context = Mock()
+ context.user = utils.generate_uuid()
uuid = utils.generate_uuid()
- user = "root"
password = "rootpassword"
cluster_instances = [utils.generate_uuid(), utils.generate_uuid()]
- common_models.ClusterRoot.create(context, uuid, user, password,
+ common_models.ClusterRoot.create(context, uuid, password,
cluster_instances)
- root_create.assert_called_with(context, uuid, user, password,
+ root_create.assert_called_with(context, uuid, password,
cluster_instances_list=None)
self.assertEqual(2, root_history_create.call_count)
calls = [
- call(context, cluster_instances[0], user),
- call(context, cluster_instances[1], user)
+ call(context, cluster_instances[0]),
+ call(context, cluster_instances[1])
]
root_history_create.assert_has_calls(calls)