From 91953041c05c094db012cf5b96c7aed026c7c016 Mon Sep 17 00:00:00 2001 From: wanghao Date: Wed, 27 Dec 2017 10:48:34 +0800 Subject: [PATCH] Use constants for cinder-volume Since we have defined constants.VOLUME_BINARY, this patch change some cinder volume binary strings to use constans.VOLUME_BINARY. Change-Id: I91b1ed2331a3b197a2ba39fa5cfb02e9d161d709 --- cinder/api/contrib/capabilities.py | 3 +- cinder/api/contrib/services.py | 2 +- cinder/api/v3/clusters.py | 5 ++-- cinder/api/v3/workers.py | 3 +- cinder/cmd/manage.py | 4 ++- cinder/cmd/volume.py | 3 +- cinder/db/sqlalchemy/api.py | 3 +- .../unit/api/contrib/test_admin_actions.py | 12 ++++---- cinder/tests/unit/api/contrib/test_hosts.py | 9 +++--- .../tests/unit/api/contrib/test_services.py | 30 ++++++++++--------- .../unit/api/contrib/test_snapshot_manage.py | 5 ++-- .../tests/unit/api/v3/test_snapshot_manage.py | 5 ++-- .../tests/unit/api/v3/test_volume_manage.py | 3 +- cinder/tests/unit/api/v3/test_workers.py | 9 +++--- cinder/tests/unit/scheduler/test_scheduler.py | 21 ++++++------- cinder/tests/unit/test_cmd.py | 13 ++++---- cinder/tests/unit/test_db_api.py | 19 ++++++------ cinder/tests/unit/test_service.py | 7 +++-- cinder/tests/unit/test_setup_profiler.py | 9 +++--- cinder/tests/unit/utils.py | 3 +- .../unit/volume/test_replication_manager.py | 12 ++++---- cinder/tests/unit/volume/test_rpcapi.py | 5 ++-- cinder/volume/api.py | 2 +- cinder/volume/rpcapi.py | 2 +- 24 files changed, 106 insertions(+), 83 deletions(-) diff --git a/cinder/api/contrib/capabilities.py b/cinder/api/contrib/capabilities.py index f40723b5c01..79e1282a74f 100644 --- a/cinder/api/contrib/capabilities.py +++ b/cinder/api/contrib/capabilities.py @@ -18,6 +18,7 @@ import oslo_messaging from cinder.api import extensions from cinder.api.openstack import wsgi from cinder.api.views import capabilities as capabilities_view +from cinder.common import constants from cinder import exception from cinder.i18n import _ from cinder import objects @@ -41,7 +42,7 @@ class CapabilitiesController(wsgi.Controller): """Return capabilities list of given backend.""" context = req.environ['cinder.context'] context.authorize(policy.CAPABILITIES_POLICY) - filters = {'host_or_cluster': id, 'binary': 'cinder-volume'} + filters = {'host_or_cluster': id, 'binary': constants.VOLUME_BINARY} services = objects.ServiceList.get_all(context, filters) if not services: msg = (_("Can't find service: %s") % id) diff --git a/cinder/api/contrib/services.py b/cinder/api/contrib/services.py index d6737c7c3f5..a5a530b9825 100644 --- a/cinder/api/contrib/services.py +++ b/cinder/api/contrib/services.py @@ -101,7 +101,7 @@ class ServiceController(wsgi.Controller): if detailed: ret_fields['disabled_reason'] = svc.disabled_reason - if svc.binary == "cinder-volume": + if svc.binary == constants.VOLUME_BINARY: ret_fields['replication_status'] = svc.replication_status ret_fields['active_backend_id'] = svc.active_backend_id ret_fields['frozen'] = svc.frozen diff --git a/cinder/api/v3/clusters.py b/cinder/api/v3/clusters.py index 9271e24a5c6..342273b5c2b 100644 --- a/cinder/api/v3/clusters.py +++ b/cinder/api/v3/clusters.py @@ -16,6 +16,7 @@ from cinder.api import microversions as mv from cinder.api.openstack import wsgi from cinder.api.v3.views import clusters as clusters_view +from cinder.common import constants from cinder import exception from cinder.i18n import _ from cinder import objects @@ -30,7 +31,7 @@ class ClusterController(wsgi.Controller): replication_fields = {'replication_status', 'frozen', 'active_backend_id'} @wsgi.Controller.api_version(mv.CLUSTER_SUPPORT) - def show(self, req, id, binary='cinder-volume'): + def show(self, req, id, binary=constants.VOLUME_BINARY): """Return data for a given cluster name with optional binary.""" # Let the wsgi middleware convert NotAuthorized exceptions context = req.environ['cinder.context'] @@ -111,7 +112,7 @@ class ClusterController(wsgi.Controller): if not name: raise exception.MissingRequired(element='name') - binary = body.get('binary', 'cinder-volume') + binary = body.get('binary', constants.VOLUME_BINARY) # Let wsgi handle NotFound exception cluster = objects.Cluster.get_by_id(context, None, binary=binary, diff --git a/cinder/api/v3/workers.py b/cinder/api/v3/workers.py index bfdd62bf365..061ce0e446d 100644 --- a/cinder/api/v3/workers.py +++ b/cinder/api/v3/workers.py @@ -19,6 +19,7 @@ from oslo_utils import uuidutils from cinder.api import microversions as mv from cinder.api.openstack import wsgi from cinder.api.v3.views import workers as workers_view +from cinder.common import constants from cinder import db from cinder import exception from cinder.i18n import _ @@ -43,7 +44,7 @@ class WorkerController(wsgi.Controller): msg = _('Invalid filter keys: %s') % ', '.join(invalid_keys) raise exception.InvalidInput(reason=msg) - if params.get('binary') not in (None, 'cinder-volume', + if params.get('binary') not in (None, constants.VOLUME_BINARY, 'cinder-scheduler'): msg = _('binary must be empty or set to cinder-volume or ' 'cinder-scheduler') diff --git a/cinder/cmd/manage.py b/cinder/cmd/manage.py index 86b38a11664..27fc64e5054 100644 --- a/cinder/cmd/manage.py +++ b/cinder/cmd/manage.py @@ -69,6 +69,7 @@ from oslo_utils import timeutils # Need to register global_opts from cinder.common import config # noqa +from cinder.common import constants from cinder import context from cinder import db from cinder.db import migration as db_migration @@ -92,7 +93,8 @@ def _get_non_shared_target_hosts(ctxt): rpc.init(CONF) rpcapi = volume_rpcapi.VolumeAPI() - services = objects.ServiceList.get_all_by_topic(ctxt, 'cinder-volume') + services = objects.ServiceList.get_all_by_topic(ctxt, + constants.VOLUME_TOPIC) for service in services: capabilities = rpcapi.get_capabilities(ctxt, service.host, True) if not capabilities.get('shared_targets', True): diff --git a/cinder/cmd/volume.py b/cinder/cmd/volume.py index 3807145b148..18eb4b6ee08 100644 --- a/cinder/cmd/volume.py +++ b/cinder/cmd/volume.py @@ -45,6 +45,7 @@ i18n.enable_lazy() # Need to register global_opts from cinder.common import config # noqa +from cinder.common import constants from cinder.db import api as session from cinder.i18n import _ from cinder import service @@ -93,7 +94,7 @@ def main(): try: server = service.Service.create(host=host, service_name=backend, - binary='cinder-volume', + binary=constants.VOLUME_BINARY, coordination=True, cluster=cluster) except Exception: diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index f9c436a4f37..e67a7dc4e29 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -52,6 +52,7 @@ from sqlalchemy.sql import func from sqlalchemy.sql import sqltypes from cinder.api import common +from cinder.common import constants from cinder.common import sqlalchemyutils from cinder import db from cinder.db.sqlalchemy import models @@ -626,7 +627,7 @@ def volume_service_uuids_online_data_migration(context, max_count): vol_refs = query.limit(max_count).all() service_refs = model_query(context, models.Service).filter_by( - topic="cinder-volume").limit(max_count).all() + topic=constants.VOLUME_TOPIC).limit(max_count).all() # build a map to access the service uuid by host svc_map = {} diff --git a/cinder/tests/unit/api/contrib/test_admin_actions.py b/cinder/tests/unit/api/contrib/test_admin_actions.py index d479f056f02..cbd61db44e6 100644 --- a/cinder/tests/unit/api/contrib/test_admin_actions.py +++ b/cinder/tests/unit/api/contrib/test_admin_actions.py @@ -63,7 +63,7 @@ class BaseAdminTest(test.TestCase): def _create_volume(self, context, updates=None): db_volume = {'status': 'available', 'host': 'test', - 'binary': 'cinder-volume', + 'binary': constants.VOLUME_BINARY, 'availability_zone': 'fake_zone', 'attach_status': fields.VolumeAttachStatus.DETACHED} if updates: @@ -98,9 +98,9 @@ class AdminActionsTest(BaseAdminTest): def _get_minimum_rpc_version_mock(ctxt, binary): binary_map = { - 'cinder-volume': rpcapi.VolumeAPI, - 'cinder-backup': backup_rpcapi.BackupAPI, - 'cinder-scheduler': scheduler_rpcapi.SchedulerAPI, + constants.VOLUME_BINARY: rpcapi.VolumeAPI, + constants.BACKUP_BINARY: backup_rpcapi.BackupAPI, + constants.SCHEDULER_BINARY: scheduler_rpcapi.SchedulerAPI, } return binary_map[binary].RPC_API_VERSION @@ -501,12 +501,12 @@ class AdminActionsTest(BaseAdminTest): db.service_create(self.ctx, {'host': 'test', 'topic': constants.VOLUME_TOPIC, - 'binary': 'cinder-volume', + 'binary': constants.VOLUME_BINARY, 'created_at': timeutils.utcnow()}) db.service_create(self.ctx, {'host': 'test2', 'topic': constants.VOLUME_TOPIC, - 'binary': 'cinder-volume', + 'binary': constants.VOLUME_BINARY, 'created_at': timeutils.utcnow()}) db.service_create(self.ctx, {'host': 'clustered_host', diff --git a/cinder/tests/unit/api/contrib/test_hosts.py b/cinder/tests/unit/api/contrib/test_hosts.py index 6f803e15d26..f4d2a849a79 100644 --- a/cinder/tests/unit/api/contrib/test_hosts.py +++ b/cinder/tests/unit/api/contrib/test_hosts.py @@ -21,6 +21,7 @@ from oslo_utils import timeutils import webob.exc from cinder.api.contrib import hosts as os_hosts +from cinder.common import constants from cinder import context from cinder import exception from cinder.objects import service @@ -113,9 +114,9 @@ class HostTestCase(test.TestCase): hosts = os_hosts._list_hosts(self.req) self.assertEqual(LIST_RESPONSE, hosts) - cinder_hosts = os_hosts._list_hosts(self.req, 'cinder-volume') + cinder_hosts = os_hosts._list_hosts(self.req, constants.VOLUME_BINARY) expected = [host for host in LIST_RESPONSE - if host['service'] == 'cinder-volume'] + if host['service'] == constants.VOLUME_BINARY] self.assertEqual(expected, cinder_hosts) def test_list_hosts_with_zone(self): @@ -158,8 +159,8 @@ class HostTestCase(test.TestCase): def test_show_host(self, mock_get_host): host = 'test_host' test_service = service.Service(id=1, host=host, - binary='cinder-volume', - topic='cinder-volume') + binary=constants.VOLUME_BINARY, + topic=constants.VOLUME_TOPIC) mock_get_host.return_value = test_service ctxt1 = context.RequestContext(project_id=fake_constants.PROJECT_ID, diff --git a/cinder/tests/unit/api/contrib/test_services.py b/cinder/tests/unit/api/contrib/test_services.py index 869b2a7fd02..28b405f73ec 100644 --- a/cinder/tests/unit/api/contrib/test_services.py +++ b/cinder/tests/unit/api/contrib/test_services.py @@ -26,6 +26,7 @@ import webob.exc from cinder.api.contrib import services from cinder.api import extensions from cinder.api import microversions as mv +from cinder.common import constants from cinder import context from cinder import exception from cinder import objects @@ -129,7 +130,7 @@ class FakeRequest(object): class FakeRequestWithBinary(FakeRequest): def __init__(self, **kwargs): - kwargs.setdefault('binary', 'cinder-volume') + kwargs.setdefault('binary', constants.VOLUME_BINARY) super(FakeRequestWithBinary, self).__init__(**kwargs) @@ -177,7 +178,7 @@ def fake_service_update(context, service_id, values): if service is None: raise exception.ServiceNotFound(service_id=service_id) else: - {'host': 'host1', 'service': 'cinder-volume', + {'host': 'host1', 'service': constants.VOLUME_BINARY, 'disabled': values['disabled']} @@ -571,7 +572,7 @@ class ServicesTest(test.TestCase): self.assertEqual(response, res_dict) def test_services_enable_with_service_key(self): - body = {'host': 'host1', 'service': 'cinder-volume'} + body = {'host': 'host1', 'service': constants.VOLUME_BINARY} req = fakes.HTTPRequest.blank( '/v2/%s/os-services/enable' % fake.PROJECT_ID) res_dict = self.controller.update(req, "enable", body) @@ -579,7 +580,7 @@ class ServicesTest(test.TestCase): self.assertEqual('enabled', res_dict['status']) def test_services_enable_with_binary_key(self): - body = {'host': 'host1', 'binary': 'cinder-volume'} + body = {'host': 'host1', 'binary': constants.VOLUME_BINARY} req = fakes.HTTPRequest.blank( '/v2/%s/os-services/enable' % fake.PROJECT_ID) res_dict = self.controller.update(req, "enable", body) @@ -589,7 +590,7 @@ class ServicesTest(test.TestCase): def test_services_disable_with_service_key(self): req = fakes.HTTPRequest.blank( '/v2/%s/os-services/disable' % fake.PROJECT_ID) - body = {'host': 'host1', 'service': 'cinder-volume'} + body = {'host': 'host1', 'service': constants.VOLUME_BINARY} res_dict = self.controller.update(req, "disable", body) self.assertEqual('disabled', res_dict['status']) @@ -597,7 +598,7 @@ class ServicesTest(test.TestCase): def test_services_disable_with_binary_key(self): req = fakes.HTTPRequest.blank( '/v2/%s/os-services/disable' % fake.PROJECT_ID) - body = {'host': 'host1', 'binary': 'cinder-volume'} + body = {'host': 'host1', 'binary': constants.VOLUME_BINARY} res_dict = self.controller.update(req, "disable", body) self.assertEqual('disabled', res_dict['status']) @@ -779,7 +780,7 @@ class ServicesTest(test.TestCase): mock.sentinel.context, body) self.assertEqual([binary], binaries) - if binary == 'cinder-api': + if binary == constants.API_BINARY: self.assertEqual([], services) service_list_mock.assert_not_called() else: @@ -804,9 +805,9 @@ class ServicesTest(test.TestCase): def test__set_log(self, backup_rpc_mock, vol_rpc_mock, sch_rpc_mock, set_log_mock, get_all_mock, get_log_mock): services = [ - objects.Service(self.context, binary='cinder-scheduler'), - objects.Service(self.context, binary='cinder-volume'), - objects.Service(self.context, binary='cinder-backup'), + objects.Service(self.context, binary=constants.SCHEDULER_BINARY), + objects.Service(self.context, binary=constants.VOLUME_BINARY), + objects.Service(self.context, binary=constants.BACKUP_BINARY), ] get_all_mock.return_value = services body = {'binary': '*', 'prefix': 'eventlet.', 'level': 'debug'} @@ -852,11 +853,12 @@ class ServicesTest(test.TestCase): ] services = [ - objects.Service(self.context, binary='cinder-scheduler', + objects.Service(self.context, binary=constants.SCHEDULER_BINARY, host='host'), - objects.Service(self.context, binary='cinder-volume', + objects.Service(self.context, binary=constants.VOLUME_BINARY, host='host@backend#pool'), - objects.Service(self.context, binary='cinder-backup', host='host'), + objects.Service(self.context, binary=constants.BACKUP_BINARY, + host='host'), ] get_all_mock.return_value = services body = {'binary': '*', 'prefix': 'eventlet.'} @@ -874,7 +876,7 @@ class ServicesTest(test.TestCase): 'levels': mock.sentinel.api_levels}, {'binary': 'cinder-scheduler', 'host': 'host', 'levels': {'p5': 'l5', 'p6': 'l6'}}, - {'binary': 'cinder-volume', + {'binary': constants.VOLUME_BINARY, 'host': 'host@backend#pool', 'levels': {'p3': 'l3', 'p4': 'l4'}}, {'binary': 'cinder-backup', 'host': 'host', diff --git a/cinder/tests/unit/api/contrib/test_snapshot_manage.py b/cinder/tests/unit/api/contrib/test_snapshot_manage.py index 933e3da62e5..2d35163c0cd 100644 --- a/cinder/tests/unit/api/contrib/test_snapshot_manage.py +++ b/cinder/tests/unit/api/contrib/test_snapshot_manage.py @@ -21,6 +21,7 @@ from six.moves import http_client from six.moves.urllib.parse import urlencode import webob +from cinder.common import constants from cinder import context from cinder import exception from cinder import objects @@ -120,14 +121,14 @@ class SnapshotManageTest(test.TestCase): """ mock_db.return_value = fake_service.fake_service_obj( self._admin_ctxt, - binary='cinder-volume') + binary=constants.VOLUME_BINARY) body = {'snapshot': {'volume_id': fake.VOLUME_ID, 'ref': 'fake_ref'}} res = self._get_resp_post(body) self.assertEqual(http_client.ACCEPTED, res.status_int, res) # Check the db.service_get was called with correct arguments. mock_db.assert_called_once_with( - mock.ANY, None, host='fake_host', binary='cinder-volume', + mock.ANY, None, host='fake_host', binary=constants.VOLUME_BINARY, cluster_name=None) # Check the create_snapshot_in_db was called with correct arguments. diff --git a/cinder/tests/unit/api/v3/test_snapshot_manage.py b/cinder/tests/unit/api/v3/test_snapshot_manage.py index b333cd54052..1e012a085de 100644 --- a/cinder/tests/unit/api/v3/test_snapshot_manage.py +++ b/cinder/tests/unit/api/v3/test_snapshot_manage.py @@ -22,6 +22,7 @@ import webob from cinder.api import microversions as mv from cinder.api.v3 import router as router_v3 +from cinder.common import constants from cinder import context from cinder import objects from cinder import test @@ -77,7 +78,7 @@ class SnapshotManageTest(test.TestCase): """ mock_service_get.return_value = fake_service.fake_service_obj( self._admin_ctxt, - binary='cinder-volume') + binary=constants.VOLUME_BINARY) body = {'snapshot': {'volume_id': fake.VOLUME_ID, 'ref': 'fake_ref'}} res = self._get_resp_post(body) @@ -187,7 +188,7 @@ class SnapshotManageTest(test.TestCase): sort_dirs=['desc'], want_objects=True) detail_view_mock.assert_called_once_with(mock.ANY, snaps, len(snaps)) get_service_mock.assert_called_once_with( - mock.ANY, None, host=host, binary='cinder-volume', + mock.ANY, None, host=host, binary=constants.VOLUME_BINARY, cluster_name=cluster_name) @ddt.data(mv.MANAGE_EXISTING_LIST, mv.MANAGE_EXISTING_CLUSTER) diff --git a/cinder/tests/unit/api/v3/test_volume_manage.py b/cinder/tests/unit/api/v3/test_volume_manage.py index 96406183767..8d1ca65bc60 100644 --- a/cinder/tests/unit/api/v3/test_volume_manage.py +++ b/cinder/tests/unit/api/v3/test_volume_manage.py @@ -22,6 +22,7 @@ import webob from cinder.api import microversions as mv from cinder.api.v3 import router as router_v3 +from cinder.common import constants from cinder import context from cinder import objects from cinder import test @@ -188,7 +189,7 @@ class VolumeManageTest(test.TestCase): detail_view_mock.assert_called_once_with(mock.ANY, volumes, len(volumes)) get_service_mock.assert_called_once_with( - mock.ANY, None, host=host, binary='cinder-volume', + mock.ANY, None, host=host, binary=constants.VOLUME_BINARY, cluster_name=cluster_name) @ddt.data(mv.MANAGE_EXISTING_LIST, mv.MANAGE_EXISTING_CLUSTER) diff --git a/cinder/tests/unit/api/v3/test_workers.py b/cinder/tests/unit/api/v3/test_workers.py index ea154f24bd6..03bec3585a1 100644 --- a/cinder/tests/unit/api/v3/test_workers.py +++ b/cinder/tests/unit/api/v3/test_workers.py @@ -22,6 +22,7 @@ import webob from cinder.api import microversions as mv from cinder.api.v3 import router as router_v3 from cinder.api.v3 import workers +from cinder.common import constants from cinder import context from cinder import objects from cinder import test @@ -30,13 +31,13 @@ from cinder.tests.unit import fake_constants as fake SERVICES = ( - [objects.Service(id=1, host='host1', binary='cinder-volume', + [objects.Service(id=1, host='host1', binary=constants.VOLUME_BINARY, cluster_name='mycluster'), - objects.Service(id=2, host='host2', binary='cinder-volume', + objects.Service(id=2, host='host2', binary=constants.VOLUME_BINARY, cluster_name='mycluster')], - [objects.Service(id=3, host='host3', binary='cinder-volume', + [objects.Service(id=3, host='host3', binary=constants.VOLUME_BINARY, cluster_name='mycluster'), - objects.Service(id=4, host='host4', binary='cinder-volume', + objects.Service(id=4, host='host4', binary=constants.VOLUME_BINARY, cluster_name='mycluster')], ) diff --git a/cinder/tests/unit/scheduler/test_scheduler.py b/cinder/tests/unit/scheduler/test_scheduler.py index 88c28d7daab..27d905fbb52 100644 --- a/cinder/tests/unit/scheduler/test_scheduler.py +++ b/cinder/tests/unit/scheduler/test_scheduler.py @@ -23,6 +23,7 @@ import ddt import mock from oslo_config import cfg +from cinder.common import constants from cinder import context from cinder import exception from cinder.message import message_field @@ -424,17 +425,17 @@ class SchedulerManagerTestCase(test.TestCase): def test_cleanup_destination_volume(self): service = objects.Service(id=1, host='hostname', cluster_name=None, - binary='cinder-volume') + binary=constants.VOLUME_BINARY) result = self.manager._cleanup_destination(None, service) expected = self.manager.volume_api.do_cleanup, service, service.host self.assertEqual(expected, result) def test_cleanup_destination_volume_cluster_cache_hit(self): cluster = objects.Cluster(id=1, name='mycluster', - binary='cinder-volume') + binary=constants.VOLUME_BINARY) service = objects.Service(id=2, host='hostname', cluster_name=cluster.name, - binary='cinder-volume') + binary=constants.VOLUME_BINARY) cluster_cache = {'cinder-volume': {'mycluster': cluster}} result = self.manager._cleanup_destination(cluster_cache, service) expected = self.manager.volume_api.do_cleanup, cluster, cluster.name @@ -443,11 +444,11 @@ class SchedulerManagerTestCase(test.TestCase): @mock.patch('cinder.objects.Cluster.get_by_id') def test_cleanup_destination_volume_cluster_cache_miss(self, get_mock): cluster = objects.Cluster(id=1, name='mycluster', - binary='cinder-volume') + binary=constants.VOLUME_BINARY) service = objects.Service(self.context, id=2, host='hostname', cluster_name=cluster.name, - binary='cinder-volume') + binary=constants.VOLUME_BINARY) get_mock.return_value = cluster cluster_cache = collections.defaultdict(dict) result = self.manager._cleanup_destination(cluster_cache, service) @@ -470,24 +471,24 @@ class SchedulerManagerTestCase(test.TestCase): @mock.patch('cinder.objects.ServiceList.get_all') def test_work_cleanup(self, get_mock, vol_clean_mock, sch_clean_mock): args = dict(service_id=1, cluster_name='cluster_name', host='host', - binary='cinder-volume', is_up=False, disabled=True, + binary=constants.VOLUME_BINARY, is_up=False, disabled=True, resource_id=fake.VOLUME_ID, resource_type='Volume') cluster = objects.Cluster(id=1, name=args['cluster_name'], - binary='cinder-volume') + binary=constants.VOLUME_BINARY) services = [objects.Service(self.context, id=2, host='hostname', cluster_name=cluster.name, - binary='cinder-volume', + binary=constants.VOLUME_BINARY, cluster=cluster), objects.Service(self.context, id=3, host='hostname', cluster_name=None, - binary='cinder-scheduler'), + binary=constants.SCHEDULER_BINARY), objects.Service(self.context, id=4, host='hostname', cluster_name=None, - binary='cinder-volume')] + binary=constants.VOLUME_BINARY)] get_mock.return_value = services cleanup_request = objects.CleanupRequest(self.context, **args) diff --git a/cinder/tests/unit/test_cmd.py b/cinder/tests/unit/test_cmd.py index 240e8669735..bf4654ea022 100644 --- a/cinder/tests/unit/test_cmd.py +++ b/cinder/tests/unit/test_cmd.py @@ -37,6 +37,7 @@ from cinder.cmd import rtstool as cinder_rtstool from cinder.cmd import scheduler as cinder_scheduler from cinder.cmd import volume as cinder_volume from cinder.cmd import volume_usage_audit +from cinder.common import constants from cinder import context from cinder.db.sqlalchemy import api as sqlalchemy_api from cinder import exception @@ -173,10 +174,10 @@ class TestCinderVolumeCmd(test.TestCase): log_setup.assert_called_once_with(CONF, "cinder") monkey_patch.assert_called_once_with() get_launcher.assert_called_once_with() - c1 = mock.call(binary='cinder-volume', host='host@backend1', + c1 = mock.call(binary=constants.VOLUME_BINARY, host='host@backend1', service_name='backend1', coordination=True, cluster=None) - c2 = mock.call(binary='cinder-volume', host='host@backend2', + c2 = mock.call(binary=constants.VOLUME_BINARY, host='host@backend2', service_name='backend2', coordination=True, cluster=None) service_create.assert_has_calls([c1, c2]) @@ -2052,8 +2053,8 @@ class TestVolumeSharedTargetsOnlineMigration(test.TestCase): # Need a service to query values = { 'host': 'host1@lvm-driver1', - 'binary': 'cinder-volume', - 'topic': 'cinder-volume', + 'binary': constants.VOLUME_BINARY, + 'topic': constants.VOLUME_TOPIC, 'uuid': 'f080f895-cff2-4eb3-9c61-050c060b59ad'} utils.create_service(ctxt, values) @@ -2090,8 +2091,8 @@ class TestVolumeSharedTargetsOnlineMigration(test.TestCase): values = { 'host': 'host1@lvm-driver1', - 'binary': 'cinder-volume', - 'topic': 'cinder-volume', + 'binary': constants.VOLUME_BINARY, + 'topic': constants.VOLUME_TOPIC, 'uuid': 'f080f895-cff2-4eb3-9c61-050c060b59ad'} utils.create_service(ctxt, values) diff --git a/cinder/tests/unit/test_db_api.py b/cinder/tests/unit/test_db_api.py index 064ac1a91e7..97242da8849 100644 --- a/cinder/tests/unit/test_db_api.py +++ b/cinder/tests/unit/test_db_api.py @@ -27,6 +27,7 @@ import six from sqlalchemy.sql import operators from cinder.api import common +from cinder.common import constants from cinder import context from cinder import db from cinder.db.sqlalchemy import api as sqlalchemy_api @@ -166,13 +167,13 @@ class DBAPIServiceTestCase(BaseTest): # Force create one entry with no UUID sqlalchemy_api.service_create(self.ctxt, { 'host': 'host1', - 'binary': 'cinder-volume', + 'binary': constants.VOLUME_BINARY, 'topic': 'volume', }) # Create another one with a valid UUID sqlalchemy_api.service_create(self.ctxt, { 'host': 'host2', - 'binary': 'cinder-volume', + 'binary': constants.VOLUME_BINARY, 'topic': 'volume', 'uuid': 'a3a593da-7f8d-4bb7-8b4c-f2bc1e0b4824'}) @@ -186,15 +187,15 @@ class DBAPIServiceTestCase(BaseTest): def test_service_uuid_migrations_with_limit(self): sqlalchemy_api.service_create(self.ctxt, { 'host': 'host1', - 'binary': 'cinder-volume', + 'binary': constants.VOLUME_BINARY, 'topic': 'volume', }) sqlalchemy_api.service_create(self.ctxt, { 'host': 'host2', - 'binary': 'cinder-volume', + 'binary': constants.VOLUME_BINARY, 'topic': 'volume', }) sqlalchemy_api.service_create(self.ctxt, { 'host': 'host3', - 'binary': 'cinder-volume', + 'binary': constants.VOLUME_BINARY, 'topic': 'volume', }) # Run the migration and verify that we updated 1 entry total, updated = db.service_uuids_online_data_migration( @@ -474,8 +475,8 @@ class DBAPIServiceTestCase(BaseTest): # Need a service to query values = { 'host': 'host1@lvm-driver1', - 'binary': 'cinder-volume', - 'topic': 'cinder-volume'} + 'binary': constants.VOLUME_BINARY, + 'topic': constants.VOLUME_TOPIC} utils.create_service(self.ctxt, values) # Run the migration and verify that we updated 1 entry @@ -496,8 +497,8 @@ class DBAPIServiceTestCase(BaseTest): values = { 'host': 'host1@lvm-driver1', - 'binary': 'cinder-volume', - 'topic': 'cinder-volume', + 'binary': constants.VOLUME_BINARY, + 'topic': constants.VOLUME_TOPIC, 'uuid': 'a3a593da-7f8d-4bb7-8b4c-f2bc1e0b4824'} utils.create_service(self.ctxt, values) diff --git a/cinder/tests/unit/test_service.py b/cinder/tests/unit/test_service.py index e9adbfa5095..c918ea9373b 100644 --- a/cinder/tests/unit/test_service.py +++ b/cinder/tests/unit/test_service.py @@ -25,6 +25,7 @@ from oslo_concurrency import processutils from oslo_config import cfg from oslo_db import exception as db_exc +from cinder.common import constants from cinder import context from cinder import db from cinder import exception @@ -385,7 +386,8 @@ class ServiceTestCase(test.TestCase): return_value='1.6') def test_start_rpc_and_init_host_no_cluster(self, is_upgrading_mock): """Test that without cluster we don't create rpc service.""" - app = service.Service.create(host=self.host, binary='cinder-volume', + app = service.Service.create(host=self.host, + binary=constants.VOLUME_BINARY, cluster=None, topic=self.topic) self._check_rpc_servers_and_init_host(app, True, None) @@ -395,7 +397,8 @@ class ServiceTestCase(test.TestCase): get_min_obj_mock.return_value = '1.7' cluster = 'cluster@backend#pool' self.host = 'host@backend#pool' - app = service.Service.create(host=self.host, binary='cinder-volume', + app = service.Service.create(host=self.host, + binary=constants.VOLUME_BINARY, cluster=cluster, topic=self.topic) self._check_rpc_servers_and_init_host(app, True, cluster) diff --git a/cinder/tests/unit/test_setup_profiler.py b/cinder/tests/unit/test_setup_profiler.py index f29ba96f8db..bd9cb0a46f6 100644 --- a/cinder/tests/unit/test_setup_profiler.py +++ b/cinder/tests/unit/test_setup_profiler.py @@ -15,6 +15,7 @@ import mock +from cinder.common import constants from cinder import service from cinder import test @@ -30,7 +31,7 @@ class SetupProfilerTestCase(test.TestCase): def test_profiler_not_present(self): service.profiler = None service.LOG.debug = mock.MagicMock() - service.setup_profiler("cinder-volume", "localhost") + service.setup_profiler(constants.VOLUME_BINARY, "localhost") service.LOG.debug.assert_called_once_with("osprofiler is not present") @mock.patch("cinder.service.context") @@ -38,15 +39,15 @@ class SetupProfilerTestCase(test.TestCase): service.CONF.profiler.enabled = True return_value = {"Meaning Of Life": 42} context.get_admin_context().to_dict.return_value = return_value - service.setup_profiler("cinder-volume", "localhost") + service.setup_profiler(constants.VOLUME_BINARY, "localhost") service.osprofiler_initializer.init_from_conf.assert_called_once_with( conf=service.CONF, context=return_value, project="cinder", - service="cinder-volume", + service=constants.VOLUME_BINARY, host="localhost") def test_profiler_disabled(self): service.CONF.profiler.enabled = False - service.setup_profiler("cinder-volume", "localhost") + service.setup_profiler(constants.VOLUME_BINARY, "localhost") service.osprofiler_initializer.init_from_conf.assert_not_called() diff --git a/cinder/tests/unit/utils.py b/cinder/tests/unit/utils.py index fd5a0fcf4c1..a5478e480e6 100644 --- a/cinder/tests/unit/utils.py +++ b/cinder/tests/unit/utils.py @@ -24,6 +24,7 @@ from oslo_service import loopingcall from oslo_utils import timeutils import oslo_versionedobjects +from cinder.common import constants from cinder import context from cinder import db from cinder import exception @@ -496,7 +497,7 @@ def create_service(ctxt, values=None): def default_cluster_values(): return { 'name': 'cluster_name', - 'binary': 'cinder-volume', + 'binary': constants.VOLUME_BINARY, 'disabled': False, 'disabled_reason': None, 'deleted': False, diff --git a/cinder/tests/unit/volume/test_replication_manager.py b/cinder/tests/unit/volume/test_replication_manager.py index e3f95b3f5be..b3d65001035 100644 --- a/cinder/tests/unit/volume/test_replication_manager.py +++ b/cinder/tests/unit/volume/test_replication_manager.py @@ -121,7 +121,7 @@ class ReplicationTestCase(base.BaseVolumeTestCase): mock_db_get_all.return_value = [fake_service.fake_service_obj( self.context, - binary='cinder-volume')] + binary=constants.VOLUME_BINARY)] mock_db_update.return_value = None volume_api = cinder.volume.api.API() self.assertRaises(exception.InvalidInput, @@ -138,7 +138,7 @@ class ReplicationTestCase(base.BaseVolumeTestCase): """Test replication freeze_host.""" service = fake_service.fake_service_obj(self.context, - binary='cinder-volume') + binary=constants.VOLUME_BINARY) mock_get_all.return_value = [service] mock_freeze.return_value = True volume_api = cinder.volume.api.API() @@ -155,7 +155,7 @@ class ReplicationTestCase(base.BaseVolumeTestCase): mock_get_all.return_value = [fake_service.fake_service_obj( self.context, - binary='cinder-volume')] + binary=constants.VOLUME_BINARY)] mock_db_update.return_value = None volume_api = cinder.volume.api.API() self.assertRaises(exception.InvalidInput, @@ -172,7 +172,7 @@ class ReplicationTestCase(base.BaseVolumeTestCase): """Test replication thaw_host.""" service = fake_service.fake_service_obj(self.context, - binary='cinder-volume') + binary=constants.VOLUME_BINARY) mock_get_all.return_value = [service] mock_thaw.return_value = True volume_api = cinder.volume.api.API() @@ -189,7 +189,7 @@ class ReplicationTestCase(base.BaseVolumeTestCase): mock_get_all.return_value = [fake_service.fake_service_obj( self.context, - binary='cinder-volume')] + binary=constants.VOLUME_BINARY)] mock_db_update.return_value = None volume_api = cinder.volume.api.API() self.assertRaises(exception.InvalidInput, @@ -463,7 +463,7 @@ class ReplicationTestCase(base.BaseVolumeTestCase): secondary_id=None): host = vol_utils.extract_host(self.manager.host) utils.create_service(self.context, {'host': host, - 'binary': 'cinder-volume'}) + 'binary': constants.VOLUME_BINARY}) for volume in in_volumes: utils.create_volume(self.context, self.manager.host, **volume) diff --git a/cinder/tests/unit/volume/test_rpcapi.py b/cinder/tests/unit/volume/test_rpcapi.py index 137f2f541ae..b9115b2b03e 100644 --- a/cinder/tests/unit/volume/test_rpcapi.py +++ b/cinder/tests/unit/volume/test_rpcapi.py @@ -21,6 +21,7 @@ import mock from oslo_config import cfg from oslo_serialization import jsonutils +from cinder.common import constants from cinder import db from cinder import exception from cinder import objects @@ -356,7 +357,7 @@ class VolumeRPCAPITestCase(test.RPCAPITestCase): def test_freeze_host(self): service = fake_service.fake_service_obj(self.context, host='fake_host', - binary='cinder-volume') + binary=constants.VOLUME_BINARY) self._test_rpc_api('freeze_host', rpc_method='call', server='fake_host', @@ -366,7 +367,7 @@ class VolumeRPCAPITestCase(test.RPCAPITestCase): def test_thaw_host(self): service = fake_service.fake_service_obj(self.context, host='fake_host', - binary='cinder-volume') + binary=constants.VOLUME_BINARY) self._test_rpc_api('thaw_host', rpc_method='call', server='fake_host', diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 02223928e5b..993f1e9198a 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -1686,7 +1686,7 @@ class API(base.Base): # cluster itself is also up. try: service = objects.Service.get_by_id(elevated, None, host=svc_host, - binary='cinder-volume', + binary=constants.VOLUME_BINARY, cluster_name=svc_cluster) except exception.ServiceNotFound: with excutils.save_and_reraise_exception(): diff --git a/cinder/volume/rpcapi.py b/cinder/volume/rpcapi.py index 443bab6daa9..5568a8cd92f 100644 --- a/cinder/volume/rpcapi.py +++ b/cinder/volume/rpcapi.py @@ -138,7 +138,7 @@ class VolumeAPI(rpc.RPCAPI): RPC_API_VERSION = '3.15' RPC_DEFAULT_VERSION = '3.0' TOPIC = constants.VOLUME_TOPIC - BINARY = 'cinder-volume' + BINARY = constants.VOLUME_BINARY def _get_cctxt(self, host=None, version=None, **kwargs): if host: