From 37316f24f7cbef1f4176a7b31e2386cc2a25e36a Mon Sep 17 00:00:00 2001 From: Alexander Nevenchannyy Date: Wed, 5 Aug 2015 02:41:45 +0300 Subject: [PATCH] Move rally/db -> rally/common/db MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no need to have db directory on the top level. They are quite rare changed and in most case one don’t need to know about internal details of it to fulfill their task. So hiding these directory under common/* makes perfect sense Change-Id: I791b17cc101a00bfcd9bd951fac83fc4459c6c4f --- rally/cli/commands/deployment.py | 2 +- rally/cli/commands/show.py | 2 +- rally/cli/commands/task.py | 2 +- rally/cli/commands/verify.py | 2 +- rally/cli/manage.py | 2 +- rally/{ => common}/db/__init__.py | 2 +- rally/{ => common}/db/api.py | 7 +++-- rally/{ => common}/db/sqlalchemy/__init__.py | 0 rally/{ => common}/db/sqlalchemy/api.py | 6 ++-- rally/{ => common}/db/sqlalchemy/models.py | 8 ++--- rally/{ => common}/db/sqlalchemy/types.py | 0 rally/deployment/engines/multihost.py | 2 +- rally/objects/deploy.py | 2 +- rally/objects/task.py | 2 +- rally/objects/verification.py | 2 +- rally/verification/tempest/config.py | 2 +- tests/unit/cli/commands/test_verify.py | 32 +++++++++++--------- tests/unit/cli/test_cliutils.py | 2 +- tests/unit/{ => common}/db/__init__.py | 0 tests/unit/{ => common}/db/test_api.py | 2 +- tests/unit/test.py | 2 +- 21 files changed, 42 insertions(+), 39 deletions(-) rename rally/{ => common}/db/__init__.py (93%) rename rally/{ => common}/db/api.py (97%) rename rally/{ => common}/db/sqlalchemy/__init__.py (100%) rename rally/{ => common}/db/sqlalchemy/api.py (98%) rename rally/{ => common}/db/sqlalchemy/models.py (97%) rename rally/{ => common}/db/sqlalchemy/types.py (100%) rename tests/unit/{ => common}/db/__init__.py (100%) rename tests/unit/{ => common}/db/test_api.py (99%) diff --git a/rally/cli/commands/deployment.py b/rally/cli/commands/deployment.py index 81a5c6d5be..5f516d48b1 100644 --- a/rally/cli/commands/deployment.py +++ b/rally/cli/commands/deployment.py @@ -30,10 +30,10 @@ import yaml from rally import api from rally.cli import cliutils from rally.cli import envutils +from rally.common import db from rally.common import fileutils from rally.common.i18n import _ from rally.common import utils -from rally import db from rally import exceptions from rally import objects from rally import osclients diff --git a/rally/cli/commands/show.py b/rally/cli/commands/show.py index 65455a516c..3ef7b0d450 100644 --- a/rally/cli/commands/show.py +++ b/rally/cli/commands/show.py @@ -19,9 +19,9 @@ from __future__ import print_function from rally.cli import cliutils from rally.cli import envutils +from rally.common import db from rally.common.i18n import _ from rally.common import utils -from rally import db from rally import objects from rally import osclients diff --git a/rally/cli/commands/task.py b/rally/cli/commands/task.py index 0b98b9ed54..00d28d8d75 100644 --- a/rally/cli/commands/task.py +++ b/rally/cli/commands/task.py @@ -28,13 +28,13 @@ import yaml from rally import api from rally.cli import cliutils from rally.cli import envutils +from rally.common import db from rally.common import fileutils from rally.common.i18n import _ from rally.common import junit from rally.common import log as logging from rally.common import utils as rutils from rally import consts -from rally import db from rally import exceptions from rally import objects from rally import plugins diff --git a/rally/cli/commands/verify.py b/rally/cli/commands/verify.py index ef9c7c7735..dfeeffcc22 100644 --- a/rally/cli/commands/verify.py +++ b/rally/cli/commands/verify.py @@ -24,10 +24,10 @@ import six from rally import api from rally.cli import cliutils from rally.cli import envutils +from rally.common import db from rally.common import fileutils from rally.common.i18n import _ from rally import consts -from rally import db from rally import exceptions from rally import objects from rally.verification.tempest import diff diff --git a/rally/cli/manage.py b/rally/cli/manage.py index 1958e8b68a..cb342e2f3e 100644 --- a/rally/cli/manage.py +++ b/rally/cli/manage.py @@ -22,7 +22,7 @@ import sys from rally import api from rally.cli import cliutils from rally.cli import envutils -from rally import db +from rally.common import db class DBCommands(object): diff --git a/rally/db/__init__.py b/rally/common/db/__init__.py similarity index 93% rename from rally/db/__init__.py rename to rally/common/db/__init__.py index 08780c3b1e..f09aa7a209 100644 --- a/rally/db/__init__.py +++ b/rally/common/db/__init__.py @@ -13,4 +13,4 @@ # License for the specific language governing permissions and limitations # under the License. -from rally.db.api import * # noqa +from rally.common.db.api import * # noqa diff --git a/rally/db/api.py b/rally/common/db/api.py similarity index 97% rename from rally/db/api.py rename to rally/common/db/api.py index 892461e144..5c148fefd6 100644 --- a/rally/db/api.py +++ b/rally/common/db/api.py @@ -17,8 +17,9 @@ The underlying driver is loaded as a :class:`LazyPluggable`. -Functions in this module are imported into the rally.db namespace. Call these -functions from rally.db namespace, not the rally.db.api namespace. +Functions in this module are imported into the rally.common.db namespace. +Call these functions from rally.common.db namespace, not the +rally.common.db.api namespace. All functions in this module return objects that implement a dictionary-like interface. Currently, many of these objects are sqlalchemy objects that @@ -58,7 +59,7 @@ def get_impl(): global IMPL if not IMPL: - _BACKEND_MAPPING = {"sqlalchemy": "rally.db.sqlalchemy.api"} + _BACKEND_MAPPING = {"sqlalchemy": "rally.common.db.sqlalchemy.api"} IMPL = db_api.DBAPI.from_config(CONF, backend_mapping=_BACKEND_MAPPING) return IMPL diff --git a/rally/db/sqlalchemy/__init__.py b/rally/common/db/sqlalchemy/__init__.py similarity index 100% rename from rally/db/sqlalchemy/__init__.py rename to rally/common/db/sqlalchemy/__init__.py diff --git a/rally/db/sqlalchemy/api.py b/rally/common/db/sqlalchemy/api.py similarity index 98% rename from rally/db/sqlalchemy/api.py rename to rally/common/db/sqlalchemy/api.py index f045dc0423..3af3ec3826 100644 --- a/rally/db/sqlalchemy/api.py +++ b/rally/common/db/sqlalchemy/api.py @@ -23,8 +23,8 @@ from oslo_utils import timeutils import sqlalchemy as sa from sqlalchemy.orm.exc import NoResultFound +from rally.common.db.sqlalchemy import models from rally.common.i18n import _ -from rally.db.sqlalchemy import models from rally import exceptions @@ -74,13 +74,13 @@ class Connection(object): """The helper method to create query. :param model: The instance of - :class:`rally.db.sqlalchemy.models.RallyBase` to + :class:`rally.common.db.sqlalchemy.models.RallyBase` to request it. :param session: Reuse the session object or get new one if it is None. :returns: The query object. :raises: :class:`Exception` when the model is not a sublcass of - :class:`rally.db.sqlalchemy.models.RallyBase`. + :class:`rally.common.db.sqlalchemy.models.RallyBase`. """ session = session or get_session() query = session.query(model) diff --git a/rally/db/sqlalchemy/models.py b/rally/common/db/sqlalchemy/models.py similarity index 97% rename from rally/db/sqlalchemy/models.py rename to rally/common/db/sqlalchemy/models.py index 2afb6c0152..9f15edb41f 100644 --- a/rally/db/sqlalchemy/models.py +++ b/rally/common/db/sqlalchemy/models.py @@ -26,8 +26,8 @@ from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import schema from sqlalchemy import types +from rally.common.db.sqlalchemy import types as sa_types from rally import consts -from rally.db.sqlalchemy import types as sa_types BASE = declarative_base() @@ -44,7 +44,7 @@ class RallyBase(models.ModelBase): onupdate=lambda: timeutils.utcnow()) def save(self, session=None): - from rally.db.sqlalchemy import api as sa_api + from rally.common.db.sqlalchemy import api as sa_api if session is None: session = sa_api.get_session() @@ -234,7 +234,7 @@ class Worker(BASE, RallyBase): def create_db(): - from rally.db.sqlalchemy import api as sa_api + from rally.common.db.sqlalchemy import api as sa_api BASE.metadata.create_all(sa_api.get_engine()) @@ -281,5 +281,5 @@ def drop_all_objects(engine): def drop_db(): - from rally.db.sqlalchemy import api as sa_api + from rally.common.db.sqlalchemy import api as sa_api drop_all_objects(sa_api.get_engine()) diff --git a/rally/db/sqlalchemy/types.py b/rally/common/db/sqlalchemy/types.py similarity index 100% rename from rally/db/sqlalchemy/types.py rename to rally/common/db/sqlalchemy/types.py diff --git a/rally/deployment/engines/multihost.py b/rally/deployment/engines/multihost.py index 792f2e035e..f4dd96c3b5 100644 --- a/rally/deployment/engines/multihost.py +++ b/rally/deployment/engines/multihost.py @@ -18,8 +18,8 @@ import six from six.moves.urllib import parse import rally +from rally.common import db from rally import consts -from rally import db from rally.deployment import engine from rally import objects diff --git a/rally/objects/deploy.py b/rally/objects/deploy.py index cfd940f47a..be5d1a4acb 100644 --- a/rally/objects/deploy.py +++ b/rally/objects/deploy.py @@ -15,8 +15,8 @@ import datetime +from rally.common import db from rally import consts -from rally import db class Deployment(object): diff --git a/rally/objects/task.py b/rally/objects/task.py index 5239d5e5f7..bf17342c57 100644 --- a/rally/objects/task.py +++ b/rally/objects/task.py @@ -16,8 +16,8 @@ import json import uuid +from rally.common import db from rally import consts -from rally import db TASK_RESULT_SCHEMA = { diff --git a/rally/objects/verification.py b/rally/objects/verification.py index f39c014c93..a4cadc0806 100644 --- a/rally/objects/verification.py +++ b/rally/objects/verification.py @@ -13,8 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +from rally.common import db from rally import consts -from rally import db from rally import exceptions diff --git a/rally/verification/tempest/config.py b/rally/verification/tempest/config.py index 62e549a63c..6a0b75ab61 100644 --- a/rally/verification/tempest/config.py +++ b/rally/verification/tempest/config.py @@ -23,9 +23,9 @@ import requests from six.moves import configparser from six.moves.urllib import parse +from rally.common import db from rally.common.i18n import _ from rally.common import log as logging -from rally import db from rally import exceptions from rally import objects from rally import osclients diff --git a/tests/unit/cli/commands/test_verify.py b/tests/unit/cli/commands/test_verify.py index 04616e71ab..badc054e5e 100644 --- a/tests/unit/cli/commands/test_verify.py +++ b/tests/unit/cli/commands/test_verify.py @@ -95,27 +95,27 @@ class VerifyCommandsTestCase(test.TestCase): self.assertFalse(mock_verification_verify.called) @mock.patch("rally.cli.cliutils.print_list") - @mock.patch("rally.db.verification_list") - def test_list(self, mock_db_verification_list, mock_print_list): + @mock.patch("rally.common.db.verification_list") + def test_list(self, mock_common_db_verification_list, mock_print_list): fields = ["UUID", "Deployment UUID", "Set name", "Tests", "Failures", "Created at", "Duration", "Status"] verifications = [{"created_at": date.datetime.now(), "updated_at": date.datetime.now()}] - mock_db_verification_list.return_value = verifications + mock_common_db_verification_list.return_value = verifications self.verify.list() for row in verifications: self.assertEqual(row["updated_at"] - row["created_at"], row["duration"]) - mock_db_verification_list.assert_called_once_with() + mock_common_db_verification_list.assert_called_once_with() mock_print_list.assert_called_once_with(verifications, fields, sortby_index=fields.index( "Created at")) @mock.patch("rally.cli.cliutils.print_list") - @mock.patch("rally.db.verification_get") - @mock.patch("rally.db.verification_result_get") + @mock.patch("rally.common.db.verification_get") + @mock.patch("rally.common.db.verification_result_get") @mock.patch("rally.objects.Verification") def test_show(self, mock_objects_verification, mock_verification_result_get, mock_verification_get, @@ -147,7 +147,8 @@ class VerifyCommandsTestCase(test.TestCase): mock_verification_get.assert_called_once_with(verification_id) mock_verification_result_get.assert_called_once_with(verification_id) - @mock.patch("rally.db.verification_result_get", return_value={"data": {}}) + @mock.patch("rally.common.db.verification_result_get", + return_value={"data": {}}) @mock.patch("json.dumps") def test_results(self, mock_json_dumps, mock_verification_result_get): verification_uuid = "a0231bdf-6a4e-4daf-8ab1-ae076f75f070" @@ -157,7 +158,7 @@ class VerifyCommandsTestCase(test.TestCase): mock_verification_result_get.assert_called_once_with(verification_uuid) mock_json_dumps.assert_called_once_with({}, sort_keys=True, indent=4) - @mock.patch("rally.db.verification_result_get") + @mock.patch("rally.common.db.verification_result_get") def test_results_verification_not_found( self, mock_verification_result_get): verification_uuid = "9044ced5-9c84-4666-8a8f-4b73a2b62acb" @@ -172,7 +173,8 @@ class VerifyCommandsTestCase(test.TestCase): @mock.patch("rally.cli.commands.verify.open", side_effect=mock.mock_open(), create=True) - @mock.patch("rally.db.verification_result_get", return_value={"data": {}}) + @mock.patch("rally.common.db.verification_result_get", + return_value={"data": {}}) def test_results_with_output_json_and_output_file( self, mock_verification_result_get, mock_open): mock_open.side_effect = mock.mock_open() @@ -186,7 +188,7 @@ class VerifyCommandsTestCase(test.TestCase): @mock.patch("rally.cli.commands.verify.open", side_effect=mock.mock_open(), create=True) - @mock.patch("rally.db.verification_result_get") + @mock.patch("rally.common.db.verification_result_get") @mock.patch("rally.verification.tempest.json2html.HtmlOutput") def test_results_with_output_html_and_output_file( self, mock_html_output, mock_verification_result_get, mock_open): @@ -205,7 +207,7 @@ class VerifyCommandsTestCase(test.TestCase): mock_open.assert_called_once_with("results", "wb") mock_open.side_effect().write.assert_called_once_with("html_report") - @mock.patch("rally.db.verification_result_get", + @mock.patch("rally.common.db.verification_result_get", return_value={"data": {"test_cases": {}}}) @mock.patch("json.dumps") def test_compare(self, mock_json_dumps, mock_verification_result_get): @@ -221,7 +223,7 @@ class VerifyCommandsTestCase(test.TestCase): mock_json_dumps.assert_called_once_with(fake_data, sort_keys=True, indent=4) - @mock.patch("rally.db.verification_result_get", + @mock.patch("rally.common.db.verification_result_get", side_effect=exceptions.NotFoundException()) def test_compare_verification_not_found(self, mock_verification_result_get): @@ -236,7 +238,7 @@ class VerifyCommandsTestCase(test.TestCase): @mock.patch("rally.cli.commands.verify.open", side_effect=mock.mock_open(), create=True) - @mock.patch("rally.db.verification_result_get", + @mock.patch("rally.common.db.verification_result_get", return_value={"data": {"test_cases": {}}}) def test_compare_with_output_csv_and_output_file( self, mock_verification_result_get, mock_open): @@ -256,7 +258,7 @@ class VerifyCommandsTestCase(test.TestCase): @mock.patch("rally.cli.commands.verify.open", side_effect=mock.mock_open(), create=True) - @mock.patch("rally.db.verification_result_get", + @mock.patch("rally.common.db.verification_result_get", return_value={"data": {"test_cases": {}}}) def test_compare_with_output_json_and_output_file( self, mock_verification_result_get, mock_open): @@ -275,7 +277,7 @@ class VerifyCommandsTestCase(test.TestCase): @mock.patch("rally.cli.commands.verify.open", side_effect=mock.mock_open(), create=True) - @mock.patch("rally.db.verification_result_get") + @mock.patch("rally.common.db.verification_result_get") @mock.patch(("rally.verification.tempest." "compare2html.create_report"), return_value="") def test_compare_with_output_html_and_output_file( diff --git a/tests/unit/cli/test_cliutils.py b/tests/unit/cli/test_cliutils.py index 588a8a94be..54ef354328 100644 --- a/tests/unit/cli/test_cliutils.py +++ b/tests/unit/cli/test_cliutils.py @@ -179,7 +179,7 @@ class CliUtilsTestCase(test.TestCase): ret = cliutils.run(["rally", "show", "keypairs"], self.categories) self.assertEqual(ret, 1) - @mock.patch("rally.db.task_get", + @mock.patch("rally.common.db.task_get", side_effect=exceptions.TaskNotFound(FAKE_TASK_UUID)) def test_run_task_not_found(self, mock_task_get): ret = cliutils.run(["rally", "task", "status", "%s" % FAKE_TASK_UUID], diff --git a/tests/unit/db/__init__.py b/tests/unit/common/db/__init__.py similarity index 100% rename from tests/unit/db/__init__.py rename to tests/unit/common/db/__init__.py diff --git a/tests/unit/db/test_api.py b/tests/unit/common/db/test_api.py similarity index 99% rename from tests/unit/db/test_api.py rename to tests/unit/common/db/test_api.py index 343f1f4071..f730727542 100644 --- a/tests/unit/db/test_api.py +++ b/tests/unit/common/db/test_api.py @@ -17,8 +17,8 @@ from six import moves +from rally.common import db from rally import consts -from rally import db from rally import exceptions from tests.unit import test diff --git a/tests/unit/test.py b/tests/unit/test.py index 744efa7792..b4fd9f82fc 100644 --- a/tests/unit/test.py +++ b/tests/unit/test.py @@ -20,7 +20,7 @@ from oslo_config import fixture from oslotest import base from oslotest import mockpatch -from rally import db +from rally.common import db from rally import plugins from tests.unit import fakes