summaryrefslogtreecommitdiff
path: root/ick2/actions.py
diff options
context:
space:
mode:
Diffstat (limited to 'ick2/actions.py')
-rw-r--r--ick2/actions.py63
1 files changed, 62 insertions, 1 deletions
diff --git a/ick2/actions.py b/ick2/actions.py
index 202bcb6..3d77aa5 100644
--- a/ick2/actions.py
+++ b/ick2/actions.py
@@ -35,7 +35,9 @@ class ActionFactory:
'container': ick2.ContainerEnvironment,
}
- def __init__(self, systree, workspace_area, reporter):
+ def __init__(self, build_id, systree, workspace_area, reporter):
+ self._cc = None
+ self._build_id = build_id
self._systree = systree
self._workspace_area = workspace_area
self._reporter = reporter
@@ -46,6 +48,9 @@ class ActionFactory:
def add_env_var(self, name, value): # pragma: no cover
self._extra_env[name] = value
+ def set_controller_client(self, cc): # pragma: no cover
+ self._cc = cc
+
def set_token(self, token):
self._token = token
@@ -79,6 +84,8 @@ class ActionFactory:
def create_action(self, spec, project_name):
env = self.create_environment(spec, project_name)
action = self._create_action_object(env, spec)
+ action.set_controller_client(self._cc)
+ action.set_build_id(self._build_id)
action.set_token(self.get_token())
action.set_blob_url_func(self.get_blob_url_func())
return action
@@ -103,6 +110,7 @@ class ActionFactory:
'git': GitAction,
'rsync': RsyncAction,
'dput': DputAction,
+ 'notify': NotifyAction,
}
kind = spec['action']
klass = rules2.get(kind)
@@ -116,9 +124,23 @@ class Action: # pragma: no cover
def __init__(self, env):
self._env = env
+ self._cc = None
+ self._build_id = None
self._token = None
self._blob_url = None
+ def set_controller_client(self, cc):
+ self._cc = cc
+
+ def get_controller_client(self):
+ return self._cc
+
+ def set_build_id(self, build_id):
+ self._build_id = build_id
+
+ def get_build_id(self):
+ return self._build_id
+
def set_token(self, token):
self._token = token
@@ -444,6 +466,45 @@ class DputAction(Action): # pragma: no cover
return exit_code
+class NotifyAction(Action): # pragma: no cover
+
+ def encode_parameters(self, params):
+ pass
+
+ def execute(self, params, step):
+ env = self.get_env()
+ cc = self.get_controller_client()
+ assert cc is not None
+ build_id = self.get_build_id()
+
+ env.report(None, 'Notifying about build ending\n')
+
+ build_path = '/builds/{}'.format(build_id)
+ build = cc.show(build_path)
+
+ params = build.get('parameters', {})
+ if 'notify' not in params:
+ env.report(
+ 0,
+ 'NOT notifying about build ending: no "notify" parameter.\n')
+ return
+
+ recipients = params['notify']
+
+ log = cc.get_log(build_id)
+ log = log.decode('utf-8')
+
+ notify = {
+ 'recipients': recipients,
+ 'build': build,
+ 'log': log,
+ }
+
+ cc.notify(notify)
+
+ env.report(0, 'Notified about build {} ending\n'.format(build_id))
+
+
def make_directory_empty(env, dirname):
return env.runcmd(
['sudo', 'find', dirname, '-mindepth', '1', '-delete'])