Add UI support for interop schema 2.0

New schema[1] will be released soon, so RefStack UI needs
to be able to handle it.

[1] https://review.openstack.org/#/c/430556

Change-Id: Ifdfe40c12a7a97ff742ed15aeb5d9ce399ee3cb1
This commit is contained in:
Paul Van Eck 2017-07-17 22:10:06 -07:00
parent c9bc0987af
commit 88e42fe9a3
8 changed files with 333 additions and 26 deletions

View File

@ -25,13 +25,13 @@
<br />
<div ng-if="ctrl.guidelines">
<strong>Guideline Status:</strong>
{{ctrl.guidelines.status | capitalize}}
{{ctrl.guidelineStatus | capitalize}}
</div>
<div ng-show="ctrl.guidelines">
<strong>Corresponding OpenStack Releases:</strong>
<ul class="list-inline">
<li ng-repeat="release in ctrl.guidelines.releases">
<li ng-repeat="release in ctrl.releases">
{{release | capitalize}}
</li>
</ul>

View File

@ -87,7 +87,22 @@
ctrl.capsRequest =
$http.get(content_url).success(function (data) {
ctrl.guidelines = data;
if ('metadata' in data && data.metadata.schema >= '2.0') {
ctrl.schema = data.metadata.schema;
ctrl.criteria = data.metadata.scoring.criteria;
ctrl.releases =
data.metadata.os_trademark_approval.releases;
ctrl.guidelineStatus =
data.metadata.os_trademark_approval.status;
}
else {
ctrl.schema = data.schema;
ctrl.criteria = data.criteria;
ctrl.releases = data.releases;
ctrl.guidelineStatus = data.status;
}
ctrl.updateTargetCapabilities();
}).error(function (error) {
ctrl.showError = true;
ctrl.guidelines = null;
@ -110,8 +125,24 @@
// The 'platform' target is comprised of multiple components, so
// we need to get the capabilities belonging to each of its
// components.
if (ctrl.target === 'platform') {
var platform_components = ctrl.guidelines.platform.required;
if (ctrl.target === 'platform' || ctrl.schema >= '2.0') {
if (ctrl.schema >= '2.0') {
var platformsMap = {
'platform': 'OpenStack Powered Platform',
'compute': 'OpenStack Powered Compute',
'object': 'OpenStack Powered Storage'
};
var targetComponents = ctrl.guidelines.platforms[
platformsMap[ctrl.target]].components.map(
function(c) {
return c.name;
}
);
}
else {
var targetComponents = ctrl.guidelines.platform.required;
}
// This will contain status priority values, where lower
// values mean higher priorities.
@ -123,9 +154,13 @@
};
// For each component required for the platform program.
angular.forEach(platform_components, function (component) {
angular.forEach(targetComponents, function (component) {
// Get each capability list belonging to each status.
angular.forEach(components[component],
var componentList = components[component];
if (ctrl.schema >= '2.0') {
componentList = componentList.capabilities;
}
angular.forEach(componentList,
function (caps, status) {
// For each capability.
angular.forEach(caps, function(cap) {

View File

@ -19,11 +19,11 @@ variable 'guidelines'.
<a ng-click="showTests = !showTests">Tests ({{ctrl.getObjectLength(capability.tests)}})</a>
<ul uib-collapse="!showTests">
<li ng-if="ctrl.guidelines.schema === '1.2'" ng-repeat="test in capability.tests">
<li ng-if="ctrl.schema === '1.2'" ng-repeat="test in capability.tests">
<span ng-class="{'glyphicon glyphicon-flag text-warning': capability.flagged.indexOf(test) > -1}"></span>
{{test}}
</li>
<li ng-if="ctrl.guidelines.schema > '1.2'" ng-repeat="(testName, testDetails) in capability.tests">
<li ng-if="ctrl.schema > '1.2'" ng-repeat="(testName, testDetails) in capability.tests">
<span ng-class="{'glyphicon glyphicon-flag text-warning': testDetails.flagged}" title="{{testDetails.flagged.reason}}"></span>
{{testName}}
<div class="test-detail" ng-if="testDetails.aliases">
@ -35,14 +35,14 @@ variable 'guidelines'.
</li>
</ol>
<div ng-show="ctrl.guidelines" class="criteria">
<div ng-show="ctrl.criteria" class="criteria">
<hr>
<h4><a ng-click="showCriteria = !showCriteria">Criteria</a></h4>
<div uib-collapse="showCriteria">
<ul>
<li ng-repeat="(key, criterion) in ctrl.guidelines.criteria">
<li ng-repeat="(key, criterion) in ctrl.criteria">
<span class="criterion-name">{{criterion.name}}</span><br />
<em>{{criterion.Description}}</em><br />
<em>{{criterion.Description || criterion.description}}</em><br />
Weight: {{criterion.weight}}
</li>
</ul>

View File

@ -93,12 +93,12 @@
<br />
<div ng-if="ctrl.guidelineData">
<strong>Guideline Status:</strong>
{{ctrl.guidelineData.status | capitalize}}
{{ctrl.guidelineStatus | capitalize}}
</div>
<strong>Corresponding OpenStack Releases:</strong>
<ul class="list-inline">
<li ng-repeat="release in ctrl.guidelineData.releases">
<li ng-repeat="release in ctrl.releases">
{{release | capitalize}}
</li>
</ul>

View File

@ -228,7 +228,18 @@
ctrl.capsRequest =
$http.get(content_url).success(function (data) {
ctrl.guidelineData = data;
ctrl.schemaVersion = data.schema;
if ('metadata' in data && data.metadata.schema >= '2.0') {
ctrl.schemaVersion = data.metadata.schema;
ctrl.guidelineStatus =
data.metadata.os_trademark_approval.status;
ctrl.releases =
data.metadata.os_trademark_approval.releases;
}
else {
ctrl.schemaVersion = data.schema;
ctrl.guidelineStatus = data.status;
ctrl.releases = data.releases;
}
ctrl.buildCapabilitiesObject();
}).error(function (error) {
ctrl.showError = true;
@ -250,9 +261,24 @@
// The 'platform' target is comprised of multiple components, so
// we need to get the capabilities belonging to each of its
// components.
if (ctrl.target === 'platform') {
var platform_components =
ctrl.guidelineData.platform.required;
if (ctrl.target === 'platform' || ctrl.schemaVersion >= '2.0') {
if (ctrl.schemaVersion >= '2.0') {
var platformsMap = {
'platform': 'OpenStack Powered Platform',
'compute': 'OpenStack Powered Compute',
'object': 'OpenStack Powered Storage'
};
var targetComponents = ctrl.guidelineData.platforms[
platformsMap[ctrl.target]].components.map(
function(c) {
return c.name;
}
);
}
else {
var targetComponents = ctrl.guidelineData.platform.required;
}
// This will contain status priority values, where lower
// values mean higher priorities.
@ -264,9 +290,13 @@
};
// For each component required for the platform program.
angular.forEach(platform_components, function (component) {
angular.forEach(targetComponents, function (component) {
var componentList = components[component];
if (ctrl.schemaVersion >= '2.0') {
componentList = componentList.capabilities;
}
// Get each capability list belonging to each status.
angular.forEach(components[component],
angular.forEach(componentList,
function (caps, status) {
// For each capability.
angular.forEach(caps, function(cap) {
@ -422,6 +452,7 @@
case '1.4':
case '1.5':
case '1.6':
case '2.0':
capMethod = 'buildCapabilityV1_3';
break;
default:

View File

@ -146,7 +146,7 @@ describe('Refstack controllers', function () {
'2015.03.json']);
expect(ctrl.guidelines).toEqual(fakeCaps);
// The guideline status should be approved.
expect(ctrl.guidelines.status).toEqual('approved');
expect(ctrl.guidelineStatus).toEqual('approved');
var expectedTargetCaps = {
'cap_id_1': 'required',
'cap_id_2': 'advisory',
@ -156,6 +156,75 @@ describe('Refstack controllers', function () {
expect(ctrl.targetCapabilities).toEqual(expectedTargetCaps);
});
it('should be able to handle guidelines using schema 2.0',
function () {
var fakeCaps = {
'metadata': {
'id': '2017.08',
'schema': '2.0',
'scoring': {},
'os_trademark_approval': {
'target_approval': '2017.08',
'replaces': '2017.01',
'releases': ['newton', 'ocata', 'pike'],
'status': 'approved'
}
},
'platforms': {
'OpenStack Powered Platform': {
'description': 'foo bar',
'components': [
{ 'name': 'os_powered_compute' },
{ 'name': 'os_powered_storage' }
]
}
},
'components': {
'os_powered_compute': {
'capabilities': {
'required': ['cap_id_1'],
'advisory': ['cap_id_2'],
'deprecated': ['cap_id_3'],
'removed': ['cap_id_4']
}
},
'os_powered_storage': {
'capabilities': {
'required': ['cap_id_5'],
'advisory': ['cap_id_6'],
'deprecated': ['cap_id_7'],
'removed': ['cap_id_8']
}
}
}
};
$httpBackend.expectGET(fakeApiUrl +
'/guidelines').respond(['next.json', '2015.03.json',
'2017.08.json']);
// Should call request with latest version.
$httpBackend.expectGET(fakeApiUrl +
'/guidelines/2017.08.json').respond(fakeCaps);
$httpBackend.flush();
ctrl.update();
// The version list should be sorted latest first.
expect(ctrl.guidelines).toEqual(fakeCaps);
// The guideline status should be approved.
expect(ctrl.guidelineStatus).toEqual('approved');
var expectedTargetCaps = {
'cap_id_1': 'required',
'cap_id_2': 'advisory',
'cap_id_3': 'deprecated',
'cap_id_4': 'removed',
'cap_id_5': 'required',
'cap_id_6': 'advisory',
'cap_id_7': 'deprecated',
'cap_id_8': 'removed'
};
expect(ctrl.targetCapabilities).toEqual(expectedTargetCaps);
});
it('should have a function to check if a capability status is selected',
function () {
ctrl.targetCapabilities = {
@ -497,6 +566,63 @@ describe('Refstack controllers', function () {
expect(ctrl.getTargetCapabilities()).toEqual(expected);
});
it('should be able create an object containing each relevant' +
'capability and its highest priority status for schema 2.0',
function () {
ctrl.schemaVersion = '2.0';
ctrl.guidelineData = {
'metadata': {
'id': '2017.08',
'schema': '2.0',
'scoring': {},
'os_trademark_approval': {
'target_approval': '2017.08',
'replaces': '2017.01',
'releases': ['newton', 'ocata', 'pike'],
'status': 'approved'
}
},
'platforms': {
'OpenStack Powered Platform': {
'description': 'foo bar',
'components': [
{ 'name': 'os_powered_compute' },
{ 'name': 'os_powered_storage' }
]
}
},
'components': {
'os_powered_compute': {
'capabilities': {
'required': ['cap_id_1'],
'advisory': ['cap_id_2'],
'deprecated': ['cap_id_3'],
'removed': ['cap_id_4']
}
},
'os_powered_storage': {
'capabilities': {
'required': ['cap_id_5'],
'advisory': ['cap_id_6'],
'deprecated': ['cap_id_7'],
'removed': ['cap_id_8']
}
}
}
};
var expected = {
'cap_id_1': 'required',
'cap_id_2': 'advisory',
'cap_id_3': 'deprecated',
'cap_id_4': 'removed',
'cap_id_5': 'required',
'cap_id_6': 'advisory',
'cap_id_7': 'deprecated',
'cap_id_8': 'removed'
};
expect(ctrl.getTargetCapabilities()).toEqual(expected);
});
it('should be able to sort the results into a capability object for ' +
'schema version 1.2',
function () {

View File

@ -110,15 +110,32 @@ class Guidelines:
are given. If not target is specified, then all capabilities are given.
"""
components = guideline_json['components']
targets = set()
if target != 'platform':
targets.add(target)
if ('metadata' in guideline_json and
guideline_json['metadata']['schema'] >= '2.0'):
schema = guideline_json['metadata']['schema']
platformsMap = {
'platform': 'OpenStack Powered Platform',
'compute': 'OpenStack Powered Compute',
'object': 'OpenStack Powered Storage'
}
comps = \
guideline_json['platforms'][platformsMap[target]]['components']
targets = (obj['name'] for obj in comps)
else:
targets.update(guideline_json['platform']['required'])
schema = guideline_json['schema']
targets = set()
if target != 'platform':
targets.add(target)
else:
targets.update(guideline_json['platform']['required'])
target_caps = set()
for component in targets:
for status, capabilities in components[component].items():
complist = components[component]
if schema >= '2.0':
complist = complist['capabilities']
for status, capabilities in complist.items():
if types is None or status in types:
target_caps.update(capabilities)
@ -134,7 +151,11 @@ class Guidelines:
included in the list.
"""
caps = guideline_json['capabilities']
schema = guideline_json['schema']
if ('metadata' in guideline_json and
guideline_json['metadata']['schema'] >= '2.0'):
schema = guideline_json['metadata']['schema']
else:
schema = guideline_json['schema']
test_list = []
for cap, cap_details in caps.items():
if cap in capabilities:

View File

@ -91,6 +91,67 @@ class GuidelinesTestCase(base.BaseTestCase):
def test_get_target_capabilities(self):
"""Test getting relevant capabilities."""
# Schema version 2.0
json = {
'metadata': {
'id': '2017.08',
'schema': '2.0',
'scoring': {},
'os_trademark_approval': {
'target_approval': '2017.08',
'replaces': '2017.01',
'releases': ['newton', 'ocata', 'pike'],
'status': 'approved'
}
},
'platforms': {
'OpenStack Powered Platform': {
'description': 'foo platform',
'components': [
{'name': 'os_powered_compute'},
{'name': 'os_powered_storage'}
]
},
'OpenStack Powered Storage': {
'description': 'foo storage',
'components': [
{'name': 'os_powered_storage'}
]
},
},
'components': {
'os_powered_compute': {
'capabilities': {
'required': ['cap_id_1'],
'advisory': ['cap_id_2'],
'deprecated': ['cap_id_3'],
'removed': []
}
},
'os_powered_storage': {
'capabilities': {
'required': ['cap_id_5'],
'advisory': ['cap_id_6'],
'deprecated': [],
'removed': []
}
}
}
}
caps = self.guidelines.get_target_capabilities(json)
expected = sorted(['cap_id_1', 'cap_id_2', 'cap_id_3',
'cap_id_5', 'cap_id_6'])
self.assertEqual(expected, sorted(caps))
caps = self.guidelines.get_target_capabilities(json,
types=['required'],
target='object')
expected = ['cap_id_5']
self.assertEqual(expected, caps)
# Schema version 1.4
json = {
'platform': {'required': ['compute', 'object']},
'schema': '1.4',
@ -124,6 +185,39 @@ class GuidelinesTestCase(base.BaseTestCase):
def test_get_test_list(self):
"""Test when getting the guideline test list."""
# Schema version 2.0
json = {
'metadata': {
'schema': '2.0',
},
'capabilities': {
'cap-1': {
'tests': {
'test_1': {'idempotent_id': 'id-1234'},
'test_2': {'idempotent_id': 'id-5678',
'aliases': ['test_2_1']},
'test_3': {'idempotent_id': 'id-1111',
'flagged': {'reason': 'foo'}}
}
},
'cap-2': {
'tests': {
'test_4': {'idempotent_id': 'id-1233'}
}
}
}
}
tests = self.guidelines.get_test_list(json, ['cap-1'])
expected = ['test_1[id-1234]', 'test_2[id-5678]',
'test_2_1[id-5678]', 'test_3[id-1111]']
self.assertEqual(expected, tests)
tests = self.guidelines.get_test_list(json, ['cap-1'],
alias=False, show_flagged=False)
expected = ['test_1[id-1234]', 'test_2[id-5678]']
self.assertEqual(expected, tests)
# Schema version 1.4
json = {
'schema': '1.4',