WIP, observer-exercising compute test
diff --git a/xos/tosca/tests/observerComputeTest.py b/xos/tosca/tests/observerComputeTest.py
new file mode 100644
index 0000000..c2ca42c
--- /dev/null
+++ b/xos/tosca/tests/observerComputeTest.py
@@ -0,0 +1,45 @@
+from observertest import BaseObserverToscaTest
+
+from core.models import Instance, Site
+
+class ObserverComputeTest(BaseObserverToscaTest):
+    tests = ["create_instance"]
+    # hide_observer_output = False # uncomment to display lots of stuff to screen
+
+    def cleanup(self):
+        self.try_to_delete(Instance, purge=False, name="test_compute1")
+        self.try_to_delete(Site, purge=False, name="testsite")
+        self.run_observer()
+        self.try_to_delete(Site, purge=True, name="testsite")   # make it go away
+
+    def get_base_templates(self):
+        return self.make_nodetemplate("testsite", "tosca.nodes.Site") + \
+               self.make_nodetemplate("testsite_slice1", "tosca.nodes.Slice", reqs=[("testsite", "tosca.relationships.MemberOfSite")])
+
+    def create_instance(self):
+        self.assert_noobj(Instance, "test_compute1")
+        self.execute(self.get_base_templates() +
+                     self.make_compute("testsite_slice1", "test_compute1", disk_size="1 GB", mem_size="513 MB"))
+        instance = self.assert_obj(Instance, "test_compute1")
+        assert(instance.flavor.name == "m1.small")
+
+        self.run_model_policy()
+
+        # this should make the ports
+        self.run_observer()
+
+        # reset the exponential backoff
+        instance = self.assert_obj(Instance, "test_compute1")
+        instance.backend_register="{}"
+
+        # this should instantiate the instance
+        self.run_observer()
+
+        instance = self.assert_obj(Instance, "test_compute1")
+
+        assert(instance.instance_id is not None)
+        assert(instance.instance_name is not None)
+
+if __name__ == "__main__":
+    ObserverComputeTest()
+
diff --git a/xos/tosca/tests/observertest.py b/xos/tosca/tests/observertest.py
new file mode 100644
index 0000000..32dcf24
--- /dev/null
+++ b/xos/tosca/tests/observertest.py
@@ -0,0 +1,64 @@
+from basetest import *
+
+import logging
+import StringIO
+import subprocess
+import sys
+
+from observer.event_loop import XOSObserver
+from model_policy import run_policy_once
+from xos.config import set_override
+from util.logger import Logger, observer_logger
+
+class BaseObserverToscaTest(BaseToscaTest):
+    hide_observer_output = True
+
+    def __init__(self):
+        super(BaseObserverToscaTest, self).__init__()
+
+    def ensure_observer_not_running(self):
+        ps_output = subprocess.Popen("ps -elfy", shell=True, stdout=subprocess.PIPE).stdout.read()
+        if "/opt/xos/xos-observer.py" in ps_output:
+            print >> sys.stderr, "an observer is still running"
+            print >> sys.stderr, "please stop it, for example 'supervisorctl stop observer'"
+            sys.exit(-1)
+
+    def log_to_memory(self):
+        set_override("observer_console_print", False)
+
+        if self.hide_observer_output:
+            logStream = StringIO.StringIO()
+            handler = logging.StreamHandler(stream=logStream)
+            handler.setLevel(logging.DEBUG)
+            handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
+
+            loggername = Logger().loggername
+            log = logging.getLogger(loggername)
+            for hdlr in log.handlers[:]:
+                log.removeHandler(hdlr)
+            log.addHandler(handler)
+            log.propagate = False
+
+            log = observer_logger.logger
+            for hdlr in log.handlers[:]:
+                log.removeHandler(hdlr)
+            log.addHandler(handler)
+            log.propagate = False
+
+    def run_model_policy(self):
+        self.ensure_observer_not_running()
+        self.log_to_memory()
+
+        #print ">>>>> run model_policies"
+        run_policy_once()
+        #print ">>>>> done model_policies"
+
+    def run_observer(self):
+        self.ensure_observer_not_running()
+        self.log_to_memory()
+
+        observer = XOSObserver()
+        #print ">>>>> run observer"
+        observer.run_once()
+        #print ">>>>> done observer"
+