From 9bf2adc131ee671165a4b1e63adf531bd811645a Mon Sep 17 00:00:00 2001 From: Victor Gao Date: Tue, 18 Sep 2018 15:47:28 +0800 Subject: Implement requirement r02454 Change-Id: Icac494bda73069fb5435600e7d5144c584a692b6 Issue-ID: VNFSDK-175 Signed-off-by: Victor Gao --- .../org/onap/validation/csar/CommonConstants.java | 4 +++ .../org/onap/validation/csar/CsarValidator.java | 41 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) (limited to 'csarvalidation/src/main/java') diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/CommonConstants.java b/csarvalidation/src/main/java/org/onap/validation/csar/CommonConstants.java index 29c4bdf..5f4e053 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/CommonConstants.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/CommonConstants.java @@ -45,6 +45,10 @@ public class CommonConstants { public static final String MAINSERV_TEMPLATE = "MainServiceTemplate.yaml"; + public static final String TOSCA_SWIMAGE = "tosca.artifacts.nfv.SwImage"; + + public static final String TOSCA_IMAGE = "tosca.artifacts.Deployment.Image"; + public static final String CSAR_SUFFIX = ".csar"; public static final String HTTP_HEADER_CONTENT_RANGE = "Content-Range"; diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java index 88cd0e0..d27aa5a 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java @@ -108,6 +108,8 @@ public class CsarValidator { String vms = validateMainService(); + //String r02454 = r02454(); + if((CommonConstants.SUCCESS_STR != vsm) && (CommonConstants.SUCCESS_STR != vms)) { return vsm + " OR " + vms; @@ -116,7 +118,11 @@ public class CsarValidator { if(CommonConstants.SUCCESS_STR != vtm) { return vtm; } - +/* + if (CommonConstants.SUCCESS_STR != r02454) { + return r02454; + } +*/ return CommonConstants.SUCCESS_STR; } @@ -291,12 +297,45 @@ public class CsarValidator { if(!Paths.get(MAINSERV_TEMPLATE).isAbsolute()) { mainservTemplate = csarFiles.get(FilenameUtils.getName(mainservTemplate)); } + if(StringUtils.isEmpty(mainservTemplate)) { return "MainServiceTemplate does not exist in the package"; } return CommonConstants.SUCCESS_STR; } + /* + * @Author: Victor Gao + * @Description: + * @Date: 2018/9/18 + * @Param: [filePath] + * @return: boolean + **/ + public static String r02454() { + String mainservTemplate = MAINSERV_TEMPLATE; + mainservTemplate = csarFiles.get(FilenameUtils.getName(mainservTemplate)); + + //TODO: Fixme R3 only check the existence of swImage filed inside VNFD. + File file = new File(mainservTemplate); + try (BufferedReader reader = new BufferedReader(new FileReader(file))) { + String tempString = null; + while ((tempString = reader.readLine()) != null) { + if (tempString.contains((CommonConstants.TOSCA_SWIMAGE))) { + return CommonConstants.SUCCESS_STR; + } + } + } catch(IOException e2) { + return ("CSAR_META_VALIDATION" + ":" + "Exception caught while validateCsarMeta ! " + ErrorCodes.FILE_IO + + e2); + } + + if(StringUtils.isEmpty(mainservTemplate)) { + return "Can not find the swImage inside Mainservicetemplate"; + } + + return "Can not find the swImage inside Mainservicetemplate"; + } + private static String checkEntryFor(String fileWithPath, String attribute) throws IOException { List lines = Files.readAllLines(Paths.get(fileWithPath), UTF_8); -- cgit 1.2.3-korg