Merge "LIO: Fix terminate_connection AttributeError" into stable/ocata

This commit is contained in:
Jenkins 2017-05-24 16:40:29 +00:00 committed by Gerrit Code Review
commit 20ef5883a3
3 changed files with 26 additions and 0 deletions

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
import os
import shutil
import tempfile
@ -55,6 +56,9 @@ class TargetDriverFixture(test.TestCase):
'created_at': timeutils.utcnow(),
'host': 'fake_host@lvm#lvm'}
self.testvol_no_prov_loc = copy.copy(self.testvol)
self.testvol_no_prov_loc['provider_location'] = None
self.iscsi_target_prefix = 'iqn.2010-10.org.openstack:'
self.target_string = ('127.0.0.1:3260,1 ' +
self.iscsi_target_prefix +

View File

@ -283,6 +283,23 @@ class TestLioAdmDriver(tf.TargetDriverFixture):
mock_execute.assert_called_once_with(*expected_args, run_as_root=True)
mpersist_cfg.assert_called_once_with(self.fake_volume_id)
@mock.patch.object(lio.LioAdm, '_execute', side_effect=lio.LioAdm._execute)
@mock.patch.object(lio.LioAdm, '_persist_configuration')
@mock.patch('cinder.utils.execute')
def test_terminate_connection_no_prov_loc(self,
mock_execute,
mpersist_cfg,
mlock_exec):
"""terminate_connection does nothing if provider_location is None"""
connector = {'initiator': 'fake_init'}
self.target.terminate_connection(self.testvol_no_prov_loc,
connector)
mlock_exec.assert_not_called()
mock_execute.assert_not_called()
mpersist_cfg.assert_not_called()
@mock.patch.object(lio.LioAdm, '_execute', side_effect=lio.LioAdm._execute)
@mock.patch.object(lio.LioAdm, '_persist_configuration')
@mock.patch('cinder.utils.execute')

View File

@ -187,6 +187,11 @@ class LioAdm(iscsi.ISCSITarget):
return super(LioAdm, self).initialize_connection(volume, connector)
def terminate_connection(self, volume, connector, **kwargs):
if volume['provider_location'] is None:
LOG.debug('No provider_location for volume %s.',
volume['id'])
return
volume_iqn = volume['provider_location'].split(' ')[1]
# Delete initiator iqns from target ACL