Esempio n. 1
0
    def test_device_status_success_response(self):
        responses.add(
            responses.GET,
            TEST_SUPERVISOR_DEVICE_STATUS_URL,
            status=200,
            json={'appState': 'applied'}
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)
        assert bs.get_device_status('appState') == 'applied'
Esempio n. 2
0
    def test_shutdown_gateway_success_response(self):
        responses.add(
            responses.POST,
            TEST_SUPERVISOR_SHUTDOWN_URL,
            status=200,
            json={"Data": "OK", "Error": ""}
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)
        resp = bs.shutdown()

        assert resp['Data'] == 'OK'
Esempio n. 3
0
    def test_device_status_error_on_connection_timeout(self):
        responses.add(
            responses.GET,
            TEST_SUPERVISOR_DEVICE_STATUS_URL,
            body=ConnectTimeout('Timout trying to make connection')
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)

        with self.assertRaises(RuntimeError) as exp:
            bs.get_device_status('appState')

        assert str(exp.exception).startswith("Device status request failed")
Esempio n. 4
0
    def test_shutdown_gateway_error_on_connection_timeout(self):
        responses.add(
            responses.POST,
            TEST_SUPERVISOR_SHUTDOWN_URL,
            body=ConnectTimeout('Timout trying to make connection')
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)

        with self.assertRaises(Exception) as exp:
            bs.shutdown()

        assert str(exp.exception) == 'supervisor API not accessible'
Esempio n. 5
0
    def test_shutdown_gateway_error_on_connection_error(self):
        responses.add(
            responses.POST,
            TEST_SUPERVISOR_SHUTDOWN_URL,
            body=ConnectionError('Unable to connect')
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)

        with self.assertRaises(Exception) as exp:
            bs.shutdown()

        assert str(exp.exception) == "supervisor API not accessible"
Esempio n. 6
0
    def test_device_status_empty_response(self):
        responses.add(
            responses.GET,
            TEST_SUPERVISOR_DEVICE_STATUS_URL,
            body='',
            status=200
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)

        with self.assertRaises(RuntimeError) as exp:
            bs.get_device_status('appState')

        assert str(exp.exception).startswith("Supervisor API did not return valid json response")
Esempio n. 7
0
    def test_shutdown_gateway_empty_response(self):
        responses.add(
            responses.POST,
            TEST_SUPERVISOR_SHUTDOWN_URL,
            body='',
            status=200
        )

        bs = BalenaSupervisor(TEST_SUPERVISOR_ADDRESS, TEST_SUPERVISOR_API_KEY)

        with self.assertRaises(Exception) as exp:
            bs.shutdown()

        assert str(exp.exception) == 'shutdown failed due to supervisor API issue'
Esempio n. 8
0
    def use_verified_json(self, diagnostics_report: DiagnosticsReport) -> None:
        if SHUTDOWN_GATEWAY_KEY not in self.verified_json:
            diagnostics_report.record_failure(self.NO_SHUTDOWN_GATEWAY_KEY_MSG,
                                              self)
            return

        try:
            balena_supervisor = BalenaSupervisor.new_from_env()
            shutdown_response = balena_supervisor.shutdown()
            diagnostics_report.record_result(shutdown_response, self)
        except Exception as e:
            diagnostics_report.record_failure(e, self)
Esempio n. 9
0
    def perform_test(self, diagnostics_report: DiagnosticsReport) -> None:
        try:
            balena_supervisor = BalenaSupervisor.new_from_env()
            device_status = balena_supervisor.get_device_status('appState')

            if device_status == 'applied':
                diagnostics_report.record_result("device_ready", self)
            else:
                diagnostics_report.record_failure(
                    f"appState is {device_status}", self)

        except Exception as e:
            diagnostics_report.record_failure(e, self)
Esempio n. 10
0
    def test_creation_from_env(self):
        bs = BalenaSupervisor.new_from_env()

        assert bs.supervisor_address == TEST_SUPERVISOR_ADDRESS
        assert bs.supervisor_api_key == TEST_SUPERVISOR_API_KEY
        assert bs.headers == {'Content-type': 'application/json'}