def test_refresh(self, attachment_get): db_attachment1 = fake_volume.volume_attachment_db_obj() attachment_obj1 = fake_volume.volume_attachment_ovo(self.context) db_attachment2 = fake_volume.volume_attachment_db_obj() db_attachment2.mountpoint = '/dev/sdc' attachment_obj2 = fake_volume.volume_attachment_ovo( self.context, mountpoint='/dev/sdc') # On the second volume_attachment_get, return the volume attachment # with an updated mountpoint attachment_get.side_effect = [db_attachment1, db_attachment2] attachment = objects.VolumeAttachment.get_by_id(self.context, fake.ATTACHMENT_ID) self._compare(self, attachment_obj1, attachment) # mountpoint was updated, so a volume attachment refresh should have a # new value for that field attachment.refresh() self._compare(self, attachment_obj2, attachment) if six.PY3: call_bool = mock.call.__bool__() else: call_bool = mock.call.__nonzero__() attachment_get.assert_has_calls([mock.call(self.context, fake.ATTACHMENT_ID), call_bool, mock.call(self.context, fake.ATTACHMENT_ID)])
def test_refresh(self, attachment_get): db_attachment1 = fake_volume.volume_attachment_db_obj() attachment_obj1 = fake_volume.volume_attachment_ovo(self.context) db_attachment2 = fake_volume.volume_attachment_db_obj() db_attachment2.mountpoint = '/dev/sdc' attachment_obj2 = fake_volume.volume_attachment_ovo( self.context, mountpoint='/dev/sdc') # On the second volume_attachment_get, return the volume attachment # with an updated mountpoint attachment_get.side_effect = [db_attachment1, db_attachment2] attachment = objects.VolumeAttachment.get_by_id( self.context, fake.ATTACHMENT_ID) self._compare(self, attachment_obj1, attachment) # mountpoint was updated, so a volume attachment refresh should have a # new value for that field attachment.refresh() self._compare(self, attachment_obj2, attachment) if six.PY3: call_bool = mock.call.__bool__() else: call_bool = mock.call.__nonzero__() attachment_get.assert_has_calls([ mock.call(self.context, fake.ATTACHMENT_ID), call_bool, mock.call(self.context, fake.ATTACHMENT_ID) ])
def test_multiattach_terminate_connection(self): # Ensure that target_driver.terminate_connection is only called when a # single active volume attachment remains per host for each volume. host1_connector = {'ip': '10.0.0.2', 'host': 'fakehost1', 'initiator': 'iqn.2012-07.org.fake:01'} host2_connector = {'ip': '10.0.0.3', 'host': 'fakehost2', 'initiator': 'iqn.2012-07.org.fake:02'} host1_attachment1 = fake_volume.volume_attachment_ovo( self.context) host1_attachment1.connector = host1_connector host1_attachment2 = fake_volume.volume_attachment_ovo( self.context) host1_attachment2.connector = host1_connector host2_attachment = fake_volume.volume_attachment_ovo(self.context) host2_attachment.connector = host2_connector # Create a multiattach volume object with two active attachments on # host1 and another single attachment on host2. vol = fake_volume.fake_volume_obj(self.context) vol.multiattach = True vol.volume_attachment.objects.append(host1_attachment1) vol.volume_attachment.objects.append(host1_attachment2) vol.volume_attachment.objects.append(host2_attachment) self.configuration = conf.Configuration(None) vg_obj = fake_lvm.FakeBrickLVM('cinder-volumes', False, None, 'default') lvm_driver = lvm.LVMVolumeDriver(configuration=self.configuration, db=db, vg_obj=vg_obj) with mock.patch.object(lvm_driver.target_driver, 'terminate_connection') as mock_term_conn: # Verify that terminate_connection is not called against host1 when # there are multiple active attachments against that host. self.assertTrue(lvm_driver.terminate_connection(vol, host1_connector)) mock_term_conn.assert_not_called() # Verify that terminate_connection is called against either host # when only one active attachment per host is present. vol.volume_attachment.objects.remove(host1_attachment1) self.assertTrue(lvm_driver.terminate_connection(vol, host1_connector)) self.assertTrue(lvm_driver.terminate_connection(vol, host2_connector)) mock_term_conn.assert_has_calls([mock.call(vol, host1_connector), mock.call(vol, host2_connector)])
def test_save(self, volume_attachment_update): attachment = fake_volume.volume_attachment_ovo(self.context) attachment.attach_status = fields.VolumeAttachStatus.ATTACHING attachment.save() volume_attachment_update.assert_called_once_with( self.context, attachment.id, {'attach_status': fields.VolumeAttachStatus.ATTACHING})
def test_get_by_id(self, volume_attachment_get): db_attachment = fake_volume.volume_attachment_db_obj() attachment_obj = fake_volume.volume_attachment_ovo(self.context) volume_attachment_get.return_value = db_attachment attachment = objects.VolumeAttachment.get_by_id( self.context, fake.ATTACHMENT_ID) self._compare(self, attachment_obj, attachment)
def test_get_by_id(self, volume_attachment_get): db_attachment = fake_volume.volume_attachment_db_obj() attachment_obj = fake_volume.volume_attachment_ovo(self.context) volume_attachment_get.return_value = db_attachment attachment = objects.VolumeAttachment.get_by_id(self.context, fake.ATTACHMENT_ID) self._compare(self, attachment_obj, attachment)
def test_get_all_by_instance_uuid(self, get_by_instance_uuid): db_attachment = fake_volume.volume_attachment_db_obj() get_by_instance_uuid.return_value = [db_attachment] attachment_obj = fake_volume.volume_attachment_ovo(self.context) attachments = objects.VolumeAttachmentList.get_all_by_instance_uuid( self.context, mock.sentinel.uuid) self.assertEqual(1, len(attachments)) self._compare(self, attachment_obj, attachments[0])
def test_volume_attached(self, volume_attached): attachment = fake_volume.volume_attachment_ovo(self.context) updated_values = { 'mountpoint': '/dev/sda', 'attach_status': fields.VolumeAttachStatus.ATTACHED, 'instance_uuid': fake.INSTANCE_ID } volume_attached.return_value = (fake_volume.fake_db_volume(), updated_values) volume = attachment.finish_attach(fake.INSTANCE_ID, 'fake_host', '/dev/sda', 'rw') self.assertIsInstance(volume, objects.Volume) volume_attached.assert_called_once_with(mock.ANY, attachment.id, fake.INSTANCE_ID, 'fake_host', '/dev/sda', 'rw', True) self.assertEqual('/dev/sda', attachment.mountpoint) self.assertEqual(fake.INSTANCE_ID, attachment.instance_uuid) self.assertEqual(fields.VolumeAttachStatus.ATTACHED, attachment.attach_status)