summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-04-06 15:08:44 +0300
committerLars Wirzenius <liw@liw.fi>2019-04-06 15:08:44 +0300
commit161cd6ead960ecf6afc05bd583718724140d6973 (patch)
tree08ebfd2ce661787fabe7cfaf4731ba9e92a0bc93
parente34fe17957621386706febab0389d9c00985a611 (diff)
downloadick2-161cd6ead960ecf6afc05bd583718724140d6973.tar.gz
Refactor: use name V instead of vars in yarn implements
vars is a Python builtin, and as such it's not a great name.
-rw-r--r--yarns/900-implements.yarn56
-rw-r--r--yarns/900-local.yarn90
-rw-r--r--yarns/900-remote.yarn14
-rw-r--r--yarns/lib.py14
4 files changed, 87 insertions, 87 deletions
diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn
index 5468a6c..490f46e 100644
--- a/yarns/900-implements.yarn
+++ b/yarns/900-implements.yarn
@@ -33,46 +33,46 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
user = get_next_match()
path = get_next_match()
token = get_token(user)
- url = vars['url']
- http(vars, get, url + path, token=token)
+ url = V['url']
+ http(V, get, url + path, token=token)
IMPLEMENTS WHEN (\S+) retrieves (\S+) from artifact store
user = get_next_match()
path = get_next_match()
token = get_token(user)
- url = vars['bsurl']
- http(vars, get_blob, url + path, token=token)
+ url = V['bsurl']
+ http(V, get_blob, url + path, token=token)
IMPLEMENTS WHEN (\S+) makes request GET (\S+) with an invalid token
user = get_next_match()
path = get_next_match()
token = get_token(user)
- url = vars['url']
- http(vars, get, url + path, token='invalid')
+ url = V['url']
+ http(V, get, url + path, token='invalid')
IMPLEMENTS WHEN (\S+) makes request POST (\S+) with a valid token and body (.+)
user = get_next_match()
path = get_next_match()
body = get_next_match()
token = get_token(user)
- url = vars['url']
- http(vars, post, url + path, body=body, token=token)
+ url = V['url']
+ http(V, post, url + path, body=body, token=token)
IMPLEMENTS WHEN (\S+) makes request POST (\S+) with an invalid token and body (.+)
user = get_next_match()
path = get_next_match()
body = get_next_match()
token = get_token(user)
- url = vars['url']
- http(vars, post, url + path, body=body, token='invalid')
+ url = V['url']
+ http(V, post, url + path, body=body, token='invalid')
IMPLEMENTS WHEN (\S+) makes request PUT (\S+) with a valid token and body (.+)
user = get_next_match()
path = get_next_match()
body = get_next_match()
token = get_token(user)
- url = vars['url']
- http(vars, put, url + path, body=body, token=token)
+ url = V['url']
+ http(V, put, url + path, body=body, token=token)
IMPLEMENTS WHEN (\S+) sends blob (\S+) to artifact store as (\S+)
user = get_next_match()
@@ -80,34 +80,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
path = get_next_match()
body = cat(filename)
token = get_token(user)
- url = vars['bsurl']
- http(vars, put_blob, url + path, body=body, token=token)
+ url = V['bsurl']
+ http(V, put_blob, url + path, body=body, token=token)
IMPLEMENTS WHEN (\S+) makes request PUT (\S+) with an invalid token
user = get_next_match()
path = get_next_match()
body = '{}'
token = get_token(user)
- url = vars['url']
- http(vars, put, url + path, body=body, token='invalid')
+ url = V['url']
+ http(V, put, url + path, body=body, token='invalid')
IMPLEMENTS WHEN (\S+) makes request DELETE (\S+)
user = get_next_match()
path = get_next_match()
token = get_token(user)
- url = vars['url']
- http(vars, delete, url + path, token=token)
+ url = V['url']
+ http(V, delete, url + path, token=token)
## HTTP response inspection
IMPLEMENTS THEN result has status code (\d+)
expected = int(get_next_match())
- assertEqual(expected, vars['status_code'])
+ assertEqual(expected, V['status_code'])
IMPLEMENTS THEN body matches (.+)
expected_text = get_next_match()
expected = json.loads(expected_text)
- actual = json.loads(vars['body'])
+ actual = json.loads(V['body'])
print 'expected'
json.dump(expected, sys.stdout, indent=4, sort_keys=True)
print
@@ -121,7 +121,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
IMPLEMENTS THEN body text contains "(.*)"
pattern = unescape(get_next_match())
- text = vars['body']
+ text = V['body']
print 'pattern:', repr(pattern)
print 'text:', text
assertTrue(pattern in text)
@@ -129,11 +129,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
IMPLEMENTS THEN body is the same as the blob (\S+)
filename = get_next_match()
blob = cat(filename)
- body = vars['body']
+ body = V['body']
assertEqual(body, blob)
IMPLEMENTS THEN version in body matches version from setup.py
- body = vars['body']
+ body = V['body']
obj = json.loads(body)
actual = obj['version']
setup_py = os.path.join(srcdir, 'setup.py')
@@ -143,13 +143,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
IMPLEMENTS THEN result has header (\S+): (\S+)
name = get_next_match()
value = get_next_match()
- headers = vars['headers']
+ headers = V['headers']
assertEqual(headers[name].lower(), value.lower())
IMPLEMENTS THEN result is step (.+)
step = json.loads(get_next_match())
print('expected step', step)
- body = json.loads(vars['body'])
+ body = json.loads(V['body'])
print('actual body', body)
actual_step = body['step']
print('actual step', actual_step)
@@ -160,14 +160,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
IMPLEMENTS WHEN (\S+) requests list of builds
user = get_next_match()
token = get_token(user)
- url = vars['url']
+ url = V['url']
path = '/builds'
- http(vars, get, url + path, token=token)
+ http(V, get, url + path, token=token)
IMPLEMENTS THEN the list of builds is (.+)
expected = set(json.loads(get_next_match()))
print('expected', expected)
- body = json.loads(vars['body'])['builds']
+ body = json.loads(V['body'])['builds']
print('body', body)
builds = set(build['build_id'] for build in body)
assertEqual(builds, expected)
diff --git a/yarns/900-local.yarn b/yarns/900-local.yarn
index 4a315ae..5fa06f3 100644
--- a/yarns/900-local.yarn
+++ b/yarns/900-local.yarn
@@ -39,48 +39,48 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
]
token = cliapp.runcmd(argv, feed_stdin=key)
store_token(user, token)
- vars['issuer'] = 'localhost'
- vars['audience'] = user
+ V['issuer'] = 'localhost'
+ V['audience'] = user
## Controller configuration
IMPLEMENTS GIVEN controller config uses (\S+) at the state directory
- vars['statedir'] = get_next_match()
+ V['statedir'] = get_next_match()
IMPLEMENTS GIVEN controller config uses (\S+) as artifact store
- vars['artifact_store'] = get_next_match()
+ V['artifact_store'] = get_next_match()
IMPLEMENTS GIVEN controller config uses (\S+) as authentication
- vars['auth_url'] = get_next_match()
+ V['auth_url'] = get_next_match()
IMPLEMENTS GIVEN controller config uses (\S+) as notify
- vars['notify_url'] = get_next_match()
- assert vars['notify_url'] is not None
+ V['notify_url'] = get_next_match()
+ assert V['notify_url'] is not None
## Start and stop the controller
IMPLEMENTS GIVEN a running ick controller
import os, time, cliapp, yaml
- vars['controller.log'] = 'ick_controller.log'
- vars['gunicorn3.log'] = 'gunicorn3.log'
- vars['port'] = random_free_port()
- vars['url'] = 'http://127.0.0.1:{}'.format(vars['port'])
- assert vars['auth_url'] is not None
- assert vars['notify_url'] is not None
+ V['controller.log'] = 'ick_controller.log'
+ V['gunicorn3.log'] = 'gunicorn3.log'
+ V['port'] = random_free_port()
+ V['url'] = 'http://127.0.0.1:{}'.format(V['port'])
+ assert V['auth_url'] is not None
+ assert V['notify_url'] is not None
config = {
- 'token-issuer': vars['issuer'],
- 'token-audience': vars['audience'],
+ 'token-issuer': V['issuer'],
+ 'token-audience': V['audience'],
'token-public-key': cat('token.key.pub'),
'log': [
{
- 'filename': vars['controller.log'],
+ 'filename': V['controller.log'],
},
],
- 'statedir': vars['statedir'],
+ 'statedir': V['statedir'],
'apt-server': 'localhost',
- 'artifact-store': vars['artifact_store'],
- 'auth-url': vars['auth_url'],
- 'notify-url': vars['notify_url'],
+ 'artifact-store': V['artifact_store'],
+ 'auth-url': V['auth_url'],
+ 'notify-url': V['notify_url'],
}
assert config['notify-url'] is not None
env = dict(os.environ)
@@ -89,30 +89,30 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
argv = [
'gunicorn3',
'--daemon',
- '--bind', '127.0.0.1:{}'.format(vars['port']),
- '--log-file', vars['gunicorn3.log'],
+ '--bind', '127.0.0.1:{}'.format(V['port']),
+ '--log-file', V['gunicorn3.log'],
'--log-level', 'debug',
'-p', 'pid',
'ick_controller:app',
]
cliapp.runcmd(argv, env=env)
- vars['pid'] = int(cat('pid'))
- wait_for_port(vars['port'])
+ V['pid'] = int(cat('pid'))
+ wait_for_port(V['port'])
IMPLEMENTS WHEN user stops ick controller
import os, signal
- os.kill(int(vars['pid']), signal.SIGTERM)
+ os.kill(int(V['pid']), signal.SIGTERM)
IMPLEMENTS FINALLY stop ick controller
import os, signal
- os.kill(vars['pid'], signal.SIGTERM)
+ os.kill(V['pid'], signal.SIGTERM)
## Controller state inspection
IMPLEMENTS THEN controller state directory contains project (\S+)
name = get_next_match()
basename = encode_basename(name)
- filename = os.path.join(vars['statedir'], 'projects', basename)
+ filename = os.path.join(V['statedir'], 'projects', basename)
print 'name', name
print 'basename', basename
print 'filename', filename
@@ -121,7 +121,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
IMPLEMENTS THEN controller state directory contains worker (\S+)
name = get_next_match()
basename = encode_basename(name)
- filename = os.path.join(vars['statedir'], 'workers', basename)
+ filename = os.path.join(V['statedir'], 'workers', basename)
print 'filename', filename
assertTrue(os.path.exists(filename))
@@ -129,21 +129,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
IMPLEMENTS THEN artifact store URL is (\S+)
expected = get_next_match()
- body = vars['body']
+ body = V['body']
obj = json.loads(body)
actual = obj['artifact_store']
assertEqual(actual, expected)
IMPLEMENTS THEN authentication URL is (\S+)
expected = get_next_match()
- body = vars['body']
+ body = V['body']
obj = json.loads(body)
actual = obj['auth_url']
assertEqual(actual, expected)
IMPLEMENTS THEN notify URL is (\S+)
expected = get_next_match()
- body = vars['body']
+ body = V['body']
obj = json.loads(body)
actual = obj['notify_url']
assertEqual(actual, expected)
@@ -151,24 +151,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
## Start and stop artifact store
IMPLEMENTS GIVEN artifact store config uses (\S+) at the blob directory
- vars['blobdir'] = get_next_match()
+ V['blobdir'] = get_next_match()
IMPLEMENTS GIVEN a running artifact store
import os, time, cliapp, yaml
- vars['artifact_store.log'] = 'artifact_store.log'
- vars['gunicorn3_as.log'] = 'gunicorn3_as.log'
- vars['bsport'] = random_free_port()
- vars['bsurl'] = 'http://127.0.0.1:{}'.format(vars['bsport'])
+ V['artifact_store.log'] = 'artifact_store.log'
+ V['gunicorn3_as.log'] = 'gunicorn3_as.log'
+ V['bsport'] = random_free_port()
+ V['bsurl'] = 'http://127.0.0.1:{}'.format(V['bsport'])
config = {
- 'token-issuer': vars['issuer'],
- 'token-audience': vars['audience'],
+ 'token-issuer': V['issuer'],
+ 'token-audience': V['audience'],
'token-public-key': cat('token.key.pub'),
'log': [
{
- 'filename': vars['artifact_store.log'],
+ 'filename': V['artifact_store.log'],
},
],
- 'blobdir': vars['blobdir'],
+ 'blobdir': V['blobdir'],
}
env = dict(os.environ)
env['ARTIFACT_STORE_CONFIG'] = 'artifact_store.yaml'
@@ -176,16 +176,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
argv = [
'gunicorn3',
'--daemon',
- '--bind', '127.0.0.1:{}'.format(vars['bsport']),
- '--log-file', vars['gunicorn3_as.log'],
+ '--bind', '127.0.0.1:{}'.format(V['bsport']),
+ '--log-file', V['gunicorn3_as.log'],
'--log-level', 'debug',
'-p', 'bspid',
'artifact_store:app',
]
cliapp.runcmd(argv, env=env)
- vars['bspid'] = int(cat('bspid'))
- wait_for_port(vars['bsport'])
+ V['bspid'] = int(cat('bspid'))
+ wait_for_port(V['bsport'])
IMPLEMENTS FINALLY stop artifact store
import os, signal
- os.kill(vars['bspid'], signal.SIGTERM)
+ os.kill(V['bspid'], signal.SIGTERM)
diff --git a/yarns/900-remote.yarn b/yarns/900-remote.yarn
index 2875d27..6cc7f88 100644
--- a/yarns/900-remote.yarn
+++ b/yarns/900-remote.yarn
@@ -22,31 +22,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
## Authentication setup
IMPLEMENTS GIVEN an RSA key pair for token signing
- vars['private_key_file'] = os.environ['ICK_PRIVATE_KEY']
- assertTrue(os.path.exists(vars['private_key_file']))
+ V['private_key_file'] = os.environ['ICK_PRIVATE_KEY']
+ assertTrue(os.path.exists(V['private_key_file']))
IMPLEMENTS GIVEN an access token for (\S+) with scopes (.+)
user = get_next_match()
scopes = get_next_match()
- key = open(vars['private_key_file']).read()
+ key = open(V['private_key_file']).read()
argv = [
os.path.join(srcdir, 'create-token'),
scopes,
]
token = cliapp.runcmd(argv, feed_stdin=key)
store_token(user, token)
- vars['issuer'] = 'localhost'
- vars['audience'] = 'localhost'
+ V['issuer'] = 'localhost'
+ V['audience'] = 'localhost'
## Controller configuration
IMPLEMENTS GIVEN controller config uses (\S+) at the state directory
- vars['statedir'] = get_next_match()
+ V['statedir'] = get_next_match()
## Start and stop the controller
IMPLEMENTS GIVEN a running ick controller
- vars['url'] = os.environ['ICK_URL']
+ V['url'] = os.environ['ICK_URL']
IMPLEMENTS WHEN user stops ick controller
pass
diff --git a/yarns/lib.py b/yarns/lib.py
index f3ac9d9..290512c 100644
--- a/yarns/lib.py
+++ b/yarns/lib.py
@@ -1,4 +1,4 @@
-# Copyright 2017-2018 Lars Wirzenius
+# Copyright 2017-2019 Lars Wirzenius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -32,7 +32,7 @@ from yarnutils import *
srcdir = os.environ['SRCDIR']
datadir = os.environ['DATADIR']
-vars = Variables(datadir)
+V = Variables(datadir)
def random_free_port():
@@ -101,12 +101,12 @@ def get_token(user):
return cat(filename)
-def http(vars, func, url, **kwargs):
+def http(V, func, url, **kwargs):
status, content_type, headers, body = func(url, **kwargs)
- vars['status_code'] = status
- vars['content_type'] = content_type
- vars['headers'] = headers
- vars['body'] = body
+ V['status_code'] = status
+ V['content_type'] = content_type
+ V['headers'] = headers
+ V['body'] = body
def get(url, token):