예제 #1
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.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)
예제 #2
0
    def test_check_is_processing_refreshing(self):
        self.conn.reset_mock()
        self.conn.get.return_value.status_code = 202
        self.conn.get.return_value.headers = {}
        self.conn.get.return_value.content = None

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

        self.assertEqual(True, task_monitor.check_is_processing)
예제 #3
0
    def test_init_no_response(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)
예제 #4
0
    def test_check_is_processing_not_processing(self):
        response = mock.Mock()
        response.status_code = http_client.OK
        response.headers = {}
        response.content = None
        task_monitor = taskmonitor.TaskMonitor(self.conn,
                                               '/Task/545',
                                               response=response)

        self.assertEqual(False, task_monitor.check_is_processing)
예제 #5
0
    def get_task_monitor(self, task_monitor):
        """Used to retrieve a TaskMonitor.

        Deprecated: Use sushy.Sushy.get_task_monitor
        :returns: A task monitor.
        """
        return taskmonitor.TaskMonitor(self._conn,
                                       task_monitor,
                                       redfish_version=self.redfish_version,
                                       registries=self.registries)
예제 #6
0
    def get_task_monitor(self, task_monitor_uri):
        """Used to retrieve a TaskMonitor by task monitor URI.

        :param task_monitor_uri: Task monitor URI
        :returns: A task monitor.
        """
        return taskmonitor.TaskMonitor(
            self._conn,
            task_monitor_uri,
            redfish_version=self.redfish_version,
            registries=self.registries)
예제 #7
0
    def test_init_accepted_no_content(self):
        response = mock.Mock()
        response.status_code = http_client.ACCEPTED
        response.headers = {
            'Location': '/Task/545',
            'Retry-After': 20,
            'Allow': 'DELETE'
        }
        response.content = None

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

        self.assertIsNone(task_monitor.task)
예제 #8
0
    def test_not_cancellable_no_header(self):
        response = mock.Mock()
        response.status_code = http_client.ACCEPTED
        response.headers = {
            'Content-Length': 42,
            'Location': '/Task/545',
            'Retry-After': 20
        }
        response.json.return_value = self.json_doc

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

        self.assertFalse(task_monitor.cancellable)
예제 #9
0
    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.')
예제 #10
0
def TaskMonitor(connector,
                task_monitor,
                redfish_version=None,
                registries=None,
                field_data=None):
    """A class representing a task monitor

    Deprecated, use sushy.taskmonitor.TaskMonitor.

    :param connector: A Connector instance
    :param task_monitor: The task monitor URI
    :param redfish_version: The version of RedFish. Used to construct
        the object according to schema of the given version.
    :param registries: Dict of Redfish Message Registry objects to be
        used in any resource that needs registries to parse messages.
    :param field_data: the data to use populating the fields.
    """
    LOG.warning('sushy.resources.taskservice.taskmonitor.TaskMonitor '
                'is deprecated. Use sushy.taskmonitor.TaskMonitor.')
    return taskmonitor.TaskMonitor(connector, task_monitor, redfish_version,
                                   registries, field_data)