switch to using tosca-parser instead of subdir from heat-translator
add suffix to yaml file and fix import in run.py
remove unnecessary includes
don't nest requirements, new tosca-parser fails this
fix 'scalable' to work with tosca-parser defaults
typo, typo2
check against max_instances to determine if scalable
don't clean up after a tosca test fails in ways that prevent db inspection debugging
better debugging support
save test run TOSCA to /tmp for debugging
fix other scalable check
better naming for temp test tosca files

Change-Id: I434dada57258e61a2d3905e6ab58b7b171fa993f
diff --git a/containers/xos/Dockerfile.base b/containers/xos/Dockerfile.base
index a511986..6d045aa 100644
--- a/containers/xos/Dockerfile.base
+++ b/containers/xos/Dockerfile.base
@@ -70,15 +70,3 @@
     mv jquery-ui-themes-*/themes/smoothness/jquery-ui.min.css /usr/local/lib/python2.7/dist-packages/suit/static/suit/css/ && \
     rm -rf jquery-ui-themes.zip jquery-ui-themes-*
 
-# Install heat-translator for TOSCA support
-ENV HT_REPO_URL https://github.com/openstack/heat-translator.git
-ENV HT_REF a951b93c16e54046ed2d233d814860181c772e30
-
-RUN git clone $HT_REPO_URL /tmp/heat-translator && \
-    cd /tmp/heat-translator && \
-    git checkout $HT_REF && \
-    mkdir -p /opt/tosca && \
-    mv /tmp/heat-translator/translator /opt/tosca/translator && \
-    echo > /opt/tosca/translator/__init__.py && \
-    rm -rf /tmp/heat-translator
-
diff --git a/containers/xos/pip_requirements.txt b/containers/xos/pip_requirements.txt
index ae66fbe..6006928 100644
--- a/containers/xos/pip_requirements.txt
+++ b/containers/xos/pip_requirements.txt
@@ -125,6 +125,7 @@
 six==1.10.0
 stevedore==1.17.1
 supervisor==3.0b2
+tosca-parser==0.6.0
 unicodecsv==0.14.1
 uritemplate==0.6
 urllib3==1.7.1
diff --git a/xos/synchronizers/base/observer b/xos/synchronizers/base/observer
deleted file mode 120000
index ae75af5..0000000
--- a/xos/synchronizers/base/observer
+++ /dev/null
@@ -1 +0,0 @@
-openstack_observer
\ No newline at end of file
diff --git a/xos/tosca/engine.py b/xos/tosca/engine.py
index e3d74c7..12ab3f5 100644
--- a/xos/tosca/engine.py
+++ b/xos/tosca/engine.py
@@ -1,17 +1,15 @@
 import os
 import pdb
+import resources
 import sys
 import tempfile
 import traceback
 
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
+from toscaparser.tosca_template import ToscaTemplate
 from core.models import Slice,Instance,User,Flavor,Node,Image
 from nodeselect import XOSNodeSelector
 from imageselect import XOSImageSelector
 
-import resources
 
 class XOSTosca(object):
     def __init__(self, tosca_yaml, parent_dir=None, log_to_console = False):
@@ -23,7 +21,7 @@
 
         tmp_pathname = None
         try:
-            (tmp_handle, tmp_pathname) = tempfile.mkstemp(dir=parent_dir)
+            (tmp_handle, tmp_pathname) = tempfile.mkstemp(dir=parent_dir, suffix=".yaml")
             os.write(tmp_handle, tosca_yaml)
             os.close(tmp_handle)
 
diff --git a/xos/tosca/install_tosca.sh b/xos/tosca/install_tosca.sh
deleted file mode 100755
index f212abf..0000000
--- a/xos/tosca/install_tosca.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#! /bin/bash
-
-rm -rf /tmp/tosca_install
-mkdir /tmp/tosca_install
-cd /tmp/tosca_install
-git clone https://github.com/openstack/heat-translator.git
-cd heat-translator
-git reset --hard a951b93c16e54046ed2d233d814860181c772e30
-rm -rf /opt/tosca
-mkdir /opt/tosca
-cp -a /tmp/tosca_install/heat-translator/translator /opt/tosca/
-echo > /opt/tosca/translator/__init__.py
diff --git a/xos/tosca/resources/addresspool.py b/xos/tosca/resources/addresspool.py
index 8cd3e83..bc2b9b0 100644
--- a/xos/tosca/resources/addresspool.py
+++ b/xos/tosca/resources/addresspool.py
@@ -1,15 +1,8 @@
-import os
-import pdb
 import socket
-import sys
 import struct
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import AddressPool
 
 from xosresource import XOSResource
+from core.models import AddressPool
 
 class XOSAddressPool(XOSResource):
     provides = "tosca.nodes.AddressPool"
diff --git a/xos/tosca/resources/compute.py b/xos/tosca/resources/compute.py
index 2af010a..9508a6d 100644
--- a/xos/tosca/resources/compute.py
+++ b/xos/tosca/resources/compute.py
@@ -1,17 +1,9 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
+from xosresource import XOSResource
 from core.models import Slice,Instance,User,Flavor,Node,Image
 from nodeselect import XOSNodeSelector
 from imageselect import XOSImageSelector
 from flavorselect import XOSFlavorSelector
 
-from xosresource import XOSResource
-
 class XOSCompute(XOSResource):
     provides = ["tosca.nodes.Compute", "tosca.nodes.Compute.Container"]
     xos_model = Instance
@@ -102,9 +94,9 @@
 
     def create_or_update(self):
         scalable = self.get_scalable()
-        if scalable:
-            default_instances = scalable.get("default_instances",1)
-            for i in range(0, default_instances):
+
+        if scalable.get("max_instances",1) > 1:
+            for i in range(0, scalable.get("default_instances",1)):
                 name = "%s-%d" % (self.obj_name, i)
                 existing_instances = Instance.objects.filter(name=name)
                 if existing_instances:
@@ -117,14 +109,13 @@
 
     def get_existing_objs(self):
         scalable = self.get_scalable()
-        if scalable:
+
+        if scalable.get("max_instances",1) > 1:
             existing_instances = []
-            max_instances = scalable.get("max_instances",1)
-            for i in range(0, max_instances):
+            for i in range(0, scalable.get("default_instances",1)):
                 name = "%s-%d" % (self.obj_name, i)
                 existing_instances = existing_instances + list(Instance.objects.filter(name=name))
             return existing_instances
         else:
             return super(XOSCompute,self).get_existing_objs()
 
-
diff --git a/xos/tosca/resources/controller.py b/xos/tosca/resources/controller.py
index 2aa208c..3fad2a6 100644
--- a/xos/tosca/resources/controller.py
+++ b/xos/tosca/resources/controller.py
@@ -1,16 +1,5 @@
-# note: this module named xossite.py instead of site.py due to conflict with
-#    /usr/lib/python2.7/site.py
-
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import User,Controller,Deployment
-
 from xosresource import XOSResource
+from core.models import User,Controller,Deployment
 
 class XOSController(XOSResource):
     provides = "tosca.nodes.Controller"
@@ -48,7 +37,6 @@
             if sd.nodes.exists():
                 self.info("Controller %s has active nodes; skipping delete" % obj.name)
                 return
-        super(XOSController, self).delete(obj)
 
 
 
diff --git a/xos/tosca/resources/dashboardview.py b/xos/tosca/resources/dashboardview.py
index cadbfed..94ed911 100644
--- a/xos/tosca/resources/dashboardview.py
+++ b/xos/tosca/resources/dashboardview.py
@@ -1,12 +1,5 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-from core.models import DashboardView, Site, Deployment, SiteDeployment
 from xosresource import XOSResource
-
+from core.models import DashboardView, Site, Deployment, SiteDeployment
 
 class XOSDashboardView(XOSResource):
     provides = "tosca.nodes.DashboardView"
diff --git a/xos/tosca/resources/deployment.py b/xos/tosca/resources/deployment.py
index e5ab4b1..dc2a79f 100644
--- a/xos/tosca/resources/deployment.py
+++ b/xos/tosca/resources/deployment.py
@@ -1,16 +1,5 @@
-# note: this module named xossite.py instead of site.py due to conflict with
-#    /usr/lib/python2.7/site.py
-
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import User,Deployment,DeploymentRole,DeploymentPrivilege,Image,ImageDeployments,Flavor
-
 from xosresource import XOSResource
+from core.models import User,Deployment,DeploymentRole,DeploymentPrivilege,Image,ImageDeployments,Flavor
 
 class XOSDeployment(XOSResource):
     provides = "tosca.nodes.Deployment"
diff --git a/xos/tosca/resources/deploymentrole.py b/xos/tosca/resources/deploymentrole.py
index 4339026..eadea56 100644
--- a/xos/tosca/resources/deploymentrole.py
+++ b/xos/tosca/resources/deploymentrole.py
@@ -1,16 +1,5 @@
-# note: this module named xossite.py instead of site.py due to conflict with
-#    /usr/lib/python2.7/site.py
-
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import User, Deployment, DeploymentRole
-
 from xosresource import XOSResource
+from core.models import User, Deployment, DeploymentRole
 
 class XOSDeploymentRole(XOSResource):
     provides = "tosca.nodes.DeploymentRole"
@@ -25,5 +14,3 @@
     def delete(self, obj):
         super(XOSDeploymentRole, self).delete(obj)
 
-
-
diff --git a/xos/tosca/resources/flavor.py b/xos/tosca/resources/flavor.py
index f61ccad..f78ab88 100644
--- a/xos/tosca/resources/flavor.py
+++ b/xos/tosca/resources/flavor.py
@@ -1,16 +1,5 @@
-# note: this module named xossite.py instead of site.py due to conflict with
-#    /usr/lib/python2.7/site.py
-
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import User, Deployment, Flavor
-
 from xosresource import XOSResource
+from core.models import User, Deployment, Flavor
 
 class XOSFlavor(XOSResource):
     provides = "tosca.nodes.Flavor"
diff --git a/xos/tosca/resources/image.py b/xos/tosca/resources/image.py
index fcd53b4..a7e549b 100644
--- a/xos/tosca/resources/image.py
+++ b/xos/tosca/resources/image.py
@@ -1,16 +1,5 @@
-# note: this module named xossite.py instead of site.py due to conflict with
-#    /usr/lib/python2.7/site.py
-
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import User, Deployment, Image
-
 from xosresource import XOSResource
+from core.models import User, Deployment, Image
 
 class XOSImage(XOSResource):
     provides = "tosca.nodes.Image"
diff --git a/xos/tosca/resources/network.py b/xos/tosca/resources/network.py
index 8672b76..817d5b8 100644
--- a/xos/tosca/resources/network.py
+++ b/xos/tosca/resources/network.py
@@ -1,14 +1,5 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-import pdb
-
-from core.models import Slice,User,Network,NetworkTemplate,NetworkSlice,Service,Tenant
-
 from xosresource import XOSResource
+from core.models import Slice,User,Network,NetworkTemplate,NetworkSlice,Service,Tenant
 
 class XOSNetwork(XOSResource):
     provides = ["tosca.nodes.network.Network", "tosca.nodes.network.Network.XOS"]
diff --git a/xos/tosca/resources/networkparametertype.py b/xos/tosca/resources/networkparametertype.py
index e0cc93e..2061595 100644
--- a/xos/tosca/resources/networkparametertype.py
+++ b/xos/tosca/resources/networkparametertype.py
@@ -1,13 +1,5 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import Slice,User,Network,NetworkParameterType
-
 from xosresource import XOSResource
+from core.models import Slice,User,Network,NetworkParameterType
 
 class XOSNetworkParameterType(XOSResource):
     provides = "tosca.nodes.NetworkParameterType"
diff --git a/xos/tosca/resources/networktemplate.py b/xos/tosca/resources/networktemplate.py
index afd604e..4546330 100644
--- a/xos/tosca/resources/networktemplate.py
+++ b/xos/tosca/resources/networktemplate.py
@@ -1,13 +1,5 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import Slice,User,Network,NetworkTemplate
-
 from xosresource import XOSResource
+from core.models import Slice,User,Network,NetworkTemplate
 
 class XOSNetworkTemplate(XOSResource):
     provides = "tosca.nodes.NetworkTemplate"
diff --git a/xos/tosca/resources/node.py b/xos/tosca/resources/node.py
index c823914..399a3e6 100644
--- a/xos/tosca/resources/node.py
+++ b/xos/tosca/resources/node.py
@@ -1,13 +1,5 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import Node, NodeLabel, Site, Deployment, SiteDeployment
-
 from xosresource import XOSResource
+from core.models import Node, NodeLabel, Site, Deployment, SiteDeployment
 
 class XOSNode(XOSResource):
     provides = "tosca.nodes.Node"
diff --git a/xos/tosca/resources/nodelabel.py b/xos/tosca/resources/nodelabel.py
index 9a8df3e..37bd871 100644
--- a/xos/tosca/resources/nodelabel.py
+++ b/xos/tosca/resources/nodelabel.py
@@ -1,13 +1,5 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import NodeLabel
-
 from xosresource import XOSResource
+from core.models import NodeLabel
 
 class XOSNodeLabel(XOSResource):
     provides = "tosca.nodes.NodeLabel"
diff --git a/xos/tosca/resources/port.py b/xos/tosca/resources/port.py
index 791a226..b03b168 100644
--- a/xos/tosca/resources/port.py
+++ b/xos/tosca/resources/port.py
@@ -1,13 +1,5 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import Instance,User,Network,NetworkTemplate,Port
-
 from xosresource import XOSResource
+from core.models import Instance,User,Network,NetworkTemplate,Port
 
 class XOSPort(XOSResource):
     provides = ["tosca.nodes.network.Port"]
diff --git a/xos/tosca/resources/service.py b/xos/tosca/resources/service.py
index 5a57418..56d51cc 100644
--- a/xos/tosca/resources/service.py
+++ b/xos/tosca/resources/service.py
@@ -1,14 +1,5 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-import pdb
-
-from core.models import Service,User,CoarseTenant,AddressPool
-
 from xosresource import XOSResource
+from core.models import Service,User,CoarseTenant,AddressPool
 
 class XOSService(XOSResource):
     provides = "tosca.nodes.Service"
diff --git a/xos/tosca/resources/servicecontrollerresource.py b/xos/tosca/resources/servicecontrollerresource.py
index 91e61dd..ef37b19 100644
--- a/xos/tosca/resources/servicecontrollerresource.py
+++ b/xos/tosca/resources/servicecontrollerresource.py
@@ -2,11 +2,9 @@
 import pdb
 import sys
 import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
 
+from toscaparser.tosca_template import ToscaTemplate
 from core.models import ServiceControllerResource, ServiceController, LoadableModuleResource, LoadableModule
-
 from xosresource import XOSResource
 
 class XOSServiceControllerResource(XOSResource):
diff --git a/xos/tosca/resources/siterole.py b/xos/tosca/resources/siterole.py
index abb1f0d..52abe20 100644
--- a/xos/tosca/resources/siterole.py
+++ b/xos/tosca/resources/siterole.py
@@ -1,16 +1,5 @@
-# note: this module named xossite.py instead of site.py due to conflict with
-#    /usr/lib/python2.7/site.py
-
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import User, Deployment, SiteRole
-
 from xosresource import XOSResource
+from core.models import User, Deployment, SiteRole
 
 class XOSSiteRole(XOSResource):
     provides = "tosca.nodes.SiteRole"
diff --git a/xos/tosca/resources/slice.py b/xos/tosca/resources/slice.py
index 693d6ab..df9fcc9 100644
--- a/xos/tosca/resources/slice.py
+++ b/xos/tosca/resources/slice.py
@@ -1,13 +1,5 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import Slice,User,Site,Network,NetworkSlice,SliceRole,SlicePrivilege,Service,Image,Flavor,Node
-
 from xosresource import XOSResource
+from core.models import Slice,User,Site,Network,NetworkSlice,SliceRole,SlicePrivilege,Service,Image,Flavor,Node
 
 class XOSSlice(XOSResource):
     provides = "tosca.nodes.Slice"
diff --git a/xos/tosca/resources/slicerole.py b/xos/tosca/resources/slicerole.py
index fc7d3f1..3c21872 100644
--- a/xos/tosca/resources/slicerole.py
+++ b/xos/tosca/resources/slicerole.py
@@ -1,16 +1,5 @@
-# note: this module named xossite.py instead of site.py due to conflict with
-#    /usr/lib/python2.7/site.py
-
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import User, Deployment, SliceRole
-
 from xosresource import XOSResource
+from core.models import User, Deployment, SliceRole
 
 class XOSSliceRole(XOSResource):
     provides = "tosca.nodes.SliceRole"
diff --git a/xos/tosca/resources/subscriber.py b/xos/tosca/resources/subscriber.py
index 5ec0462..f69a3be 100644
--- a/xos/tosca/resources/subscriber.py
+++ b/xos/tosca/resources/subscriber.py
@@ -1,14 +1,5 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-import pdb
-
-from core.models import Subscriber,User
-
 from xosresource import XOSResource
+from core.models import Subscriber
 
 class XOSSubscriber(XOSResource):
     provides = "tosca.nodes.Subscriber"
diff --git a/xos/tosca/resources/tag.py b/xos/tosca/resources/tag.py
index 001cba8..955fabf 100644
--- a/xos/tosca/resources/tag.py
+++ b/xos/tosca/resources/tag.py
@@ -1,14 +1,6 @@
-import importlib
-import os
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-from django.contrib.contenttypes.models import ContentType
-
-from core.models import Tag, Service
-
 from xosresource import XOSResource
+from core.models import Tag, Service
+from django.contrib.contenttypes.models import ContentType
 
 class XOSTag(XOSResource):
     provides = "tosca.nodes.Tag"
diff --git a/xos/tosca/resources/tenant.py b/xos/tosca/resources/tenant.py
index 21b8e88..c22eecf 100644
--- a/xos/tosca/resources/tenant.py
+++ b/xos/tosca/resources/tenant.py
@@ -1,15 +1,8 @@
 import importlib
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-import pdb
-
-from core.models import Tenant, Service
 
 from xosresource import XOSResource
+from toscaparser.tosca_template import ToscaTemplate
+from core.models import Tenant, Service
 
 class XOSTenant(XOSResource):
     provides = "tosca.nodes.Tenant"
diff --git a/xos/tosca/resources/tenantrole.py b/xos/tosca/resources/tenantrole.py
index 316a5a3..ffb6171 100644
--- a/xos/tosca/resources/tenantrole.py
+++ b/xos/tosca/resources/tenantrole.py
@@ -1,16 +1,5 @@
-# note: this module named xossite.py instead of site.py due to conflict with
-#    /usr/lib/python2.7/site.py
-
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import User, Deployment, TenantRole
-
 from xosresource import XOSResource
+from core.models import TenantRole
 
 class XOSTenantRole(XOSResource):
     provides = "tosca.nodes.TenantRole"
diff --git a/xos/tosca/resources/user.py b/xos/tosca/resources/user.py
index 52456d5..f1ff044 100644
--- a/xos/tosca/resources/user.py
+++ b/xos/tosca/resources/user.py
@@ -1,13 +1,5 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import User, Site, SiteRole, SliceRole, SlicePrivilege, SitePrivilege, DashboardView, UserDashboardView
-
 from xosresource import XOSResource
+from core.models import User, Site, SiteRole, SliceRole, SlicePrivilege, SitePrivilege, DashboardView, UserDashboardView
 
 class XOSUser(XOSResource):
     provides = "tosca.nodes.User"
diff --git a/xos/tosca/resources/xosmodel.py b/xos/tosca/resources/xosmodel.py
index c500d7e..e9662b3 100644
--- a/xos/tosca/resources/xosmodel.py
+++ b/xos/tosca/resources/xosmodel.py
@@ -1,13 +1,5 @@
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import XOS, XOSVolume
-
 from xosresource import XOSResource
+from core.models import XOS, XOSVolume
 
 class XOSXOS(XOSResource):
     provides = "tosca.nodes.XOS"
diff --git a/xos/tosca/resources/xosresource.py b/xos/tosca/resources/xosresource.py
index 427b5eb..24edb14 100644
--- a/xos/tosca/resources/xosresource.py
+++ b/xos/tosca/resources/xosresource.py
@@ -1,5 +1,4 @@
 import os
-import pdb
 import json
 import subprocess
 import sys
@@ -62,12 +61,18 @@
 
     def get_scalable(self):
         scalable = self.nodetemplate.get_capabilities().get("scalable", None)
-        if scalable:
-            return {"min_instances": scalable.get_property_value("min_instances"),
-                    "max_instances": scalable.get_property_value("max_instances"),
-                    "default_instances": scalable.get_property_value("default_instances")}
-        else:
-            return {}
+
+        min_instances = scalable.get_property_value("min_instances")
+        max_instances = scalable.get_property_value("max_instances")
+
+        # default_instances may be None, set to min_instances if not set
+        default_instances = scalable.get_property_value("default_instances")
+        if not default_instances:
+            default_instances = min_instances
+
+        return {"min_instances": min_instances,
+                "max_instances": max_instances,
+                "default_instances": default_instances}
 
     def get_property(self, name):
         return self.nodetemplate.get_property_value(name)
diff --git a/xos/tosca/resources/xossite.py b/xos/tosca/resources/xossite.py
index e5b54b5..946b0e2 100644
--- a/xos/tosca/resources/xossite.py
+++ b/xos/tosca/resources/xossite.py
@@ -1,16 +1,5 @@
-# note: this module named xossite.py instead of site.py due to conflict with
-#    /usr/lib/python2.7/site.py
-
-import os
-import pdb
-import sys
-import tempfile
-sys.path.append("/opt/tosca")
-from translator.toscalib.tosca_template import ToscaTemplate
-
-from core.models import User,Site,Deployment,Controller,SiteDeployment
-
 from xosresource import XOSResource
+from core.models import User,Site,Deployment,Controller,SiteDeployment
 
 class XOSSite(XOSResource):
     provides = "tosca.nodes.Site"
@@ -111,5 +100,3 @@
             return
         super(XOSSite, self).delete(obj)
 
-
-
diff --git a/xos/tosca/run.py b/xos/tosca/run.py
index ff8b68d..a286d2e 100755
--- a/xos/tosca/run.py
+++ b/xos/tosca/run.py
@@ -1,8 +1,8 @@
 import os
 import sys
+import inspect
 
 # add the parent directory to sys.path
-import os,sys,inspect
 currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
 parentdir = os.path.dirname(currentdir)
 sys.path.append(parentdir)
diff --git a/xos/tosca/tests/basetest.py b/xos/tosca/tests/basetest.py
index 7dda96f..80bbe58 100644
--- a/xos/tosca/tests/basetest.py
+++ b/xos/tosca/tests/basetest.py
@@ -2,6 +2,7 @@
 import random
 import string
 import sys
+import tempfile
 
 # add the parent parent directory to sys.path
 # XXX this is very hackish :(
@@ -21,6 +22,7 @@
 
 class BaseToscaTest(object):
     username = "padmin@vicci.org"
+    current_test = ""
     base_yaml = \
 """tosca_definitions_version: tosca_simple_yaml_1_0
 
@@ -120,7 +122,11 @@
     def execute(self, yml):
         u = User.objects.get(email=self.username)
 
-        #print self.base_yaml+yml
+        # save test tosca to a temporary file
+        (tf_h, tf_p) = tempfile.mkstemp(dir="/tmp/", prefix=("tosca_test_%s_" % self.current_test))
+        # print "Saving TOSCA to file: '%s'" % tf_p
+        os.write(tf_h, self.base_yaml+yml)
+        os.close(tf_h)
 
         xt = XOSTosca(self.base_yaml+yml, parent_dir=parentdir, log_to_console=False)
         xt.execute(u)
@@ -135,12 +141,12 @@
 
     def runtest(self):
         for test in self.tests:
+            self.current_test = test.replace(' ','_')
             print "running", test
             self.cleanup()
-            try:
-                getattr(self,test)()
-            finally:
-                self.cleanup()
+            getattr(self,test)()
+
+        self.cleanup()
 
     def cleanup(self):
         pass
diff --git a/xos/tosca/tests/nodetest.py b/xos/tosca/tests/nodetest.py
index 76c56a8..76b597c 100644
--- a/xos/tosca/tests/nodetest.py
+++ b/xos/tosca/tests/nodetest.py
@@ -32,11 +32,10 @@
       requirements:
         - deployment:
              node: testdep
-             relationship: tosca.relationships.SiteDeployment
-             requirements:
-                 - controller:
-                     node: testcon
-                     relationship: tosca.relationships.UsesController
+             relationship: tosca.relationships.MemberOfDeployment
+        - controller:
+             node: testcon
+             relationship: tosca.relationships.UsesController
 """
 
     def create_node_minimal(self):
diff --git a/xos/tosca/tests/observerSiteTest.py b/xos/tosca/tests/observerSiteTest.py
index 0ebc8be..a17c692 100644
--- a/xos/tosca/tests/observerSiteTest.py
+++ b/xos/tosca/tests/observerSiteTest.py
@@ -28,10 +28,9 @@
           - deployment:
                node: %s
                relationship: tosca.relationships.SiteDeployment
-               requirements:
-                   - controller:
-                       node: %s
-                       relationship: tosca.relationships.UsesController
+          - controller:
+               node: %s
+               relationship: tosca.relationships.UsesController
 """ % (self.get_usable_deployment(), self.get_usable_controller()))
 
         testsite = self.assert_obj(Site, "testsite")
diff --git a/xos/tosca/tests/observerUserTest.py b/xos/tosca/tests/observerUserTest.py
index a6b5897..d2e0293 100644
--- a/xos/tosca/tests/observerUserTest.py
+++ b/xos/tosca/tests/observerUserTest.py
@@ -43,10 +43,9 @@
           - deployment:
                node: %s
                relationship: tosca.relationships.SiteDeployment
-               requirements:
-                   - controller:
-                       node: %s
-                       relationship: tosca.relationships.UsesController
+          - controller:
+               node: %s
+               relationship: tosca.relationships.UsesController
     johndoe@foo.bar:
       type: tosca.nodes.User
       properties: