Browse Source

libvirt: Collocate encryptor and volume driver calls

This change introduces new utility methods for attaching and detaching
frontend volume encryptors. These methods centralise the optional
fetching of encryption metadata associated with a volume, fetching of the
required encryptor and calls to detach or attach the encryptor.

These new utility methods are called either after initially connecting
to or before disconnecting from a volume. This ensures encryptors are
correctly connected when swapping volumes for example, where previously
no attempt was made to attach an encryptor to the target volume.

The request context is provided to swap_volume and various other config
generation related methods to allow for the lookup of the relevant
encryption metadata if it is not provided.

Closes-bug: #1739593
Change-Id: Ica323b87fa85a454fca9d46ada3677f18fe50022
tags/17.0.0.0b3
Lee Yarwood 2 years ago
parent
commit
cd3eb60c2c

+ 2
- 2
nova/compute/manager.py View File

@@ -5438,8 +5438,8 @@ class ComputeManager(manager.Manager):
5438 5438
                       "old: %(old_cinfo)s",
5439 5439
                       {'new_cinfo': new_cinfo, 'old_cinfo': old_cinfo},
5440 5440
                       instance=instance)
5441
-            self.driver.swap_volume(old_cinfo, new_cinfo, instance, mountpoint,
5442
-                                    resize_to)
5441
+            self.driver.swap_volume(context, old_cinfo, new_cinfo, instance,
5442
+                                    mountpoint, resize_to)
5443 5443
             if new_attachment_id:
5444 5444
                 self.volume_api.attachment_complete(context, new_attachment_id)
5445 5445
             LOG.debug("swap_volume: Driver volume swap returned, new "

+ 4
- 3
nova/tests/unit/compute/test_compute_mgr.py View File

@@ -1966,8 +1966,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
1966 1966
         self.assertTrue(uuidutils.is_uuid_like(volume))
1967 1967
         return {}
1968 1968
 
1969
-    def _assert_swap_volume(self, old_connection_info, new_connection_info,
1970
-                            instance, mountpoint, resize_to):
1969
+    def _assert_swap_volume(self, context, old_connection_info,
1970
+                            new_connection_info, instance, mountpoint,
1971
+                            resize_to):
1971 1972
         self.assertEqual(2, resize_to)
1972 1973
 
1973 1974
     @mock.patch.object(cinder.API, 'initialize_connection')
@@ -2306,7 +2307,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
2306 2307
                 instance, uuids.new_attachment_id)
2307 2308
             # Assert the expected calls.
2308 2309
             # The new connection_info has the new_volume_id as the serial.
2309
-            new_cinfo = mock_driver_swap.call_args[0][1]
2310
+            new_cinfo = mock_driver_swap.call_args[0][2]
2310 2311
             self.assertIn('serial', new_cinfo)
2311 2312
             self.assertEqual(uuids.new_volume_id, new_cinfo['serial'])
2312 2313
             get_bdm.assert_called_once_with(

+ 238
- 45
nova/tests/unit/virt/libvirt/test_driver.py View File

@@ -6706,7 +6706,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
6706 6706
                     test.MatchType(objects.ImageMeta),
6707 6707
                     bdm)
6708 6708
                 mock_connect_volume.assert_called_with(
6709
-                    connection_info, instance)
6709
+                    self.context, connection_info, instance, encryption=None)
6710 6710
                 mock_get_volume_config.assert_called_with(
6711 6711
                     connection_info, disk_info)
6712 6712
                 mock_dom.attachDeviceFlags.assert_called_with(
@@ -6761,7 +6761,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
6761 6761
 </disk>
6762 6762
 """, flags=flags)
6763 6763
                 mock_disconnect_volume.assert_called_with(
6764
-                    connection_info, instance)
6764
+                    None, connection_info, instance, encryption=None)
6765 6765
 
6766 6766
     @mock.patch('nova.virt.libvirt.host.Host._get_domain')
6767 6767
     def test_detach_volume_disk_not_found(self, mock_get_domain):
@@ -6785,12 +6785,15 @@ class LibvirtConnTestCase(test.NoDBTestCase,
6785 6785
 
6786 6786
         mock_get_domain.assert_called_once_with(instance)
6787 6787
 
6788
-    @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._disconnect_volume')
6788
+    @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_driver')
6789 6789
     @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
6790 6790
     @mock.patch('nova.virt.libvirt.host.Host.get_guest')
6791 6791
     def test_detach_volume_order_with_encryptors(self, mock_get_guest,
6792
-            mock_get_encryptor, mock_disconnect_volume):
6792
+            mock_get_encryptor, mock_get_volume_driver):
6793 6793
 
6794
+        mock_volume_driver = mock.MagicMock(
6795
+            spec=volume_drivers.LibvirtBaseVolumeDriver)
6796
+        mock_get_volume_driver.return_value = mock_volume_driver
6794 6797
         mock_guest = mock.MagicMock(spec=libvirt_guest.Guest)
6795 6798
         mock_guest.get_power_state.return_value = power_state.RUNNING
6796 6799
         mock_get_guest.return_value = mock_guest
@@ -6799,7 +6802,8 @@ class LibvirtConnTestCase(test.NoDBTestCase,
6799 6802
         mock_get_encryptor.return_value = mock_encryptor
6800 6803
 
6801 6804
         mock_order = mock.Mock()
6802
-        mock_order.attach_mock(mock_disconnect_volume, 'disconnect_volume')
6805
+        mock_order.attach_mock(mock_volume_driver.disconnect_volume,
6806
+                'disconnect_volume')
6803 6807
         mock_order.attach_mock(mock_guest.detach_device_with_retry(),
6804 6808
                 'detach_volume')
6805 6809
         mock_order.attach_mock(mock_encryptor.detach_volume,
@@ -6917,6 +6921,196 @@ class LibvirtConnTestCase(test.NoDBTestCase,
6917 6921
                           drvr.extend_volume,
6918 6922
                           connection_info, instance)
6919 6923
 
6924
+    @mock.patch('os_brick.encryptors.get_encryption_metadata')
6925
+    @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
6926
+    def test_use_encryptor_connection_info_incomplete(self,
6927
+            mock_get_encryptor, mock_get_metadata):
6928
+        """Assert no attach attempt is made given incomplete connection_info.
6929
+        """
6930
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
6931
+        connection_info = {'data': {}}
6932
+
6933
+        drvr._attach_encryptor(self.context, connection_info, None)
6934
+
6935
+        mock_get_metadata.assert_not_called()
6936
+        mock_get_encryptor.assert_not_called()
6937
+
6938
+    @mock.patch('os_brick.encryptors.get_encryption_metadata')
6939
+    @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
6940
+    def test_attach_encryptor_unencrypted_volume_meta_missing(self,
6941
+            mock_get_encryptor, mock_get_metadata):
6942
+        """Assert that if not provided encryption metadata is fetched even
6943
+        if the volume is ultimately unencrypted and no attempt to attach
6944
+        is made.
6945
+        """
6946
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
6947
+        encryption = {}
6948
+        connection_info = {'data': {'volume_id': uuids.volume_id}}
6949
+        mock_get_metadata.return_value = encryption
6950
+
6951
+        drvr._attach_encryptor(self.context, connection_info, None)
6952
+
6953
+        mock_get_metadata.assert_called_once_with(self.context,
6954
+                drvr._volume_api, uuids.volume_id, connection_info)
6955
+        mock_get_encryptor.assert_not_called()
6956
+
6957
+    @mock.patch('os_brick.encryptors.get_encryption_metadata')
6958
+    @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
6959
+    def test_attach_encryptor_unencrypted_volume_meta_provided(self,
6960
+            mock_get_encryptor, mock_get_metadata):
6961
+        """Assert that if an empty encryption metadata dict is provided that
6962
+        there is no additional attempt to lookup the metadata or attach the
6963
+        encryptor.
6964
+        """
6965
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
6966
+        encryption = {}
6967
+        connection_info = {'data': {'volume_id': uuids.volume_id}}
6968
+
6969
+        drvr._attach_encryptor(self.context, connection_info,
6970
+                               encryption=encryption)
6971
+
6972
+        mock_get_metadata.assert_not_called()
6973
+        mock_get_encryptor.assert_not_called()
6974
+
6975
+    @mock.patch('os_brick.encryptors.get_encryption_metadata')
6976
+    @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
6977
+    def test_attach_encryptor_encrypted_volume_meta_missing(self,
6978
+            mock_get_encryptor, mock_get_metadata):
6979
+        """Assert that if missing the encryption metadata of an encrypted
6980
+        volume is fetched and then used to attach the encryptor for the volume.
6981
+        """
6982
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
6983
+        mock_encryptor = mock.MagicMock()
6984
+        mock_get_encryptor.return_value = mock_encryptor
6985
+        encryption = {'provider': 'luks', 'control_location': 'front-end'}
6986
+        mock_get_metadata.return_value = encryption
6987
+        connection_info = {'data': {'volume_id': uuids.volume_id}}
6988
+
6989
+        drvr._attach_encryptor(self.context, connection_info, None)
6990
+
6991
+        mock_get_metadata.assert_called_once_with(self.context,
6992
+                drvr._volume_api, uuids.volume_id, connection_info)
6993
+        mock_get_encryptor.assert_called_once_with(connection_info,
6994
+                                                   encryption)
6995
+        mock_encryptor.attach_volume.assert_called_once_with(self.context,
6996
+                                                             **encryption)
6997
+
6998
+    @mock.patch('os_brick.encryptors.get_encryption_metadata')
6999
+    @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
7000
+    def test_attach_encryptor_encrypted_volume_meta_provided(self,
7001
+            mock_get_encryptor, mock_get_metadata):
7002
+        """Assert that when provided there are no further attempts to fetch the
7003
+        encryption metadata for the volume and that the provided metadata is
7004
+        then used to attach the volume.
7005
+        """
7006
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
7007
+        mock_encryptor = mock.MagicMock()
7008
+        mock_get_encryptor.return_value = mock_encryptor
7009
+        encryption = {'provider': 'luks', 'control_location': 'front-end'}
7010
+        connection_info = {'data': {'volume_id': uuids.volume_id}}
7011
+
7012
+        drvr._attach_encryptor(self.context, connection_info,
7013
+                encryption=encryption)
7014
+
7015
+        mock_get_metadata.assert_not_called()
7016
+        mock_get_encryptor.assert_called_once_with(connection_info,
7017
+                                                   encryption)
7018
+        mock_encryptor.attach_volume.assert_called_once_with(self.context,
7019
+                                                             **encryption)
7020
+
7021
+    @mock.patch('os_brick.encryptors.get_encryption_metadata')
7022
+    @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
7023
+    def test_detach_encryptor_connection_info_incomplete(self,
7024
+            mock_get_encryptor, mock_get_metadata):
7025
+        """Assert no detach attempt is made given incomplete connection_info.
7026
+        """
7027
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
7028
+        connection_info = {'data': {}}
7029
+
7030
+        drvr._detach_encryptor(self.context, connection_info, None)
7031
+
7032
+        mock_get_metadata.assert_not_called()
7033
+        mock_get_encryptor.assert_not_called()
7034
+
7035
+    @mock.patch('os_brick.encryptors.get_encryption_metadata')
7036
+    @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
7037
+    def test_detach_encryptor_unencrypted_volume_meta_missing(self,
7038
+            mock_get_encryptor, mock_get_metadata):
7039
+        """Assert that if not provided encryption metadata is fetched even
7040
+        if the volume is ultimately unencrypted and no attempt to detach
7041
+        is made.
7042
+        """
7043
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
7044
+        encryption = {}
7045
+        connection_info = {'data': {'volume_id': uuids.volume_id}}
7046
+        mock_get_metadata.return_value = encryption
7047
+
7048
+        drvr._detach_encryptor(self.context, connection_info, None)
7049
+
7050
+        mock_get_metadata.assert_called_once_with(self.context,
7051
+                drvr._volume_api, uuids.volume_id, connection_info)
7052
+        mock_get_encryptor.assert_not_called()
7053
+
7054
+    @mock.patch('os_brick.encryptors.get_encryption_metadata')
7055
+    @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
7056
+    def test_detach_encryptor_unencrypted_volume_meta_provided(self,
7057
+            mock_get_encryptor, mock_get_metadata):
7058
+        """Assert that if an empty encryption metadata dict is provided that
7059
+        there is no additional attempt to lookup the metadata or detach the
7060
+        encryptor.
7061
+        """
7062
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
7063
+        encryption = {}
7064
+        connection_info = {'data': {'volume_id': uuids.volume_id}}
7065
+
7066
+        drvr._detach_encryptor(self.context, connection_info, encryption)
7067
+
7068
+        mock_get_metadata.assert_not_called()
7069
+        mock_get_encryptor.assert_not_called()
7070
+
7071
+    @mock.patch('os_brick.encryptors.get_encryption_metadata')
7072
+    @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
7073
+    def test_detach_encryptor_encrypted_volume_meta_missing(self,
7074
+            mock_get_encryptor, mock_get_metadata):
7075
+        """Assert that if missing the encryption metadata of an encrypted
7076
+        volume is fetched and then used to detach the encryptor for the volume.
7077
+        """
7078
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
7079
+        mock_encryptor = mock.MagicMock()
7080
+        mock_get_encryptor.return_value = mock_encryptor
7081
+        encryption = {'provider': 'luks', 'control_location': 'front-end'}
7082
+        mock_get_metadata.return_value = encryption
7083
+        connection_info = {'data': {'volume_id': uuids.volume_id}}
7084
+
7085
+        drvr._detach_encryptor(self.context, connection_info, None)
7086
+
7087
+        mock_get_metadata.assert_called_once_with(self.context,
7088
+                drvr._volume_api, uuids.volume_id, connection_info)
7089
+        mock_get_encryptor.assert_called_once_with(connection_info,
7090
+                                                   encryption)
7091
+        mock_encryptor.detach_volume.assert_called_once_with(**encryption)
7092
+
7093
+    @mock.patch('os_brick.encryptors.get_encryption_metadata')
7094
+    @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
7095
+    def test_detach_encryptor_encrypted_volume_meta_provided(self,
7096
+            mock_get_encryptor, mock_get_metadata):
7097
+        """Assert that when provided there are no further attempts to fetch the
7098
+        encryption metadata for the volume and that the provided metadata is
7099
+        then used to detach the volume.
7100
+        """
7101
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
7102
+        mock_encryptor = mock.MagicMock()
7103
+        mock_get_encryptor.return_value = mock_encryptor
7104
+        encryption = {'provider': 'luks', 'control_location': 'front-end'}
7105
+        connection_info = {'data': {'volume_id': uuids.volume_id}}
7106
+
7107
+        drvr._detach_encryptor(self.context, connection_info, encryption)
7108
+
7109
+        mock_get_metadata.assert_not_called()
7110
+        mock_get_encryptor.assert_called_once_with(connection_info,
7111
+                                                   encryption)
7112
+        mock_encryptor.detach_volume.assert_called_once_with(**encryption)
7113
+
6920 7114
     def test_multi_nic(self):
6921 7115
         network_info = _fake_network_info(self, 2)
6922 7116
         drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
@@ -10146,7 +10340,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
10146 10340
             ).AndReturn(vol['block_device_mapping'])
10147 10341
         self.mox.StubOutWithMock(drvr, "_connect_volume")
10148 10342
         for v in vol['block_device_mapping']:
10149
-            drvr._connect_volume(v['connection_info'], instance)
10343
+            drvr._connect_volume(c, v['connection_info'], instance)
10150 10344
         self.mox.StubOutWithMock(drvr, 'plug_vifs')
10151 10345
         drvr.plug_vifs(mox.IsA(instance), nw_info)
10152 10346
 
@@ -10278,7 +10472,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
10278 10472
             # Creating mocks
10279 10473
             self.mox.StubOutWithMock(drvr, "_connect_volume")
10280 10474
             for v in vol['block_device_mapping']:
10281
-                drvr._connect_volume(v['connection_info'], inst_ref)
10475
+                drvr._connect_volume(c, v['connection_info'], inst_ref)
10282 10476
             self.mox.StubOutWithMock(drvr, 'plug_vifs')
10283 10477
             drvr.plug_vifs(mox.IsA(inst_ref), nw_info)
10284 10478
             self.mox.ReplayAll()
@@ -10627,8 +10821,9 @@ class LibvirtConnTestCase(test.NoDBTestCase,
10627 10821
             get_volume_connector.assert_has_calls([
10628 10822
                 mock.call(inst_ref)])
10629 10823
             _disconnect_volume.assert_has_calls([
10630
-                mock.call({'data': {'multipath_id': 'dummy1'}}, inst_ref),
10631
-                mock.call({'data': {}}, inst_ref)])
10824
+                mock.call(cntx, {'data': {'multipath_id': 'dummy1'}},
10825
+                          inst_ref),
10826
+                mock.call(cntx, {'data': {}}, inst_ref)])
10632 10827
 
10633 10828
     def test_post_live_migration_cinder_v3(self):
10634 10829
         cntx = context.get_admin_context()
@@ -10666,7 +10861,8 @@ class LibvirtConnTestCase(test.NoDBTestCase,
10666 10861
 
10667 10862
             mock_attachment_get.assert_called_once_with(cntx,
10668 10863
                                                         old_attachment_id)
10669
-            mock_disconnect.assert_called_once_with(connection_info, instance)
10864
+            mock_disconnect.assert_called_once_with(cntx, connection_info,
10865
+                                                    instance)
10670 10866
         _test()
10671 10867
 
10672 10868
     def test_get_instance_disk_info_excludes_volumes(self):
@@ -11024,7 +11220,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
11024 11220
                   'delete_on_termination': False
11025 11221
               }
11026 11222
 
11027
-        def _connect_volume_side_effect(connection_info, instance):
11223
+        def _connect_volume_side_effect(ctxt, connection_info, instance):
11028 11224
             bdm['connection_info']['data']['device_path'] = '/dev/path/to/dev'
11029 11225
 
11030 11226
         def _get(key, opt=None):
@@ -14563,8 +14759,8 @@ class LibvirtConnTestCase(test.NoDBTestCase,
14563 14759
             connection_info = {'driver_volume_type': 'fake'}
14564 14760
             drvr.detach_volume(connection_info, instance, '/dev/sda')
14565 14761
             _get_domain.assert_called_once_with(instance)
14566
-            _disconnect_volume.assert_called_once_with(connection_info,
14567
-                                                       instance)
14762
+            _disconnect_volume.assert_called_once_with(None, connection_info,
14763
+                                instance, encryption=None)
14568 14764
 
14569 14765
     def _test_attach_detach_interface_get_config(self, method_name):
14570 14766
         """Tests that the get_config() method is properly called in
@@ -15047,25 +15243,20 @@ class LibvirtConnTestCase(test.NoDBTestCase,
15047 15243
                         network_model.VIF(id='2', active=True)]
15048 15244
 
15049 15245
         with test.nested(
15050
-            mock.patch.object(drvr, '_get_volume_encryptor'),
15051 15246
             mock.patch.object(drvr, 'plug_vifs'),
15052 15247
             mock.patch.object(drvr.firewall_driver, 'setup_basic_filtering'),
15053 15248
             mock.patch.object(drvr.firewall_driver,
15054 15249
                               'prepare_instance_filter'),
15055 15250
             mock.patch.object(drvr, '_create_domain'),
15056 15251
             mock.patch.object(drvr.firewall_driver, 'apply_instance_filter'),
15057
-        ) as (get_volume_encryptor, plug_vifs, setup_basic_filtering,
15058
-              prepare_instance_filter, create_domain, apply_instance_filter):
15252
+        ) as (plug_vifs, setup_basic_filtering, prepare_instance_filter,
15253
+              create_domain, apply_instance_filter):
15059 15254
             create_domain.return_value = libvirt_guest.Guest(mock_dom)
15060 15255
 
15061 15256
             guest = drvr._create_domain_and_network(
15062 15257
                     self.context, fake_xml, instance, network_info,
15063 15258
                     block_device_info=block_device_info)
15064 15259
 
15065
-            get_encryption_metadata.assert_called_once_with(self.context,
15066
-                drvr._volume_api, fake_volume_id, connection_info)
15067
-            get_volume_encryptor.assert_called_once_with(connection_info,
15068
-                                                         mock_encryption_meta)
15069 15260
             plug_vifs.assert_called_once_with(instance, network_info)
15070 15261
             setup_basic_filtering.assert_called_once_with(instance,
15071 15262
                                                           network_info)
@@ -15109,13 +15300,14 @@ class LibvirtConnTestCase(test.NoDBTestCase,
15109 15300
             mock.patch.object(drvr, '_get_volume_config',
15110 15301
                               return_value=mock_conf)
15111 15302
         ) as (volume_save, connect_volume, get_volume_config):
15112
-            devices = drvr._get_guest_storage_config(instance, image_meta,
15113
-                disk_info, False, bdi, flavor, "hvm")
15303
+            devices = drvr._get_guest_storage_config(self.context, instance,
15304
+                image_meta, disk_info, False, bdi, flavor, "hvm")
15114 15305
 
15115 15306
             self.assertEqual(3, len(devices))
15116 15307
             self.assertEqual('/dev/vdb', instance.default_ephemeral_device)
15117 15308
             self.assertIsNone(instance.default_swap_device)
15118
-            connect_volume.assert_called_with(bdm['connection_info'], instance)
15309
+            connect_volume.assert_called_with(self.context,
15310
+                bdm['connection_info'], instance)
15119 15311
             get_volume_config.assert_called_with(bdm['connection_info'],
15120 15312
                 {'bus': 'virtio', 'type': 'disk', 'dev': 'vdc'})
15121 15313
             volume_save.assert_called_once_with()
@@ -15325,14 +15517,16 @@ class LibvirtConnTestCase(test.NoDBTestCase,
15325 15517
         conf = mock.MagicMock(source_path='/fake-new-volume')
15326 15518
         get_volume_config.return_value = conf
15327 15519
 
15328
-        conn.swap_volume(old_connection_info, new_connection_info, instance,
15329
-                         '/dev/vdb', 1)
15520
+        conn.swap_volume(self.context, old_connection_info,
15521
+                         new_connection_info, instance, '/dev/vdb', 1)
15330 15522
 
15331 15523
         get_guest.assert_called_once_with(instance)
15332
-        connect_volume.assert_called_once_with(new_connection_info, instance)
15524
+        connect_volume.assert_called_once_with(self.context,
15525
+                                               new_connection_info, instance)
15333 15526
 
15334 15527
         swap_volume.assert_called_once_with(guest, 'vdb', conf, 1)
15335
-        disconnect_volume.assert_called_once_with(old_connection_info,
15528
+        disconnect_volume.assert_called_once_with(self.context,
15529
+                                                  old_connection_info,
15336 15530
                                                   instance)
15337 15531
 
15338 15532
     def test_swap_volume_driver_source_is_volume(self):
@@ -15366,12 +15560,12 @@ class LibvirtConnTestCase(test.NoDBTestCase,
15366 15560
         rebase.side_effect = exc
15367 15561
 
15368 15562
         self.assertRaises(exception.VolumeRebaseFailed, conn.swap_volume,
15369
-                          mock.sentinel.old_connection_info,
15563
+                          self.context, mock.sentinel.old_connection_info,
15370 15564
                           mock.sentinel.new_connection_info,
15371 15565
                           instance, '/dev/vdb', 0)
15372
-        connect_volume.assert_called_once_with(
15566
+        connect_volume.assert_called_once_with(self.context,
15373 15567
                 mock.sentinel.new_connection_info, instance)
15374
-        disconnect_volume.assert_called_once_with(
15568
+        disconnect_volume.assert_called_once_with(self.context,
15375 15569
                 mock.sentinel.new_connection_info, instance)
15376 15570
 
15377 15571
     @mock.patch('nova.virt.libvirt.guest.BlockDevice.is_job_complete')
@@ -15398,12 +15592,12 @@ class LibvirtConnTestCase(test.NoDBTestCase,
15398 15592
         abort_job.side_effect = [None, exc]
15399 15593
 
15400 15594
         self.assertRaises(exception.VolumeRebaseFailed, conn.swap_volume,
15401
-                          mock.sentinel.old_connection_info,
15595
+                          self.context, mock.sentinel.old_connection_info,
15402 15596
                           mock.sentinel.new_connection_info,
15403 15597
                           instance, '/dev/vdb', 0)
15404
-        connect_volume.assert_called_once_with(
15598
+        connect_volume.assert_called_once_with(self.context,
15405 15599
                 mock.sentinel.new_connection_info, instance)
15406
-        disconnect_volume.assert_called_once_with(
15600
+        disconnect_volume.assert_called_once_with(self.context,
15407 15601
                 mock.sentinel.new_connection_info, instance)
15408 15602
 
15409 15603
     @mock.patch('nova.virt.libvirt.guest.BlockDevice.is_job_complete')
@@ -16171,7 +16365,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
16171 16365
                           context.get_admin_context(), ins_ref, '10.0.0.2',
16172 16366
                           flavor_obj, None)
16173 16367
 
16174
-    def _test_migrate_disk_and_power_off(self, flavor_obj,
16368
+    def _test_migrate_disk_and_power_off(self, ctxt, flavor_obj,
16175 16369
                                          block_device_info=None,
16176 16370
                                          params_for_instance=None):
16177 16371
         """Test for nova.virt.libvirt.libvirt_driver.LivirtConnection
@@ -16210,21 +16404,20 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
16210 16404
 
16211 16405
         # dest is different host case
16212 16406
         out = self.drvr.migrate_disk_and_power_off(
16213
-               context.get_admin_context(), instance, '10.0.0.2',
16214
-               flavor_obj, None, block_device_info=block_device_info)
16407
+               ctxt, instance, '10.0.0.2', flavor_obj, None,
16408
+               block_device_info=block_device_info)
16215 16409
         self.assertEqual(out, disk_info_text)
16216 16410
 
16217 16411
         # dest is same host case
16218 16412
         out = self.drvr.migrate_disk_and_power_off(
16219
-               context.get_admin_context(), instance, '10.0.0.1',
16220
-               flavor_obj, None, block_device_info=block_device_info)
16413
+               ctxt, instance, '10.0.0.1', flavor_obj, None,
16414
+               block_device_info=block_device_info)
16221 16415
         self.assertEqual(out, disk_info_text)
16222 16416
 
16223 16417
     def test_migrate_disk_and_power_off(self):
16224 16418
         flavor = {'root_gb': 10, 'ephemeral_gb': 20}
16225 16419
         flavor_obj = objects.Flavor(**flavor)
16226
-
16227
-        self._test_migrate_disk_and_power_off(flavor_obj)
16420
+        self._test_migrate_disk_and_power_off(self.context, flavor_obj)
16228 16421
 
16229 16422
     @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._disconnect_volume')
16230 16423
     def test_migrate_disk_and_power_off_boot_from_volume(self,
@@ -16240,14 +16433,14 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
16240 16433
         flavor = {'root_gb': 1, 'ephemeral_gb': 0}
16241 16434
         flavor_obj = objects.Flavor(**flavor)
16242 16435
         # Note(Mike_D): The size of instance's ephemeral_gb is 0 gb.
16243
-        self._test_migrate_disk_and_power_off(
16436
+        self._test_migrate_disk_and_power_off(self.context,
16244 16437
             flavor_obj, block_device_info=info,
16245 16438
             params_for_instance={'image_ref': None,
16246 16439
                                  'root_gb': 10,
16247 16440
                                  'ephemeral_gb': 0,
16248 16441
                                  'flavor': {'root_gb': 10,
16249 16442
                                             'ephemeral_gb': 0}})
16250
-        disconnect_volume.assert_called_with(
16443
+        disconnect_volume.assert_called_with(self.context,
16251 16444
             mock.sentinel.conn_info_vda, mock.ANY)
16252 16445
 
16253 16446
     @mock.patch('nova.virt.libvirt.driver.LibvirtDriver._disconnect_volume')
@@ -16265,7 +16458,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
16265 16458
                  'connection_info': mock.sentinel.conn_info_vda}]}
16266 16459
         flavor = {'root_gb': 1, 'ephemeral_gb': 0}
16267 16460
         flavor_obj = objects.Flavor(**flavor)
16268
-        self._test_migrate_disk_and_power_off(
16461
+        self._test_migrate_disk_and_power_off(self.context,
16269 16462
             flavor_obj, block_device_info=info,
16270 16463
             params_for_instance={
16271 16464
                 'image_ref': uuids.fake_volume_backed_image_ref,
@@ -16273,7 +16466,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
16273 16466
                 'ephemeral_gb': 0,
16274 16467
                 'flavor': {'root_gb': 10,
16275 16468
                            'ephemeral_gb': 0}})
16276
-        disconnect_volume.assert_called_with(
16469
+        disconnect_volume.assert_called_with(self.context,
16277 16470
             mock.sentinel.conn_info_vda, mock.ANY)
16278 16471
 
16279 16472
     @mock.patch('nova.utils.execute')
@@ -16540,7 +16733,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
16540 16733
         # Old flavor, eph is 20, real disk is 3, target is 4
16541 16734
         flavor = {'root_gb': 10, 'ephemeral_gb': 4}
16542 16735
         flavor_obj = objects.Flavor(**flavor)
16543
-        self._test_migrate_disk_and_power_off(flavor_obj)
16736
+        self._test_migrate_disk_and_power_off(self.context, flavor_obj)
16544 16737
 
16545 16738
     @mock.patch('nova.utils.execute')
16546 16739
     @mock.patch('nova.virt.libvirt.utils.copy_image')

+ 1
- 1
nova/tests/unit/virt/test_virt_drivers.py View File

@@ -494,7 +494,7 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
494 494
                                           instance_ref,
495 495
                                           '/dev/sda'))
496 496
         self.assertIsNone(
497
-            self.connection.swap_volume({'driver_volume_type': 'fake',
497
+            self.connection.swap_volume(None, {'driver_volume_type': 'fake',
498 498
                                          'data': {}},
499 499
                                         {'driver_volume_type': 'fake',
500 500
                                          'data': {}},

+ 2
- 1
nova/virt/driver.py View File

@@ -471,10 +471,11 @@ class ComputeDriver(object):
471 471
         """Detach the disk attached to the instance."""
472 472
         raise NotImplementedError()
473 473
 
474
-    def swap_volume(self, old_connection_info, new_connection_info,
474
+    def swap_volume(self, context, old_connection_info, new_connection_info,
475 475
                     instance, mountpoint, resize_to):
476 476
         """Replace the volume attached to the given `instance`.
477 477
 
478
+        :param context: The request context.
478 479
         :param dict old_connection_info:
479 480
             The volume for this connection gets detached from the given
480 481
             `instance`.

+ 1
- 1
nova/virt/fake.py View File

@@ -317,7 +317,7 @@ class FakeDriver(driver.ComputeDriver):
317 317
         except KeyError:
318 318
             pass
319 319
 
320
-    def swap_volume(self, old_connection_info, new_connection_info,
320
+    def swap_volume(self, context, old_connection_info, new_connection_info,
321 321
                     instance, mountpoint, resize_to):
322 322
         """Replace the disk attached to the instance."""
323 323
         instance_name = instance.name

+ 79
- 68
nova/virt/libvirt/driver.py View File

@@ -1008,23 +1008,8 @@ class LibvirtDriver(driver.ComputeDriver):
1008 1008
             disk_dev = vol['mount_device']
1009 1009
             if disk_dev is not None:
1010 1010
                 disk_dev = disk_dev.rpartition("/")[2]
1011
-
1012
-            if ('data' in connection_info and
1013
-                    'volume_id' in connection_info['data']):
1014
-                volume_id = connection_info['data']['volume_id']
1015
-                encryption = encryptors.get_encryption_metadata(
1016
-                    context, self._volume_api, volume_id, connection_info)
1017
-
1018
-                if encryption:
1019
-                    # The volume must be detached from the VM before
1020
-                    # disconnecting it from its encryptor. Otherwise, the
1021
-                    # encryptor may report that the volume is still in use.
1022
-                    encryptor = self._get_volume_encryptor(connection_info,
1023
-                                                           encryption)
1024
-                    encryptor.detach_volume(**encryption)
1025
-
1026 1011
             try:
1027
-                self._disconnect_volume(connection_info, instance)
1012
+                self._disconnect_volume(context, connection_info, instance)
1028 1013
             except Exception as exc:
1029 1014
                 with excutils.save_and_reraise_exception() as ctxt:
1030 1015
                     if destroy_disks:
@@ -1207,11 +1192,15 @@ class LibvirtDriver(driver.ComputeDriver):
1207 1192
             raise exception.VolumeDriverNotFound(driver_type=driver_type)
1208 1193
         return self.volume_drivers[driver_type]
1209 1194
 
1210
-    def _connect_volume(self, connection_info, instance):
1195
+    def _connect_volume(self, context, connection_info, instance,
1196
+                        encryption=None):
1211 1197
         vol_driver = self._get_volume_driver(connection_info)
1212 1198
         vol_driver.connect_volume(connection_info, instance)
1199
+        self._attach_encryptor(context, connection_info, encryption=encryption)
1213 1200
 
1214
-    def _disconnect_volume(self, connection_info, instance):
1201
+    def _disconnect_volume(self, context, connection_info, instance,
1202
+                           encryption=None):
1203
+        self._detach_encryptor(context, connection_info, encryption=encryption)
1215 1204
         vol_driver = self._get_volume_driver(connection_info)
1216 1205
         vol_driver.disconnect_volume(connection_info, instance)
1217 1206
 
@@ -1232,6 +1221,44 @@ class LibvirtDriver(driver.ComputeDriver):
1232 1221
                                                connection_info=connection_info,
1233 1222
                                                **encryption)
1234 1223
 
1224
+    def _get_volume_encryption(self, context, connection_info):
1225
+        """Get the encryption metadata dict if it is not provided
1226
+        """
1227
+        encryption = {}
1228
+        if connection_info.get('data', {}).get('volume_id'):
1229
+            volume_id = connection_info['data']['volume_id']
1230
+            encryption = encryptors.get_encryption_metadata(context,
1231
+                            self._volume_api, volume_id, connection_info)
1232
+        return encryption
1233
+
1234
+    def _attach_encryptor(self, context, connection_info, encryption):
1235
+        """Attach the frontend encryptor if one is required by the volume.
1236
+
1237
+        The request context is only used when an encryption metadata dict is
1238
+        not provided. The encryption metadata dict being populated is then used
1239
+        to determine if an attempt to attach the encryptor should be made.
1240
+        """
1241
+        if encryption is None:
1242
+            encryption = self._get_volume_encryption(context, connection_info)
1243
+        if encryption:
1244
+            encryptor = self._get_volume_encryptor(connection_info,
1245
+                                                   encryption)
1246
+            encryptor.attach_volume(context, **encryption)
1247
+
1248
+    def _detach_encryptor(self, context, connection_info, encryption):
1249
+        """Detach the frontend encryptor if one is required by the volume.
1250
+
1251
+        The request context is only used when an encryption metadata dict is
1252
+        not provided. The encryption metadata dict being populated is then used
1253
+        to determine if an attempt to detach the encryptor should be made.
1254
+        """
1255
+        if encryption is None:
1256
+            encryption = self._get_volume_encryption(context, connection_info)
1257
+        if encryption:
1258
+            encryptor = self._get_volume_encryptor(connection_info,
1259
+                                                   encryption)
1260
+            encryptor.detach_volume(**encryption)
1261
+
1235 1262
     def _check_discard_for_attach_volume(self, conf, instance):
1236 1263
         """Perform some checks for volumes configured for discard support.
1237 1264
 
@@ -1274,7 +1301,8 @@ class LibvirtDriver(driver.ComputeDriver):
1274 1301
                         "block size") % CONF.libvirt.virt_type
1275 1302
                 raise exception.InvalidHypervisorType(msg)
1276 1303
 
1277
-        self._connect_volume(connection_info, instance)
1304
+        self._connect_volume(context, connection_info, instance,
1305
+                             encryption=encryption)
1278 1306
         disk_info = blockinfo.get_info_from_bdm(
1279 1307
             instance, CONF.libvirt.virt_type, instance.image_meta, bdm)
1280 1308
         if disk_info['bus'] == 'scsi':
@@ -1288,11 +1316,6 @@ class LibvirtDriver(driver.ComputeDriver):
1288 1316
             state = guest.get_power_state(self._host)
1289 1317
             live = state in (power_state.RUNNING, power_state.PAUSED)
1290 1318
 
1291
-            if encryption:
1292
-                encryptor = self._get_volume_encryptor(connection_info,
1293
-                                                       encryption)
1294
-                encryptor.attach_volume(context, **encryption)
1295
-
1296 1319
             guest.attach_device(conf, persistent=True, live=live)
1297 1320
             # NOTE(artom) If we're attaching with a device role tag, we need to
1298 1321
             # rebuild device_metadata. If we're attaching without a role
@@ -1309,7 +1332,8 @@ class LibvirtDriver(driver.ComputeDriver):
1309 1332
             LOG.exception(_('Failed to attach volume at mountpoint: %s'),
1310 1333
                           mountpoint, instance=instance)
1311 1334
             with excutils.save_and_reraise_exception():
1312
-                self._disconnect_volume(connection_info, instance)
1335
+                self._disconnect_volume(context, connection_info, instance,
1336
+                                        encryption=encryption)
1313 1337
 
1314 1338
     def _swap_volume(self, guest, disk_path, conf, resize_to):
1315 1339
         """Swap existing disk with a new block device."""
@@ -1367,7 +1391,7 @@ class LibvirtDriver(driver.ComputeDriver):
1367 1391
         finally:
1368 1392
             self._host.write_instance_config(xml)
1369 1393
 
1370
-    def swap_volume(self, old_connection_info,
1394
+    def swap_volume(self, context, old_connection_info,
1371 1395
                     new_connection_info, instance, mountpoint, resize_to):
1372 1396
 
1373 1397
         guest = self._host.get_guest(instance)
@@ -1388,19 +1412,19 @@ class LibvirtDriver(driver.ComputeDriver):
1388 1412
         # LibvirtConfigGuestDisk object it returns. We do not explicitly save
1389 1413
         # this to the BDM here as the upper compute swap_volume method will
1390 1414
         # eventually do this for us.
1391
-        self._connect_volume(new_connection_info, instance)
1415
+        self._connect_volume(context, new_connection_info, instance)
1392 1416
         conf = self._get_volume_config(new_connection_info, disk_info)
1393 1417
         if not conf.source_path:
1394
-            self._disconnect_volume(new_connection_info, instance)
1418
+            self._disconnect_volume(context, new_connection_info, instance)
1395 1419
             raise NotImplementedError(_("Swap only supports host devices"))
1396 1420
 
1397 1421
         try:
1398 1422
             self._swap_volume(guest, disk_dev, conf, resize_to)
1399 1423
         except exception.VolumeRebaseFailed:
1400 1424
             with excutils.save_and_reraise_exception():
1401
-                self._disconnect_volume(new_connection_info, instance)
1425
+                self._disconnect_volume(context, new_connection_info, instance)
1402 1426
 
1403
-        self._disconnect_volume(old_connection_info, instance)
1427
+        self._disconnect_volume(context, old_connection_info, instance)
1404 1428
 
1405 1429
     def _get_existing_domain_xml(self, instance, network_info,
1406 1430
                                  block_device_info=None):
@@ -1426,20 +1450,15 @@ class LibvirtDriver(driver.ComputeDriver):
1426 1450
 
1427 1451
             state = guest.get_power_state(self._host)
1428 1452
             live = state in (power_state.RUNNING, power_state.PAUSED)
1429
-
1430
-            # The volume must be detached from the VM before disconnecting it
1431
-            # from its encryptor. Otherwise, the encryptor may report that the
1432
-            # volume is still in use.
1453
+            # NOTE(lyarwood): The volume must be detached from the VM before
1454
+            # detaching any attached encryptors or disconnecting the underlying
1455
+            # volume in _disconnect_volume. Otherwise, the encryptor or volume
1456
+            # driver may report that the volume is still in use.
1433 1457
             wait_for_detach = guest.detach_device_with_retry(guest.get_disk,
1434 1458
                                                              disk_dev,
1435 1459
                                                              live=live)
1436 1460
             wait_for_detach()
1437 1461
 
1438
-            if encryption:
1439
-                encryptor = self._get_volume_encryptor(connection_info,
1440
-                                                       encryption)
1441
-                encryptor.detach_volume(**encryption)
1442
-
1443 1462
         except exception.InstanceNotFound:
1444 1463
             # NOTE(zhaoqin): If the instance does not exist, _lookup_by_name()
1445 1464
             #                will throw InstanceNotFound exception. Need to
@@ -1460,7 +1479,12 @@ class LibvirtDriver(driver.ComputeDriver):
1460 1479
             else:
1461 1480
                 raise
1462 1481
 
1463
-        self._disconnect_volume(connection_info, instance)
1482
+        # NOTE(lyarwood): We can provide None as the request context here as we
1483
+        # already have the encryption metadata dict from the compute layer.
1484
+        # This avoids the need to add the request context to the signature of
1485
+        # detach_volume requiring changes across all drivers.
1486
+        self._disconnect_volume(None, connection_info, instance,
1487
+                                encryption=encryption)
1464 1488
 
1465 1489
     def extend_volume(self, connection_info, instance):
1466 1490
         try:
@@ -3682,7 +3706,7 @@ class LibvirtDriver(driver.ComputeDriver):
3682 3706
         disk = self.image_backend.by_name(instance, name, image_type)
3683 3707
         return disk.libvirt_fs_info("/", "ploop")
3684 3708
 
3685
-    def _get_guest_storage_config(self, instance, image_meta,
3709
+    def _get_guest_storage_config(self, context, instance, image_meta,
3686 3710
                                   disk_info,
3687 3711
                                   rescue, block_device_info,
3688 3712
                                   inst_type, os_type):
@@ -3793,7 +3817,7 @@ class LibvirtDriver(driver.ComputeDriver):
3793 3817
             connection_info = vol['connection_info']
3794 3818
             vol_dev = block_device.prepend_dev(vol['mount_device'])
3795 3819
             info = disk_mapping[vol_dev]
3796
-            self._connect_volume(connection_info, instance)
3820
+            self._connect_volume(context, connection_info, instance)
3797 3821
             if scsi_controller and scsi_controller.model == 'virtio-scsi':
3798 3822
                 info['unit'] = disk_mapping['unit']
3799 3823
                 disk_mapping['unit'] += 1
@@ -4881,7 +4905,7 @@ class LibvirtDriver(driver.ComputeDriver):
4881 4905
                            image_meta)
4882 4906
         self._set_clock(guest, instance.os_type, image_meta, virt_type)
4883 4907
 
4884
-        storage_configs = self._get_guest_storage_config(
4908
+        storage_configs = self._get_guest_storage_config(context,
4885 4909
                 instance, image_meta, disk_info, rescue, block_device_info,
4886 4910
                 flavor, guest.os_type)
4887 4911
         for config in storage_configs:
@@ -5097,14 +5121,15 @@ class LibvirtDriver(driver.ComputeDriver):
5097 5121
         # workaround, see libvirt/compat.py
5098 5122
         return guest.get_info(self._host)
5099 5123
 
5100
-    def _create_domain_setup_lxc(self, instance, image_meta,
5124
+    def _create_domain_setup_lxc(self, context, instance, image_meta,
5101 5125
                                  block_device_info):
5102 5126
         inst_path = libvirt_utils.get_instance_path(instance)
5103 5127
         block_device_mapping = driver.block_device_info_get_mapping(
5104 5128
             block_device_info)
5105 5129
         root_disk = block_device.get_root_bdm(block_device_mapping)
5106 5130
         if root_disk:
5107
-            self._connect_volume(root_disk['connection_info'], instance)
5131
+            self._connect_volume(context, root_disk['connection_info'],
5132
+                                 instance)
5108 5133
             disk_path = root_disk['connection_info']['data']['device_path']
5109 5134
 
5110 5135
             # NOTE(apmelton) - Even though the instance is being booted from a
@@ -5153,7 +5178,8 @@ class LibvirtDriver(driver.ComputeDriver):
5153 5178
             disk_api.teardown_container(container_dir=container_dir)
5154 5179
 
5155 5180
     @contextlib.contextmanager
5156
-    def _lxc_disk_handler(self, instance, image_meta, block_device_info):
5181
+    def _lxc_disk_handler(self, context, instance, image_meta,
5182
+                          block_device_info):
5157 5183
         """Context manager to handle the pre and post instance boot,
5158 5184
            LXC specific disk operations.
5159 5185
 
@@ -5167,7 +5193,8 @@ class LibvirtDriver(driver.ComputeDriver):
5167 5193
             yield
5168 5194
             return
5169 5195
 
5170
-        self._create_domain_setup_lxc(instance, image_meta, block_device_info)
5196
+        self._create_domain_setup_lxc(context, instance, image_meta,
5197
+                                      block_device_info)
5171 5198
 
5172 5199
         try:
5173 5200
             yield
@@ -5233,23 +5260,6 @@ class LibvirtDriver(driver.ComputeDriver):
5233 5260
                                    destroy_disks_on_failure=False):
5234 5261
 
5235 5262
         """Do required network setup and create domain."""
5236
-        block_device_mapping = driver.block_device_info_get_mapping(
5237
-            block_device_info)
5238
-
5239
-        for vol in block_device_mapping:
5240
-            connection_info = vol['connection_info']
5241
-
5242
-            if ('data' in connection_info and
5243
-                    'volume_id' in connection_info['data']):
5244
-                volume_id = connection_info['data']['volume_id']
5245
-                encryption = encryptors.get_encryption_metadata(
5246
-                    context, self._volume_api, volume_id, connection_info)
5247
-
5248
-                if encryption:
5249
-                    encryptor = self._get_volume_encryptor(connection_info,
5250
-                                                           encryption)
5251
-                    encryptor.attach_volume(context, **encryption)
5252
-
5253 5263
         timeout = CONF.vif_plugging_timeout
5254 5264
         if (self._conn_supports_start_paused and
5255 5265
             utils.is_neutron() and not
@@ -5269,7 +5279,8 @@ class LibvirtDriver(driver.ComputeDriver):
5269 5279
                                                            network_info)
5270 5280
                 self.firewall_driver.prepare_instance_filter(instance,
5271 5281
                                                              network_info)
5272
-                with self._lxc_disk_handler(instance, instance.image_meta,
5282
+                with self._lxc_disk_handler(context, instance,
5283
+                                            instance.image_meta,
5273 5284
                                             block_device_info):
5274 5285
                     guest = self._create_domain(
5275 5286
                         xml, pause=pause, power_on=power_on,
@@ -7061,7 +7072,7 @@ class LibvirtDriver(driver.ComputeDriver):
7061 7072
 
7062 7073
         for bdm in block_device_mapping:
7063 7074
             connection_info = bdm['connection_info']
7064
-            self._connect_volume(connection_info, instance)
7075
+            self._connect_volume(context, connection_info, instance)
7065 7076
 
7066 7077
         # We call plug_vifs before the compute manager calls
7067 7078
         # ensure_filtering_rules_for_instance, to ensure bridge is set up
@@ -7260,7 +7271,7 @@ class LibvirtDriver(driver.ComputeDriver):
7260 7271
                 multipath_id = vol['connection_info']['data']['multipath_id']
7261 7272
                 connection_info['data']['multipath_id'] = multipath_id
7262 7273
 
7263
-            self._disconnect_volume(connection_info, instance)
7274
+            self._disconnect_volume(context, connection_info, instance)
7264 7275
 
7265 7276
     def post_live_migration_at_source(self, context, instance, network_info):
7266 7277
         """Unplug VIFs from networks at source.
@@ -7616,7 +7627,7 @@ class LibvirtDriver(driver.ComputeDriver):
7616 7627
             block_device_info)
7617 7628
         for vol in block_device_mapping:
7618 7629
             connection_info = vol['connection_info']
7619
-            self._disconnect_volume(connection_info, instance)
7630
+            self._disconnect_volume(context, connection_info, instance)
7620 7631
 
7621 7632
         disk_info = self._get_instance_disk_info(instance, block_device_info)
7622 7633
 

Loading…
Cancel
Save