- Make validation a bit nicer:

- Add timeout to the DB validation
  - Make DB validation exception handling a bit nicer
  - Move the DB validation error message

- Fix bug around RADOS config default for Is Secure
- Allow hiding of the validation box
This commit is contained in:
Joseph Schorr 2015-01-08 15:27:49 -05:00
parent 47fb10b79f
commit bfd273d16f
6 changed files with 56 additions and 20 deletions

View file

@ -71,7 +71,9 @@ db_random_func = CallableProxy()
def validate_database_url(url): def validate_database_url(url):
driver = _db_from_url(url, {}) driver = _db_from_url(url, {
'connect_timeout': 5
})
driver.connect() driver.connect()
driver.close() driver.close()

View file

@ -4924,3 +4924,8 @@ i.slack-icon {
vertical-align: middle; vertical-align: middle;
padding: 4px; padding: 4px;
} }
.modal-footer.alert {
text-align: left;
margin-bottom: -16px;
}

View file

@ -546,7 +546,7 @@
<div class="modal-header"> <div class="modal-header">
<h4 class="modal-title" <h4 class="modal-title"
ng-show="mapped.$hasChanges && validationStatus(validating) == 'validating'"> ng-show="mapped.$hasChanges && validationStatus(validating) == 'validating'">
Validating Configuration... Please Wait Validating Configuration...
</h4> </h4>
<h4 class="modal-title" <h4 class="modal-title"
ng-show="mapped.$hasChanges && validationStatus(validating) == 'failed'"> ng-show="mapped.$hasChanges && validationStatus(validating) == 'failed'">
@ -595,6 +595,13 @@
<div class="modal-footer" ng-show="mapped.$hasChanges"> <div class="modal-footer" ng-show="mapped.$hasChanges">
<span ng-show="validating.length == 0">Please Wait...</span> <span ng-show="validating.length == 0">Please Wait...</span>
<button class="btn btn-default"
ng-show="validationStatus(validating) == 'validating'"
ng-click="cancelValidation()">
Stop Validating
</button>
<button class="btn btn-primary" <button class="btn btn-primary"
ng-show="validationStatus(validating) == 'success'" ng-show="validationStatus(validating) == 'success'"
ng-click="saveConfiguration()" ng-click="saveConfiguration()"

View file

@ -110,6 +110,12 @@ angular.module("core-config-setup", ['angularFileUpload'])
return hasError ? 'failed' : 'success'; return hasError ? 'failed' : 'success';
}; };
$scope.cancelValidation = function() {
$('#validateAndSaveModal').modal('hide');
$scope.validating = null;
$scope.savingConfiguration = false;
};
$scope.validateService = function(serviceInfo) { $scope.validateService = function(serviceInfo) {
var params = { var params = {
'service': serviceInfo.service.id 'service': serviceInfo.service.id
@ -238,6 +244,7 @@ angular.module("core-config-setup", ['angularFileUpload'])
var allowedFields = $scope.STORAGE_CONFIG_FIELDS[value]; var allowedFields = $scope.STORAGE_CONFIG_FIELDS[value];
var configObject = $scope.config.DISTRIBUTED_STORAGE_CONFIG.local[1]; var configObject = $scope.config.DISTRIBUTED_STORAGE_CONFIG.local[1];
// Remove any fields not allowed.
for (var fieldName in configObject) { for (var fieldName in configObject) {
if (!configObject.hasOwnProperty(fieldName)) { if (!configObject.hasOwnProperty(fieldName)) {
continue; continue;
@ -251,6 +258,13 @@ angular.module("core-config-setup", ['angularFileUpload'])
delete configObject[fieldName]; delete configObject[fieldName];
} }
} }
// Set any boolean fields to false.
for (var i = 0; i < allowedFields.length; ++i) {
if (allowedFields[i].kind == 'bool') {
configObject[allowedFields[i].name] = false;
}
}
}); });
$scope.$watch('config', function(value) { $scope.$watch('config', function(value) {

View file

@ -348,10 +348,6 @@
Could not connect to or validate the database configuration found. Please reconfigure to continue. Could not connect to or validate the database configuration found. Please reconfigure to continue.
</div> </div>
<div class="alert alert-warning" ng-show="databaseInvalid">
Database Validation Issue: {{ databaseInvalid }}
</div>
<p> <p>
Please enter the connection details for your <strong>empty</strong> database. The schema will be created in the following step.</p> Please enter the connection details for your <strong>empty</strong> database. The schema will be created in the following step.</p>
</p> </p>
@ -369,33 +365,32 @@
</select> </select>
</td> </td>
</tr> </tr>
</table> <tr ng-show="fields.kind">
<table class="config-table" ng-show="fields.kind">
<tr>
<td>Database Server:</td> <td>Database Server:</td>
<td> <td>
<span class="config-string-field" binding="fields.server" <span class="config-string-field" binding="fields.server"
placeholder="The database server hostname"></span> placeholder="localhost"></span>
<div class="help-text">
The server (and optionally, custom port) where the database lives
</div>
</td> </td>
</tr> </tr>
<tr> <tr ng-show="fields.kind">
<td>Database Name:</td> <td>Database Name:</td>
<td> <td>
<span class="config-string-field" binding="fields.database" <span class="config-string-field" binding="fields.database"
placeholder="The name of the database on the server"></span> placeholder="registry-database"></span>
</td> </td>
</tr> </tr>
<tr ng-show="fields.kind">
<tr>
<td>Username:</td> <td>Username:</td>
<td> <td>
<span class="config-string-field" binding="fields.username" <span class="config-string-field" binding="fields.username"
placeholder="Username for accessing the database"></span> placeholder="someuser"></span>
<div class="help-text">The user must have full access to the database</div> <div class="help-text">This user must have <strong>full access</strong> to the database</div>
</td> </td>
</tr> </tr>
<tr> <tr ng-show="fields.kind">
<td>Password:</td> <td>Password:</td>
<td> <td>
<input class="form-control" type="password" ng-model="fields.password"></span> <input class="form-control" type="password" ng-model="fields.password"></span>
@ -404,6 +399,9 @@
</table> </table>
</div> </div>
</div> </div>
<div class="modal-footer alert alert-warning" ng-show="databaseInvalid">
Database Validation Issue: {{ databaseInvalid }}
</div>
<div class="modal-footer"> <div class="modal-footer">
<button type="submit" class="btn btn-primary" ng-disabled="!databaseUri" <button type="submit" class="btn btn-primary" ng-disabled="!databaseUri"
ng-click="validateDatabase()" ng-click="validateDatabase()"

View file

@ -2,6 +2,7 @@ import redis
import os import os
import json import json
import ldap import ldap
import peewee
from data.users import LDAPConnection from data.users import LDAPConnection
from flask import Flask from flask import Flask
@ -35,12 +36,21 @@ def validate_service_for_config(service, config):
def _validate_database(config): def _validate_database(config):
""" Validates connecting to the database. """ """ Validates connecting to the database. """
validate_database_url(config['DB_URI']) try:
validate_database_url(config['DB_URI'])
except peewee.OperationalError as ex:
if ex.args and len(ex.args) > 1:
raise Exception(ex.args[1])
else:
raise ex
def _validate_redis(config): def _validate_redis(config):
""" Validates connecting to redis. """ """ Validates connecting to redis. """
redis_config = config['BUILDLOGS_REDIS'] redis_config = config.get('BUILDLOGS_REDIS', {})
if not 'host' in redis_config:
raise Exception('Missing redis hostname')
client = redis.StrictRedis(socket_connect_timeout=5, **redis_config) client = redis.StrictRedis(socket_connect_timeout=5, **redis_config)
client.ping() client.ping()