aboutsummaryrefslogtreecommitdiffstats
path: root/3rd_party/static/testapi-ui/components/results-report/resultsReportController.js
blob: ea8fdedbf9bd900f6176d8376fc474d8de7f4477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

(function () {
    'use strict';

    angular
        .module('testapiApp')
        .controller('ResultsReportController', ResultsReportController);

    ResultsReportController.$inject = [
        '$scope', '$http', '$stateParams', '$window',
        '$uibModal', 'testapiApiUrl', 'raiseAlert'
    ];

    /**
     * TestAPI Results Report Controller
     * This controller is for the '/results/<test run ID>' page where a user can
     * view details for a specific test run.
     */
    function ResultsReportController($scope, $http, $stateParams, $window,
        $uibModal, testapiApiUrl, raiseAlert) {

        var ctrl = this;

        ctrl.testStatus = 'total';
        ctrl.case_list = [];
        ctrl.case_list_skip = [];
        ctrl.case_list_fail = [];
        ctrl.data = {};
        ctrl.statistics = {
            'total': 0, 'pass': 0, 'fail': 0, 'skip': 0,
            'mandatory': {'total': 0, 'pass': 0, 'fail': 0, 'skip': 0, 'area': 0},
            'optional': {'total': 0, 'pass': 0, 'fail': 0, 'skip': 0, 'area': 0}
        };

        ctrl.gotoDoc = gotoDoc;
        ctrl.openAll = openAll;
        ctrl.folderAll = folderAll;
        ctrl.gotoResultLog = gotoResultLog;
        ctrl.changeStatus = changeStatus;

        /** The testID extracted from the URL route. */
        ctrl.testId = $stateParams.testID;
        ctrl.innerId = $stateParams.innerID;
        ctrl.validation = '';
        ctrl.version = '';

        /** The HTML template that all accordian groups will use. */
        ctrl.detailsTemplate = 'testapi-ui/components/results-report/partials/' +
                               'reportDetails.html';

        $scope.load_finish = false;

        function changeStatus(value){
            ctrl.testStatus = value;
        }

        function extend(case_list) {
            angular.forEach(case_list, function(ele){
                ctrl.case_list.push(ele);
            });
        }

        function extend_skip(case_list_skip) {
            angular.forEach(case_list_skip, function(ele){
                ctrl.case_list_skip.push(ele);
            });
        }

        function extend_fail(case_list_fail) {
            angular.forEach(case_list_fail, function(ele){
                ctrl.case_list_fail.push(ele);
            });
        }

        function strip(word) {
              return word.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
        }

        function gotoResultLog(case_name) {
            function openFile(log_url) {
                var is_reachable = false;

                $.ajax({
                    url: log_url,
                    async: false,
                    success: function (response) {
                        is_reachable = true;
                    },
                    error: function (response){
                        alert("Log file could not be found. Please confirm this case has been executed successfully.");
                    }
                });

                if(is_reachable == true){
                    window.open(log_url);
                }
            }

            var log_url = "/logs/"+ctrl.testId+"/results/";
            var case_area = case_name.split(".")[1];
            if (ctrl.version == '2018.01') {
                if (case_area == "vping") {
                    log_url += "functest.log";
                } else if (case_area == "ha") {
                    log_url += "yardstick.log";
                } else {
                    log_url += case_area+"_logs/"+case_name+".log";
                }
                openFile(log_url);
            } else if (ctrl.version == '2018.09') {
                log_url += case_area + "_logs/";
                if (case_area == "tempest" || case_area == "security") {
                    log_url += case_name + ".html";
                } else {
                    log_url += case_name + ".log";
                }
                openFile(log_url);
            } else {
                var test_url = testapiApiUrl + '/tests/' + ctrl.innerId;
                $http.get(test_url).then(function(test_resp){
                    var result_url = testapiApiUrl + '/results/' + test_resp.data.results[0];
                    $http.get(result_url).then(function(result_resp){
                        var keepGoing = true;
                        angular.forEach(result_resp.data.testcases_list, function(testcase, index) {
                            if (keepGoing == true) {
                                if (testcase.name == case_name) {
                                    log_url += testcase.portal_key_file;
                                    openFile(log_url);
                                    keepGoing = false;
                                }
                            }
                        });
                        if (keepGoing == true) {
                            alert("Log file could not be found. Please confirm this case has been executed successfully.");
                        }
                    }, function(result_error) {
                        alert('Error when get result record');
                    });
                }, function(test_error) {
                    alert('Error when get test record');
                });
            }
        }

        $scope.$watch('load_finish', function(){
            if($scope.load_finish == true){
                var case_url = 'testapi-ui/components/results-report/data/' + ctrl.version + '/testcases.json'
                $http.get(case_url).then(function(response){
                    ctrl.data = response.data;

                    angular.forEach(ctrl.data.mandatory, function(value, name){
                        ctrl.data.mandatory[name].folder = true;
                        ctrl.data.mandatory[name].pass = 0;
                        ctrl.data.mandatory[name].fail = 0;
                        ctrl.data.mandatory[name].skip = 0;
                        angular.forEach(value.cases, function(sub_case){
                            ctrl.statistics.total += 1;
                            ctrl.statistics.mandatory.total += 1;
                            if(ctrl.case_list.indexOf(sub_case) > -1){
                                ctrl.data.mandatory[name].pass += 1;
                                ctrl.statistics.mandatory.pass += 1;
                                ctrl.statistics.pass += 1;
                            }else if(ctrl.case_list_skip.indexOf(sub_case) > -1){
                                ctrl.data.mandatory[name].skip += 1;
                                ctrl.statistics.mandatory.skip += 1;
                                ctrl.statistics.skip += 1;
                            }else {
                                ctrl.data.mandatory[name].fail += 1;
                                ctrl.statistics.mandatory.fail += 1;
                                ctrl.statistics.fail += 1;
                            }

                        });
                    });

                    angular.forEach(ctrl.data.optional, function(value, name){
                        ctrl.data.optional[name].folder = true;
                        ctrl.data.optional[name].pass = 0;
                        ctrl.data.optional[name].fail = 0;
                        ctrl.data.optional[name].skip = 0;
                        angular.forEach(value.cases, function(sub_case){
                            ctrl.statistics.total += 1;
                            ctrl.statistics.optional.total += 1;
                            if(ctrl.case_list.indexOf(sub_case) > -1){
                                ctrl.data.optional[name].pass += 1;
                                ctrl.statistics.optional.pass += 1;
                                ctrl.statistics.pass += 1;
                            }else if(ctrl.case_list_skip.indexOf(sub_case) > -1){
                                ctrl.data.optional[name].skip += 1;
                                ctrl.statistics.optional.skip += 1;
                                ctrl.statistics.skip += 1;
                            }else {
                                ctrl.data.optional[name].fail += 1;
                                ctrl.statistics.optional.fail += 1;
                                ctrl.statistics.fail += 1;
                            }

                        });
                    });

                    ctrl.statistics.mandatory.area = Object.keys(ctrl.data.mandatory).length;
                    ctrl.statistics.optional.area = Object.keys(ctrl.data.optional).length;
                }, function(error){
                    alert('error to get test case info');
                });
            }
        });

        function generate_format_data() {
            var test_url = testapiApiUrl + '/tests/' + ctrl.innerId;
            $http.get(test_url).then(function(test_resp){
               ctrl.validation = test_resp.data.validation;

               // OVP 2018.01 results are stored as individual result sets per test case:
               // Looping over all individual test cases
               angular.forEach(test_resp.data.results, function(result, index){
                   var result_url = testapiApiUrl + '/results/' + result;
                   $http.get(result_url).then(function(result_resp){

                       ctrl.version = result_resp.data.version
                       if(ctrl.version == 'master' || ctrl.version == 'unknown') {
                            // there was no result format versioning in the first release of OVP but
                            // instead the version was set to 'master'. We are using this as an indicator
                            // that a set of results were created based on the 2018.01 release
                            ctrl.version = '2018.01'
                       }

                       if(ctrl.version == '2018.01') {
                           var sub_case_list_total = get_sub_case_list_2018_01(result_resp.data);
                           var sub_case_list = sub_case_list_total[0];
                           var sub_case_list_skip = sub_case_list_total[1];
                           var sub_case_list_fail = sub_case_list_total[2];
                           extend(sub_case_list);
                           extend_skip(sub_case_list_skip);
                           extend_fail(sub_case_list_fail);
                       }
                       else {
                           // OVP 2018.09 and later results store all results in a single json structure:
                           // Looping over all test cases of this individual test run
                           angular.forEach(result_resp.data.testcases_list, function(testcase, index){
                               var sub_case_list_total = get_sub_case_list(testcase);
                               var sub_case_list = sub_case_list_total[0];
                               var sub_case_list_skip = sub_case_list_total[1];
                               var sub_case_list_fail = sub_case_list_total[2];
                               extend(sub_case_list);
                               extend_skip(sub_case_list_skip);
                               extend_fail(sub_case_list_fail);
                           });
                       }

                       if(index == test_resp.data.results.length - 1){
                           $scope.load_finish = true;
                       }
                   }, function(result_error){
                   });
               });

            }, function(test_error){
                alert('Error when get test record');
            });
        }

        function get_sub_case_list_2018_01(result) {
            if(result.project_name == 'yardstick'){
                return yardstickPass_2018_01(result);
            }else{
                return functestPass_2018_01(result);
            }
        }

        function yardstickPass_2018_01(result) {
            var case_list = [];
            var case_list_skip = [];
            var case_list_fail = [];
            angular.forEach(result.details.results, function(ele){
                if(ele.benchmark){
                    if(ele.benchmark.data.sla_pass == 1){
                        case_list.push(result.case_name);
                    } else if(ele.benchmark.data.sla_skip == 1){
                        case_list_skip.push(result.case_name);
                    } else {
                        case_list_fail.push(result.case_name);
                    }
                }
            });
            return [case_list, case_list_skip, case_list_fail];
        }

        function functestPass_2018_01(result){
            var case_list = [];
            var case_list_skip = [];
            var case_list_fail = [];
            if(result.case_name == 'refstack_defcore'){
                angular.forEach(result.details.success, function(ele){
                    if(strip(ele) == 'tempest.api.identity.v3.test_t'){
                        case_list.push('tempest.api.identity.v3.test_tokens.TokensV3Test.test_create_token');
                    }else{
                        case_list.push(ele.split(' ')[ele.split(' ').length - 2]);
                    }
                });
            }else if(result.case_name == 'tempest_custom'){
                angular.forEach(result.details.success, function(ele){
                    case_list.push(ele.split(' ')[ele.split(' ').length - 1]);
                });
            }else{
                if(result.criteria == 'PASS'){
                    case_list.push(result.case_name);
                } else if(result.criteria == 'SKIP'){
                    case_list_skip.push(result.case_name);
                } else {
                    case_list_fail.push(result.case_name);
                }
            }
            return [case_list, case_list_skip, case_list_fail];
        }

        function get_sub_case_list(result) {
            var case_list = [];
            var case_list_skip = [];
            var case_list_fail = [];
            if(result.sub_testcase.length == 0 && result.result == "PASS") {
                case_list.push(result.name);
            }
            else if(result.sub_testcase.length == 0 && result.result == "SKIP") {
                case_list_skip.push(result.name);
            }
            else if(result.sub_testcase.length == 0) {
                case_list_fail.push(result.name);
            }
            else {
                angular.forEach(result.sub_testcase, function(subtest, index) {
                    if(subtest.result == "PASS") {
                        case_list.push(subtest.name);
                    } else if(subtest.result == "SKIP") {
                        case_list_skip.push(subtest.name);
                    } else {
                        case_list_fail.push(subtest.name);
                    }
                });
            }
            return [case_list, case_list_skip, case_list_fail];
        }

        function gotoDoc(sub_case){
        }

        function openAll(){
            angular.forEach(ctrl.data.mandatory, function(ele, id){
                ele.folder = false;
            });
            angular.forEach(ctrl.data.optional, function(ele, id){
                ele.folder = false;
            });
        }

        function folderAll(){
            angular.forEach(ctrl.data.mandatory, function(ele, id){
                ele.folder = true;
            });
            angular.forEach(ctrl.data.optional, function(ele, id){
                ele.folder = true;
            });
        }

        generate_format_data();
    }

})();