def test_global_faulty_json(self): with open("tests/unit/data/configs/global_mender_faulty.conf", "w") as f: json.dump(GLOBAL_TESTDATA, f) f.write("this makes the json file faulty") with pytest.raises(json.decoder.JSONDecodeError): config.load( "tests/unit/data/configs/local_mender.conf", "tests/unit/data/configs/global_mender_faulty.conf", ) os.remove("tests/unit/data/configs/global_mender_faulty.conf")
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
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 fixture_(): with open("tests/unit/data/configs/global_mender_testdata.conf", "w") as f: json.dump(GLOBAL_TESTDATA, f) yield config.load("", "tests/unit/data/configs/global_mender_testdata.conf") if os.path.isfile("tests/unit/data/configs/global_mender_testdata.conf"): os.remove("tests/unit/data/configs/global_mender_testdata.conf")
def fixture_local_and_global(): return config.load( "tests/unit/data/configs/local_mender.conf", "tests/unit/data/configs/global_medner.conf", )
def test_file_not_found_error_(self, caplog): config.load("", "tests/unit/data/configs/global_mender.conf") assert "Global configuration file: '' not found" not in caplog.text assert "Local configuration file: '' not found" in caplog.text
def test_file_not_found_error_both(self, caplog): with pytest.raises(config.NoConfigurationFileError): config.load("", "") assert "Global configuration file: '' not found" in caplog.text assert "Local configuration file: '' not found" in caplog.text
def test_no_path_instance(self): with pytest.raises(config.NoConfigurationFileError): config.load("", "")