Esempio n. 1
0
 def test_get_device_type_info_error(self, file_create_fixture):
     """Test that multiple different keys in the device_type file fails."""
     fpath = file_create_fixture("""device_type=foo\nkey=val""")
     dtype_info = devicetype.get(fpath)
     if dtype_info:
         pytest.fail(
             "Multiple different keys in device_type file should fail")
Esempio n. 2
0
 def run(self, context):
     log.info("Checking for updates...")
     device_type = devicetype.get(settings.PATHS.device_type)
     artifact_name = artifactinfo.get(settings.PATHS.artifact_info)
     deployment = deployments.request(
         context.config.ServerURL,
         context.JWT,
         device_type=device_type,
         artifact_name=artifact_name,
         server_certificate=context.config.ServerCertificate,
     )
     if deployment:
         context.deployment = deployment
         context.deployment_log_handler.enable()
         return True
     time.sleep(2)
     return False
Esempio n. 3
0
def aggregate(script_path: str, device_type_path: str,
              artifact_info_path: str) -> dict:
    """Runs all the inventory scripts in 'path', and parses the 'key=value' pairs
    into a data-structure ready for passing it on to the Mender server"""
    log.info(f"Aggregating inventory data from {script_path}")
    keyvals: dict = {}
    for inventory_script in inventory_scripts(script_path):
        keyvals.update(inventory_script.run())
    device_type = devicetype.get(device_type_path)
    log.info(f"Found the device type: {device_type}")
    if device_type:
        keyvals.update(device_type)
    artifact_name = artifactinfo.get(artifact_info_path)
    log.info(f"Found the artifact_name: {artifact_name}")
    if artifact_name:
        keyvals.update(artifact_name)
    return keyvals
Esempio n. 4
0
    def run(self, context):
        if not context.update_timer.is_it_time():
            return False

        log.info("Checking for updates...")
        device_type = devicetype.get(settings.PATHS.device_type)
        artifact_name = artifactinfo.get(settings.PATHS.artifact_info)
        deployment = deployments.request(
            context.config.ServerURL,
            context.JWT,
            device_type=device_type,
            artifact_name=artifact_name,
            server_certificate=context.config.ServerCertificate,
        )
        if deployment:
            context.deployment = deployment
            log.parent.deployment_log_handler.enable(reset=True)
            return True
        return False
Esempio n. 5
0
 def test_get_device_type_info(self, data, expected, file_create_fixture):
     fpath = file_create_fixture(data)
     dtype_info = devicetype.get(fpath)
     assert dtype_info == expected