Browse Source

Updated usage of locks

Changes:
- replaced direct usage of sychronized func from lockutils with local wrapper,
  that provides prefix;
- 'lock_path' is not provided anymore as hardcode, defined 'lock_path'
  in config is expected;
- added MANILA_LOCK_PATH to devstack plugin, to be able to set path
  before installation.

Change-Id: I6518df0a6d32f1021b19a48f928f9ec8b00140b2
Closes-Bug: #1347915
tags/2014.2.b3
Valeriy Ponomaryov 4 years ago
parent
commit
fe675be832

+ 1
- 2
.gitignore View File

@@ -38,5 +38,4 @@ doc/build
38 38
 .pydevproject
39 39
 
40 40
 # Lock dirs and files
41
-service_instance_locks
42
-attach_detach_locks
41
+manila_locks

+ 3
- 0
contrib/devstack/lib/manila View File

@@ -34,6 +34,7 @@ MANILACLIENT_BRANCH=master
34 34
 
35 35
 # set up default directories
36 36
 MANILA_DIR=${MANILA_DIR:=$DEST/manila}
37
+MANILA_LOCK_PATH=${MANILA_LOCK_PATH:=$MANILA_DIR/manila_locks}
37 38
 MANILACLIENT_DIR=${MANILACLIENT_DIR:=$DEST/python-manilaclient}
38 39
 MANILA_STATE_PATH=${MANILA_STATE_PATH:=$DATA_DIR/manila}
39 40
 MANILA_MNT_DIR=${MANILA_MNT_DIR:=$MANILA_STATE_PATH/mnt}
@@ -179,6 +180,8 @@ function configure_manila {
179 180
     iniset $MANILA_CONF DEFAULT cinder_admin_password $SERVICE_PASSWORD
180 181
     iniset $MANILA_CONF DEFAULT neutron_admin_password $SERVICE_PASSWORD
181 182
 
183
+    iniset $MANILA_CONF DEFAULT lock_path $MANILA_LOCK_PATH
184
+
182 185
     add_share_backend $MANILA_BACKEND1_CONFIG_GROUP_NAME $MANILA_SHARE_BACKEND1_NAME
183 186
     enabled_backends=$MANILA_BACKEND1_CONFIG_GROUP_NAME
184 187
 

+ 1
- 3
manila/network/linux/interface.py View File

@@ -22,7 +22,6 @@ import six
22 22
 from manila import exception
23 23
 from manila.network.linux import ip_lib
24 24
 from manila.network.linux import ovs_lib
25
-from manila.openstack.common import lockutils
26 25
 from manila.openstack.common import log as logging
27 26
 from manila import utils
28 27
 
@@ -45,8 +44,7 @@ def device_name_synchronized(f):
45 44
     def wrapped_func(self, *args, **kwargs):
46 45
         device_name = "device_name_%s" % args[0]
47 46
 
48
-        @lockutils.synchronized(device_name, external=True,
49
-                                lock_path="service_instance_locks")
47
+        @utils.synchronized("linux_interface_%s" % device_name, external=True)
50 48
         def source_func(self, *args, **kwargs):
51 49
             return f(self, *args, **kwargs)
52 50
 

+ 4
- 5
manila/share/drivers/generic.py View File

@@ -27,7 +27,6 @@ from manila import context
27 27
 from manila import exception
28 28
 from manila.openstack.common import excutils
29 29
 from manila.openstack.common import importutils
30
-from manila.openstack.common import lockutils
31 30
 from manila.openstack.common import log as logging
32 31
 from manila.openstack.common import processutils
33 32
 from manila.share import driver
@@ -272,8 +271,8 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
272 271
 
273 272
     def _attach_volume(self, context, share, instance_id, volume):
274 273
         """Attaches cinder volume to service vm."""
275
-        @lockutils.synchronized(instance_id, external=True,
276
-                                lock_path="attach_detach_locks")
274
+        @utils.synchronized(
275
+            "generic_driver_attach_detach_%s" % instance_id, external=True)
277 276
         def do_attach(volume):
278 277
             if volume['status'] == 'in-use':
279 278
                 attached_volumes = [vol.id for vol in
@@ -337,8 +336,8 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
337 336
         """Detaches cinder volume from service vm."""
338 337
         instance_id = server_details['instance_id']
339 338
 
340
-        @lockutils.synchronized(instance_id, external=True,
341
-                                lock_path="attach_detach_locks")
339
+        @utils.synchronized(
340
+            "generic_driver_attach_detach_%s" % instance_id, external=True)
342 341
         def do_detach():
343 342
             attached_volumes = [vol.id for vol in
344 343
                                 self.compute_api.instance_volumes_list(

+ 15
- 21
manila/share/drivers/service_instance.py View File

@@ -31,7 +31,6 @@ from manila import exception
31 31
 from manila.network.linux import ip_lib
32 32
 from manila.network.neutron import api as neutron
33 33
 from manila.openstack.common import importutils
34
-from manila.openstack.common import lockutils
35 34
 from manila.openstack.common import log as logging
36 35
 from manila import utils
37 36
 
@@ -159,8 +158,7 @@ class ServiceInstanceManager(object):
159 158
             "path_to_private_key")
160 159
         self.path_to_public_key = self.get_config_option("path_to_public_key")
161 160
 
162
-    @lockutils.synchronized("_get_service_network", external=True,
163
-                            lock_path="service_instance_locks")
161
+    @utils.synchronized("service_instance_get_service_network", external=True)
164 162
     def _get_service_network(self):
165 163
         """Finds existing or creates new service network."""
166 164
         service_network_name = self.get_config_option("service_network_name")
@@ -202,8 +200,8 @@ class ServiceInstanceManager(object):
202 200
             raise exception.ServiceInstanceException(msg)
203 201
         return net_ips[0]
204 202
 
205
-    @lockutils.synchronized("_get_or_create_security_group",
206
-                            external=True, lock_path="service_instance_locks")
203
+    @utils.synchronized(
204
+        "service_instance_get_or_create_security_group", external=True)
207 205
     def _get_or_create_security_group(self, context, name=None,
208 206
                                       description=None):
209 207
         """Get or create security group for service_instance.
@@ -301,8 +299,7 @@ class ServiceInstanceManager(object):
301 299
                     'service_instance_password'),
302 300
                 'username': self.get_config_option('service_instance_user')}
303 301
 
304
-    @lockutils.synchronized("_get_key", external=True,
305
-                            lock_path="service_instance_locks")
302
+    @utils.synchronized("service_instance_get_key", external=True)
306 303
     def _get_key(self, context):
307 304
         """Get ssh key.
308 305
 
@@ -441,8 +438,8 @@ class ServiceInstanceManager(object):
441 438
                 time.sleep(5)
442 439
         return False
443 440
 
444
-    @lockutils.synchronized("_setup_network_for_instance", external=True,
445
-                            lock_path="service_instance_locks")
441
+    @utils.synchronized(
442
+        "service_instance_setup_network_for_instance", external=True)
446 443
     def _setup_network_for_instance(self, neutron_net_id, neutron_subnet_id):
447 444
         """Sets up network for service vm."""
448 445
 
@@ -477,8 +474,7 @@ class ServiceInstanceManager(object):
477 474
                                             device_owner='manila')
478 475
         return service_subnet['id'], private_router['id'], port['id']
479 476
 
480
-    @lockutils.synchronized("_get_private_router", external=True,
481
-                            lock_path="service_instance_locks")
477
+    @utils.synchronized("service_instance_get_private_router", external=True)
482 478
     def _get_private_router(self, neutron_net_id, neutron_subnet_id):
483 479
         """Returns router attached to private subnet gateway."""
484 480
         private_subnet = self.neutron_api.get_subnet(neutron_subnet_id)
@@ -526,8 +522,8 @@ class ServiceInstanceManager(object):
526 522
         # here we are checking for garbage devices from removed service port
527 523
         self._remove_outdated_interfaces(device)
528 524
 
529
-    @lockutils.synchronized("_remove_outdated_interfaces", external=True,
530
-                            lock_path="service_instance_locks")
525
+    @utils.synchronized(
526
+        "service_instance_remove_outdated_interfaces", external=True)
531 527
     def _remove_outdated_interfaces(self, device):
532 528
         """Finds and removes unused network device."""
533 529
         list_dev = []
@@ -546,8 +542,7 @@ class ServiceInstanceManager(object):
546 542
             if device_cidr_set & cidr_set:
547 543
                 self.vif_driver.unplug(dev_name)
548 544
 
549
-    @lockutils.synchronized("_get_service_port", external=True,
550
-                            lock_path="service_instance_locks")
545
+    @utils.synchronized("service_instance_get_service_port", external=True)
551 546
     def _get_service_port(self):
552 547
         """Find or creates service neutron port.
553 548
 
@@ -575,8 +570,8 @@ class ServiceInstanceManager(object):
575 570
             port = ports[0]
576 571
         return port
577 572
 
578
-    @lockutils.synchronized("_add_fixed_ips_to_service_port", external=True,
579
-                            lock_path="service_instance_locks")
573
+    @utils.synchronized(
574
+        "service_instance_add_fixed_ips_to_service_port", external=True)
580 575
     def _add_fixed_ips_to_service_port(self, port):
581 576
         network = self.neutron_api.get_network(self.service_network_id)
582 577
         subnets = set(network['subnets'])
@@ -630,15 +625,14 @@ class ServiceInstanceManager(object):
630 625
                            'router_id': router_id})
631 626
             self.neutron_api.update_subnet(subnet_id, '')
632 627
 
633
-    @lockutils.synchronized("_get_all_service_subnets", external=True,
634
-                            lock_path="service_instance_locks")
628
+    @utils.synchronized(
629
+        "service_instance_get_all_service_subnets", external=True)
635 630
     def _get_all_service_subnets(self):
636 631
         service_network = self.neutron_api.get_network(self.service_network_id)
637 632
         return [self.neutron_api.get_subnet(subnet_id)
638 633
                 for subnet_id in service_network['subnets']]
639 634
 
640
-    @lockutils.synchronized("_get_service_subnet", external=True,
641
-                            lock_path="service_instance_locks")
635
+    @utils.synchronized("service_instance_get_service_subnet", external=True)
642 636
     def _get_service_subnet(self, subnet_name):
643 637
         all_service_subnets = self._get_all_service_subnets()
644 638
         service_subnets = [subnet for subnet in all_service_subnets

+ 4
- 3
manila/share/manager.py View File

@@ -26,11 +26,11 @@ from manila import manager
26 26
 from manila import network
27 27
 from manila.openstack.common import excutils
28 28
 from manila.openstack.common import importutils
29
-from manila.openstack.common import lockutils
30 29
 from manila.openstack.common import log as logging
31 30
 from manila.openstack.common import timeutils
32 31
 from manila import quota
33 32
 import manila.share.configuration
33
+from manila import utils
34 34
 
35 35
 from oslo.config import cfg
36 36
 
@@ -116,7 +116,7 @@ class ShareManager(manager.SchedulerDependentManager):
116 116
                   share updated with share_server_id.
117 117
         """
118 118
 
119
-        @lockutils.synchronized(share_network_id)
119
+        @utils.synchronized("share_manager_%s" % share_network_id)
120 120
         def _provide_share_server_for_share():
121 121
             exist = False
122 122
             try:
@@ -424,7 +424,8 @@ class ShareManager(manager.SchedulerDependentManager):
424 424
 
425 425
     def delete_share_server(self, context, share_server):
426 426
 
427
-        @lockutils.synchronized(share_server['share_network_id'])
427
+        @utils.synchronized(
428
+            "share_manager_%s" % share_server['share_network_id'])
428 429
         def _teardown_server():
429 430
             # NOTE(vponomaryov): Verify that there are no dependent shares.
430 431
             # Without this verification we can get here exception in next case:

+ 3
- 4
manila/tests/test_service_instance.py View File

@@ -19,17 +19,16 @@ import copy
19 19
 import os
20 20
 
21 21
 import mock
22
+from oslo.config import cfg
22 23
 
23 24
 from manila import context
24 25
 from manila import exception
25
-from manila.openstack.common import lockutils
26 26
 from manila.share.drivers import service_instance
27 27
 from manila import test
28 28
 from manila.tests.db import fakes as db_fakes
29 29
 from manila.tests import fake_compute
30 30
 from manila.tests import fake_network
31
-
32
-from oslo.config import cfg
31
+from manila import utils
33 32
 
34 33
 CONF = cfg.CONF
35 34
 
@@ -69,7 +68,7 @@ class ServiceInstanceManagerTestCase(test.TestCase):
69 68
         self._manager.admin_context = self._context
70 69
         self._manager._execute = mock.Mock(return_value=('', ''))
71 70
         self._manager.vif_driver = mock.Mock()
72
-        self.stubs.Set(lockutils, 'synchronized',
71
+        self.stubs.Set(utils, 'synchronized',
73 72
                        mock.Mock(return_value=lambda f: f))
74 73
         self.stubs.Set(service_instance.os.path, 'exists',
75 74
                        mock.Mock(return_value=True))

+ 2
- 3
manila/tests/test_share_generic.py View File

@@ -23,7 +23,6 @@ from oslo.config import cfg
23 23
 from manila import compute
24 24
 from manila import context
25 25
 from manila import exception
26
-from manila.openstack.common import lockutils
27 26
 import manila.share.configuration
28 27
 from manila.share.drivers import generic
29 28
 from manila import test
@@ -32,9 +31,9 @@ from manila.tests import fake_compute
32 31
 from manila.tests import fake_service_instance
33 32
 from manila.tests import fake_utils
34 33
 from manila.tests import fake_volume
34
+from manila import utils
35 35
 from manila import volume
36 36
 
37
-
38 37
 CONF = cfg.CONF
39 38
 
40 39
 
@@ -115,7 +114,7 @@ class GenericShareDriverTestCase(test.TestCase):
115 114
             share_network_id=self.fake_sn["id"], old_server_ip="fake")
116 115
 
117 116
         self._driver._ssh_exec = mock.Mock(return_value=('', ''))
118
-        self.stubs.Set(lockutils, 'synchronized',
117
+        self.stubs.Set(utils, 'synchronized',
119 118
                        mock.Mock(return_value=lambda f: f))
120 119
         self.stubs.Set(generic.os.path, 'exists', mock.Mock(return_value=True))
121 120
         self._driver._helpers = {

Loading…
Cancel
Save