blob: 9e5fe671d963ae0a57ff7fd3c7a427ca410c41b4 [file] [log] [blame]
Adam Israel5e08a0e2018-09-06 19:22:47 -04001from charmhelpers.core.hookenv import (
2 action_fail,
3 action_set,
4 action_get,
5 status_set,
6)
7from charms.reactive import (
8 clear_flag,
9 set_flag,
10 when,
11 when_not,
12)
13
14
15@when_not('native-ci.installed')
16def install_native_ci_charm():
17 set_flag('native-ci.installed')
18 status_set('active', 'Ready!')
19
20
21@when('actions.test', 'native-ci.installed')
22def test():
23 try:
24 result = True
25 except Exception as e:
26 action_fail('command failed: {}'.format(e))
27 else:
28 action_set({'output': result})
29 finally:
30 clear_flag('actions.test')
31
32
33@when('actions.testint', 'native-ci.installed')
34def testint():
35 try:
36 # Test the value is an int by performing a mathmatical operation on it.
37 intval = action_get('intval')
38 intval = intval + 1
39 except Exception as e:
40 action_fail('command failed: {}'.format(e))
41 else:
42 action_set({'output': intval})
43 finally:
44 clear_flag('actions.testint')
Adam Israel136186e2018-09-14 12:01:12 -040045
46
47@when('db.joined')
48def provides_db(db):
49 """Simulate providing database credentials."""
50 db.configure(
51 database="mydb",
52 user="myuser",
53 password="mypassword",
54 host="myhost",
55 slave="myslave",
56 )
57
58
59@when('db.available')
60def requires_db(db):
61 """Simulate receiving database credentials."""
62 pass