RIS: Check if virtual media is attached before ejecting
This commit changes eject_virtual_media in RIS to check if virtual media is attached before trying to eject it. This will no longer raise exception if virtual media is not attached. Change-Id: Id764ebe437be3f63a0957aa15e60417478df8d34
This commit is contained in:
parent
6396b5170e
commit
68bfa97b55
|
@ -1125,6 +1125,10 @@ class RISOperations(operations.IloOperations):
|
|||
"""
|
||||
response, vm_device_uri = self._get_vm_device_status(device)
|
||||
|
||||
# Check if virtual media is connected.
|
||||
if response.get('Inserted') is False:
|
||||
return
|
||||
|
||||
# Update required property
|
||||
vm_settings = dict()
|
||||
vm_settings['Image'] = None
|
||||
|
|
|
@ -1437,6 +1437,31 @@ GET_VM_STATUS_FLOPPY_INSERTED = """
|
|||
}
|
||||
"""
|
||||
|
||||
RESP_VM_STATUS_CDROM_INSERTED = """
|
||||
{
|
||||
"Description": "Virtual Removable Media",
|
||||
"links": {
|
||||
"self": {"href": "/rest/v1/Managers/1/VirtualMedia/2"
|
||||
}
|
||||
},
|
||||
"Type": "VirtualMedia.0.9.5",
|
||||
"Image": "http://foo/foo", "ConnectedVia": "NotConnected",
|
||||
"MediaTypes": [
|
||||
"CD",
|
||||
"DVD"
|
||||
],
|
||||
"Oem": {
|
||||
"Hp": {
|
||||
"Type": "HpiLOVirtualMedia.0.9.5",
|
||||
"BootOnNextServerReset": false
|
||||
}
|
||||
},
|
||||
"WriteProtected": true,
|
||||
"Inserted": true,
|
||||
"Name": "VirtualMedia"
|
||||
}
|
||||
"""
|
||||
|
||||
RESP_VM_STATUS_CDROM_EMPTY = """
|
||||
{
|
||||
"Description": "Virtual Removable Media",
|
||||
|
|
|
@ -559,7 +559,7 @@ class IloRisTestCase(testtools.TestCase):
|
|||
def test_eject_virtual_media(self, get_vm_device_mock, patch_mock):
|
||||
vm_uri = '/rest/v1/Managers/1/VirtualMedia/2'
|
||||
|
||||
cdrom_resp = json.loads(ris_outputs.RESP_VM_STATUS_CDROM_EMPTY)
|
||||
cdrom_resp = json.loads(ris_outputs.RESP_VM_STATUS_CDROM_INSERTED)
|
||||
device_uri = cdrom_resp["links"]["self"]["href"]
|
||||
get_vm_device_mock.return_value = (cdrom_resp, device_uri)
|
||||
|
||||
|
@ -571,12 +571,25 @@ class IloRisTestCase(testtools.TestCase):
|
|||
get_vm_device_mock.assert_called_once_with('CDROM')
|
||||
patch_mock.assert_called_once_with(vm_uri, None, vm_patch)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_rest_patch')
|
||||
@mock.patch.object(ris.RISOperations, '_get_vm_device_status')
|
||||
def test_eject_virtual_media_cdrom_empty(
|
||||
self, get_vm_device_mock, patch_mock):
|
||||
cdrom_resp = json.loads(ris_outputs.RESP_VM_STATUS_CDROM_EMPTY)
|
||||
device_uri = cdrom_resp["links"]["self"]["href"]
|
||||
get_vm_device_mock.return_value = (cdrom_resp, device_uri)
|
||||
|
||||
self.client.eject_virtual_media(device='CDROM')
|
||||
|
||||
get_vm_device_mock.assert_called_once_with('CDROM')
|
||||
self.assertFalse(patch_mock.called)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_rest_patch')
|
||||
@mock.patch.object(ris.RISOperations, '_get_vm_device_status')
|
||||
def test_eject_virtual_media_fail(self, get_vm_device_mock, patch_mock):
|
||||
vm_uri = '/rest/v1/Managers/1/VirtualMedia/2'
|
||||
|
||||
cdrom_resp = json.loads(ris_outputs.RESP_VM_STATUS_CDROM_EMPTY)
|
||||
cdrom_resp = json.loads(ris_outputs.RESP_VM_STATUS_CDROM_INSERTED)
|
||||
device_uri = cdrom_resp["links"]["self"]["href"]
|
||||
get_vm_device_mock.return_value = (cdrom_resp, device_uri)
|
||||
|
||||
|
|
Loading…
Reference in New Issue