Exemplo n.º 1
0
 def run(self, context, force_bootstrap=False):
     log.debug("InitState: run()")
     try:
         context.config = config.load(
             local_path=settings.PATHS.local_conf,
             global_path=settings.PATHS.global_conf,
         )
         log.info(f"Loaded configuration: {context.config}")
     except config.NoConfigurationFileError:
         log.error("No configuration files found for the device."
                   " Most likely, the device will not be functional.")
     identity_data = identity.aggregate(
         path=settings.PATHS.identity_scripts)
     context.identity_data = identity_data
     private_key = bootstrap.now(force_bootstrap=force_bootstrap,
                                 private_key_path=settings.PATHS.key)
     context.private_key = private_key
     context.inventory_timer = timeutil.IsItTime(
         context.config.InventoryPollIntervalSeconds)
     context.update_timer = timeutil.IsItTime(
         context.config.UpdatePollIntervalSeconds)
     context.retry_timer = timeutil.IsItTime(
         context.config.RetryPollIntervalSeconds)
     log.debug(f"Init set context to: {context}")
     return context
Exemplo n.º 2
0
 def run(self, context, force_bootstrap=False):
     log.debug("InitState: run()")
     context.config = config.Config({}, {})
     try:
         context.config = config.load(
             local_path=settings.PATHS.local_conf,
             global_path=settings.PATHS.global_conf,
         )
         log.info(f"Loaded configuration: {context.config}")
     except config.NoConfigurationFileError:
         log.error("No configuration files found for the device."
                   "Most likely, the device will not be functional.")
     identity_data = identity.aggregate(
         path=settings.PATHS.identity_scripts)
     context.identity_data = identity_data
     private_key = bootstrap.now(force_bootstrap=force_bootstrap,
                                 private_key_path=settings.PATHS.key)
     context.private_key = private_key
     log.debug(f"Init set context to: {context}")
     #
     # We need some way of knowing whether or not a deployment was in
     # progress, and what the last state was, so that the deployment can be
     # resumed, and so that we can start the state-machine on the passive
     # partition, whenever needed. For now though, this is always False.
     #
     context.deployment_active = False
     return context
Exemplo n.º 3
0
 def test_identity_not_executable(self, caplog, tmpdir):
     d = tmpdir.mkdir("identity-test")
     f = d.join("mender-device-identity")
     f.write("""#! /bin/sh
     echo mac=c8:5b:76:fb:c8:75""")
     identity_data = identity.aggregate(path=f)
     assert not identity_data
     assert "is not executable" in caplog.text
Exemplo n.º 4
0
 def test_no_identity(self, caplog):
     identity_data = identity.aggregate(path="/i/do/not/exist")
     assert not identity_data
     assert "No identity can be collected" in caplog.text
Exemplo n.º 5
0
 def test_identity(self, data, expected, file_create_fixture):
     tpath = file_create_fixture(data)
     identity_data = identity.aggregate(tpath)
     assert identity_data
     assert identity_data == expected