Merge feature5837: support of K8s

Change-Id: I4567a0fc1f155a40ea1f81b2a645aad65488ebf4
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/.gitignore b/.gitignore
index 3e381c6..893f025 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,16 @@
+# 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.
+
 *.pyc
 .cache
 
@@ -9,7 +22,6 @@
 .eggs
 *egg-info
 *.gz
-osm_im
 osm_im_trees
 dists
 pool
@@ -18,6 +30,11 @@
 osm-im-*.post*
 osm-imdocs-*.post*
 osm-imdocs_*.post*
+osm_im/nsd.py
+osm_im/vnfd.py
+osm_im/nst.py
+osm_im/nsi.py
+osm_im/osm.yaml
 
 #Pyang and other tools' folders
 pyangbind
diff --git a/Jenkinsfile b/Jenkinsfile
index 650ff43..3e3af2e 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -27,6 +27,6 @@
                            params.GERRIT_BRANCH,
                            params.GERRIT_REFSPEC,
                            params.GERRIT_PATCHSET_REVISION,
-                           false,
+                           params.TEST_INSTALL,
                            params.ARTIFACTORY_SERVER)
 }
diff --git a/Makefile b/Makefile
index 8256a67..e4e8fef 100644
--- a/Makefile
+++ b/Makefile
@@ -45,14 +45,10 @@
 
 openapi_schemas: $(OPENAPI_SCHEMAS)
 
-$(OUT_DIR):
-	$(Q)mkdir -p $(OUT_DIR)
-	$(Q)touch $(OUT_DIR)/__init__.py
-
 $(TREES_DIR):
 	$(Q)mkdir -p $(TREES_DIR)
 
-%.py: $(OUT_DIR) yang-ietf
+%.py: yang-ietf
 	$(Q)echo generating $@ from $*.yang
 	$(Q)pyang $(PYANG_OPTIONS) --path $(MODEL_DIR) --plugindir $(PYBINDPLUGIN) -f pybind -o $(OUT_DIR)/$@ $(MODEL_DIR)/$*.yang
 
@@ -78,7 +74,7 @@
 	$(Q)sed -r -i 's|<a href=\"http://www.tail-f.com">|<a href="http://osm.etsi.org">|g' $(TREES_DIR)/$@
 	$(Q)mv $(TREES_DIR)/$@ $(TREES_DIR)/$*.html
 
-osm.yaml: $(OUT_DIR) yang-ietf yang2swagger
+osm.yaml: yang-ietf yang2swagger
 	$(Q)echo generating $@
 	$(Q)$(JAVA) -jar ${HOME}/.m2/repository/com/mrv/yangtools/swagger-generator-cli/1.1.11/swagger-generator-cli-1.1.11-executable.jar -yang-dir $(MODEL_DIR) -output $(OUT_DIR)/$@
 
@@ -108,4 +104,4 @@
 	$(Q)cp -n ~/.m2/settings.xml{,.orig} ; wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml
 
 clean:
-	$(Q)rm -rf dist osm_im.egg-info deb deb_dist *.gz osm-imdocs* yang2swagger $(OUT_DIR) $(TREES_DIR)
+	$(Q)rm -rf dist osm_im.egg-info deb deb_dist *.gz osm-imdocs* yang2swagger $(TREES_DIR)
diff --git a/osm_im/__init__.py b/osm_im/__init__.py
new file mode 100644
index 0000000..7284a2b
--- /dev/null
+++ b/osm_im/__init__.py
@@ -0,0 +1,13 @@
+##
+# 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.
+##
diff --git a/osm_im/validation.py b/osm_im/validation.py
new file mode 100644
index 0000000..7334fbb
--- /dev/null
+++ b/osm_im/validation.py
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+
+# 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.
+
+import yaml
+import json
+# import logging
+from osm_im.vnfd import vnfd as vnfd_im
+from osm_im.nsd import nsd as nsd_im
+from osm_im.nst import nst as nst_im
+from pyangbind.lib.serialise import pybindJSONDecoder
+import pyangbind.lib.pybindJSON as pybindJSON
+
+class ValidationException(Exception):
+    pass
+
+class Validation:
+
+    def pyangbind_validation(self, item, data, force=False):
+        '''
+        item: vnfd, nst, nsd
+        data: dict object loaded from the descriptor file
+        force: True to skip unknown fields in the descriptor
+        '''
+        if item == "vnfd":
+            myobj = vnfd_im()
+        elif item == "nsd":
+            myobj = nsd_im()
+        elif item == "nst":
+            myobj = nst_im()
+        else:
+            raise ValidationException("Not possible to validate '{}' item".format(item))
+
+        try:
+            pybindJSONDecoder.load_ietf_json(data, None, None, obj=myobj,
+                                             path_helper=True, skip_unknown=force)
+            out = pybindJSON.dumps(myobj, mode="ietf")
+            desc_out = yaml.safe_load(out)
+            return desc_out
+        except Exception as e:
+            raise ValidationException("Error in pyangbind validation: {}".format(str(e)))
+
+    def yaml_validation(self, descriptor):
+        try:
+            data = yaml.safe_load(descriptor)
+        except Exception as e:
+            raise ValidationException("Error in YAML validation. Not a proper YAML file: {}".format(e))
+        if 'vnfd:vnfd-catalog' in data or 'vnfd-catalog' in data:
+            item = "vnfd"
+        elif 'nsd:nsd-catalog' in data or 'nsd-catalog' in data:
+            item = "nsd"
+        elif 'nst' in data:
+            item = "nst"
+        else:
+            raise ValidationException("Error in YAML validation. Not possible to determine the type of descriptor in the first line. Expected values: vnfd:vnfd-catalog, vnfd-catalog, nsd:nsd-catalog, nsd-catalog, nst")
+
+        return item, data
+
+    def descriptor_validation(self, descriptor):
+        item, data = self.yaml_validation(descriptor)
+        self.pyangbind_validation(item, data)
+
diff --git a/setup.py b/setup.py
index ef8da90..f59e790 100644
--- a/setup.py
+++ b/setup.py
@@ -33,11 +33,8 @@
         self.pipinstall('pyang')
         self.pipinstall('pyangbind')
         import pyangbind
-        print("Creating dir {}/{} for python artifacts".format(os.getcwd(), self.im_dir))
+        print("Using dir {}/{} for python artifacts".format(os.getcwd(), self.im_dir))
         path = "{}/{}".format(os.getcwd(), self.im_dir)
-        if not os.path.exists(path):
-            os.makedirs(path)
-        open("{}/{}/__init__.py".format(os.getcwd(), self.im_dir), 'a').close()
         for files_item in ['vnfd', 'nsd', 'nst']:
             protoc_command = ["pyang",
                               "-Werror",