tools/validate_descriptor.py reconverted as python3 script
[osm/devops.git] / descriptor-packages / tools / generate_descriptor_pkg.sh
index d076b28..1b9a9e0 100755 (executable)
@@ -43,10 +43,11 @@ VNFD_FOLDERS=(images scripts icons charms cloud_init)
 # Supported folders for NSD
 # OSM document specifies (ns|vnf)-config folder, while Rel 4.3
 # is using (ns|vnf)_config.
-NSD_FOLDERS=(scripts icons ns_config vnf_config)
+NSD_FOLDERS=(scripts charms icons ns_config vnf_config)
 
 # Other files allowed in the descriptor base directory
 ALLOWED_FILES=(README)
+ALLOWED_FILES_WILDCARDS=(README)
 
 DESC_TYPES=(vnfd nsd)
 DESC_EXTN=(yml yaml json xml)
@@ -61,7 +62,7 @@ DEBUG=false
 ARCHIVE=false
 CREATE_NSD=false
 VENDOR='OSM'
-INTF_TYPE='VIRTIO'
+INTF_TYPE='PARAVIRT'
 VCPU=2
 MEMORY=4096
 STORAGE=10
@@ -98,8 +99,8 @@ Usage:
 
             --vendor : Vendor name for descriptor. Default OSM
 
-            --interface-type : Interface type [VIRTIO|SR-IOV|PCI-PASSTHROUGH|E1000]
-                               Default VIRTIO
+            --interface-type : Interface type [PARAVIRT|SR-IOV|PCI-PASSTHROUGH|E1000]
+                               Default PARAVIRT
 
           VM Flavour options:
 
@@ -137,7 +138,7 @@ EOF
 CP_TYPE='VPORT'
 function get_cp_type() {
     case ${INTF_TYPE} in
-        VIRTIO ) CP_TYPE='VPORT';;
+        PARAVIRT ) CP_TYPE='VPORT';;
         SR-IOV ) CP_TYPE='VPORT';;
         PCI-PASSTHROUGH ) CP_TYPE='VPORT';;
         OM-MGMT ) CP_TYPE='VPORT';;
@@ -173,7 +174,7 @@ vnfd:vnfd-catalog:
     -   id: ${name}
         name: ${name}
         short-name: ${name}
-        description: Generated by OSM pacakage generator
+        description: Generated by OSM package generator
         vendor: ${VENDOR}
         version: '1.0'
 
@@ -182,7 +183,7 @@ vnfd:vnfd-catalog:
 
         # Management interface
         mgmt-interface:
-            vdu-id: ${name}-VM
+            cp: vnf-cp0
 
         # Atleast one VDU need to be specified
         vdu:
@@ -220,7 +221,7 @@ EOF
 
     # Add external interfaces
     cat >>$desc_file <<EOF
-            external-interface:
+            interface:
             # Specify the external interfaces
             # There can be multiple interfaces defined
 EOF
@@ -228,24 +229,21 @@ EOF
     # Add mgmt interface
     cat >>$desc_file <<EOF
             -   name: eth0
+                type: EXTERNAL
                 virtual-interface:
-                    type: VIRTIO
-                    bandwidth: '0'
-                    vpci: '0000:00:0a.0'
-                vnfd-connection-point-ref: eth0
+                    type: PARAVIRT
+                external-connection-point-ref: vnf-cp0
 EOF
 
     # Add external interfaces
     for i in `seq 1 ${INTERFACES}`; do
         eth=$(($i))
-        pci=$(get_pci $eth)
         cat >>$desc_file <<EOF
             -   name: eth${eth}
+                type: EXTERNAL
                 virtual-interface:
                     type: ${INTF_TYPE}
-                    bandwidth: '0'
-                    vpci: '0000:00:${pci}.0'
-                vnfd-connection-point-ref: eth${eth}
+                external-connection-point-ref: vnf-cp${eth}
 EOF
     done
 
@@ -258,8 +256,7 @@ EOF
     for i in `seq 0 ${INTERFACES}`; do
         eth=$(($i))
         cat >>$desc_file <<EOF
-            -   name: eth${eth}
-                type: ${CP_TYPE}
+        -   name: vnf-cp${eth}
 EOF
     done
 
@@ -310,7 +307,7 @@ nsd:nsd-catalog:
     -   id: ${name}
         name: ${name}
         short-name: ${name}
-        description: Generated by OSM pacakage generator
+        description: Generated by OSM package generator
         vendor: ${VENDOR}
         version: '1.0'
 
@@ -334,49 +331,49 @@ EOF
 
     # Add management VLD
     cat >>$desc_file <<EOF
-            -   id: ${name}_vld0
-                name: management
-                short-name: management
-                type: ELAN
-                mgmt-network: 'true'
-                # vim-network-name: <update>
-                # provider-network:
-                #     overlay-type: VLAN
-                #     segmentation_id: <update>
-                vnfd-connection-point-ref:
-                # Specify the constituent VNFs
-                # member-vnf-index-ref - entry from constituent vnf
-                # vnfd-id-ref - VNFD id
-                # vnfd-connection-point-ref - connection point name in the VNFD
-                -   nsd:member-vnf-index-ref: 1
-                    nsd:vnfd-id-ref: ${vnfd}
-                    # NOTE: Validate the entry below
-                    nsd:vnfd-connection-point-ref: eth0
+        -   id: ${name}_vld0
+            name: management
+            short-name: management
+            type: ELAN
+            mgmt-network: 'true'
+            # vim-network-name: <update>
+            # provider-network:
+            #     overlay-type: VLAN
+            #     segmentation_id: <update>
+            vnfd-connection-point-ref:
+            # Specify the constituent VNFs
+            # member-vnf-index-ref - entry from constituent vnf
+            # vnfd-id-ref - VNFD id
+            # vnfd-connection-point-ref - connection point name in the VNFD
+            -   member-vnf-index-ref: 1
+                vnfd-id-ref: ${vnfd}
+                # NOTE: Validate the entry below
+                vnfd-connection-point-ref: vnf-cp0
 EOF
 
     # Add rest of VLDs
     for i in `seq 1 ${INTERFACES}`; do
         eth=$(($i))
         cat >>$desc_file <<EOF
-            -   id: ${name}_vld${i}
-                name: ${name}_vld${i}
-                short-name: ${name}_vld${i}
-                type: ELAN
-                # vim-network-name: <update>
-                # provider-network:
-                #     overlay-type: VLAN
-                #     segmentation_id: <update>
-                vnfd-connection-point-ref:
-                # Specify the constituent VNFs
-                # member-vnf-index-ref - entry from constituent vnf
-                # vnfd-id-ref - VNFD id
-                # vnfd-connection-point-ref - connection point name in the VNFD
-                -   nsd:member-vnf-index-ref: 1
-                    nsd:vnfd-id-ref: ${vnfd}
-                    # NOTE: Validate the entry below
-                    nsd:vnfd-connection-point-ref: eth${eth}
+        -   id: ${name}_vld${i}
+            name: ${name}_vld${i}
+            short-name: ${name}_vld${i}
+            type: ELAN
+            # vim-network-name: <update>
+            # provider-network:
+            #     overlay-type: VLAN
+            #     segmentation_id: <update>
+            vnfd-connection-point-ref:
+            # Specify the constituent VNFs
+            # member-vnf-index-ref - entry from constituent vnf
+            # vnfd-id-ref - VNFD id
+            # vnfd-connection-point-ref - connection point name in the VNFD
+            -   member-vnf-index-ref: 1
+                vnfd-id-ref: ${vnfd}
+                # NOTE: Validate the entry below
+                vnfd-connection-point-ref: vnf-cp${eth}
 EOF
-        done
+    done
 
     if [ $VERBOSE == true ]; then
         echo "INFO: Created $desc_file"
@@ -760,7 +757,11 @@ if [ $CREATE == false ]; then
 
     for f in ${files[@]}; do
         if [ $(contains "${ALLOWED_FILES[@]}" $f)  == "n" ]; then
-            echo "WARN: Unsupported file $f found"
+            for j in ${ALLOWED_FILES_WILDCARDS[@]}; do
+                if [[ $f != *"$j"* ]]; then
+                    echo "WARN: Unsupported file $f found"
+                fi
+            done
         fi
     done
 
@@ -794,6 +795,14 @@ if [ $CREATE == false ]; then
     fi
 
     cd $BASE_DIR
+    # Mrityunjay Yadav: Validate descriptor
+    GEN_BASEDIR=$(dirname "$0")
+    python3 $GEN_BASEDIR/validate_descriptor.py $BASE_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}