diff --git a/cnf-certification-test/webserver/index.html b/cnf-certification-test/webserver/index.html index d878b7dc0..3934e2bd7 100644 --- a/cnf-certification-test/webserver/index.html +++ b/cnf-certification-test/webserver/index.html @@ -1,19 +1,21 @@ - - - - CNF Certification Test - - - - - - + + + - - - - - - - - - - -
- Red Hat -
- -
-

CNF Certification Test

-
- - -
- Environment Configuration - - -
- Upload TNF Configuration File: - -
+ label { + font-weight: var(--rh-font-weight-heading-bold, 700); + margin-block-end: var(--rh-space-sm, 6px); + } + + rh-dialog::part(footer) { + padding-block-start: var(--rh-space-lg, 16px); + } + + rh-footer-universal { + margin-block-start: auto; + } + + main, + :not(:defined) { + opacity: var(--main-opacity, 1); + transition: opacity 200ms ease; + } + + h4 input[type="checkbox"] { + display: inline-block; + } + + h4 label { + display: inline-block; + margin-left: 8px; + /* Adjust margin as needed */ + } + + + + + + + + + + + +
+ Red Hat +
+ +
+

CNF Certification Test

+ + + +
+ Environment Configuration + + +
+ Upload TNF Configuration File: + +
TNF Configuration @@ -207,20 +234,20 @@

CNF Certification Test

Add podsUnderTestLabels
Remove podsUnderTestLabels - +
Add operatorsUnderTestLabels
Remove operatorsUnderTestLabels - + Add targetCrdFilters
- Remove targetCrdFilters + Remove targetCrdFilters Add managedDeployments
Remove managedDeployments - + Add managedStatefulsets
@@ -233,117 +260,250 @@

CNF Certification Test

Add skipHelmChartList
Remove skipHelmChartList - + Add skipScalingTestDeployments
- Remove skipScalingTestDeployments + Remove skipScalingTestDeployments Add skipScalingTestStatefulsets
- Remove skipScalingTestStatefulsets - + Remove skipScalingTestStatefulsets + Add servicesignorelist
Remove servicesignorelist - + - + - + - + - + Add ValidProtocolNames
Remove ValidProtocolNames - + - - + +
+
+ Select a Test -
- Select a Test - - - - - -
+ Selcet a Test Tag + + + +
+ +

All Selected Tests: 0

+ Lifecycle + +

Selected Lifecycle Tests: 0

+ + + + + + +
+
+
+ + Manageability + +

Selected Manageability Tests: 0

+ + + + + + +
+ + Certification + +

Selected Certification Tests: 0

+ + + + + + +
+ + Operator + +

Selected Operator Tests: 0

+ + + + + +
+ + + Access Control + +

Selected Access Control Tests: 0

+ + + + + + +
+ + Platform Alteration + +

Selected Platform Alteration Tests: 0

+ + + + + + +
+ Networking + +

Selected Networking Tests: 0

+ + + + + + +
+ Performance + +

Selected Performance Tests: 0

+ + + + + + +
+ Observability + +

Selected Observability Tests: 0

+ + + + + + +
+
+ +
+ Run Certification Test + + Show Log +
+ + +

Logs

+ No Logs Found + Close +
+ + + + + + © 2022 Red Hat, Inc. + + + + - Run Certification Test - - Show Log -
- - -

Logs

- No Logs Found - Close -
- - - - - - © 2022 Red Hat, Inc. - - - - '+name1+':' + - ''+name2+':' ; - var target=clickedId+'add' - $('#'+target).after(field); - } - else{ - var i= counters[clickedId] - var t1=clickedId+name1+i+'' - var t2=clickedId+name2+i+'' - var field = - ''+name1+':' + - ''+name2+':' ; - var target=clickedId+name2+(i-1)+'' - $('#'+target).after(field); - } - return counters - } - - - $(document).ready(function() { - document.getElementById('targetNameSpacesremove').style.display = 'none'; - document.getElementById('podsUnderTestLabelsremove').style.display = 'none'; - document.getElementById('operatorsUnderTestLabelsremove').style.display = 'none'; - document.getElementById('targetCrdFiltersremove').style.display = 'none'; - document.getElementById('managedDeploymentsremove').style.display = 'none'; - document.getElementById('managedStatefulsetsremove').style.display = 'none'; - document.getElementById('acceptedKernelTaintsremove').style.display = 'none'; - document.getElementById('skipHelmChartListremove').style.display = 'none'; - document.getElementById('servicesignorelistremove').style.display = 'none'; - document.getElementById('skipScalingTestDeploymentsremove').style.display = 'none'; - document.getElementById('skipScalingTestStatefulsetsremove').style.display = 'none'; - document.getElementById('ValidProtocolNamesremove').style.display = 'none'; - const inputElement = document.getElementById('tnfFile') - inputElement.addEventListener('change', handleTnfFiles, false) - $('.add').on('click', function() { - var clickedIdOrg = $(this).attr('id'); - var clickedId = clickedIdOrg.replace('add', ''); - if (clickedId == 'targetCrdFilters'){ - counters=addCrdElem(counters,'nameSuffix','scalable',clickedId) - } - else if (clickedId == 'skipScalingTestDeployments'){ - counters=addCrdElem(counters,'name','namespace',clickedId) - } - else if (clickedId == 'skipScalingTestStatefulsets'){ - counters=addCrdElem(counters,'name','namespace',clickedId) - } - else{ - if (!counters[clickedId]|| counters[clickedId] <= 1 ) { - counters[clickedId] = 1; - var i= counters[clickedId] - console.log(i) - console.log(clickedId) - var field = ''+ - ''; - $('#'+clickedIdOrg).after(field); - } - else{ - var i= counters[clickedId] - var field = ''+ - ''; - var target=clickedId+(i-1)+'' - $('#'+target).after(field); - } - } - document.getElementById(clickedId+'remove').style.display = 'block'; - counters[clickedId] = counters[clickedId] + 1; // Increment the counter for the next call - }) - // Remove last text input - $('.remove').on('click', function() { - var clickedIdOrg = $(this).attr('id'); - var clickedId = clickedIdOrg.replace('remove', ''); - var i= counters[clickedId] - if (i>1){ - var target=clickedId+(i-1)+'' - if (clickedId == 'targetCrdFilters'){ - var target1='targetCrdFiltersnameSuffix'+(i-1)+'' - var target2='targetCrdFiltersscalable'+(i-1)+'' - console.log(target2) - $('#'+target1).remove(); - $('h7[for="' + target1 + '"]').remove(); - $('#'+target2).remove(); - $('h7[for="' + target2 + '"]').remove(); - }if (clickedId == 'skipScalingTestDeployments'){ - var target1='skipScalingTestDeploymentsname'+(i-1)+'' - var target2='skipScalingTestDeploymentsnamespace'+(i-1)+'' - console.log(target2) - $('#'+target1).remove(); - $('h7[for="' + target1 + '"]').remove(); - $('#'+target2).remove(); - $('h7[for="' + target2 + '"]').remove(); - }if (clickedId == 'skipScalingTestStatefulsets'){ - var target1='skipScalingTestStatefulsetsname'+(i-1)+'' - var target2='skipScalingTestStatefulsetsnamespace'+(i-1)+'' - console.log(target2) - $('#'+target1).remove(); - $('h7[for="' + target1 + '"]').remove(); - $('#'+target2).remove(); - $('h7[for="' + target2 + '"]').remove(); - } - else{ - $('#'+target).remove(); - } - $('label[for="' + target + '"]').remove(); - counters[clickedId] = counters[clickedId] - 1; - if (i-1 ==1){ - document.getElementById(clickedIdOrg).style.display = 'none'; - } + console.log(clickedId) + + if (!counters[clickedId] || counters[clickedId] <= 1) { + counters[clickedId] = 1; + var i = counters[clickedId] + var t1 = clickedId + name1 + i + '' + var t2 = clickedId + name2 + i + '' + var field = + '' + name1 + ':' + + '' + name2 + ':'; + var target = clickedId + 'add' + $('#' + target).after(field); + } + else { + var i = counters[clickedId] + var t1 = clickedId + name1 + i + '' + var t2 = clickedId + name2 + i + '' + var field = + '' + name1 + ':' + + '' + name2 + ':'; + var target = clickedId + name2 + (i - 1) + '' + $('#' + target).after(field); + } + return counters +} + + +$(document).ready(function () { + selectScenario('lifecycle') + selectScenario('manageability') + selectScenario('affiliated-certification') + selectScenario('operator') + selectScenario('access-control') + selectScenario('platform-alteration') + selectScenario('networking') + selectScenario('performance') + selectScenario('observability') + updateTestCounter('lifecycle') + updateAllCounter() + document.getElementById('targetNameSpacesremove').style.display = 'none'; + document.getElementById('podsUnderTestLabelsremove').style.display = 'none'; + document.getElementById('operatorsUnderTestLabelsremove').style.display = 'none'; + document.getElementById('targetCrdFiltersremove').style.display = 'none'; + document.getElementById('managedDeploymentsremove').style.display = 'none'; + document.getElementById('managedStatefulsetsremove').style.display = 'none'; + document.getElementById('acceptedKernelTaintsremove').style.display = 'none'; + document.getElementById('skipHelmChartListremove').style.display = 'none'; + document.getElementById('servicesignorelistremove').style.display = 'none'; + document.getElementById('skipScalingTestDeploymentsremove').style.display = 'none'; + document.getElementById('skipScalingTestStatefulsetsremove').style.display = 'none'; + document.getElementById('ValidProtocolNamesremove').style.display = 'none'; + + const inputElement = document.getElementById('tnfFile') + inputElement.addEventListener('change', handleTnfFiles, false) + $('.add').on('click', function () { + var clickedIdOrg = $(this).attr('id'); + var clickedId = clickedIdOrg.replace('add', ''); + if (clickedId == 'targetCrdFilters') { + counters = addCrdElem(counters, 'nameSuffix', 'scalable', clickedId) + } + else if (clickedId == 'skipScalingTestDeployments') { + counters = addCrdElem(counters, 'name', 'namespace', clickedId) + } + else if (clickedId == 'skipScalingTestStatefulsets') { + counters = addCrdElem(counters, 'name', 'namespace', clickedId) + } + else { + if (!counters[clickedId] || counters[clickedId] <= 1) { + counters[clickedId] = 1; + var i = counters[clickedId] + console.log(i) + console.log(clickedId) + var field = '' + + ''; + $('#' + clickedIdOrg).after(field); } - }); + else { + var i = counters[clickedId] + var field = '' + + ''; + var target = clickedId + (i - 1) + '' + $('#' + target).after(field); + } + } + document.getElementById(clickedId + 'remove').style.display = 'block'; + counters[clickedId] = counters[clickedId] + 1; // Increment the counter for the next call + }) + // Remove last text input + $('.remove').on('click', function () { + var clickedIdOrg = $(this).attr('id'); + var clickedId = clickedIdOrg.replace('remove', ''); + var i = counters[clickedId] + if (i > 1) { + var target = clickedId + (i - 1) + '' + if (clickedId == 'targetCrdFilters') { + var target1 = 'targetCrdFiltersnameSuffix' + (i - 1) + '' + var target2 = 'targetCrdFiltersscalable' + (i - 1) + '' + console.log(target2) + $('#' + target1).remove(); + $('h7[for="' + target1 + '"]').remove(); + $('#' + target2).remove(); + $('h7[for="' + target2 + '"]').remove(); + } if (clickedId == 'skipScalingTestDeployments') { + var target1 = 'skipScalingTestDeploymentsname' + (i - 1) + '' + var target2 = 'skipScalingTestDeploymentsnamespace' + (i - 1) + '' + console.log(target2) + $('#' + target1).remove(); + $('h7[for="' + target1 + '"]').remove(); + $('#' + target2).remove(); + $('h7[for="' + target2 + '"]').remove(); + } if (clickedId == 'skipScalingTestStatefulsets') { + var target1 = 'skipScalingTestStatefulsetsname' + (i - 1) + '' + var target2 = 'skipScalingTestStatefulsetsnamespace' + (i - 1) + '' + console.log(target2) + $('#' + target1).remove(); + $('h7[for="' + target1 + '"]').remove(); + $('#' + target2).remove(); + $('h7[for="' + target2 + '"]').remove(); + } + else { + $('#' + target).remove(); + } + $('label[for="' + target + '"]').remove(); + counters[clickedId] = counters[clickedId] - 1; + if (i - 1 == 1) { + document.getElementById(clickedIdOrg).style.display = 'none'; + } + } + }); +}) + +function handleTnfFiles() { + const fileList = this.files + if (fileList.length) { + // We have a file to load + const fileUploaded = new FileReader() + fileUploaded.addEventListener('load', e => { + yamlGlobal = jsyaml.load(fileUploaded.result); + renderResults() }) + fileUploaded.readAsText(fileList[0]) + } +} - function handleTnfFiles () { - const fileList = this.files - if (fileList.length) { - // We have a file to load - const fileUploaded = new FileReader() - fileUploaded.addEventListener('load', e => { - yamlGlobal = jsyaml.load(fileUploaded.result); - renderResults() - }) - fileUploaded.readAsText(fileList[0]) - } - } +// render results tab +function renderResults() { + if (typeof yamlGlobal !== 'undefined') { + fillData(yamlGlobal.targetNameSpaces, '#targetNameSpacesadd', 'targetNameSpaces', 'name', '') + fillData(yamlGlobal.managedDeployments, '#managedDeploymentsadd', 'managedDeployments', 'name', '') + fillData(yamlGlobal.managedStatefulsets, '#managedStatefulsetsadd', 'managedStatefulsets', 'name', '') + fillData(yamlGlobal.acceptedKernelTaints, '#acceptedKernelTaintsadd', 'acceptedKernelTaints', 'module', '') + fillData(yamlGlobal.skipHelmChartList, '#skipHelmChartListadd', 'skipHelmChartList', 'name', '') - // render results tab -function renderResults () { -if (typeof yamlGlobal !== 'undefined') { -fillData(yamlGlobal.targetNameSpaces, '#targetNameSpacesadd','targetNameSpaces','name','') -fillData(yamlGlobal.managedDeployments, '#managedDeploymentsadd','managedDeployments','name','') -fillData(yamlGlobal.managedStatefulsets, '#managedStatefulsetsadd','managedStatefulsets','name','') -fillData(yamlGlobal.acceptedKernelTaints, '#acceptedKernelTaintsadd','acceptedKernelTaints','module','') -fillData(yamlGlobal.skipHelmChartList, '#skipHelmChartListadd','skipHelmChartList','name','') + fillData(yamlGlobal.podsUnderTestLabels, '#podsUnderTestLabelsadd', 'podsUnderTestLabels', '', '') + fillData(yamlGlobal.servicesignorelist, '#servicesignorelistadd', 'servicesignorelist', '', '') + fillData(yamlGlobal.validProtocolNames, '#ValidProtocolNamesadd', 'ValidProtocolNames', '', '') + fillData(yamlGlobal.operatorsUnderTestLabels, '#operatorsUnderTestLabelsadd', 'operatorsUnderTestLabels', '', '') -fillData(yamlGlobal.podsUnderTestLabels, '#podsUnderTestLabelsadd','podsUnderTestLabels','','') -fillData(yamlGlobal.servicesignorelist, '#servicesignorelistadd','servicesignorelist','','') -fillData(yamlGlobal.validProtocolNames, '#ValidProtocolNamesadd','ValidProtocolNames','','') -fillData(yamlGlobal.operatorsUnderTestLabels, '#operatorsUnderTestLabelsadd','operatorsUnderTestLabels','','') + fillData(yamlGlobal.skipScalingTestDeployments, '#skipScalingTestDeploymentsadd', 'skipScalingTestDeployments', 'name', 'namespace') + fillData(yamlGlobal.skipScalingTestStatefulsets, '#skipScalingTestStatefulsetsadd', 'skipScalingTestStatefulsets', 'name', 'namespace') + fillData(yamlGlobal.targetCrdFilters, '#targetCrdFiltersadd', 'targetCrdFilters', 'nameSuffix', 'scalable') + if (yamlGlobal.DebugDaemonSetNamespace) { + document.getElementById('DebugDaemonSetNamespace').value = yamlGlobal.DebugDaemonSetNamespace; + } + if (yamlGlobal.DebugDaemonSetNamespace) { + document.getElementById('CollectorAppEndPoint').value = yamlGlobal.collectorAppEndPoint; + } + if (yamlGlobal.executedBy) { + document.getElementById('executedBy').value = yamlGlobal.executedBy; + } + if (yamlGlobal.partnerName) { + document.getElementById('PartnerName').value = yamlGlobal.partnerName; + } + } +} -fillData(yamlGlobal.skipScalingTestDeployments, '#skipScalingTestDeploymentsadd','skipScalingTestDeployments','name','namespace') -fillData(yamlGlobal.skipScalingTestStatefulsets, '#skipScalingTestStatefulsetsadd','skipScalingTestStatefulsets','name','namespace') -fillData(yamlGlobal.targetCrdFilters, '#targetCrdFiltersadd','targetCrdFilters','nameSuffix','scalable') -if (yamlGlobal.DebugDaemonSetNamespace){ -document.getElementById('DebugDaemonSetNamespace').value = yamlGlobal.DebugDaemonSetNamespace; +function fillData(input, element, clickedId, keyname, key2name) { + if (!counters[clickedId]) { + counters[clickedId] = 1 + } + for (const key in input) { + var target = clickedId + (counters[clickedId] - 1) + '' + if (keyname != '') { + var value = input[key][keyname] + } else { + var value = input[key] + } + if (key2name == '') { + var pf_txt = '' + } else { + var i = counters[clickedId] + var t1 = clickedId + keyname + i + '' + var t2 = clickedId + key2name + i + '' + console.log(t1) + var pf_txt = + '' + keyname + ':' + + '' + key2name + ':'; + var target = clickedId + key2name + (i - 1) + '' + } + var field = '' + pf_txt + if (counters[clickedId] == 1) { + $(element).after(field); + } else { + $('#' + target).after(field); + } + counters[clickedId] = counters[clickedId] + 1 + } } -if (yamlGlobal.DebugDaemonSetNamespace){ - document.getElementById('CollectorAppEndPoint').value = yamlGlobal.collectorAppEndPoint; + +function addCheckedTest() { + document.getElementById('lifecycle').checked = true + document.getElementById('manageability').checked = true + document.getElementById('affiliated-certification').checked = true + document.getElementById('operator').checked = true + document.getElementById('access-control').checked = true + document.getElementById('platform-alteration').checked = true + document.getElementById('networking').checked = true + document.getElementById('performance').checked = true + document.getElementById('observability').checked = true + +} + +function selectScenario(table) { + var idtable = '#' + table + '-table' + $(idtable).empty() + // addCheckedTest() + var field = "" + const selectScenarioComboBox = document.getElementById('selectScenarioComboBox') + const selectedScenario = selectScenarioComboBox.options[selectScenarioComboBox.selectedIndex].value + document.getElementById('selectOpt').setAttribute('hidden', 'hidden') + + for (const key in classification) { + if (key.startsWith(table)) { + field = + '
' + + ' ' + + '' + + '
' + + '

Description

' + + classification[key][0].description + '

' + + '

Remediation

' + + classification[key][0].remediation + '

' + + '

BestPracticeReference

' + + classification[key][0].bestPracticeReference + '
' + + '
' + $(field).appendTo(idtable); + document.getElementById(key).addEventListener('click', function (event) { + // Prevent click propagation from the input element + event.stopPropagation(); + }); + document.getElementById(key + 'l').addEventListener('click', function (event) { + // Prevent click propagation from the input element + event.stopPropagation(); + }); + } + } + + if (selectedScenario != 'all' && selectedScenario != 'none') { + document.getElementById('selectOpt').removeAttribute('hidden') + } + buildTest(selectedScenario, table) + updateTestCounter(table) + //updateAllCounter() + +} + +function updateCheckbox(table) { + document.getElementById('selectOpt').setAttribute('hidden', 'hidden') + const selectScenarioComboBox = document.getElementById('selectScenarioComboBox') + const selectedScenario = selectScenarioComboBox.options[selectScenarioComboBox.selectedIndex].value + if (selectedScenario != 'all' && selectedScenario != 'none') { + document.getElementById('selectOpt').removeAttribute('hidden') + } + buildTest(selectedScenario, table) + updateTestCounter(table) +} + +function buildTest(scenarioValue, table) { + const option = document.getElementById('selectOpt') + const selectedOptionalMandatory = option.options[option.selectedIndex].value + var eqData = "" + for (const key in classification) { + switch (scenarioValue) { + case "telco": + eqData = classification[key][0]["categoryClassification"].Telco; + break; + case "nontelco": + eqData = classification[key][0]["categoryClassification"].NonTelco; + break; + case "extended": + eqData = classification[key][0]["categoryClassification"].Extended; + break; + default: + eqData = classification[key][0]["categoryClassification"].FarEdge; + } + if (key.startsWith(table)) { + var selectedTestItem = document.getElementById(key); + if (eqData == selectedOptionalMandatory || scenarioValue == "all") { + selectedTestItem.checked = true; + } if (scenarioValue != "all" && (eqData != selectedOptionalMandatory || scenarioValue == "none")) { + selectedTestItem.checked = false; + } + } + } +} + +function show(id) { + updateTestCounter(id) + if (id != "lifecycle") { + document.getElementById('lifecycle-table').setAttribute('hidden', 'hidden') + + } + if (id != "manageability") { + document.getElementById('manageability-table').setAttribute('hidden', 'hidden') + + } + if (id != "affiliated-certification") { + document.getElementById('affiliated-certification-table').setAttribute('hidden', 'hidden') + + } + if (id != "operator") { + document.getElementById('operator-table').setAttribute('hidden', 'hidden') + + } + if (id != "access-control") { + document.getElementById('access-control-table').setAttribute('hidden', 'hidden') + + } + if (id != "platform-alteration") { + document.getElementById('platform-alteration-table').setAttribute('hidden', 'hidden') + + } + if (id != "networking") { + document.getElementById('networking-table').setAttribute('hidden', 'hidden') + + } + if (id != "performance") { + document.getElementById('performance-table').setAttribute('hidden', 'hidden') + + } + if (id != "observability") { + document.getElementById('observability-table').setAttribute('hidden', 'hidden') + } + document.getElementById(id + '-table').removeAttribute('hidden') } -if(yamlGlobal.executedBy){ - document.getElementById('executedBy').value = yamlGlobal.executedBy; + +function updateTestCounter(id) { + var CountElement = document.getElementById(id + '-count'); + var matchResult = CountElement.textContent.match(/(.*?:\s)(\d+)/); + var nonNumericPart = matchResult[1]; + CountElement.textContent = nonNumericPart + 0; + + for (const key in classification) { + if (key.startsWith(id)) { + updateTestCounterTest(id, key, false) + } + } } -if(yamlGlobal.partnerName){ - document.getElementById('PartnerName').value = yamlGlobal.partnerName; + + +function updateAllCounter() { + testsList = ['lifecycle', 'manageability', 'affiliated-certification', 'operator' + , 'access-control', 'platform-alteration', 'networking', 'performance', 'observability'] + var allCountElement = document.getElementById('all-count'); + var allmatchResult = allCountElement.textContent.match(/(.*?:\s)(\d+)/); + var allnonNumericPart = allmatchResult[1]; + var count = 0 + for (var i = 0; i < testsList.length; i++) { + var test = testsList[i] + var CountElement = document.getElementById(test + '-count'); + var matchResult = CountElement.textContent.match(/(.*?:\s)(\d+)/); + var newCount = parseInt(matchResult[2]); + count += newCount + } + allCountElement.textContent = allnonNumericPart + count; } +function updateTestCounterTest(id, key, comfromsmallCombox) { + var CountElement = document.getElementById(id + '-count'); + var matchResult = CountElement.textContent.match(/(.*?:\s)(\d+)/); + var newCount = parseInt(matchResult[2]); + var nonNumericPart = matchResult[1]; + var checkedkey = document.getElementById(key); + if (checkedkey.checked) { + newCount = newCount + 1; + } else { + if (comfromsmallCombox) { + newCount = newCount - 1; + } + } + if (newCount < 0) { + newCount = 0 + } + CountElement.textContent = nonNumericPart + newCount; + updateAllCounter() } + +function show(id) { + updateTestCounter(id) + if (id != "lifecycle") { + document.getElementById('lifecycle-table').setAttribute('hidden', 'hidden') + + } + if (id != "manageability") { + document.getElementById('manageability-table').setAttribute('hidden', 'hidden') + + } + if (id != "affiliated-certification") { + document.getElementById('affiliated-certification-table').setAttribute('hidden', 'hidden') + + } + if (id != "operator") { + document.getElementById('operator-table').setAttribute('hidden', 'hidden') + + } + if (id != "access-control") { + document.getElementById('access-control-table').setAttribute('hidden', 'hidden') + + } + if (id != "platform-alteration") { + document.getElementById('platform-alteration-table').setAttribute('hidden', 'hidden') + + } + if (id != "networking") { + document.getElementById('networking-table').setAttribute('hidden', 'hidden') + + } + if (id != "performance") { + document.getElementById('performance-table').setAttribute('hidden', 'hidden') + + } + if (id != "observability") { + document.getElementById('observability-table').setAttribute('hidden', 'hidden') + } + document.getElementById(id + '-table').removeAttribute('hidden') } -function fillData(input,element,clickedId,keyname,key2name){ -if (!counters[clickedId]){ -counters[clickedId] =1 + +function updateTestCounter(id) { + var CountElement = document.getElementById(id + '-count'); + var matchResult = CountElement.textContent.match(/(.*?:\s)(\d+)/); + var nonNumericPart = matchResult[1]; + CountElement.textContent = nonNumericPart + 0; + + for (const key in classification) { + if (key.startsWith(id)) { + updateTestCounterTest(id, key) + } + } + //updateAllCounter() } -for (const key in input) { -var target=clickedId+(counters[clickedId]-1)+'' -if (keyname!=''){ - var value = input[key][keyname] -}else{ - var value = input[key] + + +function updateAllCounter() { + testsList = ['lifecycle', 'manageability', 'affiliated-certification', 'operator' + , 'access-control', 'platform-alteration', 'networking', 'performance', 'observability'] + var allCountElement = document.getElementById('all-count'); + var allmatchResult = allCountElement.textContent.match(/(.*?:\s)(\d+)/); + var allnonNumericPart = allmatchResult[1]; + var count = 0 + for (var i = 0; i < testsList.length; i++) { + var test = testsList[i] + var CountElement = document.getElementById(test + '-count'); + var matchResult = CountElement.textContent.match(/(.*?:\s)(\d+)/); + var newCount = parseInt(matchResult[2]); + count += newCount + } + allCountElement.textContent = allnonNumericPart + count; } -if(key2name==''){ - console.log('heeeer') - var pf_txt='' -}else{ - console.log(input[key][keyname]) - console.log(input[key][key2name]) - var i= counters[clickedId] - var t1=clickedId+keyname+i+'' - var t2=clickedId+key2name+i+'' - console.log(t1) - var pf_txt = - ''+keyname+':' + - ''+key2name+':' ; - var target=clickedId+key2name+(i-1)+'' -} -var field=''+pf_txt - if ( counters[clickedId]==1){ - $(element).after(field); - }else{ - $('#'+target).after(field); - } - counters[clickedId]= counters[clickedId]+1 +function updateTestCounterTest(id, key, comfromsmallCombox) { + var CountElement = document.getElementById(id + '-count'); + var matchResult = CountElement.textContent.match(/(.*?:\s)(\d+)/); + var newCount = parseInt(matchResult[2]); + var nonNumericPart = matchResult[1]; + var checkedkey = document.getElementById(key); + if (checkedkey.checked) { + newCount = newCount + 1; + } else { + if (comfromsmallCombox) { + newCount = newCount - 1; + + } + } + if (newCount < 0) { + newCount = 0 + } + CountElement.textContent = nonNumericPart + newCount; + updateAllCounter() } + +// Add an event listener to the checkbox +function performToggle(triggerId) { + var checkbox = document.getElementById(triggerId); + for (const key in classification) { + if (key.startsWith(triggerId)) { + if (checkbox.checked) { + var rowToRemove = document.getElementById(key); + if (rowToRemove) { + rowToRemove.checked = true; + } + + + } else { + var rowToRemove = document.getElementById(key); + // Check if the row exists + if (rowToRemove) { + // Remove the row from the table + rowToRemove.checked = false; + } + } + } + } + updateTestCounter(triggerId) + //updateAllCounter() } \ No newline at end of file diff --git a/cnf-certification-test/webserver/submit.js b/cnf-certification-test/webserver/submit.js index 3834401d4..c41da9d60 100644 --- a/cnf-certification-test/webserver/submit.js +++ b/cnf-certification-test/webserver/submit.js @@ -1,73 +1,64 @@ /** @param {HTMLFormElement} form */ export async function submit(form) { - form.elements.submit.disabled = true; - const formdata = new FormData(form); - // Iterate over form elements and add those with non-empty values to FormData - Array.from(form.elements).forEach(element => { - if ( element.hasAttribute('value') && element.type!="checkbox") { - console.log(element) - console.log(element.value) - console.log((element.id.match(/[a-zA-Z]/g) || []).join('')) - formdata.append((element.id.match(/[a-zA-Z]/g) || []).join(''), element.value); - } - }); - console.log(JSON.stringify(Object.fromEntries(formdata))) - for (const el of form.elements) if (el instanceof HTMLFieldSetElement) el.disabled = true - console.log(Array.from(formdata.entries())); - - // Collect data from form fields - const fields = Array.from(formdata.entries()).reduce((acc, [key, val]) => { - console.log(acc[key]); - console.log(val); + form.elements.submit.disabled = true; + const formdata = new FormData(form); + // Iterate over form elements and add those with non-empty values to FormData + Array.from(form.elements).forEach(element => { // this loop for the checkbox values + if (element.hasAttribute('value') && element.type != "checkbox") { + formdata.append((element.id.match(/[a-zA-Z]/g) || []).join(''), element.value); + } + }); + for (const el of form.elements) if (el instanceof HTMLFieldSetElement) el.disabled = true + + // Collect data from form fields -- will take all the fields + const fields = Array.from(formdata.entries()).reduce((acc, [key, val]) => { + if (acc[key] === undefined) { + // If the key is not in the accumulator, set it to the value or an array with the value + acc[key] = [val]; + } else if (Array.isArray(acc[key])) { + // If the key is already an array, push the new value to the array + acc[key].push(val); + } else { + // If the key is a single value, convert it to an array with both values + acc[key] = [acc[key], val]; + } + return acc; + }, {}); + + delete fields.submit; // delete unnrrd data + console.log(fields); + formdata.append("jsonData", JSON.stringify(fields)); - if (acc[key] === undefined) { - // If the key is not in the accumulator, set it to the value or an array with the value - acc[key] = [val]; - } else if (Array.isArray(acc[key])) { - // If the key is already an array, push the new value to the array - acc[key].push(val); + // Send an HTTP request to the server to run the function + let heading; + let message; + let state = 'success'; + + try { // post request with the collected data + const data = await fetch('/runFunction', { + method: 'POST', + body: formdata, + }).then(response => { + if (response.ok) { + return response.json(); } else { - // If the key is a single value, convert it to an array with both values - acc[key] = [acc[key], val]; + throw new Error(response.statusText); } - return acc; - }, {}); - - delete fields.submit; - console.log(fields); - console.log(formdata) - formdata.append("jsonData", JSON.stringify(fields)); + }); - // Send an HTTP request to the server to run the function - let heading; - let message; - let state = 'success'; - - try { - const data = await fetch('/runFunction', { - method: 'POST', - body: formdata, - }).then(response => { - if (response.ok) { - return response.json(); - } else { - throw new Error(response.statusText); - } - }); - - heading = 'Success'; - message = data.Message; - - console.log(data); - } catch (error) { - console.error(error); - heading = 'Error' - message = error.message; - state = 'danger'; - } finally { - form.elements.submit.disabled = false; - for (const el of form.elements) if (el instanceof HTMLFieldSetElement) el.disabled = false - } - - return { heading, message, state }; - } \ No newline at end of file + heading = 'Success'; + message = data.Message; + + console.log(data); + } catch (error) { + console.error(error); + heading = 'Error' + message = error.message+" Run Certification test failed, please check the logs"; + state = 'danger'; + } finally { + form.elements.submit.disabled = false; + for (const el of form.elements) if (el instanceof HTMLFieldSetElement) el.disabled = false + } + + return { heading, message, state }; +} \ No newline at end of file diff --git a/cnf-certification-test/webserver/toast.js b/cnf-certification-test/webserver/toast.js index 1516826de..2018e5749 100644 --- a/cnf-certification-test/webserver/toast.js +++ b/cnf-certification-test/webserver/toast.js @@ -8,22 +8,22 @@ export async function toast({ }) { await import('@rhds/elements/rh-alert/rh-alert.js'); const h2 = document.createElement('h2'); - h2.textContent = heading; - h2.slot = 'header'; + h2.textContent = heading; + h2.slot = 'header'; const alert = document.createElement('rh-alert'); - alert.setAttribute('aria-live', 'polite'); - alert.dismissable = true; - alert.state = state; - alert.classList.add('toast'); - alert.style.position = 'fixed'; - alert.style.margin = '0'; - alert.style.setProperty('z-index', '1000'); - alert.style.setProperty('inset-inline-end', 'var(--rh-space-xl, 24px)'); - alert.style.setProperty('inset-block-start', 'var(--rh-space-xl, 24px)'); - alert.append(h2); + alert.setAttribute('aria-live', 'polite'); + alert.dismissable = true; + alert.state = state; + alert.classList.add('toast'); + alert.style.position = 'fixed'; + alert.style.margin = '0'; + alert.style.setProperty('z-index', '1000'); + alert.style.setProperty('inset-inline-end', 'var(--rh-space-xl, 24px)'); + alert.style.setProperty('inset-block-start', 'var(--rh-space-xl, 24px)'); + alert.append(h2); if (message) { const p = document.createElement('p'); - p.textContent = message; + p.textContent = message; alert.append(message); } diff --git a/cnf-certification-test/webserver/webserver.go b/cnf-certification-test/webserver/webserver.go index b85ee52a9..178221f35 100644 --- a/cnf-certification-test/webserver/webserver.go +++ b/cnf-certification-test/webserver/webserver.go @@ -11,21 +11,30 @@ import ( "net" "net/http" "os" + "sort" "strings" "time" "github.com/gorilla/websocket" "github.com/robert-nix/ansihtml" + "github.com/test-network-function/cnf-certification-test/cnf-certification-test/identifiers" "github.com/test-network-function/cnf-certification-test/internal/clientsholder" "github.com/test-network-function/cnf-certification-test/internal/log" + "github.com/test-network-function/cnf-certification-test/pkg/arrayhelper" "github.com/test-network-function/cnf-certification-test/pkg/certsuite" "github.com/test-network-function/cnf-certification-test/pkg/configuration" "github.com/test-network-function/cnf-certification-test/pkg/provider" + "github.com/test-network-function/test-network-function-claim/pkg/claim" + yaml "gopkg.in/yaml.v2" ) type webServerContextKey string +const ( + logTimeout = 1000 +) + var ( outputFolderCtxKey webServerContextKey = "output-folder" ) @@ -73,6 +82,7 @@ func logStreamHandler(w http.ResponseWriter, r *http.Request) { fmt.Println(err) return } + time.Sleep(logTimeout) } if err := scanner.Err(); err != nil { log.Info("Error reading log file: %v", err) @@ -108,6 +118,7 @@ type ResponseData struct { Message string `json:"message"` } +//nolint:funlen func installReqHandlers() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // Set the content type to "text/html". @@ -163,6 +174,18 @@ func installReqHandlers() { return } }) + http.HandleFunc("/classification.js", func(w http.ResponseWriter, r *http.Request) { + classification := outputTestCases() + + // Set the content type to "application/javascript". + w.Header().Set("Content-Type", "application/javascript") + // Write the embedded JavaScript content to the response. + _, err := w.Write([]byte(classification)) + if err != nil { + http.Error(w, "Failed to write response", http.StatusInternalServerError) + return + } + }) // Serve the static HTML file http.HandleFunc("/logstream", logStreamHandler) @@ -259,7 +282,7 @@ func runHandler(w http.ResponseWriter, r *http.Request) { env.SetNeedsRefresh() env = provider.GetTestEnvironment() - labelsFilter := strings.Join(flattenedOptions, "") + labelsFilter := strings.Join(flattenedOptions, ",") outputFolder := r.Context().Value(outputFolderCtxKey).(string) log.Info("Running CNF Cert Suite (web-mode). Labels filter: %s, outputFolder: %s", labelsFilter, outputFolder) @@ -269,7 +292,7 @@ func runHandler(w http.ResponseWriter, r *http.Request) { response := struct { Message string `json:"Message"` }{ - Message: fmt.Sprintf("Succeeded to run %s", strings.Join(flattenedOptions, "")), + Message: fmt.Sprintf("Succeeded to run %s", strings.Join(flattenedOptions, " ")), } // Serialize the response data to JSON jsonResponse, err := json.Marshal(response) @@ -388,3 +411,77 @@ func updateTnf(tnfConfig []byte, data *RequestedData) []byte { } return newData } + +// outputTestCases outputs the Markdown representation for test cases from the catalog to stdout. +func outputTestCases() (outString string) { + // Building a separate data structure to store the key order for the map + keys := make([]claim.Identifier, 0, len(identifiers.Catalog)) + for k := range identifiers.Catalog { + keys = append(keys, k) + } + + // Sorting the map by identifier ID + sort.Slice(keys, func(i, j int) bool { + return keys[i].Id < keys[j].Id + }) + + catalog := CreatePrintableCatalogFromIdentifiers(keys) + if catalog == nil { + return + } + // we need the list of suite's names + suites := GetSuitesFromIdentifiers(keys) + + // Sort the list of suite names + sort.Strings(suites) + + // Iterating the map by test and suite names + outString = "classification= {\n" + for _, suite := range suites { + for _, k := range catalog[suite] { + classificationString := "\"categoryClassification\": " + // Every paragraph starts with a new line. + + outString += fmt.Sprintf("%q: [\n{\n", k.identifier.Id) + outString += fmt.Sprintf("\"description\": %q,\n", strings.ReplaceAll(strings.ReplaceAll(identifiers.Catalog[k.identifier].Description, "\n", " "), "\"", " ")) + outString += fmt.Sprintf("\"remediation\": %q,\n", strings.ReplaceAll(strings.ReplaceAll(identifiers.Catalog[k.identifier].Remediation, "\n", " "), "\"", " ")) + outString += fmt.Sprintf("\"bestPracticeReference\": %q,\n", strings.ReplaceAll(identifiers.Catalog[k.identifier].BestPracticeReference, "\n", " ")) + outString += classificationString + toJSONString(identifiers.Catalog[k.identifier].CategoryClassification) + ",\n}\n]\n," + } + } + outString += "}" + return outString +} +func toJSONString(data map[string]string) string { + // Convert the map to a JSON-like string + jsonbytes, err := json.MarshalIndent(data, "", " ") + if err != nil { + return "" + } + + return string(jsonbytes) +} +func GetSuitesFromIdentifiers(keys []claim.Identifier) []string { + var suites []string + for _, i := range keys { + suites = append(suites, i.Suite) + } + return arrayhelper.Unique(suites) +} + +type Entry struct { + testName string + identifier claim.Identifier // {url and version} +} + +func CreatePrintableCatalogFromIdentifiers(keys []claim.Identifier) map[string][]Entry { + catalog := make(map[string][]Entry) + // we need the list of suite's names + for _, i := range keys { + catalog[i.Suite] = append(catalog[i.Suite], Entry{ + testName: i.Id, + identifier: i, + }) + } + return catalog +}