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
def test_sync_inventory(self, ctx, monkeypatch, caplog): ctx.inventory_timer = timeutil.IsItTime sync_inventory = statemachine.SyncInventory() # Not time yet with monkeypatch.context() as m: m.setattr(ctx.inventory_timer, "is_it_time", lambda *args, **kwargs: False) assert not sync_inventory.run(ctx) # No inventory data with monkeypatch.context() as m: m.setattr(ctx.inventory_timer, "is_it_time", lambda *args, **kwargs: True) m.setattr(inventory, "aggregate", lambda *args, **kwargs: None) m.setattr(client_inventory, "request", lambda *args, **kwargs: None) sync_inventory.run(ctx) assert "No inventory data found" in caplog.text # Inventory data with monkeypatch.context() as m: ctx.config = config.Config({}, {}) ctx.JWT = "foobar" m.setattr(ctx, "JWT", "foobar") m.setattr(ctx.inventory_timer, "is_it_time", lambda *args, **kwargs: True) m.setattr(inventory, "aggregate", lambda *args, **kwargs: {"foo", "bar"}) m.setattr(client_inventory, "request", lambda *args, **kwargs: None) sync_inventory.run(ctx) assert "aggregated inventory data" in caplog.text
def fixture_ctx(): settings.PATHS.deployment_log = os.getcwd() context = statemachine.Context() context.JWT = "foobar" context.config = config.Config({}, {}) context.update_timer = timeutil.IsItTime context.deployment_log_handler = DeploymentLogHandler() context.deployment = deployments.DeploymentInfo( { "id": "bugsbunny", "artifact": { "artifact_name": "release-1", "source": {"uri": "https://docker.mender.io",}, }, } ) return context
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}") return context
def __init__(self): self.private_key = None self.config = config.Config({}, {}) self.identity_data = {}