summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenan Rodrigo <rebarbos@redhat.com>2019-09-30 11:33:47 +0200
committerMartin Styk <mastyk@redhat.com>2019-11-07 09:10:10 +0000
commit4ba9640871914a49784a2ea15b8ef6fb04260ce9 (patch)
treefcfdc1abaf06daa238c92fa2735fd650381fb5ba
parentc26dbf8595458c5b5ded6bcc0328180a7480212c (diff)
Add warning about lab controllers to distro-picker
Add a warning about unsupported lab controllers for a given distro tree when it's selected in the reserve workflow. Bug: 662517 Change-Id: Ic2016b0766f731b18949d28ebed653c7e06963cc
-rw-r--r--Server/assets/distro-picker.js33
-rw-r--r--Server/assets/jst/distro-picker.html9
-rw-r--r--Server/bkr/server/reserve_workflow.py24
3 files changed, 63 insertions, 3 deletions
diff --git a/Server/assets/distro-picker.js b/Server/assets/distro-picker.js
index c8e9486..cca04fc 100644
--- a/Server/assets/distro-picker.js
+++ b/Server/assets/distro-picker.js
@@ -16,6 +16,7 @@ window.DistroPicker = Backbone.View.extend({
'change select': 'update_state',
'change select.distro_filter_criterion': 'get_distros',
'change select.distro_tree_filter_criterion': 'get_distro_trees',
+ 'change select.unsupported_lab_controllers_filter_criterion': 'get_unsupported_lab_controllers',
},
initialize: function (options) {
_.defaults(options, {multiple: true, selection: {}});
@@ -111,6 +112,38 @@ window.DistroPicker = Backbone.View.extend({
});
select.change();
},
+ get_unsupported_lab_controllers: function () {
+ if (this.get_unsupported_lab_controllers_xhr)
+ this.get_unsupported_lab_controllers_xhr.abort();
+ if (this.$('select[name=distro_tree_id]').val()) {
+ var loading = $('<span><i class="fa fa-spinner fa-spin"></i> Loading&hellip;</span>');
+ this.$('div.lab-controller-warning').after(loading);
+ var xhr = this.get_unsupported_lab_controllers_xhr = $.ajax({
+ url: beaker_url_prefix +
+ 'reserveworkflow/unsupported-lab-controllers?' +
+ this.$('.unsupported_lab_controllers_filter_criterion').serialize(),
+ dataType: 'json',
+ });
+ xhr.done(_.bind(this.replace_unsupported_lab_controllers, this));
+ xhr.always(function () { loading.remove() ; });
+ } else {
+ // shortcut
+ this.replace_unsupported_lab_controllers({options: []});
+ }
+ },
+ replace_unsupported_lab_controllers: function (result) {
+ var warningDiv = this.$('div.lab-controller-warning');
+ warningDiv.empty();
+ for(var option in result.options){
+ var options = result.options[option]
+ if(options.length){
+ warningDiv.append($('<strong>').text("The distro tree you have selected (" + option + ") is not available in the following lab controllers:"));
+ for(var labControllerFQDN in options){
+ warningDiv.append($('<p>').text(options[labControllerFQDN]));
+ }
+ }
+ }
+ },
});
window.DistroPickerModal = Backbone.View.extend({
diff --git a/Server/assets/jst/distro-picker.html b/Server/assets/jst/distro-picker.html
index 8f77edd..3c5ea7b 100644
--- a/Server/assets/jst/distro-picker.html
+++ b/Server/assets/jst/distro-picker.html
@@ -43,7 +43,7 @@
<div class="control-group">
<label class="control-label" for="distro_tree_id">Distro Tree</label>
<div class="controls">
- <select id="distro_tree_id" name="distro_tree_id" class="input-xxlarge"
+ <select id="distro_tree_id" name="distro_tree_id" class="unsupported_lab_controllers_filter_criterion input-xxlarge"
<% if (this.multiple) { %>multiple size="7"<% } %>
>
<% _.each(distro_trees, function (distro_tree) { %>
@@ -54,3 +54,10 @@
</select>
</div>
</div>
+<div class="control-group">
+ <label class="control-label" for="lab-controller-warning"></label>
+ <div class="controls">
+ <div class="lab-controller-warning">
+ </div>
+ </div>
+</div>
diff --git a/Server/bkr/server/reserve_workflow.py b/Server/bkr/server/reserve_workflow.py
index 2d5c808..cc34162 100644
--- a/Server/bkr/server/reserve_workflow.py
+++ b/Server/bkr/server/reserve_workflow.py
@@ -5,14 +5,16 @@
# (at your option) any later version.
from turbogears import expose
-from flask import request
+from flask import request, jsonify
+from sqlalchemy import and_, not_
from sqlalchemy.orm.exc import NoResultFound
from bkr.server import identity
from bkr.server.app import app
from bkr.server.flask_util import BadRequest400, \
convert_internal_errors, auth_required
from bkr.server.model import (Distro, Job, System, Arch, OSMajor, DistroTag,
- SystemType, OSVersion, DistroTree, LabController, MachineRecipe)
+ SystemType, OSVersion, DistroTree, LabControllerDistroTree,
+ LabController, MachineRecipe)
from bkr.server.bexceptions import DatabaseLookupError
from bkr.server.util import absolute_url
from bkr.server.bexceptions import DatabaseLookupError
@@ -67,6 +69,24 @@ def doit():
job = Job.provision_system_job(distro_trees, **job_details)
return 'Created %s' % job.t_id, 201, [('Location', absolute_url('/jobs/%s' % job.id))]
+@app.route('/reserveworkflow/unsupported-lab-controllers', methods=['GET'])
+def get_unsupported_lab_controllers():
+ """
+ Returns a dict with a list of not supported lab controller for every distro tree provided.
+ """
+ distro_tree_ids = request.args.getlist('distro_tree_id')
+ unsupported_lab_controllers = {}
+ for distro_tree_id in distro_tree_ids:
+ try:
+ name = str(DistroTree.query.filter(DistroTree.id == distro_tree_id).one())
+ unsupported_lab_controllers[name] = [lab_controller.fqdn for lab_controller in
+ LabController.query.filter(and_(LabController.disabled == 0,
+ not_(LabController._distro_trees.any(LabControllerDistroTree.distro_tree_id == distro_tree_id)))).all()]
+ except DatabaseLookupError:
+ pass
+
+ return jsonify({'options': unsupported_lab_controllers})
+
class ReserveWorkflow:
@identity.require(identity.not_anonymous())