def test_success(self, mock):
        diagnostics = [
            AddGatewayTxnDiagnostic(self.gnupg,
                                    self.shipping_destination_with_signature),
        ]
        diagnostics_report = DiagnosticsReport(diagnostics)
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: True,
                DIAGNOSTICS_ERRORS_KEY: [],
                DESTINATION_ADD_GATEWAY_TXN_KEY: {
                    "address":
                    "TestAddress",
                    "fee":
                    65000,
                    "owner":
                    1111,
                    "payer":
                    2222,
                    "staking fee":
                    4000000,
                    "txn":
                    "CrkBCiEBrlImpYLbJ0z0hw5b4g9isRyPrgbXs9X+RrJ4pJJc9MkS..."
                },
            })
예제 #2
0
def get_initialisation_file():
    """
    This needs to be generated as quickly as possible,
    so we bypass the regular timer.
    """

    diagnostics = [
        SerialNumberDiagnostic(),
        EccDiagnostic(),
        MacDiagnostics(),
        EnvVarDiagnostics(),
        BtDiagnostic(),
        LteDiagnostic(),
        LoraDiagnostic(),
        KeyDiagnostics(),
        DeviceStatusDiagnostic(),
        # Must be last, it depends on previous results
        PfDiagnostic()
    ]
    diagnostics_report = DiagnosticsReport(diagnostics)
    diagnostics_report.perform_diagnostics()
    LOGGER.debug("Full diagnostics report is: %s" % diagnostics_report)

    diagnostics_str = str(json.dumps(diagnostics_report))
    response_b64 = base64.b64encode(diagnostics_str.encode('ascii'))
    return response_b64
예제 #3
0
    def test_env_vars_success(self):
        for mapping in EnvVarDiagnostics.ENV_VARS_MAPPING:
            os.environ[mapping['ENV_VAR']] = 'foo'

        diagnostic = EnvVarDiagnostics()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report,
            {
                DIAGNOSTICS_PASSED_KEY: True,
                DIAGNOSTICS_ERRORS_KEY: [],
                'BALENA_DEVICE_NAME_AT_INIT': 'foo',
                'BN': 'foo',
                'BALENA_DEVICE_UUID': 'foo',
                'ID': 'foo',
                'BALENA_APP_NAME': 'foo',
                'BA': 'foo',
                'FREQ': 'foo',
                'FR': 'foo',
                'FIRMWARE_VERSION': 'foo',
                'FW': 'foo',
                'VARIANT': 'foo',
                'VA': 'foo',
                # We're moving towards longer lowercase key naming and will
                # deprecate old ones in near future. Just keeping this entry in the
                # list for the sake of style compatibility.
                'FIRMWARE_SHORT_HASH': 'foo',
                'firmware_short_hash': 'foo'
            })
예제 #4
0
    def test_success(self, mock_interface, mock_sys_bus):
        # Make mocked modems
        modem0 = MagicMock()
        mock_modems = [modem0]

        # Properties of a mocked modem with LTE capability
        mock_modem0_properties = {
            'Model': 'QUECTEL Mobile Broadband Module',
            'Manufacturer': 'QUALCOMM INCORPORATED',
            'CurrentCapabilities': 9,
            'EquipmentIdentifier': '867698048214905',
        }

        # Set mocked modems and their properties in dbus
        mock_interface = mock_interface.return_value
        mock_interface.GetManagedObjects.return_value = mock_modems
        mock_interface.GetAll.return_value = mock_modem0_properties

        diagnostic = LteDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(diagnostics_report, {
            DIAGNOSTICS_PASSED_KEY: True,
            DIAGNOSTICS_ERRORS_KEY: [],
            'LTE': [
                {'EquipmentIdentifier': '867698048214905',
                 'Manufacturer': 'QUALCOMM INCORPORATED',
                 'Model': 'QUECTEL Mobile Broadband Module'}],
            'lte': [
                {'EquipmentIdentifier': '867698048214905',
                 'Manufacturer': 'QUALCOMM INCORPORATED',
                 'Model': 'QUECTEL Mobile Broadband Module'}],
        })
    def test_failure_invalid_signature(self, mock):
        shipping_destination_json_with_invalid_signature = b"""
            {
                "shipping_destination_label": "A Friendly User Name",
                "shipping_destination_wallets": [ "FF11" ]
            }
        """
        diagnostics = [
            AddGatewayTxnDiagnostic(
                self.gnupg, shipping_destination_json_with_invalid_signature),
        ]
        diagnostics_report = DiagnosticsReport(diagnostics)
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY:
                False,
                DIAGNOSTICS_ERRORS_KEY: [
                    DESTINATION_ADD_GATEWAY_TXN_KEY,
                    DESTINATION_ADD_GATEWAY_TXN_KEY
                ],
                DESTINATION_ADD_GATEWAY_TXN_KEY:
                'Verifying the payload PGP signature failed.',
            })
예제 #6
0
    def test_success(self, mock):
        diagnostic = EccDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(diagnostics_report, {
            DIAGNOSTICS_PASSED_KEY: True,
            DIAGNOSTICS_ERRORS_KEY: [],
            'ECC': True
        })
예제 #7
0
    def test_gateway_exception(self, mock):
        diagnostic = EccDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: False,
                DIAGNOSTICS_ERRORS_KEY: ['ECC', 'ECC'],
                'ECC': 'Gateway MFR File Not Found'
            })
예제 #8
0
    def test_resourcebusy_exception(self, mock):
        diagnostic = EccDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: False,
                DIAGNOSTICS_ERRORS_KEY: ['ECC', 'ECC'],
                'ECC': 'Resource Busy Error'
            })
예제 #9
0
    def test_failure(self, mock):
        diagnostic = DeviceStatusDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: False,
                DIAGNOSTICS_ERRORS_KEY: ['device_status', 'device_status'],
                'device_status': 'appState is applying'
            })
예제 #10
0
    def test_ecc_exception(self, mock):
        diagnostic = EccDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: False,
                DIAGNOSTICS_ERRORS_KEY: ['ECC', 'ECC'],
                'ECC': 'ECC Malfunctioned'
            })
예제 #11
0
    def test_success(self, mock):
        diagnostic = DeviceStatusDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: True,
                DIAGNOSTICS_ERRORS_KEY: [],
                'device_status': 'device_ready'
            })
예제 #12
0
    def test_unboundlocal_exception(self, mock):
        with pytest.raises(UnboundLocalError):
            diagnostic = KeyDiagnostics()
            diagnostics_report = DiagnosticsReport([diagnostic])
            diagnostics_report.perform_diagnostics()

            self.assertDictEqual(
                diagnostics_report, {
                    DIAGNOSTICS_PASSED_KEY: False,
                    DIAGNOSTICS_ERRORS_KEY: [],
                    'KK': 'Unbound Local Error',
                })
예제 #13
0
    def test_success_strip(self, mock):
        diagnostic = SerialNumberDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: True,
                DIAGNOSTICS_ERRORS_KEY: [],
                'serial_number': '00000000ddd1a4c2',
                'serial_number': '00000000ddd1a4c2'
            })
예제 #14
0
    def test_failure(self, mock):
        diagnostic = KeyDiagnostic('KK', 'test_key', 'key_location')
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: False,
                DIAGNOSTICS_ERRORS_KEY: ['KK', 'test_key'],
                'KK': 'Key key_location not found',
                'test_key': 'Key key_location not found'
            })
예제 #15
0
    def test_success(self, mock):
        diagnostic = KeyDiagnostic('KK', 'test_key', 'key_location')
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: True,
                DIAGNOSTICS_ERRORS_KEY: [],
                'KK': '123',
                'test_key': '123'
            })
예제 #16
0
    def test_resourcebusy_exception(self, mock):
        with pytest.raises(ResourceBusyError):
            diagnostic = KeyDiagnostics()
            diagnostics_report = DiagnosticsReport([diagnostic])
            diagnostics_report.perform_diagnostics()

            self.assertDictEqual(
                diagnostics_report, {
                    DIAGNOSTICS_PASSED_KEY: False,
                    DIAGNOSTICS_ERRORS_KEY: [],
                    'KK': 'Resource Busy Error',
                })
예제 #17
0
    def test_eccmalfunction_exception(self, mock):
        with pytest.raises(ECCMalfunctionException):
            diagnostic = KeyDiagnostics()
            diagnostics_report = DiagnosticsReport([diagnostic])
            diagnostics_report.perform_diagnostics()

            self.assertDictEqual(
                diagnostics_report, {
                    DIAGNOSTICS_PASSED_KEY: False,
                    DIAGNOSTICS_ERRORS_KEY: [],
                    'KK': 'ECC Malfunction Error',
                })
예제 #18
0
    def test_failure(self):
        diagnostic = PfDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: False,
                DIAGNOSTICS_ERRORS_KEY: ['PF', 'legacy_pass_fail'],
                'PF': False,
                'legacy_pass_fail': False,
            })
예제 #19
0
    def test_filenotfound_exception(self, mock):
        with pytest.raises(FileNotFoundError):
            diagnostic = KeyDiagnostics()
            diagnostics_report = DiagnosticsReport([diagnostic])
            diagnostics_report.perform_diagnostics()

            self.assertDictEqual(
                diagnostics_report, {
                    DIAGNOSTICS_PASSED_KEY: False,
                    DIAGNOSTICS_ERRORS_KEY: [],
                    'KK': 'File Not Found Error',
                })
예제 #20
0
    def test_failure(self, mock):
        diagnostic = LoraDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: False,
                DIAGNOSTICS_ERRORS_KEY: ['LOR', 'lora'],
                'LOR': False,
                'lora': False
            })
예제 #21
0
    def test_failure(self, mock):
        diagnostic = EccDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: False,
                DIAGNOSTICS_ERRORS_KEY: ['ECC', 'ECC'],
                'ECC':
                'gateway_mfr test finished with error, {"result": "fail"}'
            })
예제 #22
0
    def test_success(self, mock):
        diagnostic = MacDiagnostic('I0', 'friendly', '/')
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: True,
                DIAGNOSTICS_ERRORS_KEY: [],
                'I0': 'foo',
                'friendly': 'foo'
            })
예제 #23
0
    def test_success(self, mock_interface, mock_sys_bus):
        # Prepare mocked BT devices
        mock_bt_devices = {
            '/org/bluez/hci0': {
                'org.bluez.Adapter1': {
                    'Address': '00:E0:4C:19:D2:91',
                    'AddressType': 'public',
                    'Name': 'ble0',
                    'Alias': 'ble0',
                    'Class': '1835268',
                    'Powered': '1',
                    'Discoverable': '1',
                    'DiscoverableTimeout': 0,
                    'Pairable': '1',
                    'PairableTimeout': 0,
                    'Discovering': '0',
                    'UUIDs': [],
                    'Modalias': 'usb:v1D6Bp0246d0535'
                }
            }
        }

        # Mock BT devices in dbus
        mock_interface = mock_interface.return_value
        mock_interface.GetManagedObjects.return_value = mock_bt_devices

        diagnostic = BtDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY:
                True,
                DIAGNOSTICS_ERRORS_KEY: [],
                'BT': [{
                    'Address': '00:E0:4C:19:D2:91',
                    'Discoverable': '1',
                    'Discovering': '0',
                    'Name': 'ble0',
                    'Pairable': '1',
                    'Powered': '1'
                }],
                'bluetooth': [{
                    'Address': '00:E0:4C:19:D2:91',
                    'Discoverable': '1',
                    'Discovering': '0',
                    'Name': 'ble0',
                    'Pairable': '1',
                    'Powered': '1'
                }]
            })
예제 #24
0
    def test_success(self):
        os.environ['ENV_VAR'] = 'foo'
        diagnostic = EnvVarDiagnostic('DIAGNOSTIC_KEY', 'ENV_VAR')
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: True,
                DIAGNOSTICS_ERRORS_KEY: [],
                'DIAGNOSTIC_KEY': 'foo',
                'ENV_VAR': 'foo'
            })
예제 #25
0
    def test_error(self):
        os.environ['ENV_VAR'] = ''
        diagnostic = EnvVarDiagnostic('DIAGNOSTIC_KEY', 'ENV_VAR')
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: False,
                DIAGNOSTICS_ERRORS_KEY: ['DIAGNOSTIC_KEY', 'ENV_VAR'],
                'DIAGNOSTIC_KEY': 'Env var ENV_VAR not set',
                'ENV_VAR': 'Env var ENV_VAR not set'
            })
예제 #26
0
    def test_filenotfound(self, mock):
        mock.side_effect = FileNotFoundError("File not found")
        diagnostic = SerialNumberDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: False,
                DIAGNOSTICS_ERRORS_KEY: ['serial_number', 'serial_number'],
                'serial_number': 'File not found',
                'serial_number': 'File not found'
            })
예제 #27
0
    def test_permissionerror(self, mock):
        mock.side_effect = PermissionError("Bad permissions")
        diagnostic = SerialNumberDiagnostic()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: False,
                DIAGNOSTICS_ERRORS_KEY: ['serial_number', 'serial_number'],
                'serial_number': 'Bad permissions',
                'serial_number': 'Bad permissions'
            })
예제 #28
0
    def test_error(self, mock):
        mock.side_effect = Exception('No file')
        diagnostic = MacDiagnostic('I0', 'friendly', '/')
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: False,
                DIAGNOSTICS_ERRORS_KEY: ['I0', 'friendly'],
                'I0': 'No file',
                'friendly': 'No file'
            })
예제 #29
0
    def test_macs_success(self, mock):
        diagnostic = MacDiagnostics()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: True,
                DIAGNOSTICS_ERRORS_KEY: [],
                'E0': 'foo',
                'eth_mac_address': 'foo',
                'W0': 'foo',
                'wifi_mac_address': 'foo'
            })
예제 #30
0
    def test_keys_success(self, mock):
        diagnostic = KeyDiagnostics()
        diagnostics_report = DiagnosticsReport([diagnostic])
        diagnostics_report.perform_diagnostics()

        self.assertDictEqual(
            diagnostics_report, {
                DIAGNOSTICS_PASSED_KEY: True,
                DIAGNOSTICS_ERRORS_KEY: [],
                'PK': '123',
                'public_key': '123',
                'OK': '123',
                'onboarding_key': '123'
            })