Use Refstack API to get capabilities and versions

All capability versions listed on the capability page and
report page will now come from the API along with actual
capability content.

Change-Id: I1e39ef600c60cad7e0ada64a86fab48108fa51bf
This commit is contained in:
Paul Van Eck 2015-05-07 15:25:02 -07:00
parent 711f7527c4
commit 96558296aa
5 changed files with 103 additions and 57 deletions

View File

@ -1,7 +1,7 @@
<h3>DefCore Capabilities</h3>
<strong>Version:</strong>
<select ng-model="version" ng-change="update()">
<option value="2015.03">2015.03</option>
<option ng-repeat="versionFile in versionList" value="{{versionFile}}">{{versionFile.slice(0, -5)}}</option>
</select>
<br /><br />
<strong>Target Program:</strong>
@ -32,9 +32,11 @@
<span class="removed">Removed</span>
</label>
</div>
<p><small>Tests marked with <span class="flagged"></span> are tests flagged by DefCore.</small></p>
<p><small>Tests marked with <span class="glyphicon glyphicon-flag text-warning"></span> are tests flagged by DefCore.</small></p>
<ol class="capabilities">
<div cg-busy="{promise:versionsRequest,message:'Loading versions'}"></div>
<div cg-busy="{promise:capsRequest,message:'Loading capabilities'}"></div>
<ol ng-show="capabilities" class="capabilities">
<li class="capability-list-item" ng-repeat="capability in capabilities.capabilities | arrayConverter | filter:filterProgram | filter:filterStatus">
<span class="capability-name">{{capability.name}}</span><br />
<em>{{capability.description}}</em><br />
@ -55,9 +57,9 @@
</ul>
</li>
</ol>
<hr>
<div class="criteria">
<div ng-show="capabilities" class="criteria">
<hr>
<h4><a ng-click="hideCriteria = !hideCriteria">Criteria</a></h4>
<div collapse="hideCriteria">
<ul>
@ -69,4 +71,9 @@
</ul>
</div>
</div>
<br /><br />
<div ng-show="showError" class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Error:</span>
{{error}}
</div>

View File

@ -4,8 +4,7 @@
var refstackApp = angular.module('refstackApp');
refstackApp.controller('capabilitiesController', ['$scope', '$http', function($scope, $http) {
$scope.version = '2015.03';
refstackApp.controller('capabilitiesController', ['$scope', '$http', 'refstackApiUrl', function($scope, $http, refstackApiUrl) {
$scope.hideAchievements = true;
$scope.hideTests = true;
$scope.target = 'platform';
@ -16,20 +15,30 @@ refstackApp.controller('capabilitiesController', ['$scope', '$http', function($s
removed: ''
};
$scope.getVersionList = function() {
var content_url = refstackApiUrl + '/capabilities';
$scope.versionsRequest = $http.get(content_url).success(function(data) {
$scope.versionList = data.sort().reverse();
$scope.version = $scope.versionList[0];
$scope.update();
}).error(function(error) {
$scope.showError = true;
$scope.error = 'Error retrieving version list: ' + JSON.stringify(error);
});
};
$scope.update = function() {
// Rate-limiting is an issue with this URL. Using a local copy for now.
// var content_url = 'https://api.github.com/repos/openstack/defcore/contents/'.concat($scope.version, '.json');
var content_url = 'assets/capabilities/'.concat($scope.version, '.json');
$http.get(content_url).success(function(data) {
//$scope.data = data;
//$scope.capabilities = JSON.parse(atob($scope.data.content.replace(/\s/g, '')));
var content_url = refstackApiUrl + '/capabilities/' + $scope.version;
$scope.capsRequest = $http.get(content_url).success(function(data) {
$scope.capabilities = data;
}).error(function(error) {
console.log(error);
$scope.capabilities = 'Error retrieving capabilities.';
$scope.showError = true;
$scope.capabilities = null;
$scope.error = 'Error retrieving capabilities: ' + JSON.stringify(error);
});
}
$scope.update()
};
$scope.getVersionList();
$scope.filterProgram = function(capability){
var components = $scope.capabilities.components;

View File

@ -1,23 +1,26 @@
<h3>Test Run Results</h3>
<div cg-busy="{promise:resultsRequest,message:'Loading'}"></div>
<div ng-show="resultsData" class="test-report">
<strong>Test ID:</strong> {{testId}} <br />
<strong>Test ID:</strong> {{testId}}<br />
<strong>Upload Date:</strong> {{resultsData.created_at}} UTC<br />
<strong>Duration:</strong> {{resultsData.duration_seconds}} seconds<br />
<strong>Total Number of Passed Tests:</strong> {{resultsData.results.length}} <br />
<strong>Total Number of Passed Tests:</strong> {{resultsData.results.length}}<br />
<hr>
</div>
<div cg-busy="{promise:versionsRequest,message:'Loading versions'}"></div>
<div cg-busy="{promise:capsRequest,message:'Loading capabilities'}"></div>
<div cg-busy="{promise:resultsRequest,message:'Loading results'}"></div>
<div ng-show="capabilityData && resultsData">
<p>See how these results stack up against DefCore capabilities and OpenStack
<a target="_blank" href="http://www.openstack.org/brand/interop/">target marketing programs.</a>
</p>
<div class="row">
<div class="col-md-3">
<strong>Capabilities Version:</strong>
<select ng-model="version" ng-change="updateCapabilities()" class="form-control">
<option value="2015.03">2015.03</option>
<select ng-model="version" ng-change="update()" class="form-control">
<option ng-repeat="versionFile in versionList" value="{{versionFile}}">{{versionFile.slice(0, -5)}}</option>
</select>
</div>
<div class="col-md-4">
@ -29,9 +32,6 @@
</select>
</div>
</div>
</div>
<br />
<div ng-show="capabilityData && resultsData">
<strong>Status:</strong>
<div class="progress">
<div class="progress-bar"
@ -45,7 +45,7 @@
</div>
</div>
<p>This cloud passes <strong>{{caps.required.passedCount*100/caps.required.count | number:1}}% </strong>({{caps.required.passedCount}}/{{caps.required.count}})
of the <strong>{{version}}</strong> capability tests required by the <strong>{{targetMappings[target]}}</strong> program.</p>
of the <strong>{{version.slice(0, -5)}}</strong> capability tests required by the <strong>{{targetMappings[target]}}</strong> program.</p>
<h4>Capability Overview</h4>

View File

@ -7,7 +7,6 @@ var refstackApp = angular.module('refstackApp');
refstackApp.controller('resultsReportController', ['$scope', '$http', '$stateParams', 'refstackApiUrl',
function($scope, $http, $stateParams, refstackApiUrl) {
$scope.testId = $stateParams.testID
$scope.version = '2015.03';
$scope.hideTests = true;
$scope.target = 'platform';
$scope.requiredOpen = true;
@ -18,23 +17,38 @@ refstackApp.controller('resultsReportController', ['$scope', '$http', '$statePar
'object': 'OpenStack Powered Object Storage'
}
var content_url = refstackApiUrl +'/results/' + $scope.testId;
$scope.resultsRequest = $http.get(content_url).success(function(data) {
$scope.resultsData = data;
$scope.updateCapabilities();
}).error(function(error) {
$scope.showError = true;
$scope.resultsData = null;
$scope.error = "Error retrieving results from server: " + JSON.stringify(error);
var getResults = function() {
var content_url = refstackApiUrl +'/results/' + $scope.testId;
$scope.resultsRequest = $http.get(content_url).success(function(data) {
$scope.resultsData = data;
getVersionList();
}).error(function(error) {
$scope.showError = true;
$scope.resultsData = null;
$scope.error = "Error retrieving results from server: " + JSON.stringify(error);
});
});
};
var getVersionList = function() {
var content_url = refstackApiUrl + '/capabilities';
$scope.versionsRequest = $http.get(content_url).success(function(data) {
$scope.versionList = data.sort().reverse();
$scope.version = $scope.versionList[0];
$scope.updateCapabilities();
}).error(function(error) {
$scope.showError = true;
$scope.resultsData = null;
$scope.error = "Error retrieving version list: " + JSON.stringify(error);;
});
};
$scope.updateCapabilities = function() {
$scope.showError = false;
var content_url = 'assets/capabilities/'.concat($scope.version, '.json');
$http.get(content_url).success(function(data) {
var content_url = refstackApiUrl + '/capabilities/' + $scope.version;
$scope.capsRequest = $http.get(content_url).success(function(data) {
$scope.capabilityData = data;
$scope.buildCapabilityObject($scope.capabilityData, $scope.resultsData.results);
$scope.buildCapabilityObject();
}).error(function(error) {
$scope.showError = true;
$scope.capabilityData = null;
@ -87,5 +101,7 @@ refstackApp.controller('resultsReportController', ['$scope', '$http', '$statePar
});
$scope.caps = caps;
}
getResults();
}
]);

View File

@ -30,8 +30,14 @@ describe('Refstack controllers', function() {
});
describe('capabilitiesController', function() {
var scope, ctrl, $httpBackend;
beforeEach(module('refstackApp'));
var scope, ctrl, $httpBackend, refstackApiUrl;
var fakeApiUrl = "http://foo.bar/v1";
beforeEach(function() {
module('refstackApp');
module(function($provide) {
$provide.constant('refstackApiUrl', fakeApiUrl);
});
});
beforeEach(inject(function(_$httpBackend_, $rootScope, $controller) {
$httpBackend = _$httpBackend_;
@ -42,16 +48,18 @@ describe('Refstack controllers', function() {
it('should set default states', function() {
expect(scope.hideAchievements).toBe(true);
expect(scope.hideTests).toBe(true);
expect(scope.version).toBe('2015.03');
expect(scope.target).toBe('platform');
expect(scope.status).toEqual({required: 'required', advisory: '',
deprecated: '', removed: ''});
});
it('should fetch the selected capabilities version', function() {
$httpBackend.expectGET('assets/capabilities/2015.03.json').respond({'foo': 'bar'});
$httpBackend.expectGET(fakeApiUrl+'/capabilities').respond(['2015.03.json', '2015.04.json']);
// Should call request with latest version.
$httpBackend.expectGET(fakeApiUrl+'/capabilities/2015.04.json').respond({'foo': 'bar'});
$httpBackend.flush();
// The version list should be sorted latest first.
expect(scope.versionList).toEqual(['2015.04.json', '2015.03.json']);
expect(scope.capabilities).toEqual({'foo': 'bar'});
});
@ -94,6 +102,7 @@ describe('Refstack controllers', function() {
describe('resultsController', function() {
var scope, ctrl, $httpBackend, refstackApiUrl;
var fakeApiUrl = "http://foo.bar/v1";
var fakeResponse = {'pagination': {'current_page': 1, 'total_pages': 2},
'results': [{'created_at': '2015-03-09 01:23:45',
'test_id': 'some-id',
@ -102,7 +111,7 @@ describe('Refstack controllers', function() {
beforeEach(function() {
module('refstackApp');
module(function($provide) {
$provide.constant('refstackApiUrl', 'http://foo.bar/v1');
$provide.constant('refstackApiUrl', fakeApiUrl);
});
});
@ -114,7 +123,7 @@ describe('Refstack controllers', function() {
it('should fetch the first page of results with proper URL args', function() {
// Initial results should be page 1 of all results.
$httpBackend.expectGET('http://foo.bar/v1/results?page=1').respond(fakeResponse);
$httpBackend.expectGET(fakeApiUrl+'/results?page=1').respond(fakeResponse);
$httpBackend.flush();
expect(scope.data).toEqual(fakeResponse);
expect(scope.currentPage).toBe(1);
@ -123,14 +132,14 @@ describe('Refstack controllers', function() {
scope.startDate = new Date('2015-03-10T11:51:00');
scope.endDate = new Date('2015-04-10T11:51:00');
scope.update();
$httpBackend.expectGET('http://foo.bar/v1/results?page=1&start_date=2015-03-10 00:00:00&end_date=2015-04-10 23:59:59').respond(fakeResponse);
$httpBackend.expectGET(fakeApiUrl+'/results?page=1&start_date=2015-03-10 00:00:00&end_date=2015-04-10 23:59:59').respond(fakeResponse);
$httpBackend.flush();
expect(scope.data).toEqual(fakeResponse);
expect(scope.currentPage).toBe(1);
});
it('should set an error when results cannot be retrieved', function() {
$httpBackend.expectGET('http://foo.bar/v1/results?page=1').respond(404, {'detail': 'Not Found'});
$httpBackend.expectGET(fakeApiUrl+'/results?page=1').respond(404, {'detail': 'Not Found'});
$httpBackend.flush();
expect(scope.data).toBe(null);
expect(scope.error).toEqual('Error retrieving results listing from server: {"detail":"Not Found"}');
@ -139,13 +148,13 @@ describe('Refstack controllers', function() {
});
it('should have an function to clear filters and update the view', function() {
$httpBackend.expectGET('http://foo.bar/v1/results?page=1').respond(fakeResponse);
$httpBackend.expectGET(fakeApiUrl+'/results?page=1').respond(fakeResponse);
scope.startDate = "some date";
scope.endDate = "some other date";
scope.clearFilters();
expect(scope.startDate).toBe(null);
expect(scope.endDate).toBe(null);
$httpBackend.expectGET('http://foo.bar/v1/results?page=1').respond(fakeResponse);
$httpBackend.expectGET(fakeApiUrl+'/results?page=1').respond(fakeResponse);
$httpBackend.flush();
expect(scope.data).toEqual(fakeResponse);
});
@ -153,6 +162,7 @@ describe('Refstack controllers', function() {
describe('resultsReportController', function() {
var scope, ctrl, $httpBackend, refstackApiUrl, stateparams;
var fakeApiUrl = "http://foo.bar/v1";
var fakeResultResponse = {'results': ['test_id_1']}
var fakeCapabilityResponse = {'platform': {'required': ['compute']},
'components': {
@ -175,7 +185,7 @@ describe('Refstack controllers', function() {
beforeEach(function() {
module('refstackApp');
module(function($provide) {
$provide.constant('refstackApiUrl', 'http://foo.bar/v1');
$provide.constant('refstackApiUrl', fakeApiUrl);
});
});
@ -186,11 +196,15 @@ describe('Refstack controllers', function() {
ctrl = $controller('resultsReportController', {$scope: scope, $stateParams: stateparams});
}));
it('should get the results for a specific test ID and also the relevant capabilities', function() {
$httpBackend.expectGET('http://foo.bar/v1/results/1234').respond(fakeResultResponse);
$httpBackend.expectGET('assets/capabilities/2015.03.json').respond(fakeCapabilityResponse);
it('should make all necessary API requests to get results and capabilities', function() {
$httpBackend.expectGET(fakeApiUrl+'/results/1234').respond(fakeResultResponse);
$httpBackend.expectGET(fakeApiUrl+'/capabilities').respond(['2015.03.json', '2015.04.json']);
// Should call request with latest version.
$httpBackend.expectGET(fakeApiUrl+'/capabilities/2015.04.json').respond(fakeCapabilityResponse);
$httpBackend.flush();
expect(scope.resultsData).toEqual(fakeResultResponse);
// The version list should be sorted latest first.
expect(scope.versionList).toEqual(['2015.04.json', '2015.03.json']);
expect(scope.capabilityData).toEqual(fakeCapabilityResponse);
});