From 54fb258b0694d30770dec51b1833507fc82eb218 Mon Sep 17 00:00:00 2001 From: Corey Hammerton Date: Mon, 16 May 2016 20:00:35 -0400 Subject: [PATCH] puppetboard/app.py: Removing :func:`puppetboard/report_latest` (#237) This fixes https://github.com/voxpupuli/puppetboard/issues/234 The report_latest() function was effectively deprecated when PuppetDB introduced the latest_report_hash field in the Nodes endpoint response format in version 3.2. With the breaking changes to PuppetDB 4.0.0 support this function can be safely removed. --- puppetboard/app.py | 53 ------------------------------ puppetboard/templates/_macros.html | 6 +--- puppetboard/templates/index.html | 6 +--- puppetboard/templates/nodes.html | 6 +--- 4 files changed, 3 insertions(+), 68 deletions(-) diff --git a/puppetboard/app.py b/puppetboard/app.py index 57eca08..542d4f0 100644 --- a/puppetboard/app.py +++ b/puppetboard/app.py @@ -535,59 +535,6 @@ def reports_node(env, node_name, page): current_env=env) -@app.route('/report/latest/', defaults={'env': app.config['DEFAULT_ENVIRONMENT']}) -@app.route('//report/latest/') -def report_latest(env, node_name): - """Redirect to the latest report of a given node. - - :param env: Search for reports in this environment - :type env: :obj:`string` - :param node_name: Find the reports whose certname match this value - :type node_name: :obj:`string` - """ - envs = environments() - check_env(env, envs) - - if env == '*': - node_query = '["=", "certname", "{0}"]'.format(node_name) - else: - node_query = '["and",' \ - '["=", "report_environment", "{0}"],' \ - '["=", "certname", "{1}"]]'.format(env, node_name) - - try: - node = next(get_or_abort(puppetdb.nodes, - query=node_query, - with_status=True)) - except StopIteration: - abort(404) - - if node.latest_report_hash is not None: - hash_ = node.latest_report_hash - else: - if env == '*': - query='["and",' \ - '["=", "certname", "{0}"],' \ - '["=", "latest_report?", true]]'.format(node.name) - else: - query='["and",' \ - '["=", "environment", "{0}"],' \ - '["=", "certname", "{1}"],' \ - '["=", "latest_report?", true]]'.format( - env, - node.name) - - reports = get_or_abort(puppetdb.reports, query=query) - try: - report = next(reports) - hash_ = report.hash_ - except StopIteration: - abort(404) - - return redirect( - url_for('report', env=env, node_name=node_name, report_id=hash_)) - - @app.route('/report//', defaults={'env': app.config['DEFAULT_ENVIRONMENT']}) @app.route('//report//') def report(env, node_name, report_id): diff --git a/puppetboard/templates/_macros.html b/puppetboard/templates/_macros.html index 354cdfe..f1abedb 100644 --- a/puppetboard/templates/_macros.html +++ b/puppetboard/templates/_macros.html @@ -161,11 +161,7 @@ unchanged {% endif -%} label status" href=" - {% if report_hash -%} - {{url_for('report', env=current_env, node_name=node_name, report_id=report_hash)}} - {% else -%} - {{url_for('report_latest', env=current_env, node_name=node_name)}} - {% endif -%} + {{url_for('report', env=current_env, node_name=node_name, report_id=report_hash)}} "> {{ status|upper }} diff --git a/puppetboard/templates/index.html b/puppetboard/templates/index.html index 640dca6..1396173 100644 --- a/puppetboard/templates/index.html +++ b/puppetboard/templates/index.html @@ -89,11 +89,7 @@ {% if node.report_timestamp %} - {% if node.latest_report_hash %} - {{ node.report_timestamp }} - {% else %} - {{ node.report_timestamp }} - {% endif %} + {{ node.report_timestamp }} {% else %} {% endif %} diff --git a/puppetboard/templates/nodes.html b/puppetboard/templates/nodes.html index 2072d31..00d31bd 100644 --- a/puppetboard/templates/nodes.html +++ b/puppetboard/templates/nodes.html @@ -28,11 +28,7 @@ {{node.catalog_timestamp}} {% if node.report_timestamp %} - {% if node.latest_report_hash %} - {{ node.report_timestamp }} - {% else %} - {{ node.report_timestamp }} - {% endif %} + {{ node.report_timestamp }} {% else %} {% endif %}