observer site test
diff --git a/xos/tosca/tests/observerSiteTest.py b/xos/tosca/tests/observerSiteTest.py
new file mode 100644
index 0000000..bc1efd4
--- /dev/null
+++ b/xos/tosca/tests/observerSiteTest.py
@@ -0,0 +1,57 @@
+from observertest import BaseObserverToscaTest
+
+from core.models import Site, Deployment, ControllerSite
+
+# Note that as a side effect, these tests will also create a Site
+
+class ObserverSiteTest(BaseObserverToscaTest):
+ tests = ["create_site"]
+ # hide_observer_output = False # uncomment to display lots of stuff to screen
+
+ def cleanup(self):
+ # We don't want to leak resources, so we make sure to let the observer
+ # attempt to delete these objects.
+ self.try_to_delete(Site, purge=False, name="testsite")
+ self.run_observer()
+ self.try_to_delete(Site, purge=True, name="testsite")
+
+ def create_site(self):
+ self.assert_noobj(Site, "testsite")
+ self.execute(self.make_nodetemplate(self.get_usable_deployment(), "tosca.nodes.Deployment",
+ props={"no-delete": True}) + \
+"""
+ testsite:
+ type: tosca.nodes.Site
+ properties:
+ display_name: TestSite
+ site_url: http://opencloud.us/
+ requirements:
+ - deployment:
+ node: %s
+ relationship: tosca.relationships.SiteDeployment
+ requirements:
+ - controller:
+ node: %s
+ relationship: tosca.relationships.UsesController
+""" % (self.get_usable_deployment(), self.get_usable_controller()))
+
+ testsite = self.assert_obj(Site, "TestSite")
+
+ self.run_model_policy(save_output="/tmp/sitetest:create_site:model_policy")
+
+ # make sure a ControllerSite object was created
+ cs = ControllerSite.objects.filter(site=testsite)
+ assert(len(cs) == 1)
+
+ self.run_observer(save_output="/tmp/sitetest:create_site:observer")
+
+ testsite = self.assert_obj(Site, "TestSite")
+
+ cs = ControllerSite.objects.filter(site=testsite)
+ assert(len(cs) == 1)
+ assert(cs[0].tenant_id is not None)
+ assert(cs[0].tenant_id != "")
+
+if __name__ == "__main__":
+ ObserverSiteTest()
+
diff --git a/xos/tosca/tests/observertest.py b/xos/tosca/tests/observertest.py
index f714045..1ec8797 100644
--- a/xos/tosca/tests/observertest.py
+++ b/xos/tosca/tests/observertest.py
@@ -19,6 +19,9 @@
def get_usable_deployment(self):
return "MyDeployment"
+ def get_usable_controller(self):
+ return "CloudLab"
+
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: