예제 #1
0
    def get_task_monitor(self, task_monitor):
        """Used to retrieve a TaskMonitor.

        :returns: A task monitor.
        """
        return taskmonitor.TaskMonitor(self._conn,
                                       task_monitor,
                                       redfish_version=self.redfish_version,
                                       registries=self.registries)
예제 #2
0
    def test_init_no_field_data(self):
        self.conn.reset_mock()
        self.conn.get.return_value.status_code = 202
        self.conn.get.return_value.headers = {'Content-Length': 42}

        task_monitor = taskmonitor.TaskMonitor(self.conn, '/Task/545')

        self.conn.get.assert_called_with(path='/Task/545')
        self.assertEqual(1, self.conn.get.call_count)
        self.assertIsNotNone(task_monitor._task)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    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.task_monitor = taskmonitor.TaskMonitor(self.conn,
                                                    '/Task/545',
                                                    field_data=self.field_data)
예제 #7
0
    def test_init_deprecation_warning(self, mock_log):
        taskmonitor.TaskMonitor(self.conn, '/Task/545')

        mock_log.assert_called_once_with(
            'sushy.resources.taskservice.taskmonitor.TaskMonitor '
            'is deprecated. Use sushy.taskmonitor.TaskMonitor.')