Synchronize helm repos on ns instantiation instead of creation
[osm/N2VC.git] / tests / charms / layers / simple / reactive / simple.py
1 # Copyright 2019 Canonical Ltd.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from charmhelpers.core.hookenv import (
16 action_get,
17 action_fail,
18 action_set,
19 status_set,
20 )
21 from charms.reactive import (
22 clear_flag,
23 set_flag,
24 when,
25 when_not,
26 )
27 import charms.sshproxy
28 import os
29
30
31 @when('sshproxy.configured')
32 @when_not('simple.installed')
33 def install_simple_proxy_charm():
34 """Post-install actions.
35
36 This function will run when two conditions are met:
37 1. The 'sshproxy.configured' state is set
38 2. The 'simple.installed' state is not set
39
40 This ensures that the workload status is set to active only when the SSH
41 proxy is properly configured.
42 """
43 set_flag('simple.installed')
44 status_set('active', 'Ready!')
45
46
47 @when('actions.touch')
48 def touch():
49 if not in_action_context():
50 clear_flag('actions.touch')
51 return
52
53 err = ''
54 try:
55 filename = action_get('filename')
56 cmd = ['touch {}'.format(filename)]
57 result, err = charms.sshproxy._run(cmd)
58 except Exception:
59 action_fail('command failed:' + err)
60 else:
61 action_set({'output': result})
62 finally:
63 clear_flag('actions.touch')
64
65
66 def in_action_context():
67 """Determine whether we're running on an action context."""
68 return 'JUJU_ACTION_UUID' in os.environ