| Adam Israel | 5e08a0e | 2018-09-06 19:22:47 -0400 | [diff] [blame] | 1 | from charmhelpers.core.hookenv import ( |
| 2 | action_fail, |
| 3 | action_set, |
| 4 | action_get, |
| 5 | status_set, |
| 6 | ) |
| 7 | from charms.reactive import ( |
| 8 | clear_flag, |
| 9 | set_flag, |
| 10 | when, |
| 11 | when_not, |
| 12 | ) |
| 13 | |
| 14 | |
| 15 | @when_not('native-ci.installed') |
| 16 | def install_native_ci_charm(): |
| 17 | set_flag('native-ci.installed') |
| 18 | status_set('active', 'Ready!') |
| 19 | |
| 20 | |
| 21 | @when('actions.test', 'native-ci.installed') |
| 22 | def 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') |
| 34 | def 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 Israel | 136186e | 2018-09-14 12:01:12 -0400 | [diff] [blame] | 45 | |
| 46 | |
| Adam Israel | b2a07f5 | 2019-04-25 17:17:05 -0400 | [diff] [blame] | 47 | # @when('db.joined') |
| 48 | # def 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 | # ) |
| Adam Israel | 136186e | 2018-09-14 12:01:12 -0400 | [diff] [blame] | 57 | |
| 58 | |
| Adam Israel | b2a07f5 | 2019-04-25 17:17:05 -0400 | [diff] [blame] | 59 | # @when('db.available') |
| 60 | # def requires_db(db): |
| 61 | # """Simulate receiving database credentials.""" |
| 62 | # pass |