Add License headers to all code files
[osm/N2VC.git] / tests / charms / layers / proxy-ci / reactive / proxy_ci.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_fail,
17 action_set,
18 status_set,
19 )
20 from charms.reactive import (
21 set_flag,
22 clear_flag,
23 when_not,
24 when,
25 )
26 import charms.sshproxy
27
28
29 @when_not('proxy-ci.installed')
30 def install_proxy_ci():
31 status_set('blocked', "Waiting for SSH credentials.")
32 set_flag('proxy-ci.installed')
33
34
35 @when('actions.test', 'proxy-ci.installed')
36 def test():
37 err = ''
38 try:
39 cmd = ['hostname']
40 result, err = charms.sshproxy._run(cmd)
41 if len(result) == 0:
42 raise Exception("Proxy failed")
43 except Exception as e:
44 action_fail('command failed: {}'.format(e))
45 else:
46 action_set({'output': result})
47 finally:
48 clear_flag('actions.test')
49
50
51 @when('db.joined')
52 def provides_db(db):
53 """Simulate providing database credentials."""
54 db.configure(
55 database="mydb",
56 user="myuser",
57 password="mypassword",
58 host="myhost",
59 slave="myslave",
60 )
61
62
63 @when('db.available')
64 def requires_db(db):
65 """Simulate receiving database credentials."""
66 pass