summaryrefslogtreecommitdiff
path: root/yarns/lib.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-07-01 13:06:36 +0300
committerLars Wirzenius <liw@liw.fi>2017-07-01 23:42:22 +0300
commitf70d6c0442f8f2f01a8195f439fddc6c0831a905 (patch)
treea5d87b637ac936b0dba73f2893f74c64d2581c36 /yarns/lib.py
parent06465ff158006e01777bf5ff69aa08a400a30886 (diff)
downloadick2-f70d6c0442f8f2f01a8195f439fddc6c0831a905.tar.gz
Add: controller build scenario
This scenario test the ick2 MVP controller API. See http://ick-devel.liw.fi/f6166c07380e4cc78b5619d8c1322736.html for more detailed information.
Diffstat (limited to 'yarns/lib.py')
-rw-r--r--yarns/lib.py63
1 files changed, 62 insertions, 1 deletions
diff --git a/yarns/lib.py b/yarns/lib.py
index b7df3a7..9040bb7 100644
--- a/yarns/lib.py
+++ b/yarns/lib.py
@@ -1,11 +1,15 @@
import errno
+import json
import os
+import StringIO
import time
import cliapp
-
+import requests
+import yaml
import yarnutils
+
datadir = os.environ['DATADIR']
srcdir = os.environ['SRCDIR']
@@ -27,3 +31,60 @@ def cat(filename):
continue
raise
raise Exception("cat took more then %s seconds" % MAX_CAT_TIME)
+
+
+def write(filename, content):
+ with open(filename, 'w') as f:
+ f.write(content)
+
+
+def git(repo, *argv):
+ return cliapp.runcmd(['git'] + list(argv), cwd=repo)
+
+
+def controller_url(port, path):
+ return 'http://localhost:{}{}'.format(port, path)
+
+
+def request(method, url, body=None):
+ funcs = {
+ 'POST': requests.post,
+ 'PUT': requests.put,
+ 'GET': requests.get,
+ 'DELETE': requests.delete,
+ }
+
+ headers = {
+ 'Content-Type': 'application/json',
+ }
+
+ response = funcs[method](
+ url,
+ headers=headers,
+ data=body,
+ )
+
+ return response.status_code, response.text
+
+
+def parse_json(text):
+ return json.loads(text)
+
+
+def parse_yaml(text):
+ f = StringIO.StringIO(text)
+ return yaml.safe_load(stream=f)
+
+
+def unescape(text):
+ def helper(text):
+ while text:
+ if text.startswith('\\n'):
+ skip = 2
+ answer = '\n'
+ else:
+ skip = 1
+ answer = text[0]
+ text = text[skip:]
+ yield answer
+ return ''.join(helper(text))