From 398dcd3e75651e047e307a3207fb2b8dc1207ab0 Mon Sep 17 00:00:00 2001 From: Bogumil Zebek Date: Wed, 20 Jan 2021 14:53:39 +0100 Subject: Add release parameter to rules - All vnf/pnf rules where updated. Release parameter was added into the info->metadata section. - VNFSDK validation logic supports optional release parameter. Parameter defines which rules should be used during validation process. By default: all rules are used during validation process. --release parameter defines which rules (parent with ancestors) should be used. For example: if user run validation with --release=dublin, then amsterdam, casablanca and dublin rules will be used during validation. Rules order is defined in the vnfreqs.properties file. Change-Id: I3e9dc1e7a899fa51c266808cbcb73e04a2e252cc Issue-ID: VNFSDK-731 Signed-off-by: Zebek Bogumil --- .../main/java/org/onap/cvc/csar/CsarValidator.java | 156 +++++++++++ .../java/org/onap/cvc/csar/ReleasesResolver.java | 62 ++++ .../java/org/onap/cvc/csar/RulesToValidate.java | 40 +++ .../java/org/onap/cvc/csar/VTPValidateCSAR.java | 123 +++----- .../main/java/org/onap/cvc/csar/oclip/Command.java | 43 +++ .../org/onap/cvc/csar/oclip/CommandFactory.java | 61 ++++ .../sol001/vtp-validate-csar-r02454.yaml | 4 +- .../sol001/vtp-validate-csar-r09467.yaml | 4 +- .../sol001/vtp-validate-csar-r15837.yaml | 4 +- .../sol001/vtp-validate-csar-r17852.yaml | 4 +- .../sol001/vtp-validate-csar-r32155.yaml | 4 +- .../sol001/vtp-validate-csar-r35851.yaml | 4 +- .../sol001/vtp-validate-csar-r35854.yaml | 4 +- .../sol001/vtp-validate-csar-r46527.yaml | 4 +- .../sol001/vtp-validate-csar-r54356.yaml | 4 +- .../sol001/vtp-validate-csar-r65486.yaml | 4 +- .../sol001/vtp-validate-csar-r67895.yaml | 4 +- .../sol001/vtp-validate-csar-r95321.yaml | 4 +- .../sol004/vtp-validate-csar-r01123.yaml | 4 +- .../sol004/vtp-validate-csar-r04298.yaml | 4 +- .../sol004/vtp-validate-csar-r07879.yaml | 4 +- .../sol004/vtp-validate-csar-r10087.yaml | 4 +- .../sol004/vtp-validate-csar-r130206.yaml | 4 +- .../sol004/vtp-validate-csar-r13390.yaml | 4 +- .../sol004/vtp-validate-csar-r146092.yaml | 4 +- .../sol004/vtp-validate-csar-r21322.yaml | 4 +- .../sol004/vtp-validate-csar-r23823.yaml | 4 +- .../sol004/vtp-validate-csar-r26881.yaml | 4 +- .../sol004/vtp-validate-csar-r26885.yaml | 4 +- .../sol004/vtp-validate-csar-r27310.yaml | 4 +- .../sol004/vtp-validate-csar-r293901.yaml | 4 +- .../sol004/vtp-validate-csar-r40293.yaml | 4 +- .../sol004/vtp-validate-csar-r40820.yaml | 4 +- .../sol004/vtp-validate-csar-r43958.yaml | 4 +- .../sol004/vtp-validate-csar-r51347.yaml | 3 +- .../sol004/vtp-validate-csar-r57019.yaml | 4 +- .../sol004/vtp-validate-csar-r66070.yaml | 4 +- .../sol004/vtp-validate-csar-r77707.yaml | 4 +- .../sol004/vtp-validate-csar-r77786.yaml | 4 +- .../sol004/vtp-validate-csar-r787965.yaml | 4 +- .../sol004/vtp-validate-csar-r816745.yaml | 4 +- .../sol004/vtp-validate-csar-r87234.yaml | 4 +- .../sol004/vtp-validate-csar-r972082.yaml | 4 +- .../open-cli-schema/vtp-validate-csar.yaml | 9 +- .../src/main/resources/vnfreqs.properties | 1 + .../java/org/onap/cvc/csar/CsarValidatorTest.java | 212 ++++++++++++++ .../org/onap/cvc/csar/ReleaseResolverTest.java | 85 ++++++ .../functional/PnfValidationFunctionalTest.java | 312 +++++++++++---------- .../functional/VnfValidationFunctionalTest.java | 48 ++-- 49 files changed, 1020 insertions(+), 279 deletions(-) create mode 100644 csarvalidation/src/main/java/org/onap/cvc/csar/CsarValidator.java create mode 100644 csarvalidation/src/main/java/org/onap/cvc/csar/ReleasesResolver.java create mode 100644 csarvalidation/src/main/java/org/onap/cvc/csar/RulesToValidate.java create mode 100644 csarvalidation/src/main/java/org/onap/cvc/csar/oclip/Command.java create mode 100644 csarvalidation/src/main/java/org/onap/cvc/csar/oclip/CommandFactory.java create mode 100644 csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java create mode 100644 csarvalidation/src/test/java/org/onap/cvc/csar/ReleaseResolverTest.java (limited to 'csarvalidation/src') diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/CsarValidator.java b/csarvalidation/src/main/java/org/onap/cvc/csar/CsarValidator.java new file mode 100644 index 0000000..cee45fe --- /dev/null +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/CsarValidator.java @@ -0,0 +1,156 @@ +/* + * Copyright 2021 Nokia + *

+ * 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. + */ +package org.onap.cvc.csar; + +import org.apache.commons.lang3.tuple.Pair; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cvc.csar.oclip.Command; +import org.onap.cvc.csar.oclip.CommandFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class CsarValidator { + + private final CommandFactory commandFactory; + private final List ignoreCodes; + private final List activeRules; + private final ReleasesResolver releasesResolver; + private final RulesToValidate rulesToValidate; + + public CsarValidator(CommandFactory commandFactory, List ignoreCodes, + List activeRules, ReleasesResolver releasesResolver, + RulesToValidate rulesToValidate) { + this.commandFactory = commandFactory; + this.ignoreCodes = ignoreCodes; + this.activeRules = activeRules; + this.releasesResolver = releasesResolver; + this.rulesToValidate = rulesToValidate; + } + + Pair> validate(ValidationContext validationContext) { + + boolean overallPass = true; + List results = new ArrayList<>(); + + final List rules = getRulesToExecute(); + + for (String rule : rules) { + final Pair> pair = executeValidation(releasesResolver, ignoreCodes, rule, validationContext); + overallPass &= pair.getLeft(); + results.addAll(pair.getRight()); + } + + return Pair.of(overallPass, results); + } + + private List getRulesToExecute() { + final List rulesToExecute = rulesToValidate.get(); + + return activeRules.stream().filter( + it -> rulesToExecute.isEmpty() || rulesToExecute.contains(it) + ).collect(Collectors.toList()); + } + + private Pair> executeValidation( + ReleasesResolver releasesResolver, List ignoreCodes, + String reqName, ValidationContext validationContext) { + + boolean overallPass = true; + List results = new ArrayList<>(); + VTPValidateCSAR.CSARValidation.Result result = new VTPValidateCSAR.CSARValidation.Result(); + result.setVnfreqName(reqName); + + try { + Command cmd = getCommand(reqName, validationContext); + if (releasesResolver.resolveWithAncestors(validationContext.getRelease()).contains(cmd.getRelease())) { + final List errors = cmd.run(); + + result.setDescription(cmd.getDescription()); + + final Pair, List> segregateErrors = segregate(errors, ignoreCodes, reqName); + overallPass = segregateErrors.getLeft().isEmpty(); + result.addErrors(segregateErrors.getLeft()); + result.addErrorsAsWarnings(segregateErrors.getRight()); + result.setPassed(result.getErrors().isEmpty()); + results.add(result); + } + } catch (Exception e) { + result.setPassed(false); + overallPass = false; + result.addError(new CSARArchive.CSARErrorUnknown(e.getMessage())); + results.add(result); + } + return Pair.of(overallPass, results); + } + + private Command getCommand(String reqName, ValidationContext validationContext) throws OnapCommandException { + return validationContext.isPnf() ? commandFactory.createForPnf(reqName, validationContext.getPathToCsar(), validationContext.getProduct()) : commandFactory.createForVnf(reqName, validationContext.getPathToCsar(), validationContext.getProduct()); + } + + private Pair, List> segregate( + List errors, List ignoreCodes, String reqName){ + + final List errorsList = new ArrayList<>(); + final List warningsList = new ArrayList<>(); + + for (CSARArchive.CSARError error : errors) { + if (!isErrorIgnored(ignoreCodes, reqName, error)) { + errorsList.add(error); + } else { + warningsList.add(error); + } + } + + return Pair.of(errorsList,warningsList); + } + + private boolean isErrorIgnored(List ignoreCodes, String reqName, CSARArchive.CSARError error) { + return ignoreCodes.contains(error.getCode()) || ignoreCodes.contains(reqName + "-" + error.getCode()); + } + + public static class ValidationContext { + private final String pathToCsar; + private final String product; + private final String release; + private final boolean isPnf; + + + public ValidationContext(String pathToCsar, String product, String release, boolean isPnf) { + this.pathToCsar = pathToCsar; + this.product = product; + this.release = release; + this.isPnf = isPnf; + } + + public String getPathToCsar() { + return pathToCsar; + } + + public String getProduct() { + return product; + } + + public String getRelease() { + return release; + } + + public boolean isPnf() { + return isPnf; + } + } +} diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/ReleasesResolver.java b/csarvalidation/src/main/java/org/onap/cvc/csar/ReleasesResolver.java new file mode 100644 index 0000000..4a9c8d1 --- /dev/null +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/ReleasesResolver.java @@ -0,0 +1,62 @@ +/* + * Copyright 2021 Nokia + * + * 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. + */ +package org.onap.cvc.csar; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +public class ReleasesResolver { + public static final String SPLIT_BY_COMMA = ","; + public static final String SPECIAL_KEYWORD = "latest"; + public static final int NOT_FOUND = -1; + private final String[] releaseInOrder; + + private ReleasesResolver(String[] releaseInOrder) { + this.releaseInOrder = releaseInOrder; + } + + public static ReleasesResolver create(String releaseInOrder) { + return new ReleasesResolver(releaseInOrder.split(SPLIT_BY_COMMA)); + } + + public List resolveWithAncestors(String release) { + final int index = findIndexOf(release); + if (isReleaseAvailable(index)) { + throw new IllegalArgumentException(String.format("Release '%s' is not defined at the releases.order list in a vnfreqs.properties file!", release)); + } + return new LinkedList<>(getElements(this.releaseInOrder, index)); + } + + private boolean isReleaseAvailable(int index) { + return index == NOT_FOUND; + } + + private List getElements(String[] elements, int index) { + return Arrays.asList(elements).subList(0, index + 1); + } + + private int findIndexOf(String release) { + if (release.equals(SPECIAL_KEYWORD)) { + return getIndexOfLastElement(); + } + return Arrays.asList(this.releaseInOrder).indexOf(release); + } + + private int getIndexOfLastElement() { + return this.releaseInOrder.length - 1; + } +} diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/RulesToValidate.java b/csarvalidation/src/main/java/org/onap/cvc/csar/RulesToValidate.java new file mode 100644 index 0000000..7ca0dc5 --- /dev/null +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/RulesToValidate.java @@ -0,0 +1,40 @@ +/* + * Copyright 2021 Nokia + *

+ * 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. + */ +package org.onap.cvc.csar; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class RulesToValidate { + private static final String RULES_ATTRIBUTE_SEPARATOR = ","; + private final String rulesToValidate; + + public RulesToValidate(String rulesToValidate) { + this.rulesToValidate = rulesToValidate; + } + + public List get(){ + List rules = new ArrayList<>(); + + if(!rulesToValidate.isEmpty()){ + String[] listOfRulesToValidate = rulesToValidate.split(RULES_ATTRIBUTE_SEPARATOR); + rules.addAll(Arrays.asList(listOfRulesToValidate)); + } + + return rules; + } +} diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java b/csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java index 637a454..2e99be3 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java @@ -18,19 +18,21 @@ package org.onap.cvc.csar; import com.google.gson.Gson; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Properties; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.tuple.Pair; import org.onap.cli.fw.cmd.OnapCommand; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandExecutionFailed; -import org.onap.cli.fw.error.OnapCommandInvalidParameterValue; -import org.onap.cli.fw.input.OnapCommandParameter; import org.onap.cli.fw.output.OnapCommandResultType; -import org.onap.cli.fw.registrar.OnapCommandRegistrar; import org.onap.cli.fw.schema.OnapCommandSchema; import org.onap.cvc.csar.CSARArchive.CSARError; +import org.onap.cvc.csar.oclip.CommandFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,9 +42,9 @@ import org.slf4j.LoggerFactory; @OnapCommandSchema(schema = "vtp-validate-csar.yaml") public class VTPValidateCSAR extends OnapCommand { - private static Gson gson = new Gson(); + private static final Gson GSON = new Gson(); private static final Logger LOG = LoggerFactory.getLogger(VTPValidateCSAR.class); - private static final String RULES_ATTRIBUTE_SEPARATOR = ","; + private static final String RELEASE_ATTRIBUTE_NAME = "release"; private static final String PNF_ATTRIBUTE_NAME = "pnf"; private static final String CSAR_ATTRIBUTE_NAME = "csar"; private static final String RULES_ATTRIBUTE_NAME = "rules"; @@ -107,8 +109,8 @@ public class VTPValidateCSAR extends OnapCommand { private boolean passed; private String vnfreqName; private String description; - private List errors = new ArrayList<>(); - private List warnings = new ArrayList<>(); + private final List errors = new ArrayList<>(); + private final List warnings = new ArrayList<>(); public boolean isPassed() { return passed; @@ -149,6 +151,14 @@ public class VTPValidateCSAR extends OnapCommand { public void addErrorAsWarning(CSARError error) { this.warnings.add(error); } + + public void addErrors(List errors) { + this.errors.addAll(errors); + } + + public void addErrorsAsWarnings(List warnings) { + this.warnings.addAll(warnings); + } } private List results = new ArrayList<>(); @@ -206,11 +216,11 @@ public class VTPValidateCSAR extends OnapCommand { } } - private static Properties properties = new Properties(); + private static final Properties PROPERTIES = new Properties(); static { try { - properties.load(VTPValidateCSAR.class.getResourceAsStream("/vnfreqs.properties")); + PROPERTIES.load(VTPValidateCSAR.class.getResourceAsStream("/vnfreqs.properties")); } catch (Exception e) { LOG.error(e.getMessage(), e); } @@ -219,13 +229,14 @@ public class VTPValidateCSAR extends OnapCommand { @Override protected void run() throws OnapCommandException { //Read the input arguments - String path = (String) getParametersMap().get(CSAR_ATTRIBUTE_NAME).getValue(); + String release = (String) getParametersMap().get(RELEASE_ATTRIBUTE_NAME).getValue(); + String pathToCsarFile = (String) getParametersMap().get(CSAR_ATTRIBUTE_NAME).getValue(); boolean isPnf = (boolean) getParametersMap().get(PNF_ATTRIBUTE_NAME).getValue(); String rulesToValidate = (String) getParametersMap().get(RULES_ATTRIBUTE_NAME).getValue(); boolean overallPass = true; try (CSARArchive csar = isPnf ? new PnfCSARArchive() : new CSARArchive()) { - csar.init(path); + csar.init(pathToCsarFile); csar.parse(); CSARValidation validation = createCsarValidationFor(csar); @@ -248,26 +259,11 @@ public class VTPValidateCSAR extends OnapCommand { validation.getResults().add(resultSOL004); - String keyReqs = isPnf ? "pnfreqs.enabled" : "vnfreqs.enabled"; - List activeRules = this.getPropertiesList(keyReqs); - if(rulesToValidate.isEmpty()) { - // Run thru the vnfreqs requirement checks - for (String vnfreq : activeRules) { - CSARValidation.Result result = new CSARValidation.Result(); - result.setVnfreqName(vnfreq); - overallPass = validateVnfOrPnf(path, validation, ignoreCodes, vnfreq, result, isPnf, overallPass); - } - } else { - // Validate selected rules - String[] listOfRulesToValidate = rulesToValidate.split(RULES_ATTRIBUTE_SEPARATOR); - for (String rule : listOfRulesToValidate) { - if(activeRules.contains(rule)) { - CSARValidation.Result result = new CSARValidation.Result(); - result.setVnfreqName(rule); - overallPass = validateVnfOrPnf(path, validation, ignoreCodes, rule, result, isPnf, overallPass); - } - } - } + final Pair> validationResult = + validate(pathToCsarFile, release, isPnf, ignoreCodes, new RulesToValidate(rulesToValidate)); + + overallPass &= validationResult.getLeft(); + validation.getResults().addAll(validationResult.getRight()); validation.setDate(new Date().toString()); validation.setCriteria(overallPass ? "PASS" : "FAILED"); @@ -279,39 +275,15 @@ public class VTPValidateCSAR extends OnapCommand { } } - private boolean validateVnfOrPnf(String path, CSARValidation validation, - List ignoreCodes, String vnfreq, CSARValidation.Result result, boolean isPnf, boolean overallPass) { - try { - String command = "csar-validate-" + vnfreq; - OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get(command, this.getInfo().getProduct()); - cmd.getParametersMap().get("csar").setValue(path); - setPnfValueIfAvailable(isPnf, cmd); - - result.setDescription(cmd.getDescription()); - cmd.execute(); - - for (CSARError error : (List) cmd.getResult().getOutput()) { - if (!isErrorIgnored(ignoreCodes, vnfreq, error)) { - result.addError(error); - overallPass = false; - } else { - result.addErrorAsWarning(error); - } - } - - result.setPassed(result.getErrors().isEmpty()); - validation.getResults().add(result); - } catch (Exception e) { - result.setPassed(false); - overallPass = false; - result.addError(new CSARArchive.CSARErrorUnknown(e.getMessage())); - validation.getResults().add(result); - } - return overallPass; - } + private Pair> validate(String path, String release, boolean isPnf, List ignoreCodes, RulesToValidate rulesToValidate) { + final String keyReqs = isPnf ? "pnfreqs.enabled" : "vnfreqs.enabled"; + final List activeRules = this.getPropertiesList(keyReqs); + final String releasesOrder = PROPERTIES.getProperty("releases.order"); + final ReleasesResolver releasesResolver = ReleasesResolver.create(releasesOrder); + final String product = this.getInfo().getProduct(); - private boolean isErrorIgnored(List ignoreCodes, String vnfreq, CSARError error) { - return ignoreCodes.contains(error.getCode()) || ignoreCodes.contains(vnfreq + "-" + error.getCode()); + return new CsarValidator(new CommandFactory(), ignoreCodes, activeRules, releasesResolver, rulesToValidate) + .validate(new CsarValidator.ValidationContext(path, product, release, isPnf)); } static CSARValidation createCsarValidationFor(CSARArchive csar) { @@ -325,33 +297,20 @@ public class VTPValidateCSAR extends OnapCommand { return validation; } - private void setOperationResult(CSARValidation validation) throws Exception { //NOSONAR + private void setOperationResult(CSARValidation validation) { this.getResult().getRecordsMap().get("vnf").getValues().add( - gson.toJson(validation.getVnf())); + GSON.toJson(validation.getVnf())); this.getResult().getRecordsMap().get("date").getValues().add(validation.getDate()); this.getResult().getRecordsMap().get("criteria").getValues().add(validation.getCriteria()); this.getResult().getRecordsMap().get("results").getValues().add( - gson.toJson(validation.getResults())); + GSON.toJson(validation.getResults())); - this.getResult().setOutput(gson.toJson(validation)); + this.getResult().setOutput(GSON.toJson(validation)); this.getResult().setType(OnapCommandResultType.TEXT); } - private void setPnfValueIfAvailable(boolean isPnf, OnapCommand cmd) throws OnapCommandInvalidParameterValue { - final OnapCommandParameter pnf = cmd.getParametersMap().get(PNF_ATTRIBUTE_NAME); - if (pnf != null) { - pnf.setValue(isPnf); - } - } - private List getPropertiesList(String key) { - String[] enabledReqs = properties.getProperty(key, "").split(","); - List list = new ArrayList<>(); - for (String req : enabledReqs) { - if (!req.isEmpty()) { - list.add(req); - } - } - return list; + String[] enabledReqs = PROPERTIES.getProperty(key, "").split(","); + return Arrays.stream(enabledReqs).filter(it->!it.isEmpty()).collect(Collectors.toList()); } } diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/oclip/Command.java b/csarvalidation/src/main/java/org/onap/cvc/csar/oclip/Command.java new file mode 100644 index 0000000..6c43cc5 --- /dev/null +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/oclip/Command.java @@ -0,0 +1,43 @@ +/* + * Copyright 2021 Nokia + *

+ * 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. + */ +package org.onap.cvc.csar.oclip; + +import org.onap.cli.fw.cmd.OnapCommand; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cvc.csar.CSARArchive; + +import java.util.List; + +public class Command { + private final OnapCommand cmd; + + public Command(OnapCommand cmd) { + this.cmd = cmd; + } + + public List run() throws OnapCommandException { + cmd.execute(); + return (List) cmd.getResult().getOutput(); + } + + public String getDescription() { + return cmd.getDescription(); + } + + public String getRelease(){ + return cmd.getInfo().getMetadata().getOrDefault("release","unknown"); + } +} diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/oclip/CommandFactory.java b/csarvalidation/src/main/java/org/onap/cvc/csar/oclip/CommandFactory.java new file mode 100644 index 0000000..18c1a2c --- /dev/null +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/oclip/CommandFactory.java @@ -0,0 +1,61 @@ +/* + * Copyright 2021 Nokia + *

+ * 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. + */ +package org.onap.cvc.csar.oclip; + +import org.onap.cli.fw.cmd.OnapCommand; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.error.OnapCommandInvalidParameterValue; +import org.onap.cli.fw.input.OnapCommandParameter; +import org.onap.cli.fw.registrar.OnapCommandRegistrar; + + +public class CommandFactory { + + private static final String PNF_ATTRIBUTE_NAME = "pnf"; + private static final String COMMAND_PREFIX = "csar-validate-"; + private static final String CSAR_PARAM_NAME = "csar"; + + public Command createForVnf(String req, String pathToCsarFile, String product) throws OnapCommandException { + OnapCommand cmd = createCommand(req, pathToCsarFile, product); + return new Command(cmd); + } + + public Command createForPnf(String req, String pathToCsarFile, String product) throws OnapCommandException { + OnapCommand cmd = createCommand(req, pathToCsarFile, product); + markCommandAsPnf(cmd); + return new Command(cmd); + } + + private OnapCommand createCommand(String req, String pathToCsarFile, String product) throws OnapCommandException { + String command = createCommandFor(req); + OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get(command, product); + setPathToCsar(pathToCsarFile, cmd); + return cmd; + } + + private String createCommandFor(String req) { + return COMMAND_PREFIX + req; + } + + private void setPathToCsar(String pathToCsarFile, OnapCommand cmd) throws OnapCommandInvalidParameterValue { + cmd.getParametersMap().get(CSAR_PARAM_NAME).setValue(pathToCsarFile); + } + + private void markCommandAsPnf(OnapCommand cmd) throws OnapCommandInvalidParameterValue { + final OnapCommandParameter pnf = cmd.getParametersMap().get(PNF_ATTRIBUTE_NAME); + pnf.setValue(true); + } +} diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r02454.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r02454.yaml index dc3d18b..5606d67 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r02454.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r02454.yaml @@ -22,10 +22,12 @@ description: | and backward compatibility to be transparent to the Service Provider usage. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: casablanca parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r09467.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r09467.yaml index 71aa8f0..50c6771 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r09467.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r09467.yaml @@ -19,10 +19,12 @@ name: csar-validate-r09467 description: The VNF MUST utilize only NCSP standard compute flavors. [5] - compute, virtual storage. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r15837.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r15837.yaml index 8e7cd11..1853e92 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r15837.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r15837.yaml @@ -20,10 +20,12 @@ description: | Major TOSCA Types specified in ETSI NFV-SOL001 standard draft. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r17852.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r17852.yaml index 7e1f4b9..7ebe770 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r17852.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r17852.yaml @@ -21,10 +21,12 @@ description: | these definitions MUST comply with TOSCA Simple Profile in YAML v.1.2. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r32155.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r32155.yaml index b2e8dc9..15e12b7 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r32155.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r32155.yaml @@ -21,10 +21,12 @@ description: | An on-boarding entity (ONAP SDC) MUST support them.. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r35851.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r35851.yaml index 127dc75..4bed68b 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r35851.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r35851.yaml @@ -22,10 +22,12 @@ description: | latency, jitter, QoS (if applicable) for each interface. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: casablanca parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r35854.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r35854.yaml index ebdc83c..dce36ad 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r35854.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r35854.yaml @@ -21,10 +21,12 @@ description: | for VNF/PNF descriptor specified in ETSI NFV-SOL001. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r46527.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r46527.yaml index 72c8967..7a2e25d 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r46527.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r46527.yaml @@ -22,10 +22,12 @@ description: | and interfaces requirements and MUST comply with info elements specified in ETSI GS NFV-IFA 011. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r54356.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r54356.yaml index 9d19257..26d365d 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r54356.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r54356.yaml @@ -21,10 +21,12 @@ description: | The node data definitions/attributes used in VNFD MUST comply. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r65486.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r65486.yaml index 082da04..2f00535 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r65486.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r65486.yaml @@ -21,10 +21,12 @@ description: | maintaining the gaps with the requirements specified in ETSI GS NFV-IFA011 standard. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r67895.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r67895.yaml index 280dc68..36e6599 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r67895.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r67895.yaml @@ -21,10 +21,12 @@ description: | An on-boarding entity (ONAP SDC) MUST support them. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r95321.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r95321.yaml index 60fe9ed..486f286 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r95321.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol001/vtp-validate-csar-r95321.yaml @@ -21,10 +21,12 @@ description: | An on-boarding entity (ONAP SDC) MUST support them. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r01123.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r01123.yaml index 577b2ca..7ba4d36 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r01123.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r01123.yaml @@ -26,10 +26,12 @@ description: | description, provider and version. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r04298.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r04298.yaml index 889eb2f..0c170fe 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r04298.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r04298.yaml @@ -19,10 +19,12 @@ name: csar-validate-r04298 description: VNF provider MUST provider their testing scripts to support testing info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: casablanca parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r07879.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r07879.yaml index 9c53315..dbba3c0 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r07879.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r07879.yaml @@ -19,10 +19,12 @@ name: csar-validate-r07879 description: The VNF Package MUST include all relevant playbooks to ONAP to be loaded on the Ansible Server. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r10087.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r10087.yaml index ea8cd8d..d9911b8 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r10087.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r10087.yaml @@ -22,10 +22,12 @@ description: | CSAR Manifest file as per SOL004 - for example ROOT\ MainServiceTemplate.mf info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r130206.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r130206.yaml index ff349bc..5f02207 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r130206.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r130206.yaml @@ -20,10 +20,12 @@ description: | The VNF/PNF package shall contain a Digest (a.k.a. hash) for each of the components of the VNF package. The table of hashes is included in the manifest file, which is signed with the VNF provider private key. In addition, the VNF provider shall include a signing certificate that includes the VNF provider public key, following a pre-defined naming convention and located either at the root of the archive or in a predefined location (e.g. directory). info: - product: onap-dublin + product: onap-vtp version: 1.0 service: validation author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: guilin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r13390.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r13390.yaml index b157456..c7dccf4 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r13390.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r13390.yaml @@ -19,10 +19,12 @@ name: csar-validate-r13390 description: The VNF provider MUST provide cookbooks to be loaded on the appropriate Chef Server. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r146092.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r146092.yaml index 0f4201e..df53e7c 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r146092.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r146092.yaml @@ -27,10 +27,12 @@ description: | -onap_yang_modules info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r21322.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r21322.yaml index 08251ef..0d48065 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r21322.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r21322.yaml @@ -21,10 +21,12 @@ description: | Testing directory in CSAR. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r23823.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r23823.yaml index e061889..f877072 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r23823.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r23823.yaml @@ -19,10 +19,12 @@ name: csar-validate-r23823 description: The VNF Package MUST include appropriate credentials so that ONAP can interact with the Chef Server info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r26881.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r26881.yaml index 5836de2..7900ea1 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r26881.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r26881.yaml @@ -19,10 +19,12 @@ name: csar-validate-r26881 description: The VNF provider MUST provide the binaries and images needed to instantiate the VNF (VNF and VNFC images). info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r26885.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r26885.yaml index 44f4f04..b3a1fe2 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r26885.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r26885.yaml @@ -23,10 +23,12 @@ description: | Note: Currently, ONAP doesn’t have the capability of Image management, we upload the image into VIM/VNFM manually. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r27310.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r27310.yaml index 29e1fc9..3d8afa4 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r27310.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r27310.yaml @@ -21,10 +21,12 @@ description: | required to execute VNF actions requested by ONAP for loading on appropriate Chef Server. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r293901.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r293901.yaml index eee8c36..99ed88d 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r293901.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r293901.yaml @@ -25,10 +25,12 @@ description: | -ETSI-Entry-Change-Log info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r40293.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r40293.yaml index 7173dc2..924c425 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r40293.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r40293.yaml @@ -19,10 +19,12 @@ name: csar-validate-r40293 description: The VNF MUST make available (or load on VNF Ansible Server) playbooks that conform to the ONAP requirement. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r40820.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r40820.yaml index 45808ad..33991c3 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r40820.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r40820.yaml @@ -21,10 +21,12 @@ description: | directory as per ETSI SOL004. for example ROOT\Licenses\ License_term.txt info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r43958.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r43958.yaml index 084644a..99c5a1f 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r43958.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r43958.yaml @@ -19,10 +19,12 @@ name: csar-validate-r43958 description: The VNF Package MUST include documentation describing the tests that were conducted by the VNF provider and the test results. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r51347.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r51347.yaml index 7ed4222..5036de5 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r51347.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r51347.yaml @@ -20,13 +20,14 @@ description: | The VNF package MUST be arranged as a CSAR archive as specified in TOSCA Simple Profile in YAML 1.2. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org metadata: keyword: MUST introduced: casablanca + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r57019.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r57019.yaml index 1ca611a..ec2ab07 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r57019.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r57019.yaml @@ -26,10 +26,12 @@ description: | -pnfd_archive_version info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r66070.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r66070.yaml index d5eaf4f..5b069a0 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r66070.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r66070.yaml @@ -23,10 +23,12 @@ description: | VNF provider, and version info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: casablanca parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r77707.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r77707.yaml index 42331e3..e6478bd 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r77707.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r77707.yaml @@ -19,10 +19,12 @@ name: csar-validate-r77707 description: VNF provider MUST include manifest file that contains a list of all the components in VNF package info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: casablanca parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r77786.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r77786.yaml index 2f9c8ae..c296474 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r77786.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r77786.yaml @@ -19,10 +19,12 @@ name: csar-validate-r77786 description: The VNF Package MUST include all relevant cookbooks to be loaded on the ONAP Chef Server. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: casablanca parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r787965.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r787965.yaml index db5a1a1..e07434f 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r787965.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r787965.yaml @@ -20,10 +20,12 @@ description: | If the VNF or PNF CSAR Package utilizes Option 2 for package security, then the complete CSAR file MUST be digitally signed with the VNF or PNF provider private key. The VNF or PNF provider delivers one zip file consisting of the CSAR file, a signature file and a certificate file that includes the VNF or PNF provider public key. The certificate may also be included in the signature container, if the signature format allows that. The VNF or PNF provider creates a zip file consisting of the CSAR file with .csar extension, signature and certificate files. The signature and certificate files must be siblings of the CSAR file with extensions .cms and .cert respectively. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r816745.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r816745.yaml index 8ef80dd..14b838a 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r816745.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r816745.yaml @@ -25,10 +25,12 @@ description: | info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: guilin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r87234.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r87234.yaml index de78d8b..5d63612 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r87234.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r87234.yaml @@ -22,10 +22,12 @@ description: | (ONAP SDC) must support both options. info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: dublin parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r972082.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r972082.yaml index 53a6827..84d8a5c 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r972082.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r972082.yaml @@ -24,10 +24,12 @@ description: | - pnf_software_version: "" info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org + metadata: + release: frankfurt parameters: - name: csar diff --git a/csarvalidation/src/main/resources/open-cli-schema/vtp-validate-csar.yaml b/csarvalidation/src/main/resources/open-cli-schema/vtp-validate-csar.yaml index b77dfa2..e6727eb 100644 --- a/csarvalidation/src/main/resources/open-cli-schema/vtp-validate-csar.yaml +++ b/csarvalidation/src/main/resources/open-cli-schema/vtp-validate-csar.yaml @@ -19,12 +19,19 @@ name: csar-validate description: Validate CSAR package formats compliants to ETSI SOL004, SOL001 and VNFREQS info: - product: onap-dublin + product: onap-vtp version: 1.0 service: vnf-compliance author: ONAP VTP Team onap-discuss@lists.onap.org parameters: + - name: release + description: Name of release [amsterdam|casablanca|dublin|frankfurt|guilin|honolulu] + long_option: release + short_option: rel + type: binary + is_optional: true + default_value: "latest" - name: csar description: CSAR file path long_option: csar diff --git a/csarvalidation/src/main/resources/vnfreqs.properties b/csarvalidation/src/main/resources/vnfreqs.properties index 2e0baaf..1829629 100644 --- a/csarvalidation/src/main/resources/vnfreqs.properties +++ b/csarvalidation/src/main/resources/vnfreqs.properties @@ -3,3 +3,4 @@ pnfreqs.enabled=r01123,r10087,r15837,r17852,r35854,r57019,r87234,r130206,r146092 # ignored all chef and ansible related tests vnferrors.ignored=0x1005,0x1006,r07879-0x1000,r13390-0x1000,r27310-0x1000,r40293-0x1000,r77786-0x1000,r04298-0x1000,r07879-0x1000,r10087-0x1000,r13390-0x1000,r23823-0x1000,r26881-0x1000,r40820-0x1000,r35851-0x1000,r32155-0x1000,r54356-0x1000,r67895-0x1000,r95321-0x1000,r46527-0x1000,r02454-0x1000 pnferrors.ignored=0x1006,r130206-0x1006 +releases.order=amsterdam,casablanca,dublin,frankfurt,guilin,honolulu diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java new file mode 100644 index 0000000..d4f2891 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java @@ -0,0 +1,212 @@ +/* + * Copyright 2021 Nokia + *

+ * 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. + */ +package org.onap.cvc.csar; + +import org.apache.commons.lang3.tuple.Pair; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cvc.csar.oclip.Command; +import org.onap.cvc.csar.oclip.CommandFactory; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class CsarValidatorTest { + + private static final String PATH_TO_CSAR_FILE = "pathToCsarFile"; + private static final String PRODUCT = "onap-vtp"; + private static final boolean IS_PNF = true; + private static final String AMSTERDAM_RULE = "rAmsterdam"; + private static final String CASABLANCA_RULE = "rCasablanca"; + private static final String DUBLIN_RULE = "rDublin"; + private static final String FRANKFURT_RULE = "rFrankfurt"; + private static final String GUILIN_RULE = "rGuilin"; + private static final String HONOLULU_RULE = "rHonolulu"; + private static final String AMSTERDAM_RELEASE = "amsterdam"; + private static final String CASABLANCA_RELEASE = "casablanca"; + private static final String DUBLIN_RELEASE = "dublin"; + private static final String FRANKFURT_RELEASE = "frankfurt"; + private static final String GUILIN_RELEASE = "guilin"; + private static final String HONOLULU_RELEASE = "honolulu"; + @Mock + private CommandFactory commandFactory; + private final ReleasesResolver releasesResolver = ReleasesResolver.create("amsterdam,casablanca,dublin,frankfurt,guilin,honolulu"); + private final RulesToValidate rulesToValidate = new RulesToValidate(""); + private final List activeRules = List.of(AMSTERDAM_RULE, CASABLANCA_RULE, DUBLIN_RULE, FRANKFURT_RULE, GUILIN_RULE, HONOLULU_RULE); + + private final List ignoreCodes = List.of(); + + private CsarValidator csarValidator; + + + @Before + public void setUp() { + this.csarValidator = new CsarValidator(commandFactory, ignoreCodes, activeRules, releasesResolver, rulesToValidate); + } + + @Test + public void shouldReportAnErrorWhenReleaseIsNotRecognized() throws OnapCommandException { + + // given + Command cmdAmsterdam = givenCmdFor(AMSTERDAM_RULE, AMSTERDAM_RELEASE); + Command cmdCasablanca = givenCmdFor(CASABLANCA_RULE, CASABLANCA_RELEASE); + Command cmdDublin = givenCmdFor(DUBLIN_RULE, DUBLIN_RELEASE); + Command cmdFrankfurt = givenCmdFor(FRANKFURT_RULE, FRANKFURT_RELEASE); + Command cmdGuilin = givenCmdFor(GUILIN_RULE, GUILIN_RELEASE); + Command cmdHonolulu = givenCmdFor(HONOLULU_RULE, HONOLULU_RELEASE); + + // when + final Pair> validationResult = csarValidator.validate(new CsarValidator.ValidationContext(PATH_TO_CSAR_FILE, PRODUCT, "validationResult", IS_PNF)); + + // then + assertThat(validationResult.getLeft()).isFalse(); + verify(cmdAmsterdam, never()).run(); + verify(cmdCasablanca, never()).run(); + verify(cmdDublin, never()).run(); + verify(cmdFrankfurt, never()).run(); + verify(cmdGuilin, never()).run(); + verify(cmdHonolulu, never()).run(); + } + + @Test + public void shouldValidateCsarUsingAllRulesWhenReleaseIsLatest() throws OnapCommandException { + + // given + Command cmdAmsterdam = givenCmdFor(AMSTERDAM_RULE, AMSTERDAM_RELEASE); + Command cmdCasablanca = givenCmdFor(CASABLANCA_RULE, CASABLANCA_RELEASE); + Command cmdDublin = givenCmdFor(DUBLIN_RULE, DUBLIN_RELEASE); + Command cmdFrankfurt = givenCmdFor(FRANKFURT_RULE, FRANKFURT_RELEASE); + Command cmdGuilin = givenCmdFor(GUILIN_RULE, GUILIN_RELEASE); + Command cmdHonolulu = givenCmdFor(HONOLULU_RULE, HONOLULU_RELEASE); + + // when + csarValidator.validate(new CsarValidator.ValidationContext(PATH_TO_CSAR_FILE, PRODUCT, "latest", IS_PNF)); + + // then + verify(cmdAmsterdam).run(); + verify(cmdCasablanca).run(); + verify(cmdDublin).run(); + verify(cmdFrankfurt).run(); + verify(cmdGuilin).run(); + verify(cmdHonolulu).run(); + } + + @Test + public void shouldValidateCsarUsingOnlyAmsterdamRulesWhenReleaseIsAmsterdam() throws OnapCommandException { + // given + Command cmdAmsterdam = givenCmdFor(AMSTERDAM_RULE, AMSTERDAM_RELEASE); + Command cmdCasablanca = givenCmdFor(CASABLANCA_RULE, CASABLANCA_RELEASE); + Command cmdDublin = givenCmdFor(DUBLIN_RULE, DUBLIN_RELEASE); + Command cmdFrankfurt = givenCmdFor(FRANKFURT_RULE, FRANKFURT_RELEASE); + Command cmdGuilin = givenCmdFor(GUILIN_RULE, GUILIN_RELEASE); + Command cmdHonolulu = givenCmdFor(HONOLULU_RULE, HONOLULU_RELEASE); + + // when + csarValidator.validate(new CsarValidator.ValidationContext(PATH_TO_CSAR_FILE, PRODUCT, AMSTERDAM_RELEASE, IS_PNF)); + + // then + verify(cmdAmsterdam).run(); + verify(cmdCasablanca, never()).run(); + verify(cmdDublin, never()).run(); + verify(cmdFrankfurt, never()).run(); + verify(cmdGuilin, never()).run(); + verify(cmdHonolulu, never()).run(); + } + + @Test + public void shouldValidateCsarUsingCasablancaWithAncestorRulesWhenReleaseIsCasablanca() throws OnapCommandException { + // given + Command cmdAmsterdam = givenCmdFor(AMSTERDAM_RULE, AMSTERDAM_RELEASE); + Command cmdCasablanca = givenCmdFor(CASABLANCA_RULE, CASABLANCA_RELEASE); + Command cmdDublin = givenCmdFor(DUBLIN_RULE, DUBLIN_RELEASE); + Command cmdFrankfurt = givenCmdFor(FRANKFURT_RULE, FRANKFURT_RELEASE); + Command cmdGuilin = givenCmdFor(GUILIN_RULE, GUILIN_RELEASE); + Command cmdHonolulu = givenCmdFor(HONOLULU_RULE, HONOLULU_RELEASE); + + // when + csarValidator.validate(new CsarValidator.ValidationContext(PATH_TO_CSAR_FILE, PRODUCT, CASABLANCA_RELEASE, IS_PNF)); + + // then + verify(cmdAmsterdam).run(); + verify(cmdCasablanca).run(); + verify(cmdDublin, never()).run(); + verify(cmdFrankfurt, never()).run(); + verify(cmdGuilin, never()).run(); + verify(cmdHonolulu, never()).run(); + } + + @Test + public void shouldValidateCsarUsingDublinWithAncestorRulesWhenReleaseIsDublin() throws OnapCommandException { + // given + Command cmdAmsterdam = givenCmdFor(AMSTERDAM_RULE, AMSTERDAM_RELEASE); + Command cmdCasablanca = givenCmdFor(CASABLANCA_RULE, CASABLANCA_RELEASE); + Command cmdDublin = givenCmdFor(DUBLIN_RULE, DUBLIN_RELEASE); + Command cmdFrankfurt = givenCmdFor(FRANKFURT_RULE, FRANKFURT_RELEASE); + Command cmdGuilin = givenCmdFor(GUILIN_RULE, GUILIN_RELEASE); + Command cmdHonolulu = givenCmdFor(HONOLULU_RULE, HONOLULU_RELEASE); + + // when + csarValidator.validate(new CsarValidator.ValidationContext(PATH_TO_CSAR_FILE, PRODUCT, DUBLIN_RELEASE, IS_PNF)); + + // then + verify(cmdAmsterdam).run(); + verify(cmdCasablanca).run(); + verify(cmdDublin).run(); + verify(cmdFrankfurt, never()).run(); + verify(cmdGuilin, never()).run(); + verify(cmdHonolulu, never()).run(); + } + + @Test + public void shouldValidateCsarUsingHonoluluWithAncestorRulesWhenReleaseIsHonolulu() throws OnapCommandException { + // given + Command cmdAmsterdam = givenCmdFor(AMSTERDAM_RULE, AMSTERDAM_RELEASE); + Command cmdCasablanca = givenCmdFor(CASABLANCA_RULE, CASABLANCA_RELEASE); + Command cmdDublin = givenCmdFor(DUBLIN_RULE, DUBLIN_RELEASE); + Command cmdFrankfurt = givenCmdFor(FRANKFURT_RULE, FRANKFURT_RELEASE); + Command cmdGuilin = givenCmdFor(GUILIN_RULE, GUILIN_RELEASE); + Command cmdHonolulu = givenCmdFor(HONOLULU_RULE, HONOLULU_RELEASE); + + // when + csarValidator.validate(new CsarValidator.ValidationContext(PATH_TO_CSAR_FILE, PRODUCT, HONOLULU_RELEASE, IS_PNF)); + + // then + verify(cmdAmsterdam).run(); + verify(cmdCasablanca).run(); + verify(cmdDublin).run(); + verify(cmdFrankfurt).run(); + verify(cmdGuilin).run(); + verify(cmdHonolulu).run(); + } + + private Command givenCmdFor(String rule, String release) throws OnapCommandException { + Command cmd = Mockito.mock(Command.class); + Mockito.when(commandFactory.createForPnf(rule, PATH_TO_CSAR_FILE, PRODUCT)).thenReturn(cmd); + Mockito.when(cmd.getRelease()).thenReturn(release); + Mockito.when(cmd.run()).thenReturn(List.of()); + + return cmd; + } +} diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/ReleaseResolverTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/ReleaseResolverTest.java new file mode 100644 index 0000000..a3ad6e7 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/ReleaseResolverTest.java @@ -0,0 +1,85 @@ +/* + * Copyright 2021 Nokia + *

+ * 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. + */ +package org.onap.cvc.csar; + + +import org.junit.Test; + +import java.io.IOException; +import java.util.Properties; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class ReleaseResolverTest { + + private static final Properties APP_CONFIGURATION = new Properties(); + + static { + try { + APP_CONFIGURATION.load(VTPValidateCSAR.class.getResourceAsStream("/vnfreqs.properties")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private ReleasesResolver releaseResolver = ReleasesResolver.create(APP_CONFIGURATION.getProperty("releases.order")); + + @Test + public void shouldResolveReleasesForAmsterdam() { + assertThat(releaseResolver.resolveWithAncestors("amsterdam")) + .containsExactlyInAnyOrder("amsterdam"); + } + + @Test + public void shouldResolveReleasesForCasablanca() { + assertThat(releaseResolver.resolveWithAncestors("casablanca")) + .containsExactlyInAnyOrder("amsterdam", "casablanca"); + + } + + @Test + public void shouldResolveReleasesForDublin() { + assertThat(releaseResolver.resolveWithAncestors("dublin")) + .containsExactlyInAnyOrder("amsterdam", "casablanca", "dublin"); + } + + @Test + public void shouldResolveReleasesForGuilin() { + assertThat(releaseResolver.resolveWithAncestors("guilin")) + .containsExactlyInAnyOrder("amsterdam", "casablanca", "dublin", "frankfurt", "guilin"); + } + + @Test + public void shouldResolveReleasesForHonolulu() { + assertThat(releaseResolver.resolveWithAncestors("honolulu")) + .containsExactlyInAnyOrder("amsterdam", "casablanca", "dublin", "frankfurt", "guilin", "honolulu"); + } + + @Test + public void shouldResolveReleasesForLatest() { + assertThat(releaseResolver.resolveWithAncestors("latest")) + .containsExactlyInAnyOrder("amsterdam", "casablanca", "dublin", "frankfurt", "guilin", "honolulu"); + } + + @Test + public void shouldReportAnErrorWhenReleaseIsUnknown() { + assertThatThrownBy(() -> + releaseResolver.resolveWithAncestors("unknown") + ).isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Release 'unknown' is not defined at the releases.order list in a vnfreqs.properties file!"); + } +} diff --git a/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java b/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java index 2477377..3e3877e 100644 --- a/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java +++ b/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Nokia + * Copyright 2021 Nokia *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,10 +42,10 @@ public class PnfValidationFunctionalTest { public void shouldReportOnlyWarningWhenCsarDoNotHaveCertificateAndHashesInManifest() throws URISyntaxException { // given OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper expectedWarning = - createExpectedError(CERTIFICATION_RULE, "0x1006", - "Warning. Consider adding package integrity and authenticity assurance according to ETSI NFV-SOL 004 Security Option 1"); + createExpectedError(CERTIFICATION_RULE, "0x1006", + "Warning. Consider adding package integrity and authenticity assurance according to ETSI NFV-SOL 004 Security Option 1"); - OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( "pnf/validFile.csar")); + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo("pnf/validFile.csar")); // when cli.handle(); @@ -54,11 +54,11 @@ public class PnfValidationFunctionalTest { final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); assertThat(result.criteria).isEqualTo(OPERATION_STATUS_PASS); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.errors).isEmpty(); if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) { assertThat(ruleValidationResult.warnings) - .containsExactlyInAnyOrder(expectedWarning); + .containsExactlyInAnyOrder(expectedWarning); } else { assertThat(ruleValidationResult.warnings).isEmpty(); } @@ -69,7 +69,22 @@ public class PnfValidationFunctionalTest { @Test public void shouldNotReportThatPnfValidationFailedWhenZipDoNotHaveCertificatesAndHashesInManifest() throws URISyntaxException { // given - OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( "pnf/signed-package-valid-signature.zip")); + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo("pnf/signed-package-valid-signature.zip")); + + // when + cli.handle(); + + // then + final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); + + assertThat(result.criteria).isEqualTo(OPERATION_STATUS_PASS); + verifyThatOperationFinishedWithoutAnyError(cli); + } + + @Test + public void shouldPassForCasablancaWithAncestorRuleSet() throws URISyntaxException { + // given + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfoForSelectedRelease("pnf/signed-package-valid-signature.zip", "casablanca")); // when cli.handle(); @@ -85,19 +100,19 @@ public class PnfValidationFunctionalTest { public void shouldReportThatPnfValidationFailedWhenCsarContainsCertificateInCmsAndInToscaAndInRootAndHashIsIncorrect_allOtherRulesShouldPass() throws URISyntaxException { // given List expectedErrors = - List.of( - createExpectedError(CERTIFICATION_RULE, "0x4007", - "Manifest file has invalid signature!"), - createExpectedError(CERTIFICATION_RULE, "0x4004", - "Source 'Files/pnf-sw-information/pnf-sw-information.yaml' has wrong hash!"), - createExpectedError(CERTIFICATION_RULE, "0x4011", - "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), - createExpectedError(CERTIFICATION_RULE, "0x4012", - "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), - createExpectedError(CERTIFICATION_RULE, "0x4013", - "Certificate present in root catalog despite the certificate is included in the signature container") - ); - OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar")); + List.of( + createExpectedError(CERTIFICATION_RULE, "0x4007", + "Manifest file has invalid signature!"), + createExpectedError(CERTIFICATION_RULE, "0x4004", + "Source 'Files/pnf-sw-information/pnf-sw-information.yaml' has wrong hash!"), + createExpectedError(CERTIFICATION_RULE, "0x4011", + "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4012", + "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4013", + "Certificate present in root catalog despite the certificate is included in the signature container") + ); + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo("pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar")); // when cli.handle(); @@ -106,11 +121,11 @@ public class PnfValidationFunctionalTest { final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.warnings).isEmpty(); if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) { assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedErrors); + .containsExactlyInAnyOrderElementsOf(expectedErrors); } else { assertThat(ruleValidationResult.errors).isEmpty(); } @@ -122,23 +137,23 @@ public class PnfValidationFunctionalTest { public void shouldReportThatPnfCertificationRuleValidationFailedWhenCsarContainsCertificateInCmsAndInToscaAndInRootAndHashIsIncorrect() throws URISyntaxException { // given List expectedErrors = - List.of( - createExpectedError(CERTIFICATION_RULE, "0x4007", - "Manifest file has invalid signature!"), - createExpectedError(CERTIFICATION_RULE, "0x4004", - "Source 'Files/pnf-sw-information/pnf-sw-information.yaml' has wrong hash!"), - createExpectedError(CERTIFICATION_RULE, "0x4011", - "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), - createExpectedError(CERTIFICATION_RULE, "0x4012", - "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), - createExpectedError(CERTIFICATION_RULE, "0x4013", - "Certificate present in root catalog despite the certificate is included in the signature container") - ); + List.of( + createExpectedError(CERTIFICATION_RULE, "0x4007", + "Manifest file has invalid signature!"), + createExpectedError(CERTIFICATION_RULE, "0x4004", + "Source 'Files/pnf-sw-information/pnf-sw-information.yaml' has wrong hash!"), + createExpectedError(CERTIFICATION_RULE, "0x4011", + "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4012", + "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4013", + "Certificate present in root catalog despite the certificate is included in the signature container") + ); OnapCliWrapper cli = new OnapCliWrapper( - createPnfValidationSelectedRulesRequestInfo( - "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar", - CERTIFICATION_RULE - )); + createPnfValidationRequestInfoForSelectedRules( + "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar", + CERTIFICATION_RULE + )); // when cli.handle(); @@ -148,11 +163,11 @@ public class PnfValidationFunctionalTest { assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); assertThat(result.results).hasSize(2); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.warnings).isEmpty(); if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) { assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedErrors); + .containsExactlyInAnyOrderElementsOf(expectedErrors); } else { assertThat(ruleValidationResult.errors).isEmpty(); } @@ -164,10 +179,10 @@ public class PnfValidationFunctionalTest { public void shouldReportThatPnfPmDictionaryYamlRuleValidationSuccessWhenCsarContainsCertificateInCmsAndInToscaAndInRootAndHashIsIncorrect() throws URISyntaxException { // given OnapCliWrapper cli = new OnapCliWrapper( - createPnfValidationSelectedRulesRequestInfo( - "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar", - PM_DICTIONARY_YAML_RULE - )); + createPnfValidationRequestInfoForSelectedRules( + "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar", + PM_DICTIONARY_YAML_RULE + )); // when cli.handle(); @@ -177,7 +192,7 @@ public class PnfValidationFunctionalTest { assertThat(result.criteria).isEqualTo(OPERATION_STATUS_PASS); assertThat(result.results).hasSize(2); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.warnings).isEmpty(); assertThat(ruleValidationResult.errors).isEmpty(); }); @@ -188,23 +203,23 @@ public class PnfValidationFunctionalTest { public void shouldReportThatPnfCertificationRuleAndPnfPmDictionaryYamlRuleValidationFailedWhenCsarContainsCertificateInCmsAndInToscaAndInRootAndHashIsIncorrect() throws URISyntaxException { // given List expectedErrors = - List.of( - createExpectedError(CERTIFICATION_RULE, "0x4007", - "Manifest file has invalid signature!"), - createExpectedError(CERTIFICATION_RULE, "0x4004", - "Source 'Files/pnf-sw-information/pnf-sw-information.yaml' has wrong hash!"), - createExpectedError(CERTIFICATION_RULE, "0x4011", - "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), - createExpectedError(CERTIFICATION_RULE, "0x4012", - "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), - createExpectedError(CERTIFICATION_RULE, "0x4013", - "Certificate present in root catalog despite the certificate is included in the signature container") - ); + List.of( + createExpectedError(CERTIFICATION_RULE, "0x4007", + "Manifest file has invalid signature!"), + createExpectedError(CERTIFICATION_RULE, "0x4004", + "Source 'Files/pnf-sw-information/pnf-sw-information.yaml' has wrong hash!"), + createExpectedError(CERTIFICATION_RULE, "0x4011", + "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4012", + "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4013", + "Certificate present in root catalog despite the certificate is included in the signature container") + ); OnapCliWrapper cli = new OnapCliWrapper( - createPnfValidationSelectedRulesRequestInfo( - "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar", - CERTIFICATION_RULE+","+PM_DICTIONARY_YAML_RULE - )); + createPnfValidationRequestInfoForSelectedRules( + "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar", + CERTIFICATION_RULE + "," + PM_DICTIONARY_YAML_RULE + )); // when cli.handle(); @@ -214,11 +229,11 @@ public class PnfValidationFunctionalTest { assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); assertThat(result.results).hasSize(3); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.warnings).isEmpty(); if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) { assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedErrors); + .containsExactlyInAnyOrderElementsOf(expectedErrors); } else { assertThat(ruleValidationResult.errors).isEmpty(); } @@ -230,21 +245,21 @@ public class PnfValidationFunctionalTest { public void shouldReportThatIndividualArtifactHaveIncorrectCertificateAndCertificateAndSignatureAreNotPresentAsSources() throws URISyntaxException { // given List expectedCertificationErrors = - List.of( - createExpectedError(CERTIFICATION_RULE, "0x4020", - "Source 'Files/Scripts/my_script.sh' has incorrect signature!"), - createExpectedError(CERTIFICATION_RULE, "0x4007", - "Manifest file has invalid signature!") - ); + List.of( + createExpectedError(CERTIFICATION_RULE, "0x4020", + "Source 'Files/Scripts/my_script.sh' has incorrect signature!"), + createExpectedError(CERTIFICATION_RULE, "0x4007", + "Manifest file has invalid signature!") + ); List expectedManifestErrors = - List.of( - createExpectedError(MANIFEST_FILE_RULE, "0x1001", - "file(s): [Files/Scripts/my_script.cert, Files/Scripts/my_script.sig.cms] available in CSAR, but cannot be found in Manifest as Source", - "TOSCA-Metadata" - ) - ); + List.of( + createExpectedError(MANIFEST_FILE_RULE, "0x1001", + "file(s): [Files/Scripts/my_script.cert, Files/Scripts/my_script.sig.cms] available in CSAR, but cannot be found in Manifest as Source", + "TOSCA-Metadata" + ) + ); OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( - "pnf/r130206/csar-cert-in-cms-valid-with-incorrect-signature-of-individual-artifact.csar" + "pnf/r130206/csar-cert-in-cms-valid-with-incorrect-signature-of-individual-artifact.csar" )); // when @@ -254,14 +269,14 @@ public class PnfValidationFunctionalTest { final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.warnings).isEmpty(); if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) { assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedCertificationErrors); + .containsExactlyInAnyOrderElementsOf(expectedCertificationErrors); } else if (ruleValidationResult.vnfreqName.equals(MANIFEST_FILE_RULE)) { assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedManifestErrors); + .containsExactlyInAnyOrderElementsOf(expectedManifestErrors); } else { assertThat(ruleValidationResult.errors).isEmpty(); } @@ -273,61 +288,61 @@ public class PnfValidationFunctionalTest { public void shouldReportThatIndividualArtifactsHaveMultipleIncorrectCertificatesAndSignatures() throws URISyntaxException { // given List expectedCertificationErrors = - List.of( - createExpectedError(CERTIFICATION_RULE, "0x4004", + List.of( + createExpectedError(CERTIFICATION_RULE, "0x4004", "Source 'Artifacts/Deployment/Events/RadioNode_Pnf_v1.yaml' has wrong hash!"), createExpectedError(CERTIFICATION_RULE, "0x4020", "Source 'Artifacts/Deployment/Events/RadioNode_Pnf_v2.yaml' has incorrect signature!"), createExpectedError(CERTIFICATION_RULE, "0x4018", - "Source 'Artifacts/Deployment/Measurements/PM_Dictionary.yml' has 'signature' tag, pointing to non existing file!. Pointed file 'Artifacts/Deployment/Measurements/PM_Dictionary.sig.cms'"), - createExpectedError(CERTIFICATION_RULE, "0x4023", - "Source 'Artifacts/Deployment/Yang_module/yang-module1.yang' has 'signature' file with wrong name, signature name: 'yang-module.sig.cms'.Signature should have same name as source file!"), - createExpectedError(CERTIFICATION_RULE, "0x4023", - "Source 'Artifacts/Deployment/Yang_module/yang-module1.yang' has 'certificate' file with wrong name, signature name: 'yang-module.cert'.Signature should have same name as source file!"), - createExpectedError(CERTIFICATION_RULE, "0x4020", - "Source 'Artifacts/Other/my_script.csh' has incorrect signature!"), - createExpectedError(CERTIFICATION_RULE, "0x4022", - "Source 'Artifacts/Informational/user_guide.txt' has 'signature' file located in wrong directory, directory: 'Artifacts/user_guide.sig.cms'.Signature should be in same directory as source file!"), - createExpectedError(CERTIFICATION_RULE, "0x4022", - "Source 'Artifacts/Informational/user_guide.txt' has 'certificate' file located in wrong directory, directory: 'Artifacts/user_guide.cert'.Signature should be in same directory as source file!"), - createExpectedError(CERTIFICATION_RULE, "0x4007", - "Manifest file has invalid signature!") - ); + "Source 'Artifacts/Deployment/Measurements/PM_Dictionary.yml' has 'signature' tag, pointing to non existing file!. Pointed file 'Artifacts/Deployment/Measurements/PM_Dictionary.sig.cms'"), + createExpectedError(CERTIFICATION_RULE, "0x4023", + "Source 'Artifacts/Deployment/Yang_module/yang-module1.yang' has 'signature' file with wrong name, signature name: 'yang-module.sig.cms'.Signature should have same name as source file!"), + createExpectedError(CERTIFICATION_RULE, "0x4023", + "Source 'Artifacts/Deployment/Yang_module/yang-module1.yang' has 'certificate' file with wrong name, signature name: 'yang-module.cert'.Signature should have same name as source file!"), + createExpectedError(CERTIFICATION_RULE, "0x4020", + "Source 'Artifacts/Other/my_script.csh' has incorrect signature!"), + createExpectedError(CERTIFICATION_RULE, "0x4022", + "Source 'Artifacts/Informational/user_guide.txt' has 'signature' file located in wrong directory, directory: 'Artifacts/user_guide.sig.cms'.Signature should be in same directory as source file!"), + createExpectedError(CERTIFICATION_RULE, "0x4022", + "Source 'Artifacts/Informational/user_guide.txt' has 'certificate' file located in wrong directory, directory: 'Artifacts/user_guide.cert'.Signature should be in same directory as source file!"), + createExpectedError(CERTIFICATION_RULE, "0x4007", + "Manifest file has invalid signature!") + ); List expectedManifestErrors = - List.of( - createExpectedError(MANIFEST_FILE_RULE, "0x1001", - "file(s): [TOSCA-Metadata/TOSCA.meta, Definitions/MainServiceTemplate.yaml, Artifacts/Deployment/Yang_module/yang-module2.yang, Artifacts/Deployment/Yang_module/yang-module.cert, Artifacts/Deployment/Yang_module/yang-module.sig.cms, Artifacts/ChangeLog.txt, Artifacts/sample-pnf.cert] available in CSAR, but cannot be found in Manifest as Source", - "TOSCA-Metadata" - ) - ); + List.of( + createExpectedError(MANIFEST_FILE_RULE, "0x1001", + "file(s): [TOSCA-Metadata/TOSCA.meta, Definitions/MainServiceTemplate.yaml, Artifacts/Deployment/Yang_module/yang-module2.yang, Artifacts/Deployment/Yang_module/yang-module.cert, Artifacts/Deployment/Yang_module/yang-module.sig.cms, Artifacts/ChangeLog.txt, Artifacts/sample-pnf.cert] available in CSAR, but cannot be found in Manifest as Source", + "TOSCA-Metadata" + ) + ); List expectedPnfDictionaryErrors = - List.of( - createExpectedError(PM_DICTIONARY_YAML_RULE, "0x2000", - "Fail to load PM_Dictionary With error: PM_Dictionary YAML file is empty", - "Artifacts/Deployment/Measurements/PM_Dictionary.yml" - ) - ); + List.of( + createExpectedError(PM_DICTIONARY_YAML_RULE, "0x2000", + "Fail to load PM_Dictionary With error: PM_Dictionary YAML file is empty", + "Artifacts/Deployment/Measurements/PM_Dictionary.yml" + ) + ); List expectedNonManoFilesErrors = - List.of( - createExpectedError(NON_MANO_FILES_RULE, "0x2002", - "Missing. Entry [Source under onap_ves_events]", - "MainServiceTemplate.mf" - ), - createExpectedError(NON_MANO_FILES_RULE, "0x2002", - "Missing. Entry [onap_yang_module]", - "MainServiceTemplate.mf" - ), - createExpectedError(NON_MANO_FILES_RULE, "0x2002", - "Missing. Entry [Source under onap_others]]", - "MainServiceTemplate.mf" - ), - createExpectedError(NON_MANO_FILES_RULE, "0x2002", - "Missing. Entry [Source under onap_pm_dictionary]", - "MainServiceTemplate.mf" - ) - ); + List.of( + createExpectedError(NON_MANO_FILES_RULE, "0x2002", + "Missing. Entry [Source under onap_ves_events]", + "MainServiceTemplate.mf" + ), + createExpectedError(NON_MANO_FILES_RULE, "0x2002", + "Missing. Entry [onap_yang_module]", + "MainServiceTemplate.mf" + ), + createExpectedError(NON_MANO_FILES_RULE, "0x2002", + "Missing. Entry [Source under onap_others]]", + "MainServiceTemplate.mf" + ), + createExpectedError(NON_MANO_FILES_RULE, "0x2002", + "Missing. Entry [Source under onap_pm_dictionary]", + "MainServiceTemplate.mf" + ) + ); OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( - "pnf/r130206/csar-cert-in-tosca-multiple-individual-signature.csar" + "pnf/r130206/csar-cert-in-tosca-multiple-individual-signature.csar" )); // when @@ -337,24 +352,24 @@ public class PnfValidationFunctionalTest { final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.warnings).isEmpty(); switch (ruleValidationResult.vnfreqName) { case CERTIFICATION_RULE: assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedCertificationErrors); + .containsExactlyInAnyOrderElementsOf(expectedCertificationErrors); break; case MANIFEST_FILE_RULE: assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedManifestErrors); + .containsExactlyInAnyOrderElementsOf(expectedManifestErrors); break; case PM_DICTIONARY_YAML_RULE: assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedPnfDictionaryErrors); + .containsExactlyInAnyOrderElementsOf(expectedPnfDictionaryErrors); break; case NON_MANO_FILES_RULE: assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedNonManoFilesErrors); + .containsExactlyInAnyOrderElementsOf(expectedNonManoFilesErrors); break; default: assertThat(ruleValidationResult.errors).isEmpty(); @@ -366,22 +381,33 @@ public class PnfValidationFunctionalTest { private String[] createPnfValidationRequestInfo(String csarPath) throws URISyntaxException { return new String[]{ - "--product", "onap-dublin", - "csar-validate", - "--format", "json", - "--pnf", - "--csar", absoluteFilePath(csarPath) + "--product", "onap-vtp", + "csar-validate", + "--format", "json", + "--pnf", + "--csar", absoluteFilePath(csarPath) + }; + } + + private String[] createPnfValidationRequestInfoForSelectedRelease(String csarPath, String release) throws URISyntaxException { + return new String[]{ + "--product", "onap-vtp", + "csar-validate", + "--release", release, + "--format", "json", + "--pnf", + "--csar", absoluteFilePath(csarPath) }; } - private String[] createPnfValidationSelectedRulesRequestInfo(String csarPath, String rulesToValidate) throws URISyntaxException { + private String[] createPnfValidationRequestInfoForSelectedRules(String csarPath, String rulesToValidate) throws URISyntaxException { return new String[]{ - "--product", "onap-dublin", - "csar-validate", - "--format", "json", - "--rules", rulesToValidate, - "--pnf", - "--csar", absoluteFilePath(csarPath) + "--product", "onap-vtp", + "csar-validate", + "--format", "json", + "--rules", rulesToValidate, + "--pnf", + "--csar", absoluteFilePath(csarPath) }; } } diff --git a/csarvalidation/src/test/java/org/onap/functional/VnfValidationFunctionalTest.java b/csarvalidation/src/test/java/org/onap/functional/VnfValidationFunctionalTest.java index adaea59..e93c51f 100644 --- a/csarvalidation/src/test/java/org/onap/functional/VnfValidationFunctionalTest.java +++ b/csarvalidation/src/test/java/org/onap/functional/VnfValidationFunctionalTest.java @@ -1,6 +1,6 @@ -/** +/* * Copyright 2017 Huawei Technologies Co., Ltd. - * Copyright 2020 Nokia + * Copyright 2021 Nokia *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import java.net.URISyntaxException; import static org.assertj.core.api.Assertions.assertThat; import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.absoluteFilePath; import static org.onap.functional.CsarValidationUtility.OPERATION_STATUS_FAILED; +import static org.onap.functional.CsarValidationUtility.OPERATION_STATUS_PASS; import static org.onap.functional.CsarValidationUtility.getCliCommandValidationResult; import static org.onap.functional.CsarValidationUtility.ruleHaveOneOfCodes; import static org.onap.functional.CsarValidationUtility.verifyThatOperationFinishedWithoutAnyError; @@ -36,7 +37,7 @@ public class VnfValidationFunctionalTest { @Test public void shouldReportThanVnfValidationFailed() throws URISyntaxException { // given - OnapCliWrapper cli = new OnapCliWrapper(createVnfValidationRequestInfo("VoLTE.csar")); + OnapCliWrapper cli = new OnapCliWrapper(createVnfValidationRequestInfo("VoLTE.csar","latest")); // when cli.handle(); @@ -44,17 +45,17 @@ public class VnfValidationFunctionalTest { // then final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); - result.results.forEach((ruleValidationResult)->{ - if ( ruleHaveOneOfCodes(ruleValidationResult.vnfreqName, - "r01123", "r09467") + result.results.forEach((ruleValidationResult) -> { + if (ruleHaveOneOfCodes(ruleValidationResult.vnfreqName, + "r01123", "r09467") ) { assertThat(ruleValidationResult.errors) - .hasSize(2); - } else if ( ruleHaveOneOfCodes(ruleValidationResult.vnfreqName, - "r21322","r26885","r43958" ,"r66070","r130206") + .hasSize(2); + } else if (ruleHaveOneOfCodes(ruleValidationResult.vnfreqName, + "r21322", "r26885", "r43958", "r66070", "r130206") ) { assertThat(ruleValidationResult.errors) - .hasSize(1); + .hasSize(1); } else { assertThat(ruleValidationResult.errors).hasSize(0); } @@ -63,13 +64,28 @@ public class VnfValidationFunctionalTest { verifyThatOperationFinishedWithoutAnyError(cli); } - private String[] createVnfValidationRequestInfo(String csarPath) throws URISyntaxException { + @Test + public void shouldPassForAmsterdamWithAncestorRuleSet() throws URISyntaxException { + // given + OnapCliWrapper cli = new OnapCliWrapper(createVnfValidationRequestInfo("VoLTE.csar","amsterdam")); + + // when + cli.handle(); + + // then + final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); + assertThat(result.criteria).isEqualTo(OPERATION_STATUS_PASS); + + verifyThatOperationFinishedWithoutAnyError(cli); + } + + private String[] createVnfValidationRequestInfo(String csarPath, String release) throws URISyntaxException { return new String[]{ - "--product", "onap-dublin", - "csar-validate", - "--format", "json", - "--csar", absoluteFilePath(csarPath) + "--product", "onap-vtp", + "csar-validate", + "--release", release, + "--format", "json", + "--csar", absoluteFilePath(csarPath) }; } - } -- cgit 1.2.3-korg