Skip to content

Commit

Permalink
Updated code to update attach_time of a volume while detaching
Browse files Browse the repository at this point in the history
While detaching volume from an instance, attach_time of the
volume is not updated. This task updates volume['attach_time']
to NONE at detach_volume.

Also modified the default value of XML attribute
volume['attach_time'] '-' to ''(a 0 length string) to
maintain consistency with existing code.

Fixes bug: 1056122

Change-Id: If56ceda6caab80fb803fcf194ed1dfb18808ec3a
  • Loading branch information
Arathi committed Sep 26, 2012
1 parent c367fa5 commit ee2dd66
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nova/api/ec2/cloud.py
Expand Up @@ -978,7 +978,7 @@ def _format_instance_bdm(self, context, instance_uuid, root_device_name,
# TODO(yamahata): volume attach time
ebs = {'volumeId': volume_id,
'deleteOnTermination': bdm['delete_on_termination'],
'attachTime': vol['attach_time'] or '-',
'attachTime': vol['attach_time'] or '',
'status': vol['status'], }
res = {'deviceName': bdm['device_name'],
'ebs': ebs, }
Expand Down
1 change: 1 addition & 0 deletions nova/db/sqlalchemy/api.py
Expand Up @@ -2981,6 +2981,7 @@ def volume_detached(context, volume_id):
volume_ref['mountpoint'] = None
volume_ref['attach_status'] = 'detached'
volume_ref['instance_uuid'] = None
volume_ref['attach_time'] = None
volume_ref.save(session=session)


Expand Down
2 changes: 2 additions & 0 deletions nova/tests/api/ec2/test_cloud.py
Expand Up @@ -2051,12 +2051,14 @@ def _assert_volume_attached(self, vol, instance_uuid, mountpoint):
self.assertEqual(vol['mountpoint'], mountpoint)
self.assertEqual(vol['status'], "in-use")
self.assertEqual(vol['attach_status'], "attached")
self.assertNotEqual(vol['attach_time'], None)

def _assert_volume_detached(self, vol):
self.assertEqual(vol['instance_uuid'], None)
self.assertEqual(vol['mountpoint'], None)
self.assertEqual(vol['status'], "available")
self.assertEqual(vol['attach_status'], "detached")
self.assertEqual(vol['attach_time'], None)

def test_stop_start_with_volume(self):
"""Make sure run instance with block device mapping works"""
Expand Down
2 changes: 2 additions & 0 deletions nova/tests/test_volume.py
Expand Up @@ -273,6 +273,7 @@ def test_run_attach_detach_volume(self):
self.assertEqual(vol['attach_status'], "attached")
self.assertEqual(vol['mountpoint'], mountpoint)
self.assertEqual(vol['instance_uuid'], instance_uuid)
self.assertNotEqual(vol['attach_time'], None)

self.assertRaises(exception.VolumeAttached,
self.volume.delete_volume,
Expand All @@ -286,6 +287,7 @@ def test_run_attach_detach_volume(self):
volume_id)
vol = db.volume_get(self.context, volume_id)
self.assertEqual(vol['status'], "available")
self.assertEqual(vol['attach_time'], None)

self.volume.delete_volume(self.context, volume_id)
self.assertRaises(exception.VolumeNotFound,
Expand Down

0 comments on commit ee2dd66

Please sign in to comment.