made an intrinsic to look up stuff in a config file
diff --git a/xos/configurations/common/cloudlab.yaml b/xos/configurations/common/cloudlab.yaml
index b044acd..de614dc 100644
--- a/xos/configurations/common/cloudlab.yaml
+++ b/xos/configurations/common/cloudlab.yaml
@@ -2,9 +2,7 @@
# Note:
# assumes the following have been created and filled with appropriate data:
-# /root/setup/auth_url
-# /root/setup/admin_user
-# /root/setup/admin_password
+# /root/setup/admin_openrc
# /root/setup/flat_net_name
# /root/setup/pubkey
@@ -40,14 +38,12 @@
properties:
backend_type: OpenStack
version: Juno
- auth_url: { get_artifact: [ SELF, auth_url, LOCAL_FILE] }
- admin_user: { get_artifact: [ SELF, os_username, LOCAL_FILE] }
- admin_password: { get_artifact: [ SELF, os_password, LOCAL_FILE] }
+ auth_url: { get_script_env: [ SELF, adminrc, OS_AUTH_URL, LOCAL_FILE] }
+ admin_user: { get_script_env: [ SELF, adminrc, OS_USERNAME, LOCAL_FILE] }
+ admin_password: { get_script_env: [ SELF, adminrc, OS_PASSWORD, LOCAL_FILE] }
domain: Default
artifacts:
- auth_url: /root/setup/auth_url
- admin_user: /root/setup/admin_user
- admin_password: /root/setup/admin_password
+ adminrc: /root/setup/admin-openrc.sh
mysite:
type: tosca.nodes.Site
diff --git a/xos/tosca/resources/xosresource.py b/xos/tosca/resources/xosresource.py
index 989f3a8..62f18db 100644
--- a/xos/tosca/resources/xosresource.py
+++ b/xos/tosca/resources/xosresource.py
@@ -1,6 +1,7 @@
import os
import pdb
import json
+import subprocess
from core.models import User
@@ -114,6 +115,20 @@
raise Exception("artifact %s not found" % name)
+ def intrinsic_get_script_env(self, obj=None, name=None, varname=None, method=None):
+ if obj!="SELF":
+ raise Exception("only SELF is supported for get_artifact first arg")
+ if method!="LOCAL_FILE":
+ raise Exception("only LOCAL_FILE is supported for get_artifact fourth arg")
+
+ for (k,v) in self.nodetemplate.entity_tpl.get("artifacts", {}).items():
+ if k == name:
+ if not os.path.exists(v):
+ raise Exception("Artifact local file %s for artifact %s does not exist" % (v, k))
+ return subprocess.Popen('/bin/bash -c "source %s &> /dev/null; echo \\$%s"' % (v, varname), shell=True, stdout=subprocess.PIPE).stdout.read().strip()
+
+ raise Exception("artifact %s not found" % name)
+
def try_intrinsic_function(self, v):
try:
jsv = v.replace("'", '"')
@@ -128,6 +143,8 @@
if "get_artifact" in jsv:
return self.intrinsic_get_artifact(*jsv["get_artifact"])
+ elif "get_script_env" in jsv:
+ return self.intrinsic_get_script_env(*jsv["get_script_env"])
return v
diff --git a/xos/tosca/tests/alltests.py b/xos/tosca/tests/alltests.py
index 0ce55c4..13dfeb8 100644
--- a/xos/tosca/tests/alltests.py
+++ b/xos/tosca/tests/alltests.py
@@ -1,3 +1,4 @@
+from enginetest import EngineTest
from coarsetenancytest import CoarseTenancyTest
from porttest import PortTest
from networktest import NetworkTest
@@ -12,6 +13,7 @@
from imagetest import ImageTest
if __name__ == "__main__":
+ EngineTest()
SiteTest()
DeploymentTest()
ControllerTest()
diff --git a/xos/tosca/tests/enginetest.py b/xos/tosca/tests/enginetest.py
new file mode 100644
index 0000000..ed3d51e
--- /dev/null
+++ b/xos/tosca/tests/enginetest.py
@@ -0,0 +1,53 @@
+from basetest import BaseToscaTest
+
+from core.models import Service
+
+class EngineTest(BaseToscaTest):
+ tests = ["intrinsic_get_artifact",
+ "intrinsic_get_script_env",
+ "intrinsic_get_script_env_noisy" ]
+
+ def cleanup(self):
+ self.try_to_delete(Service, name="testservice")
+
+ def intrinsic_get_artifact(self):
+ self.assert_noobj(Service, "testservice")
+ file("/tmp/somevar","w").write("somevalue")
+ self.execute(self.make_nodetemplate("testservice", "tosca.nodes.Service",
+ props={"public_key": "{ get_artifact: [ SELF, somevar, LOCAL_FILE] }"},
+ artifacts={"somevar": "/tmp/somevar"}))
+ self.assert_obj(Service, "test_svc", public_key="somevalue")
+
+ def intrinsic_get_script_env(self):
+ self.assert_noobj(Service, "testservice")
+ file("/tmp/somescript","w").write( \
+"""#! /bin/bash
+FOO=123
+BAR=456
+JUNK=789
+""")
+ self.execute(self.make_nodetemplate("testservice", "tosca.nodes.Service",
+ props={"public_key": "{ get_script_env: [ SELF, somescript, BAR, LOCAL_FILE] }"},
+ artifacts={"somescript": "/tmp/somescript"}))
+ self.assert_obj(Service, "testservice", public_key="456")
+
+ def intrinsic_get_script_env_noisy(self):
+ self.assert_noobj(Service, "testservice")
+ file("/tmp/somescript","w").write( \
+"""#! /bin/bash
+echo "junk"
+echo "oh no! something got written to stderr! This always breaks stuff!" >&2
+FOO=123
+echo "more junk"
+BAR=456
+echo "even more junk"
+JUNK=789
+echo "BAR=oops"
+""")
+ self.execute(self.make_nodetemplate("testservice", "tosca.nodes.Service",
+ props={"public_key": "{ get_script_env: [ SELF, somescript, BAR, LOCAL_FILE] }"},
+ artifacts={"somescript": "/tmp/somescript"}))
+ self.assert_obj(Service, "testservice", public_key="456")
+
+if __name__ == "__main__":
+ EngineTest()