Bug 515 fixed 65/7765/1
authoryadavmr <my00514913@techmahindra.com>
Mon, 8 Jul 2019 15:58:34 +0000 (21:28 +0530)
committeryadavmr <my00514913@techmahindra.com>
Mon, 8 Jul 2019 15:58:34 +0000 (21:28 +0530)
Change-Id: I152ba68153d5ba4792949586d12f6d367b66a4d5
Signed-off-by: yadavmr <my00514913@techmahindra.com>
descriptor-packages/tools/generate_descriptor_pkg.sh
descriptor-packages/tools/validate_descriptor.py
docker/osmclient/Dockerfile

index 5ee4d2a..bff8785 100755 (executable)
@@ -790,6 +790,13 @@ if [ $CREATE == false ]; then
     fi
 
     cd $BASE_DIR
+    # Mrityunjay Yadav: Validate descriptor
+    python /usr/share/osm-devops/descriptor-packages/tools/validate_descriptor.py $DEST_DIR/$PKG/$descriptor
+    if [ $? -ne 0 ]; then
+        rc=$?
+        echo "ERROR: validating descriptor for $PKG ($rc)" >&2
+        exit $rc
+    fi
     if [ $DRY_RUN == false ]; then
         if [ $VERBOSE == true ]; then
             tar zcvf "$DEST_DIR/$PKG.tar.gz" "${PKG}" ${RM}
index 6ae9836..1c67195 100755 (executable)
@@ -22,6 +22,7 @@ import json
 import yaml
 import sys
 import getopt
+import os
 
 """
 Tests the format of OSM VNFD and NSD descriptors
@@ -46,6 +47,7 @@ def usage():
     print("      -i|--input FILE: (same as param FILE) descriptor file to be upgraded")
     return
 
+
 def remove_prefix(desc, prefix):
     """
     Recursively removes prefix from keys
@@ -68,7 +70,33 @@ def remove_prefix(desc, prefix):
             if isinstance(desc, (list, tuple, dict)):
                 remove_prefix(i, prefix)
 
-if __name__=="__main__":
+
+# Mrityunjay Yadav: Function to verify charm included in VNF Package
+def validate_charm(charm, desc_file):
+    """
+    Verify charm included in VNF Package and raised error if invalid
+    :param charm: vnf-configuration/vdu-configuration
+    :param desc_file: descriptor file
+    :return: None
+    """
+    check_list = ['layer.yaml', 'metadata.yaml', 'actions.yaml', 'actions', 'hooks']
+    charm_name = charm['juju']['charm']
+    charm_dir = os.path.join(os.path.abspath(os.path.dirname(desc_file)), 'charms', charm_name)
+
+    config_primitive = charm.get('config-primitive', [])
+    initial_config_primitive = charm.get('initial-config-primitive', [])
+
+    if charm.get('metrics'):
+        check_list.append('metrics.yaml')
+
+    if os.path.exists(charm_dir):
+        if not all(item in os.listdir(charm_dir) for item in check_list):
+            raise KeyError("Invalid charm {}".format(charm_name))
+    else:
+        raise KeyError("Provided charm:{} does not exist in descriptor.".format(charm_name))
+
+
+if __name__ == "__main__":
     error_position = []
     format_output_yaml = True
     input_file_name = None
@@ -133,10 +161,17 @@ if __name__=="__main__":
                         if interface.get("virtual-interface", {}).get("type") == "OM-MGMT":
                             raise KeyError(
                                 "Wrong 'Virtual-interface type': Deprecated 'OM-MGMT' value. Please, use 'PARAVIRT' instead")
+                    # Mrityunjay yadav: Verify charm if included in vdu
+                    if vdu.get("vdu-configuration", False):
+                        validate_charm(vdu["vdu-configuration"], input_file_name)
                 if vnfd.get("mgmt-interface"):
                     mgmt_iface = True
                     if vnfd["mgmt-interface"].get("vdu-id"):
                         raise KeyError("'mgmt-iface': Deprecated 'vdu-id' field. Please, use 'cp' field instead")
+                # Mrityunjay yadav: Verify charm if included in vnf
+                if vnfd.get("vnf-configuration", False):
+                    validate_charm(vnfd["vnf-configuration"], input_file_name)
+
             if not mgmt_iface:
                 raise KeyError("'mgmt-iface' is a mandatory field and it is not defined")
             myvnfd = vnfd_catalog.vnfd()
index 4d547fa..a791b04 100644 (file)
@@ -19,8 +19,9 @@ RUN add-apt-repository -y "deb ${REPOSITORY_BASE}/${RELEASE} ${REPOSITORY} devop
 
 ARG OSMCLIENT_VERSION
 ARG DEVOPS_VERSION
+ARG IM_VERSION
 
-RUN apt-get update && apt-get -y install osm-devops${DEVOPS_VERSION} python-osmclient${OSMCLIENT_VERSION}
+RUN apt-get update && apt-get -y install osm-devops${DEVOPS_VERSION} python-osmclient${OSMCLIENT_VERSION} python-osm-im${IM_VERSION}
 
 ENV OSM_SOL005=True
 ENV OSM_HOSTNAME=nbi:9999