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'
            })