6
from collections import OrderedDict
11
RESTART_MAP = OrderedDict([
12
('/etc/cinder/cinder.conf',
13
['cinder-api', 'cinder-volume', 'cinder-scheduler', 'haproxy']),
14
('/etc/cinder/api-paste.ini', ['cinder-api']),
15
('/etc/ceph/ceph.conf', ['cinder-volume']),
16
('/etc/haproxy/haproxy.cfg', ['haproxy']),
17
('/etc/apache2/sites-available/openstack_https_frontend', ['apache2']),
18
('/etc/apache2/sites-available/openstack_https_frontend.conf', ['apache2'])
24
Walk backwords from __file__ looking for config.yaml, load and return the
30
d = os.path.dirname(f)
31
if os.path.isfile(os.path.join(d, 'config.yaml')):
32
config = os.path.join(d, 'config.yaml')
37
logging.error('Could not find config.yaml in any parent directory '
41
return yaml.safe_load(open(config).read())['options']
44
def get_default_config():
46
Load default charm config from config.yaml return as a dict.
47
If no default is set in config.yaml, its value is None.
50
config = load_config()
51
for k, v in config.iteritems():
53
default_config[k] = v['default']
55
default_config[k] = None
59
class CharmTestCase(unittest.TestCase):
60
def setUp(self, obj, patches):
61
super(CharmTestCase, self).setUp()
62
self.patches = patches
64
self.test_config = TestConfig()
65
self.test_relation = TestRelation()
68
def patch(self, method):
69
_m = patch.object(self.obj, method)
71
self.addCleanup(_m.stop)
75
for method in self.patches:
76
setattr(self, method, self.patch(method))
79
class TestConfig(object):
81
self.config = get_default_config()
85
return self.config[attr]
92
def set(self, attr, value):
93
if attr not in self.config:
95
self.config[attr] = value
98
class TestRelation(object):
99
def __init__(self, relation_data={}):
100
self.relation_data = relation_data
102
def set(self, relation_data):
103
self.relation_data = relation_data
105
def get(self, attr=None, unit=None, rid=None):
107
return self.relation_data
108
elif attr in self.relation_data:
109
return self.relation_data[attr]