예제 #1
0
    def test_returns_in_progress_when_update_process_is_running(
            self, mock_read_update_result, mock_check_output):
        mock_check_output.return_value = """
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0 224928  8612 ?        Ss   Apr03   0:01 /sbin/dummy-a
root        51  0.0  0.0 103152 21264 ?        Ss   Apr03   0:00 /opt/tinypilot-privileged/update
""".lstrip().encode('utf-8')
        mock_read_update_result.return_value = None

        status_actual, error_actual = update.get_current_state()
        self.assertEqual(update.Status.IN_PROGRESS, status_actual)
        self.assertIsNone(error_actual)
예제 #2
0
    def test_returns_not_running_when_there_is_no_process_nor_result_file(
            self, mock_read_update_result, mock_check_output):
        mock_check_output.return_value = """
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0 224928  8612 ?        Ss   Apr03   0:01 /sbin/dummy-a
root        51  0.0  0.0 103152 21264 ?        Ss   Apr03   0:00 /lib/dummy-b
""".lstrip().encode('utf-8')
        mock_read_update_result.return_value = None

        status_actual, error_actual = update.get_current_state()
        self.assertEqual(update.Status.NOT_RUNNING, status_actual)
        self.assertIsNone(error_actual)
예제 #3
0
    def test_returns_success_when_no_process_is_running_and_last_run_was_ok(
            self, mock_read_update_result, mock_check_output):
        mock_check_output.return_value = """
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0 224928  8612 ?        Ss   Apr03   0:01 /sbin/dummy-a
root        51  0.0  0.0 103152 21264 ?        Ss   Apr03   0:00 /lib/dummy-b
""".lstrip().encode('utf-8')
        mock_read_update_result.return_value = update_result.Result(
            success=True, error=None, timestamp='2021-02-10T085735Z')

        status_actual, error_actual = update.get_current_state()
        self.assertEqual(update.Status.DONE, status_actual)
        self.assertIsNone(error_actual)
예제 #4
0
def update_get():
    """Fetches the state of the latest update job.

    Returns:
        A JSON string describing the latest update job.

        success: true if we were able to fetch job.
        error: null if successful, str otherwise.
        status: str describing the status of the job. Can be one of
                ["NOT_RUNNING", "DONE", "IN_PROGRESS"].
    """

    status, error = update.get_current_state()
    if error:
        return json_response.error(error), 200
    return json_response.success({'status': str(status)})
예제 #5
0
    def test_ignores_update_result_if_update_is_running(
            self, mock_read_update_result, mock_check_output):
        """If update is running, last update result does not matter."""
        mock_check_output.return_value = """
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0 224928  8612 ?        Ss   Apr03   0:01 /sbin/dummy-a
root        51  0.0  0.0 103152 21264 ?        Ss   Apr03   0:00 /opt/tinypilot-privileged/update
""".lstrip().encode('utf-8')
        # get_current_state should ignore this result because an update process
        # is currently running, which takes priority over the previous result.
        mock_read_update_result.return_value = update_result.Result(
            success=True, error=None, timestamp='2021-02-10T085735Z')

        status_actual, error_actual = update.get_current_state()
        self.assertEqual(update.Status.IN_PROGRESS, status_actual)
        self.assertIsNone(error_actual)