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_from_db_object_with_all_expected_attributes(self): expected_attrs = ['metadata', 'admin_metadata', 'glance_metadata', 'volume_type', 'volume_attachment', 'consistencygroup'] db_metadata = [{'key': 'foo', 'value': 'bar'}] db_admin_metadata = [{'key': 'admin_foo', 'value': 'admin_bar'}] db_glance_metadata = [{'key': 'glance_foo', 'value': 'glance_bar'}] db_volume_type = fake_volume.fake_db_volume_type() db_volume_attachments = fake_volume.volume_attachment_db_obj() db_consistencygroup = fake_consistencygroup.fake_db_consistencygroup() db_snapshots = fake_snapshot.fake_db_snapshot() db_volume = fake_volume.fake_db_volume( volume_metadata=db_metadata, volume_admin_metadata=db_admin_metadata, volume_glance_metadata=db_glance_metadata, volume_type=db_volume_type, volume_attachment=[db_volume_attachments], consistencygroup=db_consistencygroup, snapshots=[db_snapshots], ) volume = objects.Volume._from_db_object(self.context, objects.Volume(), db_volume, expected_attrs) self.assertEqual({'foo': 'bar'}, volume.metadata) self.assertEqual({'admin_foo': 'admin_bar'}, volume.admin_metadata) self.assertEqual({'glance_foo': 'glance_bar'}, volume.glance_metadata) self._compare(self, db_volume_type, volume.volume_type) self._compare(self, db_volume_attachments, volume.volume_attachment) self._compare(self, db_consistencygroup, volume.consistencygroup) self._compare(self, db_snapshots, volume.snapshots)
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_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_begin_attach(self, volume_attach, metadata_update): volume = fake_volume.fake_volume_obj(self.context, use_quota=True) db_attachment = fake_volume.volume_attachment_db_obj( volume_id=volume.id, attach_status=fields.VolumeAttachStatus.ATTACHING) volume_attach.return_value = db_attachment metadata_update.return_value = {'attached_mode': 'rw'} with mock.patch.object(self.context, 'elevated') as mock_elevated: mock_elevated.return_value = context.get_admin_context() attachment = volume.begin_attach("rw") self.assertIsInstance(attachment, objects.VolumeAttachment) self.assertEqual(volume.id, attachment.volume_id) self.assertEqual(fields.VolumeAttachStatus.ATTACHING, attachment.attach_status) metadata_update.assert_called_once_with(self.context.elevated(), volume.id, {'attached_mode': u'rw'}, True) self.assertEqual('rw', volume.admin_metadata['attached_mode'])