SEBA-298 Use unique temp filename when saving recipes

Change-Id: I7a18e59ac07ebbe1cc83ef5acfbe3d35967fac79
diff --git a/Dockerfile b/Dockerfile
index e4f2354..cb2110d 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,7 +1,7 @@
 # docker build -t xosproject/xos-tosca:candidate .
 
 # xosproject/xos-tosca
-FROM xosproject/xos-client:2.1.18
+FROM xosproject/xos-client:2.1.19
 
 # Set environment variables
 ENV CODE_SOURCE .
diff --git a/VERSION b/VERSION
index 781dcb0..65087b4 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.1.3
+1.1.4
diff --git a/src/tosca/parser.py b/src/tosca/parser.py
index fe8382b..3f44c50 100644
--- a/src/tosca/parser.py
+++ b/src/tosca/parser.py
@@ -14,6 +14,8 @@
 # limitations under the License.
 
 
+import os
+from tempfile import NamedTemporaryFile
 from xosconfig import Config
 from multistructlog import create_logger
 log = create_logger(Config().get('logging'))
@@ -127,11 +129,6 @@
         else:
             return msg
 
-    def save_recipe_to_tmp_file(self, recipe):
-        tmp_file = open(self.recipe_file, 'w')
-        tmp_file.write(recipe)
-        tmp_file.close()
-
     @staticmethod
     def get_tosca_models_by_name(template):
         models_by_name = {}
@@ -183,7 +180,6 @@
         self.saved_model_by_name = {}
 
         self.ordered_models_template = []
-        self.recipe_file = TOSCA_RECIPES_DIR + '/tmp.yaml'
 
         self.recipe = recipe
 
@@ -191,9 +187,17 @@
 
         try:
             # [] save the recipe to a tmp file
-            self.save_recipe_to_tmp_file(self.recipe)
-            # [] parse the recipe with TOSCA Parse
-            self.template = ToscaTemplate(self.recipe_file)
+            with NamedTemporaryFile(delete=False, suffix=".yaml", dir=TOSCA_RECIPES_DIR) as recipe_file:
+                try:
+                    recipe_file.write(self.recipe)
+                    recipe_file.close()
+
+                    # [] parse the recipe with TOSCA Parse
+                    self.template = ToscaTemplate(recipe_file.name)
+                finally:
+                    # [] Make sure the temporary file is cleaned up
+                    os.remove(recipe_file.name)
+
             # [] get all models in the recipe
             self.templates_by_model_name = self.get_tosca_models_by_name(self.template)
             # [] compute requirements
diff --git a/test/test_tosca_parser.py b/test/test_tosca_parser.py
index b16817a..9641380 100644
--- a/test/test_tosca_parser.py
+++ b/test/test_tosca_parser.py
@@ -219,20 +219,3 @@
 InvalidTypeError: with some message
 TypeMismatchError: with some message
 """)
-
-    def test_save_recipe_to_tmp_file(self):
-        """
-        [TOSCA_Parser] save_recipe_to_tmp_file: should save a TOSCA recipe to a tmp file
-        """
-        parser = TOSCA_Parser('', 'user', 'pass')
-        parser.recipe_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_tmp.yaml')
-
-        parser.save_recipe_to_tmp_file('my tosca')
-
-        self.assertTrue(os.path.exists(parser.recipe_file))
-
-        content = open(parser.recipe_file).read()
-
-        self.assertEqual(content, 'my tosca')
-
-        os.remove(parser.recipe_file)
\ No newline at end of file