def setUp(self): super(TaskMonitorTestCase, self).setUp() self.conn = mock.Mock() with open('sushy/tests/unit/json_samples/task.json') as f: self.json_doc = json.load(f) self.conn.get.return_value.json.return_value = self.json_doc self.field_data = resource_base.FieldData( http_client.ACCEPTED, { 'Content-Length': 42, 'Location': '/Task/545', 'Retry-After': 20, 'Allow': 'DELETE' }, self.json_doc) self.response = mock.Mock() self.response.status_code = http_client.ACCEPTED self.response.headers = { 'Content-Length': 42, 'Location': '/Task/545', 'Retry-After': 20, 'Allow': 'DELETE' } self.response.content = json.dumps(self.json_doc).encode('utf-8') self.response.json.return_value = self.json_doc self.task_monitor = taskmonitor.TaskMonitor(self.conn, '/Task/545', response=self.response)
def test_not_cancellable_no_header(self): field_data = resource_base.FieldData(http_client.ACCEPTED, { 'Content-Length': 42, 'Location': '/Task/545', 'Retry-After': 20 }, self.json_doc) task_monitor = taskmonitor.TaskMonitor(self.conn, '/Task/545', field_data=field_data) self.assertFalse(task_monitor.cancellable)
def simple_update(self, image_uri, targets=None, transfer_protocol=up_cons.UPDATE_PROTOCOL_HTTP): """Simple Update is used to update software components. :returns: A task monitor. """ valid_transfer_protocols = self.get_allowed_transfer_protocols() if transfer_protocol in valid_transfer_protocols: transfer_protocol = up_maps.TRANSFER_PROTOCOL_TYPE_VALUE_MAP_REV[ transfer_protocol] else: legacy_transfer_protocols = self._get_legacy_transfer_protocols() if transfer_protocol not in legacy_transfer_protocols: raise exceptions.InvalidParameterValueError( parameter='transfer_protocol', value=transfer_protocol, valid_values=valid_transfer_protocols) LOG.warning( 'Legacy transfer protocol constant %s is being used. ' 'Consider migrating to any of: %s', transfer_protocol, ', '.join(up_maps.TRANSFER_PROTOCOL_TYPE_VALUE_MAP_REV)) target_uri = self._get_simple_update_element().target_uri LOG.debug('Updating software component %s via ' '%s ...', image_uri, target_uri) data = {'ImageURI': image_uri, 'TransferProtocol': transfer_protocol} if targets: data['Targets'] = targets rsp = self._conn.post(target_uri, data=data) json_data = rsp.json() if rsp.content else {} field_data = base.FieldData(rsp.status_code, rsp.headers, json_data) header = 'Location' task_monitor = rsp.headers.get(header) if not task_monitor: raise exceptions.MissingHeaderError(target_uri=target_uri, header=header) return taskmonitor.TaskMonitor(self._conn, task_monitor, redfish_version=self.redfish_version, registries=self.registries, field_data=field_data)
def test_init_accepted_no_content(self): field_data = resource_base.FieldData( http_client.ACCEPTED, { 'Content-Length': 0, 'Location': '/Task/545', 'Retry-After': 20, 'Allow': 'DELETE' }, None) task_monitor = taskmonitor.TaskMonitor(self.conn, '/Task/545', field_data=field_data) self.assertIsNone(task_monitor.task)
def test_init_field_data(self, mock_log): field_data = resource_base.FieldData(http_client.ACCEPTED, { 'Location': '/Task/545', 'Retry-After': 20, 'Allow': 'DELETE' }, self.json_doc) task_monitor = taskmonitor.TaskMonitor(self.conn, '/Task/545', field_data=field_data) self.assertEqual(field_data.status_code, task_monitor.response.status_code) self.assertEqual(field_data.headers, task_monitor.response.headers) self.assertEqual(field_data.json_doc, task_monitor.response.json()) mock_log.assert_called_once_with( 'TaskMonitor field_data is deprecated in TaskMonitor. ' 'Use response.')