async def test_purge_on_delete_compile_failed_with_compile( event_loop, client, server, environment, snippetcompiler): config.Config.set("compiler_rest_transport", "request_timeout", "1") snippetcompiler.setup_for_snippet(""" h = std::Host(name="test", os=std::linux) f = std::ConfigFile(host=h, path="/etc/motd", content="test", purge_on_delete=true) """) version, _ = await snippetcompiler.do_export_and_deploy(do_raise=False) result = await client.get_version(environment, version) assert result.code == 200 assert result.result["model"]["total"] == 1 snippetcompiler.setup_for_snippet(""" h = std::Host(name="test") """) # force deploy by having unknown unknown_parameters.append({"parameter": "a", "source": "b"}) version, _ = await snippetcompiler.do_export_and_deploy(do_raise=False) result = await client.get_version(environment, version) assert result.code == 200 assert result.result["model"]["total"] == 0
def getfact(context: Context, resource: "any", fact_name: "string", default_value: "any"=None) -> "any": """ Retrieve a fact of the given resource """ resource_id = resources.to_id(resource) if resource_id is None: raise Exception("Facts can only be retreived from resources.") # Special case for unit testing and mocking if hasattr(context.compiler, "refs") and "facts" in context.compiler.refs: if resource_id in context.compiler.refs["facts"] and fact_name in context.compiler.refs["facts"][resource_id]: return context.compiler.refs["facts"][resource_id][fact_name] fact_value = Unknown(source=resource) unknown_parameters.append({"resource": resource_id, "parameter": fact_name, "source": "fact"}) if default_value is not None: return default_value return fact_value # End special case fact_value = None try: client = context.get_client() env = Config.get("config", "environment", None) if env is None: raise Exception("The environment of this model should be configured in config>environment") def call(): return client.get_param(tid=env, id=fact_name, resource_id=resource_id) result = context.run_sync(call) if result.code == 200: fact_value = result.result["parameter"]["value"] else: logging.getLogger(__name__).info("Param %s of resource %s is unknown", fact_name, resource_id) fact_value = Unknown(source=resource) unknown_parameters.append({"resource": resource_id, "parameter": fact_name, "source": "fact"}) except ConnectionRefusedError: logging.getLogger(__name__).warning("Param %s of resource %s is unknown because connection to server was refused", fact_name, resource_id) fact_value = Unknown(source=resource) unknown_parameters.append({"resource": resource_id, "parameter": fact_name, "source": "fact"}) if isinstance(fact_value, Unknown) and default_value is not None: return default_value return fact_value