Merge lp:~gandelman-a/juju-deployer/multi_file_include into lp:juju-deployer

Proposed by Adam Gandelman
Status: Merged
Approved by: Kapil Thangavelu
Approved revision: 77
Merged at revision: 76
Proposed branch: lp:~gandelman-a/juju-deployer/multi_file_include
Merge into: lp:juju-deployer
Diff against target: 82 lines (+40/-8)
2 files modified
deployer/config.py (+16/-7)
deployer/tests/test_config.py (+24/-1)
To merge this branch: bzr merge lp:~gandelman-a/juju-deployer/multi_file_include
Reviewer Review Type Date Requested Status
Kapil Thangavelu Approve
Review via email: mp+190492@code.launchpad.net

Description of the change

Adds the ability to include multiple configs in a single include statement. Allows for better organization of deployer config snippets among different files. Example use-case:

include-config:
   - storage/backends.yaml
   - networking/backends.yaml

test_deployment:
   inherits: [storage_ceph, networking_nvp]

To post a comment you must log in.
77. By Adam Gandelman

Also pop 'include-configs' when loading.

Revision history for this message
Kapil Thangavelu (hazmat) wrote :

Looks good, surprised it wasn't already available.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'deployer/config.py'
2--- deployer/config.py 2013-07-30 19:31:59 +0000
3+++ deployer/config.py 2013-10-11 01:44:44 +0000
4@@ -69,8 +69,9 @@
5 d = self._yaml_load(fp)
6 data = dict_merge(data, d)
7 self.data = data
8- if 'include-config' in self.data:
9- self.data.pop('include-config')
10+ for k in ['include-config', 'include-configs']:
11+ if k in self.data:
12+ self.data.pop(k)
13 self.include_dirs = include_dirs
14
15 def _inherits(self, d):
16@@ -94,11 +95,19 @@
17 def _includes(self, config_file):
18 files = [config_file]
19 d = self._yaml_load(config_file)
20- if 'include-config' in d:
21- inc_f = d['include-config']
22- if not isabs(inc_f):
23- inc_f = join(dirname(config_file), inc_f)
24- files.extend(self._includes(inc_f))
25+
26+ incs = d.get('include-configs') or d.get('include-config')
27+ if isinstance(incs, basestring):
28+ inc_fs = [incs]
29+ else:
30+ inc_fs = incs
31+
32+ if inc_fs:
33+ for inc_f in inc_fs:
34+ if not isabs(inc_f):
35+ inc_f = join(dirname(config_file), inc_f)
36+ files.extend(self._includes(inc_f))
37+
38 return files
39
40 def _resolve_included(self):
41
42=== modified file 'deployer/tests/test_config.py'
43--- deployer/tests/test_config.py 2013-07-30 20:43:31 +0000
44+++ deployer/tests/test_config.py 2013-10-11 01:44:44 +0000
45@@ -1,5 +1,7 @@
46 import logging
47 import os
48+import tempfile
49+import yaml
50
51 from deployer.deployment import Deployment
52 from deployer.config import ConfigStack
53@@ -73,7 +75,28 @@
54 ])
55 self._test_multiple_inheritance(config)
56
57- def test_multi_inheritance_included_files(self):
58+ def test_multi_inheritance_multi_included_files(self):
59+ # openstack.cfg
60+ # includes -> ubuntu_base.cfg includes
61+ # includes -> openstack_base.cfg
62+ test_conf = yaml.load(open(
63+ os.path.join(self.test_data_dir, "openstack", "openstack.cfg")))
64+ includes = [
65+ os.path.join(self.test_data_dir, "openstack", "ubuntu_base.cfg"),
66+ os.path.join(self.test_data_dir, "openstack", "openstack_base.cfg")
67+ ]
68+ for key in ['include-config', 'include-configs']:
69+ test_conf[key] = includes
70+ with tempfile.NamedTemporaryFile() as tmp_cfg:
71+ tmp_cfg.write(yaml.dump(test_conf))
72+ tmp_cfg.flush()
73+ config = ConfigStack([tmp_cfg.name])
74+ self._test_multiple_inheritance(config)
75+ del test_conf[key]
76+
77+ def test_multi_inheritance_included_multi_configs(self):
78+ # openstack.cfg
79+ # includes -> [ubuntu_base.cfg, openstack_base.cfg]
80 config = ConfigStack([
81 os.path.join(self.test_data_dir, "openstack", "openstack.cfg"),
82 ])

Subscribers

People subscribed via source and target branches