Fix TaskMonitor constructor calls in volume.py
In the volume.py module, the first parameter passed to the TaskMonitor constructor was incorrect. The parameter passed was the resource object (self), but it should have been the connector object (self._conn). This affected the create_volume() and delete_volume() methods. The constructor calls were updated to provide the correct connector parameter. And the unit tests were updated to test that the TaskMonitor objects are successfully created. Change-Id: I10e564185b4cd9faa24739766536d39646f8a7c1 Story: 2003514 Task: 41720
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixes issues in the ``volume`` module where the first parameter passed to
|
||||
the ``TaskMonitor`` constructor was incorrect. The parameter passed was
|
||||
the resource object (self), but it should have been the connector object
|
||||
(self._conn). This affected the ``create_volume()`` and
|
||||
``delete_volume()`` methods.
|
@@ -153,7 +153,7 @@ class Volume(base.ResourceBase):
|
||||
r = self._conn.delete(self._path, data=payload, blocking=blocking,
|
||||
timeout=timeout)
|
||||
if r.status_code == 202:
|
||||
return (TaskMonitor(self, r.headers.get('location'))
|
||||
return (TaskMonitor(self._conn, r.headers.get('location'))
|
||||
.set_retry_after(r.headers.get('retry-after')))
|
||||
|
||||
|
||||
@@ -221,5 +221,5 @@ class VolumeCollection(base.ResourceCollectionBase):
|
||||
self.refresh()
|
||||
return self.get_member(location)
|
||||
elif r.status_code == 202:
|
||||
return (TaskMonitor(self, location)
|
||||
return (TaskMonitor(self._conn, location)
|
||||
.set_retry_after(r.headers.get('retry-after')))
|
||||
|
@@ -97,18 +97,28 @@ class VolumeTestCase(base.TestCase):
|
||||
|
||||
def test_delete_volume_immediate(self):
|
||||
payload = {}
|
||||
self.stor_volume.delete_volume(
|
||||
self.conn.delete.return_value.status_code = 200
|
||||
resource = self.stor_volume.delete_volume(
|
||||
payload=payload, apply_time=res_cons.APPLY_TIME_IMMEDIATE)
|
||||
self.stor_volume._conn.delete.assert_called_once_with(
|
||||
self.stor_volume._path, data=payload, blocking=True, timeout=500)
|
||||
self.assertIsNone(resource)
|
||||
|
||||
def test_delete_volume_on_reset(self):
|
||||
payload = {}
|
||||
self.stor_volume.delete_volume(
|
||||
self.conn.delete.return_value.status_code = 202
|
||||
self.conn.delete.return_value.headers = {
|
||||
'location': '/redfish/v1/taskmon/4608f7e6',
|
||||
'retry-after': '120'
|
||||
}
|
||||
task_mon = self.stor_volume.delete_volume(
|
||||
payload=payload, apply_time=res_cons.APPLY_TIME_ON_RESET,
|
||||
timeout=250)
|
||||
self.stor_volume._conn.delete.assert_called_once_with(
|
||||
self.stor_volume._path, data=payload, blocking=False, timeout=250)
|
||||
self.assertIsNotNone(task_mon)
|
||||
self.assertEqual(task_mon.resource_name, 'task_monitor')
|
||||
self.assertEqual(task_mon.path, '/redfish/v1/taskmon/4608f7e6')
|
||||
|
||||
|
||||
class VolumeCollectionTestCase(base.TestCase):
|
||||
@@ -250,19 +260,16 @@ class VolumeCollectionTestCase(base.TestCase):
|
||||
expected_payload['@Redfish.OperationApplyTime'] = 'OnReset'
|
||||
with open('sushy/tests/unit/json_samples/volume4.json') as f:
|
||||
self.conn.get.return_value.json.return_value = json.load(f)
|
||||
self.conn.post.return_value.status_code = 201
|
||||
self.conn.post.return_value.headers.return_value = {
|
||||
'Location': '/redfish/v1/Systems/437XR1138R2/Storage/1/Volumes/4'
|
||||
self.conn.post.return_value.status_code = 202
|
||||
self.conn.post.return_value.headers = {
|
||||
'Location': '/redfish/v1/taskmon/4608f7e6',
|
||||
'retry-after': '120'
|
||||
}
|
||||
new_vol = self.stor_vol_col.create_volume(
|
||||
task_mon = self.stor_vol_col.create_volume(
|
||||
payload, apply_time=res_cons.APPLY_TIME_ON_RESET)
|
||||
self.stor_vol_col._conn.post.assert_called_once_with(
|
||||
'/redfish/v1/Systems/437XR1138R2/Storage/1/Volumes',
|
||||
data=expected_payload, blocking=False, timeout=500)
|
||||
self.stor_vol_col.refresh.assert_called_once()
|
||||
self.assertIsNotNone(new_vol)
|
||||
self.assertEqual('4', new_vol.identity)
|
||||
self.assertEqual('My Volume 4', new_vol.name)
|
||||
self.assertEqual(107374182400, new_vol.capacity_bytes)
|
||||
self.assertEqual(sushy.VOLUME_TYPE_MIRRORED, new_vol.volume_type)
|
||||
self.assertEqual(sushy.RAID_TYPE_RAID1, new_vol.raid_type)
|
||||
self.assertIsNotNone(task_mon)
|
||||
self.assertEqual(task_mon.resource_name, 'task_monitor')
|
||||
self.assertEqual(task_mon.path, '/redfish/v1/taskmon/4608f7e6')
|
||||
|
Reference in New Issue
Block a user