Merge lp:~raharper/curtin/trunk.passthrough-netconfig into lp:~curtin-dev/curtin/trunk
- trunk.passthrough-netconfig
- Merge into trunk
Status: | Rejected |
---|---|
Rejected by: | Scott Moser |
Proposed branch: | lp:~raharper/curtin/trunk.passthrough-netconfig |
Merge into: | lp:~curtin-dev/curtin/trunk |
Diff against target: |
1549 lines (+1116/-93) 14 files modified
curtin/block/__init__.py (+67/-0) curtin/commands/apply_net.py (+32/-8) curtin/commands/curthooks.py (+47/-53) curtin/net/__init__.py (+111/-0) curtin/util.py (+3/-0) examples/network-ipv6-bond-vlan.yaml (+2/-2) examples/tests/network_v2_passthrough.yaml (+8/-0) tests/unittests/test_commands_apply_net.py (+351/-0) tests/unittests/test_curthooks.py (+184/-0) tests/unittests/test_net.py (+137/-1) tests/vmtests/test_network.py (+147/-24) tests/vmtests/test_network_alias.py (+6/-0) tests/vmtests/test_network_bridging.py (+15/-5) tests/vmtests/test_network_ipv6_enisource.py (+6/-0) |
To merge this branch: | bzr merge lp:~raharper/curtin/trunk.passthrough-netconfig |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Server Team CI bot | continuous-integration | Approve | |
curtin developers | Pending | ||
Review via email: mp+324801@code.launchpad.net |
Commit message
Description of the change
Enable curtin to pass network configuration through to capable targets
Curtin can detect if the cloud-init package in a target is capable of
accepting network configuration, and if so, write out the network-config
into the target instead of rendering it during installation.
Ryan Harper (raharper) : | # |
Server Team CI bot (server-team-bot) wrote : | # |
Server Team CI bot (server-team-bot) wrote : | # |
PASSED: Continuous integration, rev:477
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
Scott Moser (smoser) wrote : | # |
well, first few comments
i didn't get very far. sorry.
Ryan Harper (raharper) wrote : | # |
On Wed, May 31, 2017 at 4:11 PM, Scott Moser <email address hidden> wrote:
> well, first few comments
> i didn't get very far. sorry.
>
>
> Diff comments:
>
> > === modified file 'curtin/
> > --- curtin/__init__.py 2017-03-21 16:41:33 +0000
> > +++ curtin/__init__.py 2017-05-31 00:24:53 +0000
> > @@ -37,6 +37,8 @@
> > 'SUBCOMMAND_
> > # supports new format of apt configuration
> > 'APT_CONFIG_V1',
> > + # supports passing network config to target
> > + 'NETWORK_
>
> Why would someone need to know this ?
> i think it is related to our plan on implementing images that have builtin
> hooks but dont want to use them.
> that is worth an explanation in the commit message.
>
It's worth comment and *documentation*; will add. I think we might also
want to allow caller to
control whether we render eni or passthrough; ie, MaaS may want to *force*
an eni rendering
even if passthrough is possible.
>
> > # has version module
> > 'HAS_VERSION_
> > ]
> >
> > === modified file 'curtin/
> > --- curtin/
> > +++ curtin/
> > @@ -978,4 +978,71 @@
> > else:
> > raise ValueError("wipe mode %s not supported" % mode)
> >
> > +
> > +def storage_
> > + """Read storage configuration dictionary and determine
> > + which packages are required for the supplied configuration
> > + to function. Return a list of packaged to install.
> > + """
> > +
> > + if not storage_config or not isinstance(
> > + raise ValueError('Invalid storage configuration. '
> > + 'Must be a dict:\n %s' % storage_config)
> > +
> > + if not mapping or not isinstance(mapping, dict):
> > + raise ValueError('Invalid storage mapping. Must be a dict')
> > +
> > + if 'storage' in storage_config:
> > + storage_config = storage_
> > +
> > + needed_packages = []
> > +
> > + # get reqs by device operation type
> > + dev_configs = set(operation[
> > + for operation in storage_
> > +
> > + for dev_type in dev_configs:
> > + if dev_type in mapping:
> > + needed_
> > +
> > + # for any format operations, check the fstype and
> > + # determine if we need any mkfs tools as well.
> > + format_configs = set([operation[
> > + for operation in storage_
> > + if operation['type'] == 'format'])
> > + for format_type in format_configs:
> > + if format_type in mapping:
> > + needed_
> > +
> > + return needed_packages
> > +
> > +
> > +def detect_
> > + """Return a dictionary providing a versioned configuration which
> maps
> > + storage configuration elements to the packages which are required
> > + for functionality.
> > +
> > + The mapping key is either...
Scott Moser (smoser) wrote : | # |
Summary of review:
- your commit message doesn't mention that you've modified the block/fs depends (i dont think)
- more unit tests would be good.
- I don't love the 'passthrough'. if we dont have an actual need for it i think i'd drop it for now.
but over all, seems sane.
Ryan Harper (raharper) wrote : | # |
Thanks for the review, will fix ack'ed items.
Scott Moser (smoser) wrote : | # |
Moved this to 'Work in progress'. Move it back to 'Needs Review' when you "fix ack'ed items.".
Thanks
Ryan Harper (raharper) wrote : | # |
Updated branch with fixes for items marked ACK. Custom config deps discussion still needed.
Server Team CI bot (server-team-bot) wrote : | # |
PASSED: Continuous integration, rev:483
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
Scott Moser (smoser) wrote : | # |
inline comments, also:
* Chad has started requesting Human readable """This unit tests does..."""
in each unit test, and I generally agree.
Scott Moser (smoser) wrote : | # |
shoot. hit submit before i was done... continuing.
Scott Moser (smoser) wrote : | # |
a lot of prints in test cases.
Ryan Harper (raharper) wrote : | # |
Thanks for the review, will update with ACK'ed fixes. I think the items that remain for discussion:
1) parsing shebang for which python interpreter to use for cloud-init in-target
2) side-effect = (Exception) which it appears there was some confusion with the assert_not_called (which I agree need to be replaced with call_count checks).
Ryan Harper (raharper) wrote : | # |
Fixed all of the ACK's here, filed a bug in cloud-init for UpperCase MAC issue, and applied these fixes to centos-passthrough branch, mp here (https:/
Scott Moser (smoser) : | # |
Ryan Harper (raharper) wrote : | # |
Thanks for the follow-up. I'll fix up (1) and (2) as discussed below.
Scott Moser (smoser) wrote : | # |
marking this as rejected.
the changes here all went into
https:/
which got merged (see comments there).
Unmerged revisions
Preview Diff
1 | === modified file 'curtin/block/__init__.py' | |||
2 | --- curtin/block/__init__.py 2017-05-19 18:52:21 +0000 | |||
3 | +++ curtin/block/__init__.py 2017-06-19 16:35:41 +0000 | |||
4 | @@ -978,4 +978,71 @@ | |||
5 | 978 | else: | 978 | else: |
6 | 979 | raise ValueError("wipe mode %s not supported" % mode) | 979 | raise ValueError("wipe mode %s not supported" % mode) |
7 | 980 | 980 | ||
8 | 981 | |||
9 | 982 | def storage_config_required_packages(storage_config, mapping): | ||
10 | 983 | """Read storage configuration dictionary and determine | ||
11 | 984 | which packages are required for the supplied configuration | ||
12 | 985 | to function. Return a list of packaged to install. | ||
13 | 986 | """ | ||
14 | 987 | |||
15 | 988 | if not storage_config or not isinstance(storage_config, dict): | ||
16 | 989 | raise ValueError('Invalid storage configuration. ' | ||
17 | 990 | 'Must be a dict:\n %s' % storage_config) | ||
18 | 991 | |||
19 | 992 | if not mapping or not isinstance(mapping, dict): | ||
20 | 993 | raise ValueError('Invalid storage mapping. Must be a dict') | ||
21 | 994 | |||
22 | 995 | if 'storage' in storage_config: | ||
23 | 996 | storage_config = storage_config.get('storage') | ||
24 | 997 | |||
25 | 998 | needed_packages = [] | ||
26 | 999 | |||
27 | 1000 | # get reqs by device operation type | ||
28 | 1001 | dev_configs = set(operation['type'] | ||
29 | 1002 | for operation in storage_config['config']) | ||
30 | 1003 | |||
31 | 1004 | for dev_type in dev_configs: | ||
32 | 1005 | if dev_type in mapping: | ||
33 | 1006 | needed_packages.extend(mapping[dev_type]) | ||
34 | 1007 | |||
35 | 1008 | # for any format operations, check the fstype and | ||
36 | 1009 | # determine if we need any mkfs tools as well. | ||
37 | 1010 | format_configs = set([operation['fstype'] | ||
38 | 1011 | for operation in storage_config['config'] | ||
39 | 1012 | if operation['type'] == 'format']) | ||
40 | 1013 | for format_type in format_configs: | ||
41 | 1014 | if format_type in mapping: | ||
42 | 1015 | needed_packages.extend(mapping[format_type]) | ||
43 | 1016 | |||
44 | 1017 | return needed_packages | ||
45 | 1018 | |||
46 | 1019 | |||
47 | 1020 | def detect_required_packages_mapping(): | ||
48 | 1021 | """Return a dictionary providing a versioned configuration which maps | ||
49 | 1022 | storage configuration elements to the packages which are required | ||
50 | 1023 | for functionality. | ||
51 | 1024 | |||
52 | 1025 | The mapping key is either a config type value, or an fstype value. | ||
53 | 1026 | |||
54 | 1027 | """ | ||
55 | 1028 | version = 1 | ||
56 | 1029 | mapping = { | ||
57 | 1030 | version: { | ||
58 | 1031 | 'handler': storage_config_required_packages, | ||
59 | 1032 | 'mapping': { | ||
60 | 1033 | 'bcache': ['bcache-tools'], | ||
61 | 1034 | 'btrfs': ['btrfs-tools'], | ||
62 | 1035 | 'ext2': ['e2fsprogs'], | ||
63 | 1036 | 'ext3': ['e2fsprogs'], | ||
64 | 1037 | 'ext4': ['e2fsprogs'], | ||
65 | 1038 | 'lvm_partition': ['lvm2'], | ||
66 | 1039 | 'lvm_volgroup': ['lvm2'], | ||
67 | 1040 | 'raid': ['mdadm'], | ||
68 | 1041 | 'xfs': ['xfsprogs'] | ||
69 | 1042 | }, | ||
70 | 1043 | }, | ||
71 | 1044 | } | ||
72 | 1045 | return mapping | ||
73 | 1046 | |||
74 | 1047 | |||
75 | 981 | # vi: ts=4 expandtab syntax=python | 1048 | # vi: ts=4 expandtab syntax=python |
76 | 982 | 1049 | ||
77 | === modified file 'curtin/commands/apply_net.py' | |||
78 | --- curtin/commands/apply_net.py 2017-02-08 05:56:12 +0000 | |||
79 | +++ curtin/commands/apply_net.py 2017-06-19 16:35:41 +0000 | |||
80 | @@ -21,6 +21,7 @@ | |||
81 | 21 | from .. import log | 21 | from .. import log |
82 | 22 | import curtin.net as net | 22 | import curtin.net as net |
83 | 23 | import curtin.util as util | 23 | import curtin.util as util |
84 | 24 | from curtin import config | ||
85 | 24 | from . import populate_one_subcmd | 25 | from . import populate_one_subcmd |
86 | 25 | 26 | ||
87 | 26 | 27 | ||
88 | @@ -89,15 +90,36 @@ | |||
89 | 89 | sys.stderr.write(msg + "\n") | 90 | sys.stderr.write(msg + "\n") |
90 | 90 | raise Exception(msg) | 91 | raise Exception(msg) |
91 | 91 | 92 | ||
92 | 93 | passthrough = False | ||
93 | 92 | if network_state: | 94 | if network_state: |
94 | 95 | # NB: we cannot support passthrough until curtin can convert from | ||
95 | 96 | # network_state to network-config yaml | ||
96 | 93 | ns = net.network_state.from_state_file(network_state) | 97 | ns = net.network_state.from_state_file(network_state) |
97 | 98 | raise ValueError('Not Supported; curtin lacks a network_state to ' | ||
98 | 99 | 'network_config converter.') | ||
99 | 94 | elif network_config: | 100 | elif network_config: |
103 | 95 | ns = net.parse_net_config(network_config) | 101 | netcfg = config.load_config(network_config) |
104 | 96 | 102 | ||
105 | 97 | net.render_network_state(target=target, network_state=ns) | 103 | # curtin will pass-through the netconfig into the target |
106 | 104 | # for rendering at runtime, unless: | ||
107 | 105 | # 1) target OS does not support (cloud-init too old) | ||
108 | 106 | LOG.info('Checking cloud-init in target [%s] for network ' | ||
109 | 107 | 'configuration passthrough support.', target) | ||
110 | 108 | passthrough = net.netconfig_passthrough_available(target) | ||
111 | 109 | LOG.debug('passthrough available via in-target: %s', passthrough) | ||
112 | 110 | |||
113 | 111 | if passthrough: | ||
114 | 112 | LOG.info('Passing network configuration through to target: %s', | ||
115 | 113 | target) | ||
116 | 114 | net.render_netconfig_passthrough(target, netconfig=netcfg) | ||
117 | 115 | else: | ||
118 | 116 | ns = net.parse_net_config_data(netcfg.get('network', {})) | ||
119 | 117 | |||
120 | 118 | if not passthrough: | ||
121 | 119 | LOG.info('Rendering network configuration in target') | ||
122 | 120 | net.render_network_state(target=target, network_state=ns) | ||
123 | 98 | 121 | ||
124 | 99 | _maybe_remove_legacy_eth0(target) | 122 | _maybe_remove_legacy_eth0(target) |
125 | 100 | LOG.info('Attempting to remove ipv6 privacy extensions') | ||
126 | 101 | _disable_ipv6_privacy_extensions(target) | 123 | _disable_ipv6_privacy_extensions(target) |
127 | 102 | _patch_ifupdown_ipv6_mtu_hook(target) | 124 | _patch_ifupdown_ipv6_mtu_hook(target) |
128 | 103 | 125 | ||
129 | @@ -130,6 +152,7 @@ | |||
130 | 130 | by default; this races with the cloud-image desire to disable them. | 152 | by default; this races with the cloud-image desire to disable them. |
131 | 131 | Resolve this by allowing the cloud-image setting to win. """ | 153 | Resolve this by allowing the cloud-image setting to win. """ |
132 | 132 | 154 | ||
133 | 155 | LOG.debug('Attempting to remove ipv6 privacy extensions') | ||
134 | 133 | cfg = util.target_path(target, path=path) | 156 | cfg = util.target_path(target, path=path) |
135 | 134 | if not os.path.exists(cfg): | 157 | if not os.path.exists(cfg): |
136 | 135 | LOG.warn('Failed to find ipv6 privacy conf file %s', cfg) | 158 | LOG.warn('Failed to find ipv6 privacy conf file %s', cfg) |
137 | @@ -143,7 +166,7 @@ | |||
138 | 143 | lines = [f.strip() for f in contents.splitlines() | 166 | lines = [f.strip() for f in contents.splitlines() |
139 | 144 | if not f.startswith("#")] | 167 | if not f.startswith("#")] |
140 | 145 | if lines == known_contents: | 168 | if lines == known_contents: |
142 | 146 | LOG.info('deleting file: %s', cfg) | 169 | LOG.info('Found expected contents, deleting file: %s', cfg) |
143 | 147 | util.del_file(cfg) | 170 | util.del_file(cfg) |
144 | 148 | msg = "removed %s with known contents" % cfg | 171 | msg = "removed %s with known contents" % cfg |
145 | 149 | curtin_contents = '\n'.join( | 172 | curtin_contents = '\n'.join( |
146 | @@ -153,9 +176,10 @@ | |||
147 | 153 | "# net.ipv6.conf.default.use_tempaddr = 2"]) | 176 | "# net.ipv6.conf.default.use_tempaddr = 2"]) |
148 | 154 | util.write_file(cfg, curtin_contents) | 177 | util.write_file(cfg, curtin_contents) |
149 | 155 | else: | 178 | else: |
153 | 156 | LOG.info('skipping, content didnt match') | 179 | LOG.debug('skipping removal of %s, expected content not found', |
154 | 157 | LOG.debug("found content:\n%s", lines) | 180 | cfg) |
155 | 158 | LOG.debug("expected contents:\n%s", known_contents) | 181 | LOG.debug("Found content in file %s:\n%s", cfg, lines) |
156 | 182 | LOG.debug("Expected contents in file %s:\n%s", cfg, known_contents) | ||
157 | 159 | msg = (bmsg + " '%s' exists with user configured content." % cfg) | 183 | msg = (bmsg + " '%s' exists with user configured content." % cfg) |
158 | 160 | except Exception as e: | 184 | except Exception as e: |
159 | 161 | msg = bmsg + " %s exists, but could not be read. %s" % (cfg, e) | 185 | msg = bmsg + " %s exists, but could not be read. %s" % (cfg, e) |
160 | 162 | 186 | ||
161 | === modified file 'curtin/commands/curthooks.py' | |||
162 | --- curtin/commands/curthooks.py 2017-05-12 00:49:43 +0000 | |||
163 | +++ curtin/commands/curthooks.py 2017-06-19 16:35:41 +0000 | |||
164 | @@ -25,6 +25,7 @@ | |||
165 | 25 | 25 | ||
166 | 26 | from curtin import config | 26 | from curtin import config |
167 | 27 | from curtin import block | 27 | from curtin import block |
168 | 28 | from curtin import net | ||
169 | 28 | from curtin import futil | 29 | from curtin import futil |
170 | 29 | from curtin.log import LOG | 30 | from curtin.log import LOG |
171 | 30 | from curtin import swap | 31 | from curtin import swap |
172 | @@ -648,6 +649,38 @@ | |||
173 | 648 | update_initramfs(target, all_kernels=True) | 649 | update_initramfs(target, all_kernels=True) |
174 | 649 | 650 | ||
175 | 650 | 651 | ||
176 | 652 | def detect_required_packages(cfg): | ||
177 | 653 | """ | ||
178 | 654 | detect packages that will be required in-target by custom config items | ||
179 | 655 | """ | ||
180 | 656 | |||
181 | 657 | mapping = { | ||
182 | 658 | 'storage': block.detect_required_packages_mapping(), | ||
183 | 659 | 'network': net.detect_required_packages_mapping(), | ||
184 | 660 | } | ||
185 | 661 | |||
186 | 662 | needed_packages = [] | ||
187 | 663 | for cfg_type, cfg_map in mapping.items(): | ||
188 | 664 | |||
189 | 665 | # skip missing or invalid config items, configs may | ||
190 | 666 | # only have network or storage, not always both | ||
191 | 667 | if not isinstance(cfg.get(cfg_type), dict): | ||
192 | 668 | continue | ||
193 | 669 | |||
194 | 670 | cfg_version = cfg[cfg_type].get('version') | ||
195 | 671 | if not isinstance(cfg_version, int) or cfg_version not in cfg_map: | ||
196 | 672 | msg = ('Supplied configuration version "%s", for config type' | ||
197 | 673 | '"%s" is not present in the known mapping.' % (cfg_version, | ||
198 | 674 | cfg_type)) | ||
199 | 675 | raise ValueError(msg) | ||
200 | 676 | |||
201 | 677 | mapped_config = cfg_map[cfg_version] | ||
202 | 678 | found_reqs = mapped_config['handler'](cfg, mapped_config['mapping']) | ||
203 | 679 | needed_packages.extend(found_reqs) | ||
204 | 680 | |||
205 | 681 | return needed_packages | ||
206 | 682 | |||
207 | 683 | |||
208 | 651 | def install_missing_packages(cfg, target): | 684 | def install_missing_packages(cfg, target): |
209 | 652 | ''' describe which operation types will require specific packages | 685 | ''' describe which operation types will require specific packages |
210 | 653 | 686 | ||
211 | @@ -655,46 +688,10 @@ | |||
212 | 655 | 'pkg1': ['op_name_1', 'op_name_2', ...] | 688 | 'pkg1': ['op_name_1', 'op_name_2', ...] |
213 | 656 | } | 689 | } |
214 | 657 | ''' | 690 | ''' |
233 | 658 | custom_configs = { | 691 | |
216 | 659 | 'storage': { | ||
217 | 660 | 'lvm2': ['lvm_volgroup', 'lvm_partition'], | ||
218 | 661 | 'mdadm': ['raid'], | ||
219 | 662 | 'bcache-tools': ['bcache']}, | ||
220 | 663 | 'network': { | ||
221 | 664 | 'vlan': ['vlan'], | ||
222 | 665 | 'ifenslave': ['bond'], | ||
223 | 666 | 'bridge-utils': ['bridge']}, | ||
224 | 667 | } | ||
225 | 668 | |||
226 | 669 | format_configs = { | ||
227 | 670 | 'xfsprogs': ['xfs'], | ||
228 | 671 | 'e2fsprogs': ['ext2', 'ext3', 'ext4'], | ||
229 | 672 | 'btrfs-tools': ['btrfs'], | ||
230 | 673 | } | ||
231 | 674 | |||
232 | 675 | needed_packages = [] | ||
234 | 676 | installed_packages = util.get_installed_packages(target) | 692 | installed_packages = util.get_installed_packages(target) |
256 | 677 | for cust_cfg, pkg_reqs in custom_configs.items(): | 693 | needed_packages = [pkg for pkg in detect_required_packages(cfg) |
257 | 678 | if cust_cfg not in cfg: | 694 | if pkg not in installed_packages] |
237 | 679 | continue | ||
238 | 680 | |||
239 | 681 | all_types = set( | ||
240 | 682 | operation['type'] | ||
241 | 683 | for operation in cfg[cust_cfg]['config'] | ||
242 | 684 | ) | ||
243 | 685 | for pkg, types in pkg_reqs.items(): | ||
244 | 686 | if set(types).intersection(all_types) and \ | ||
245 | 687 | pkg not in installed_packages: | ||
246 | 688 | needed_packages.append(pkg) | ||
247 | 689 | |||
248 | 690 | format_types = set( | ||
249 | 691 | [operation['fstype'] | ||
250 | 692 | for operation in cfg[cust_cfg]['config'] | ||
251 | 693 | if operation['type'] == 'format']) | ||
252 | 694 | for pkg, fstypes in format_configs.items(): | ||
253 | 695 | if set(fstypes).intersection(format_types) and \ | ||
254 | 696 | pkg not in installed_packages: | ||
255 | 697 | needed_packages.append(pkg) | ||
258 | 698 | 695 | ||
259 | 699 | arch_packages = { | 696 | arch_packages = { |
260 | 700 | 's390x': [('s390-tools', 'zipl')], | 697 | 's390x': [('s390-tools', 'zipl')], |
261 | @@ -852,7 +849,11 @@ | |||
262 | 852 | disable_overlayroot(cfg, target) | 849 | disable_overlayroot(cfg, target) |
263 | 853 | 850 | ||
264 | 854 | # packages may be needed prior to installing kernel | 851 | # packages may be needed prior to installing kernel |
266 | 855 | install_missing_packages(cfg, target) | 852 | with events.ReportEventStack( |
267 | 853 | name=stack_prefix + '/installing-missing-packages', | ||
268 | 854 | reporting_enabled=True, level="INFO", | ||
269 | 855 | description="installing missing packages"): | ||
270 | 856 | install_missing_packages(cfg, target) | ||
271 | 856 | 857 | ||
272 | 857 | # If a /etc/iscsi/nodes/... file was created by block_meta then it | 858 | # If a /etc/iscsi/nodes/... file was created by block_meta then it |
273 | 858 | # needs to be copied onto the target system | 859 | # needs to be copied onto the target system |
274 | @@ -880,10 +881,15 @@ | |||
275 | 880 | setup_zipl(cfg, target) | 881 | setup_zipl(cfg, target) |
276 | 881 | install_kernel(cfg, target) | 882 | install_kernel(cfg, target) |
277 | 882 | run_zipl(cfg, target) | 883 | run_zipl(cfg, target) |
278 | 883 | |||
279 | 884 | restore_dist_interfaces(cfg, target) | 884 | restore_dist_interfaces(cfg, target) |
280 | 885 | 885 | ||
281 | 886 | with events.ReportEventStack( | 886 | with events.ReportEventStack( |
282 | 887 | name=stack_prefix + '/system-upgrade', | ||
283 | 888 | reporting_enabled=True, level="INFO", | ||
284 | 889 | description="updating packages on target system"): | ||
285 | 890 | system_upgrade(cfg, target) | ||
286 | 891 | |||
287 | 892 | with events.ReportEventStack( | ||
288 | 887 | name=stack_prefix + '/setting-up-swap', | 893 | name=stack_prefix + '/setting-up-swap', |
289 | 888 | reporting_enabled=True, level="INFO", | 894 | reporting_enabled=True, level="INFO", |
290 | 889 | description="setting up swap"): | 895 | description="setting up swap"): |
291 | @@ -907,18 +913,6 @@ | |||
292 | 907 | description="configuring multipath"): | 913 | description="configuring multipath"): |
293 | 908 | detect_and_handle_multipath(cfg, target) | 914 | detect_and_handle_multipath(cfg, target) |
294 | 909 | 915 | ||
295 | 910 | with events.ReportEventStack( | ||
296 | 911 | name=stack_prefix + '/installing-missing-packages', | ||
297 | 912 | reporting_enabled=True, level="INFO", | ||
298 | 913 | description="installing missing packages"): | ||
299 | 914 | install_missing_packages(cfg, target) | ||
300 | 915 | |||
301 | 916 | with events.ReportEventStack( | ||
302 | 917 | name=stack_prefix + '/system-upgrade', | ||
303 | 918 | reporting_enabled=True, level="INFO", | ||
304 | 919 | description="updating packages on target system"): | ||
305 | 920 | system_upgrade(cfg, target) | ||
306 | 921 | |||
307 | 922 | # If a crypttab file was created by block_meta than it needs to be copied | 916 | # If a crypttab file was created by block_meta than it needs to be copied |
308 | 923 | # onto the target system, and update_initramfs() needs to be run, so that | 917 | # onto the target system, and update_initramfs() needs to be run, so that |
309 | 924 | # the cryptsetup hooks are properly configured on the installed system and | 918 | # the cryptsetup hooks are properly configured on the installed system and |
310 | 925 | 919 | ||
311 | === modified file 'curtin/net/__init__.py' | |||
312 | --- curtin/net/__init__.py 2017-02-06 20:58:37 +0000 | |||
313 | +++ curtin/net/__init__.py 2017-06-19 16:35:41 +0000 | |||
314 | @@ -520,7 +520,63 @@ | |||
315 | 520 | return content | 520 | return content |
316 | 521 | 521 | ||
317 | 522 | 522 | ||
318 | 523 | def netconfig_passthrough_available(target, feature='NETWORK_CONFIG_V2'): | ||
319 | 524 | """ | ||
320 | 525 | Determine if curtin can pass v2 network config to in target cloud-init | ||
321 | 526 | """ | ||
322 | 527 | LOG.debug('Checking in-target cloud-init features') | ||
323 | 528 | cmd = ("from cloudinit import version;" | ||
324 | 529 | "print('{}' in getattr(version, 'FEATURES', []))" | ||
325 | 530 | .format(feature)) | ||
326 | 531 | with util.ChrootableTarget(target) as in_chroot: | ||
327 | 532 | |||
328 | 533 | def run_cmd(cmd): | ||
329 | 534 | (out, _) = in_chroot.subp(cmd, capture=True) | ||
330 | 535 | return out.strip() | ||
331 | 536 | |||
332 | 537 | cloudinit = util.which('cloud-init', target=target) | ||
333 | 538 | if not cloudinit: | ||
334 | 539 | LOG.warning('Target does not have cloud-init installed') | ||
335 | 540 | return False | ||
336 | 541 | |||
337 | 542 | # here we read shebang from cloud-init and extract python path as we | ||
338 | 543 | # cannot use the presence of the python package to determine which | ||
339 | 544 | # python cloud-init will use. E.g trusty has python3 support but | ||
340 | 545 | # cloud-init uses python2.7 | ||
341 | 546 | python = util.load_file(util.target_path(target, path=cloudinit)) | ||
342 | 547 | python = python.splitlines()[0].split("#!")[-1].strip() | ||
343 | 548 | try: | ||
344 | 549 | feature_available = run_cmd([python, '-c', cmd]) | ||
345 | 550 | except util.ProcessExecutionError: | ||
346 | 551 | LOG.exception("An error occurred while probing cloudinit features") | ||
347 | 552 | return False | ||
348 | 553 | |||
349 | 554 | available = config.value_as_boolean(feature_available) | ||
350 | 555 | LOG.debug('%s available? %s', feature, available) | ||
351 | 556 | return available | ||
352 | 557 | |||
353 | 558 | |||
354 | 559 | def render_netconfig_passthrough(target, netconfig=None): | ||
355 | 560 | """ | ||
356 | 561 | Extract original network config and pass it | ||
357 | 562 | through to cloud-init in target | ||
358 | 563 | """ | ||
359 | 564 | LOG.debug("rendering passthrough netconfig") | ||
360 | 565 | cc = 'etc/cloud/cloud.cfg.d/curtin-networking.cfg' | ||
361 | 566 | if not isinstance(netconfig, dict): | ||
362 | 567 | raise ValueError('Network config must be a dictionary') | ||
363 | 568 | |||
364 | 569 | if 'network' not in netconfig: | ||
365 | 570 | raise ValueError("Network config must contain the key 'network'") | ||
366 | 571 | |||
367 | 572 | content = config.dump_config(netconfig) | ||
368 | 573 | cc_passthrough = os.path.sep.join((target, cc,)) | ||
369 | 574 | LOG.info('Writing ' + cc_passthrough) | ||
370 | 575 | util.write_file(cc_passthrough, content=content) | ||
371 | 576 | |||
372 | 577 | |||
373 | 523 | def render_network_state(target, network_state): | 578 | def render_network_state(target, network_state): |
374 | 579 | LOG.debug("rendering eni from netconfig") | ||
375 | 524 | eni = 'etc/network/interfaces' | 580 | eni = 'etc/network/interfaces' |
376 | 525 | netrules = 'etc/udev/rules.d/70-persistent-net.rules' | 581 | netrules = 'etc/udev/rules.d/70-persistent-net.rules' |
377 | 526 | cc = 'etc/cloud/cloud.cfg.d/curtin-disable-cloudinit-networking.cfg' | 582 | cc = 'etc/cloud/cloud.cfg.d/curtin-disable-cloudinit-networking.cfg' |
378 | @@ -542,4 +598,59 @@ | |||
379 | 542 | """Returns the string value of an interface's MAC Address""" | 598 | """Returns the string value of an interface's MAC Address""" |
380 | 543 | return read_sys_net(ifname, "address", enoent=False) | 599 | return read_sys_net(ifname, "address", enoent=False) |
381 | 544 | 600 | ||
382 | 601 | |||
383 | 602 | def network_config_required_packages(network_config, mapping=None): | ||
384 | 603 | |||
385 | 604 | if not network_config or not isinstance(network_config, dict): | ||
386 | 605 | raise ValueError('Invalid network configuration. Must be a dict') | ||
387 | 606 | |||
388 | 607 | if not mapping or not isinstance(mapping, dict): | ||
389 | 608 | raise ValueError('Invalid network mapping. Must be a dict') | ||
390 | 609 | |||
391 | 610 | # allow top-level 'network' key | ||
392 | 611 | if 'network' in network_config: | ||
393 | 612 | network_config = network_config.get('network') | ||
394 | 613 | |||
395 | 614 | # v1 has 'config' key and uses type: devtype elements | ||
396 | 615 | if 'config' in network_config: | ||
397 | 616 | dev_configs = set(device['type'] | ||
398 | 617 | for device in network_config['config']) | ||
399 | 618 | else: | ||
400 | 619 | # v2 has no config key | ||
401 | 620 | dev_configs = set(cfgtype for (cfgtype, cfg) in | ||
402 | 621 | network_config.items() if cfgtype not in ['version']) | ||
403 | 622 | |||
404 | 623 | needed_packages = [] | ||
405 | 624 | for dev_type in dev_configs: | ||
406 | 625 | if dev_type in mapping: | ||
407 | 626 | needed_packages.extend(mapping[dev_type]) | ||
408 | 627 | |||
409 | 628 | return needed_packages | ||
410 | 629 | |||
411 | 630 | |||
412 | 631 | def detect_required_packages_mapping(): | ||
413 | 632 | """Return a dictionary providing a versioned configuration which maps | ||
414 | 633 | network configuration elements to the packages which are required | ||
415 | 634 | for functionality. | ||
416 | 635 | """ | ||
417 | 636 | mapping = { | ||
418 | 637 | 1: { | ||
419 | 638 | 'handler': network_config_required_packages, | ||
420 | 639 | 'mapping': { | ||
421 | 640 | 'bond': ['ifenslave'], | ||
422 | 641 | 'bridge': ['bridge-utils'], | ||
423 | 642 | 'vlan': ['vlan']}, | ||
424 | 643 | }, | ||
425 | 644 | 2: { | ||
426 | 645 | 'handler': network_config_required_packages, | ||
427 | 646 | 'mapping': { | ||
428 | 647 | 'bonds': ['ifenslave'], | ||
429 | 648 | 'bridges': ['bridge-utils'], | ||
430 | 649 | 'vlans': ['vlan']} | ||
431 | 650 | }, | ||
432 | 651 | } | ||
433 | 652 | |||
434 | 653 | return mapping | ||
435 | 654 | |||
436 | 655 | |||
437 | 545 | # vi: ts=4 expandtab syntax=python | 656 | # vi: ts=4 expandtab syntax=python |
438 | 546 | 657 | ||
439 | === modified file 'curtin/util.py' | |||
440 | --- curtin/util.py 2017-06-05 02:55:31 +0000 | |||
441 | +++ curtin/util.py 2017-06-19 16:35:41 +0000 | |||
442 | @@ -1347,6 +1347,9 @@ | |||
443 | 1347 | if not path: | 1347 | if not path: |
444 | 1348 | return target | 1348 | return target |
445 | 1349 | 1349 | ||
446 | 1350 | if not isinstance(path, string_types): | ||
447 | 1351 | raise ValueError("Unexpected input for path: %s" % path) | ||
448 | 1352 | |||
449 | 1350 | # os.path.join("/etc", "/foo") returns "/foo". Chomp all leading /. | 1353 | # os.path.join("/etc", "/foo") returns "/foo". Chomp all leading /. |
450 | 1351 | while len(path) and path[0] == "/": | 1354 | while len(path) and path[0] == "/": |
451 | 1352 | path = path[1:] | 1355 | path = path[1:] |
452 | 1353 | 1356 | ||
453 | === modified file 'examples/network-ipv6-bond-vlan.yaml' | |||
454 | --- examples/network-ipv6-bond-vlan.yaml 2016-08-12 17:24:13 +0000 | |||
455 | +++ examples/network-ipv6-bond-vlan.yaml 2017-06-19 16:35:41 +0000 | |||
456 | @@ -3,10 +3,10 @@ | |||
457 | 3 | config: | 3 | config: |
458 | 4 | - name: interface0 | 4 | - name: interface0 |
459 | 5 | type: physical | 5 | type: physical |
461 | 6 | mac_address: BC:76:4E:06:96:B3 | 6 | mac_address: bc:76:4e:06:96:b3 |
462 | 7 | - name: interface1 | 7 | - name: interface1 |
463 | 8 | type: physical | 8 | type: physical |
465 | 9 | mac_address: BC:76:4E:04:88:41 | 9 | mac_address: bc:76:4e:04:88:41 |
466 | 10 | - type: bond | 10 | - type: bond |
467 | 11 | bond_interfaces: | 11 | bond_interfaces: |
468 | 12 | - interface0 | 12 | - interface0 |
469 | 13 | 13 | ||
470 | === added file 'examples/tests/network_v2_passthrough.yaml' | |||
471 | --- examples/tests/network_v2_passthrough.yaml 1970-01-01 00:00:00 +0000 | |||
472 | +++ examples/tests/network_v2_passthrough.yaml 2017-06-19 16:35:41 +0000 | |||
473 | @@ -0,0 +1,8 @@ | |||
474 | 1 | showtrace: true | ||
475 | 2 | network: | ||
476 | 3 | version: 2 | ||
477 | 4 | ethernets: | ||
478 | 5 | interface0: | ||
479 | 6 | match: | ||
480 | 7 | mac_address: "52:54:00:12:34:00" | ||
481 | 8 | dhcp4: true | ||
482 | 0 | 9 | ||
483 | === added file 'tests/unittests/test_commands_apply_net.py' | |||
484 | --- tests/unittests/test_commands_apply_net.py 1970-01-01 00:00:00 +0000 | |||
485 | +++ tests/unittests/test_commands_apply_net.py 2017-06-19 16:35:41 +0000 | |||
486 | @@ -0,0 +1,351 @@ | |||
487 | 1 | from unittest import TestCase | ||
488 | 2 | from mock import patch, call | ||
489 | 3 | import copy | ||
490 | 4 | import os | ||
491 | 5 | |||
492 | 6 | from curtin.commands import apply_net | ||
493 | 7 | from curtin import util | ||
494 | 8 | |||
495 | 9 | |||
496 | 10 | class ApplyNetTestBase(TestCase): | ||
497 | 11 | def setUp(self): | ||
498 | 12 | super(ApplyNetTestBase, self).setUp() | ||
499 | 13 | |||
500 | 14 | def add_patch(self, target, attr): | ||
501 | 15 | """Patches specified target object and sets it as attr on test | ||
502 | 16 | instance also schedules cleanup""" | ||
503 | 17 | m = patch(target, autospec=True) | ||
504 | 18 | p = m.start() | ||
505 | 19 | self.addCleanup(m.stop) | ||
506 | 20 | setattr(self, attr, p) | ||
507 | 21 | |||
508 | 22 | |||
509 | 23 | class TestApplyNet(ApplyNetTestBase): | ||
510 | 24 | def setUp(self): | ||
511 | 25 | super(TestApplyNet, self).setUp() | ||
512 | 26 | |||
513 | 27 | basepath = 'curtin.commands.apply_net.' | ||
514 | 28 | self.add_patch(basepath + '_maybe_remove_legacy_eth0', 'mock_legacy') | ||
515 | 29 | self.add_patch(basepath + '_disable_ipv6_privacy_extensions', | ||
516 | 30 | 'mock_ipv6_priv') | ||
517 | 31 | self.add_patch(basepath + '_patch_ifupdown_ipv6_mtu_hook', | ||
518 | 32 | 'mock_ipv6_mtu') | ||
519 | 33 | self.add_patch('curtin.net.netconfig_passthrough_available', | ||
520 | 34 | 'mock_netpass_avail') | ||
521 | 35 | self.add_patch('curtin.net.render_netconfig_passthrough', | ||
522 | 36 | 'mock_netpass_render') | ||
523 | 37 | self.add_patch('curtin.net.parse_net_config_data', | ||
524 | 38 | 'mock_net_parsedata') | ||
525 | 39 | self.add_patch('curtin.net.render_network_state', | ||
526 | 40 | 'mock_net_renderstate') | ||
527 | 41 | self.add_patch('curtin.net.network_state.from_state_file', | ||
528 | 42 | 'mock_ns_from_file') | ||
529 | 43 | self.add_patch('curtin.config.load_config', 'mock_load_config') | ||
530 | 44 | |||
531 | 45 | self.target = "my_target" | ||
532 | 46 | self.network_config = { | ||
533 | 47 | 'network': { | ||
534 | 48 | 'version': 1, | ||
535 | 49 | 'config': {}, | ||
536 | 50 | } | ||
537 | 51 | } | ||
538 | 52 | self.ns = { | ||
539 | 53 | 'interfaces': {}, | ||
540 | 54 | 'routes': [], | ||
541 | 55 | 'dns': { | ||
542 | 56 | 'nameservers': [], | ||
543 | 57 | 'search': [], | ||
544 | 58 | } | ||
545 | 59 | } | ||
546 | 60 | |||
547 | 61 | def test_apply_net_notarget(self): | ||
548 | 62 | self.assertRaises(Exception, | ||
549 | 63 | apply_net.apply_net, None, "", "") | ||
550 | 64 | |||
551 | 65 | def test_apply_net_nostate_or_config(self): | ||
552 | 66 | self.assertRaises(Exception, | ||
553 | 67 | apply_net.apply_net, "") | ||
554 | 68 | |||
555 | 69 | def test_apply_net_target_and_state(self): | ||
556 | 70 | self.mock_ns_from_file.return_value = self.ns | ||
557 | 71 | |||
558 | 72 | self.assertRaises(ValueError, | ||
559 | 73 | apply_net.apply_net, self.target, | ||
560 | 74 | network_state=self.ns, network_config=None) | ||
561 | 75 | |||
562 | 76 | def test_apply_net_target_and_config(self): | ||
563 | 77 | self.mock_load_config.return_value = self.network_config | ||
564 | 78 | self.mock_netpass_avail.return_value = False | ||
565 | 79 | self.mock_net_parsedata.return_value = self.ns | ||
566 | 80 | |||
567 | 81 | apply_net.apply_net(self.target, network_state=None, | ||
568 | 82 | network_config=self.network_config) | ||
569 | 83 | |||
570 | 84 | self.mock_netpass_avail.assert_called_with(self.target) | ||
571 | 85 | |||
572 | 86 | self.mock_net_renderstate.assert_called_with(target=self.target, | ||
573 | 87 | network_state=self.ns) | ||
574 | 88 | self.mock_legacy.assert_called_with(self.target) | ||
575 | 89 | self.mock_ipv6_priv.assert_called_with(self.target) | ||
576 | 90 | self.mock_ipv6_mtu.assert_called_with(self.target) | ||
577 | 91 | |||
578 | 92 | def test_apply_net_target_and_config_passthrough(self): | ||
579 | 93 | self.mock_load_config.return_value = self.network_config | ||
580 | 94 | self.mock_netpass_avail.return_value = True | ||
581 | 95 | |||
582 | 96 | netcfg = "network_config.yaml" | ||
583 | 97 | apply_net.apply_net(self.target, network_state=None, | ||
584 | 98 | network_config=netcfg) | ||
585 | 99 | |||
586 | 100 | self.assertFalse(self.mock_ns_from_file.called) | ||
587 | 101 | self.mock_load_config.assert_called_with(netcfg) | ||
588 | 102 | self.mock_netpass_avail.assert_called_with(self.target) | ||
589 | 103 | nc = self.network_config | ||
590 | 104 | self.mock_netpass_render.assert_called_with(self.target, netconfig=nc) | ||
591 | 105 | |||
592 | 106 | self.assertFalse(self.mock_net_renderstate.called) | ||
593 | 107 | self.mock_legacy.assert_called_with(self.target) | ||
594 | 108 | self.mock_ipv6_priv.assert_called_with(self.target) | ||
595 | 109 | self.mock_ipv6_mtu.assert_called_with(self.target) | ||
596 | 110 | |||
597 | 111 | def test_apply_net_target_and_config_passthrough_nonet(self): | ||
598 | 112 | nc = {'storage': {}} | ||
599 | 113 | self.mock_load_config.return_value = nc | ||
600 | 114 | self.mock_netpass_avail.return_value = True | ||
601 | 115 | |||
602 | 116 | netcfg = "network_config.yaml" | ||
603 | 117 | |||
604 | 118 | apply_net.apply_net(self.target, network_state=None, | ||
605 | 119 | network_config=netcfg) | ||
606 | 120 | |||
607 | 121 | self.assertFalse(self.mock_ns_from_file.called) | ||
608 | 122 | self.mock_load_config.assert_called_with(netcfg) | ||
609 | 123 | self.mock_netpass_avail.assert_called_with(self.target) | ||
610 | 124 | self.mock_netpass_render.assert_called_with(self.target, netconfig=nc) | ||
611 | 125 | |||
612 | 126 | self.assertFalse(self.mock_net_renderstate.called) | ||
613 | 127 | self.mock_legacy.assert_called_with(self.target) | ||
614 | 128 | self.mock_ipv6_priv.assert_called_with(self.target) | ||
615 | 129 | self.mock_ipv6_mtu.assert_called_with(self.target) | ||
616 | 130 | |||
617 | 131 | def test_apply_net_target_and_config_passthrough_v2_not_available(self): | ||
618 | 132 | nc = copy.deepcopy(self.network_config) | ||
619 | 133 | nc['network']['version'] = 2 | ||
620 | 134 | self.mock_load_config.return_value = nc | ||
621 | 135 | self.mock_netpass_avail.return_value = False | ||
622 | 136 | self.mock_net_parsedata.return_value = self.ns | ||
623 | 137 | |||
624 | 138 | netcfg = "network_config.yaml" | ||
625 | 139 | |||
626 | 140 | apply_net.apply_net(self.target, network_state=None, | ||
627 | 141 | network_config=netcfg) | ||
628 | 142 | |||
629 | 143 | self.assertFalse(self.mock_ns_from_file.called) | ||
630 | 144 | self.mock_load_config.assert_called_with(netcfg) | ||
631 | 145 | self.mock_netpass_avail.assert_called_with(self.target) | ||
632 | 146 | self.assertFalse(self.mock_netpass_render.called) | ||
633 | 147 | self.mock_net_parsedata.assert_called_with(nc['network']) | ||
634 | 148 | |||
635 | 149 | self.mock_net_renderstate.assert_called_with( | ||
636 | 150 | target=self.target, network_state=self.ns) | ||
637 | 151 | self.mock_legacy.assert_called_with(self.target) | ||
638 | 152 | self.mock_ipv6_priv.assert_called_with(self.target) | ||
639 | 153 | self.mock_ipv6_mtu.assert_called_with(self.target) | ||
640 | 154 | |||
641 | 155 | |||
642 | 156 | class TestApplyNetPatchIfupdown(ApplyNetTestBase): | ||
643 | 157 | |||
644 | 158 | @patch('curtin.util.write_file') | ||
645 | 159 | def test_apply_ipv6_mtu_hook(self, mock_write): | ||
646 | 160 | target = 'mytarget' | ||
647 | 161 | prehookfn = 'if-pre-up.d/mtuipv6' | ||
648 | 162 | posthookfn = 'if-up.d/mtuipv6' | ||
649 | 163 | mode = 0o755 | ||
650 | 164 | |||
651 | 165 | apply_net._patch_ifupdown_ipv6_mtu_hook(target, | ||
652 | 166 | prehookfn=prehookfn, | ||
653 | 167 | posthookfn=posthookfn) | ||
654 | 168 | |||
655 | 169 | precfg = util.target_path(target, path=prehookfn) | ||
656 | 170 | postcfg = util.target_path(target, path=posthookfn) | ||
657 | 171 | precontents = apply_net.IFUPDOWN_IPV6_MTU_PRE_HOOK | ||
658 | 172 | postcontents = apply_net.IFUPDOWN_IPV6_MTU_POST_HOOK | ||
659 | 173 | |||
660 | 174 | hook_calls = [ | ||
661 | 175 | call(precfg, precontents, mode=mode), | ||
662 | 176 | call(postcfg, postcontents, mode=mode), | ||
663 | 177 | ] | ||
664 | 178 | mock_write.assert_has_calls(hook_calls) | ||
665 | 179 | |||
666 | 180 | @patch('curtin.util.write_file') | ||
667 | 181 | def test_apply_ipv6_mtu_hook_write_fail(self, mock_write): | ||
668 | 182 | target = 'mytarget' | ||
669 | 183 | prehookfn = 'if-pre-up.d/mtuipv6' | ||
670 | 184 | posthookfn = 'if-up.d/mtuipv6' | ||
671 | 185 | mock_write.side_effect = (Exception) | ||
672 | 186 | |||
673 | 187 | self.assertRaises(Exception, | ||
674 | 188 | apply_net._patch_ifupdown_ipv6_mtu_hook, | ||
675 | 189 | target, | ||
676 | 190 | prehookfn=prehookfn, | ||
677 | 191 | posthookfn=posthookfn) | ||
678 | 192 | |||
679 | 193 | @patch('curtin.util.write_file') | ||
680 | 194 | def test_apply_ipv6_mtu_hook_invalid_target(self, mock_write): | ||
681 | 195 | """ Test that an invalid target will fail to build a | ||
682 | 196 | proper path for util.write_file | ||
683 | 197 | """ | ||
684 | 198 | target = {} | ||
685 | 199 | prehookfn = 'if-pre-up.d/mtuipv6' | ||
686 | 200 | posthookfn = 'if-up.d/mtuipv6' | ||
687 | 201 | mock_write.side_effect = (Exception) | ||
688 | 202 | |||
689 | 203 | self.assertRaises(ValueError, | ||
690 | 204 | apply_net._patch_ifupdown_ipv6_mtu_hook, | ||
691 | 205 | target, | ||
692 | 206 | prehookfn=prehookfn, | ||
693 | 207 | posthookfn=posthookfn) | ||
694 | 208 | |||
695 | 209 | @patch('curtin.util.write_file') | ||
696 | 210 | def test_apply_ipv6_mtu_hook_invalid_prepost_fn(self, mock_write): | ||
697 | 211 | """ Test that invalid prepost filenames will fail to build a | ||
698 | 212 | proper path for util.write_file | ||
699 | 213 | """ | ||
700 | 214 | target = "mytarget" | ||
701 | 215 | prehookfn = {'a': 1} | ||
702 | 216 | posthookfn = {'b': 2} | ||
703 | 217 | mock_write.side_effect = (Exception) | ||
704 | 218 | |||
705 | 219 | self.assertRaises(ValueError, | ||
706 | 220 | apply_net._patch_ifupdown_ipv6_mtu_hook, | ||
707 | 221 | target, | ||
708 | 222 | prehookfn=prehookfn, | ||
709 | 223 | posthookfn=posthookfn) | ||
710 | 224 | |||
711 | 225 | |||
712 | 226 | class TestApplyNetPatchIpv6Priv(ApplyNetTestBase): | ||
713 | 227 | |||
714 | 228 | @patch('curtin.util.del_file') | ||
715 | 229 | @patch('curtin.util.load_file') | ||
716 | 230 | @patch('os.path') | ||
717 | 231 | @patch('curtin.util.write_file') | ||
718 | 232 | def test_disable_ipv6_priv_extentions(self, mock_write, mock_ospath, | ||
719 | 233 | mock_load, mock_del): | ||
720 | 234 | target = 'mytarget' | ||
721 | 235 | path = 'etc/sysctl.d/10-ipv6-privacy.conf' | ||
722 | 236 | ipv6_priv_contents = ( | ||
723 | 237 | 'net.ipv6.conf.all.use_tempaddr = 2\n' | ||
724 | 238 | 'net.ipv6.conf.default.use_tempaddr = 2') | ||
725 | 239 | expected_ipv6_priv_contents = '\n'.join( | ||
726 | 240 | ["# IPv6 Privacy Extensions (RFC 4941)", | ||
727 | 241 | "# Disabled by curtin", | ||
728 | 242 | "# net.ipv6.conf.all.use_tempaddr = 2", | ||
729 | 243 | "# net.ipv6.conf.default.use_tempaddr = 2"]) | ||
730 | 244 | mock_ospath.exists.return_value = True | ||
731 | 245 | mock_load.side_effect = [ipv6_priv_contents] | ||
732 | 246 | |||
733 | 247 | apply_net._disable_ipv6_privacy_extensions(target) | ||
734 | 248 | |||
735 | 249 | cfg = util.target_path(target, path=path) | ||
736 | 250 | mock_write.assert_called_with(cfg, expected_ipv6_priv_contents) | ||
737 | 251 | |||
738 | 252 | @patch('curtin.util.load_file') | ||
739 | 253 | @patch('os.path') | ||
740 | 254 | def test_disable_ipv6_priv_extentions_decoderror(self, mock_ospath, | ||
741 | 255 | mock_load): | ||
742 | 256 | target = 'mytarget' | ||
743 | 257 | mock_ospath.exists.return_value = True | ||
744 | 258 | |||
745 | 259 | # simulate loading of binary data | ||
746 | 260 | mock_load.side_effect = (Exception) | ||
747 | 261 | |||
748 | 262 | self.assertRaises(Exception, | ||
749 | 263 | apply_net._disable_ipv6_privacy_extensions, | ||
750 | 264 | target) | ||
751 | 265 | |||
752 | 266 | @patch('curtin.util.load_file') | ||
753 | 267 | @patch('os.path') | ||
754 | 268 | def test_disable_ipv6_priv_extentions_notfound(self, mock_ospath, | ||
755 | 269 | mock_load): | ||
756 | 270 | target = 'mytarget' | ||
757 | 271 | path = 'foo.conf' | ||
758 | 272 | mock_ospath.exists.return_value = False | ||
759 | 273 | |||
760 | 274 | apply_net._disable_ipv6_privacy_extensions(target, path=path) | ||
761 | 275 | |||
762 | 276 | # source file not found | ||
763 | 277 | cfg = util.target_path(target, path) | ||
764 | 278 | mock_ospath.exists.assert_called_with(cfg) | ||
765 | 279 | mock_load.assert_not_called() | ||
766 | 280 | |||
767 | 281 | |||
768 | 282 | class TestApplyNetRemoveLegacyEth0(ApplyNetTestBase): | ||
769 | 283 | |||
770 | 284 | @patch('curtin.util.del_file') | ||
771 | 285 | @patch('curtin.util.load_file') | ||
772 | 286 | @patch('os.path') | ||
773 | 287 | def test_remove_legacy_eth0(self, mock_ospath, mock_load, mock_del): | ||
774 | 288 | target = 'mytarget' | ||
775 | 289 | path = 'eth0.cfg' | ||
776 | 290 | cfg = util.target_path(target, path) | ||
777 | 291 | legacy_eth0_contents = ( | ||
778 | 292 | 'auto eth0\n' | ||
779 | 293 | 'iface eth0 inet dhcp') | ||
780 | 294 | |||
781 | 295 | mock_ospath.exists.return_value = True | ||
782 | 296 | mock_load.side_effect = [legacy_eth0_contents] | ||
783 | 297 | |||
784 | 298 | apply_net._maybe_remove_legacy_eth0(target, path) | ||
785 | 299 | |||
786 | 300 | mock_del.assert_called_with(cfg) | ||
787 | 301 | |||
788 | 302 | @patch('curtin.util.del_file') | ||
789 | 303 | @patch('curtin.util.load_file') | ||
790 | 304 | @patch('os.path') | ||
791 | 305 | def test_remove_legacy_eth0_nomatch(self, mock_ospath, mock_load, | ||
792 | 306 | mock_del): | ||
793 | 307 | target = 'mytarget' | ||
794 | 308 | path = 'eth0.cfg' | ||
795 | 309 | legacy_eth0_contents = "nomatch" | ||
796 | 310 | mock_ospath.join.side_effect = os.path.join | ||
797 | 311 | mock_ospath.exists.return_value = True | ||
798 | 312 | mock_load.side_effect = [legacy_eth0_contents] | ||
799 | 313 | |||
800 | 314 | self.assertRaises(Exception, | ||
801 | 315 | apply_net._maybe_remove_legacy_eth0, | ||
802 | 316 | target, path) | ||
803 | 317 | |||
804 | 318 | mock_del.assert_not_called() | ||
805 | 319 | |||
806 | 320 | @patch('curtin.util.del_file') | ||
807 | 321 | @patch('curtin.util.load_file') | ||
808 | 322 | @patch('os.path') | ||
809 | 323 | def test_remove_legacy_eth0_badload(self, mock_ospath, mock_load, | ||
810 | 324 | mock_del): | ||
811 | 325 | target = 'mytarget' | ||
812 | 326 | path = 'eth0.cfg' | ||
813 | 327 | mock_ospath.exists.return_value = True | ||
814 | 328 | mock_load.side_effect = (Exception) | ||
815 | 329 | |||
816 | 330 | self.assertRaises(Exception, | ||
817 | 331 | apply_net._maybe_remove_legacy_eth0, | ||
818 | 332 | target, path) | ||
819 | 333 | |||
820 | 334 | mock_del.assert_not_called() | ||
821 | 335 | |||
822 | 336 | @patch('curtin.util.del_file') | ||
823 | 337 | @patch('curtin.util.load_file') | ||
824 | 338 | @patch('os.path') | ||
825 | 339 | def test_remove_legacy_eth0_notfound(self, mock_ospath, mock_load, | ||
826 | 340 | mock_del): | ||
827 | 341 | target = 'mytarget' | ||
828 | 342 | path = 'eth0.conf' | ||
829 | 343 | mock_ospath.exists.return_value = False | ||
830 | 344 | |||
831 | 345 | apply_net._maybe_remove_legacy_eth0(target, path) | ||
832 | 346 | |||
833 | 347 | # source file not found | ||
834 | 348 | cfg = util.target_path(target, path) | ||
835 | 349 | mock_ospath.exists.assert_called_with(cfg) | ||
836 | 350 | mock_load.assert_not_called() | ||
837 | 351 | mock_del.assert_not_called() | ||
838 | 0 | 352 | ||
839 | === modified file 'tests/unittests/test_curthooks.py' | |||
840 | --- tests/unittests/test_curthooks.py 2017-05-12 14:35:53 +0000 | |||
841 | +++ tests/unittests/test_curthooks.py 2017-06-19 16:35:41 +0000 | |||
842 | @@ -577,4 +577,188 @@ | |||
843 | 577 | with self.assertRaises(ValueError): | 577 | with self.assertRaises(ValueError): |
844 | 578 | curthooks.handle_cloudconfig([], target="foobar") | 578 | curthooks.handle_cloudconfig([], target="foobar") |
845 | 579 | 579 | ||
846 | 580 | |||
847 | 581 | class TestDetectRequiredPackages(TestCase): | ||
848 | 582 | test_config = { | ||
849 | 583 | 'storage': { | ||
850 | 584 | 1: { | ||
851 | 585 | 'bcache': { | ||
852 | 586 | 'type': 'bcache', 'name': 'bcache0', 'id': 'cache0', | ||
853 | 587 | 'backing_device': 'sda3', 'cache_device': 'sdb'}, | ||
854 | 588 | 'lvm_partition': { | ||
855 | 589 | 'id': 'lvol1', 'name': 'lv1', 'volgroup': 'vg1', | ||
856 | 590 | 'type': 'lvm_partition'}, | ||
857 | 591 | 'lvm_volgroup': { | ||
858 | 592 | 'id': 'vol1', 'name': 'vg1', 'devices': ['sda', 'sdb'], | ||
859 | 593 | 'type': 'lvm_volgroup'}, | ||
860 | 594 | 'raid': { | ||
861 | 595 | 'id': 'mddevice', 'name': 'md0', 'type': 'raid', | ||
862 | 596 | 'raidlevel': 5, 'devices': ['sda1', 'sdb1', 'sdc1']}, | ||
863 | 597 | 'ext2': { | ||
864 | 598 | 'id': 'format0', 'fstype': 'ext2', 'type': 'format'}, | ||
865 | 599 | 'ext3': { | ||
866 | 600 | 'id': 'format1', 'fstype': 'ext3', 'type': 'format'}, | ||
867 | 601 | 'ext4': { | ||
868 | 602 | 'id': 'format2', 'fstype': 'ext4', 'type': 'format'}, | ||
869 | 603 | 'btrfs': { | ||
870 | 604 | 'id': 'format3', 'fstype': 'btrfs', 'type': 'format'}, | ||
871 | 605 | 'xfs': { | ||
872 | 606 | 'id': 'format4', 'fstype': 'xfs', 'type': 'format'}} | ||
873 | 607 | }, | ||
874 | 608 | 'network': { | ||
875 | 609 | 1: { | ||
876 | 610 | 'bond': { | ||
877 | 611 | 'name': 'bond0', 'type': 'bond', | ||
878 | 612 | 'bond_interfaces': ['interface0', 'interface1'], | ||
879 | 613 | 'params': {'bond-mode': 'active-backup'}, | ||
880 | 614 | 'subnets': [ | ||
881 | 615 | {'type': 'static', 'address': '10.23.23.2/24'}, | ||
882 | 616 | {'type': 'static', 'address': '10.23.24.2/24'}]}, | ||
883 | 617 | 'vlan': { | ||
884 | 618 | 'id': 'interface1.2667', 'mtu': 1500, 'name': | ||
885 | 619 | 'interface1.2667', 'type': 'vlan', 'vlan_id': 2667, | ||
886 | 620 | 'vlan_link': 'interface1', | ||
887 | 621 | 'subnets': [{'address': '10.245.184.2/24', | ||
888 | 622 | 'dns_nameservers': [], 'type': 'static'}]}, | ||
889 | 623 | 'bridge': { | ||
890 | 624 | 'name': 'br0', 'bridge_interfaces': ['eth0', 'eth1'], | ||
891 | 625 | 'type': 'bridge', 'params': { | ||
892 | 626 | 'bridge_stp': 'off', 'bridge_fd': 0, | ||
893 | 627 | 'bridge_maxwait': 0}, | ||
894 | 628 | 'subnets': [ | ||
895 | 629 | {'type': 'static', 'address': '192.168.14.2/24'}, | ||
896 | 630 | {'type': 'static', 'address': '2001:1::1/64'}]}}, | ||
897 | 631 | 2: { | ||
898 | 632 | 'vlan': { | ||
899 | 633 | 'vlans': { | ||
900 | 634 | 'en-intra': {'id': 1, 'link': 'eno1', 'dhcp4': 'yes'}, | ||
901 | 635 | 'en-vpn': {'id': 2, 'link': 'eno1'}}}, | ||
902 | 636 | 'bridge': { | ||
903 | 637 | 'bridges': { | ||
904 | 638 | 'br0': { | ||
905 | 639 | 'interfaces': ['wlp1s0', 'switchports'], | ||
906 | 640 | 'dhcp4': True}}}} | ||
907 | 641 | }, | ||
908 | 642 | } | ||
909 | 643 | |||
910 | 644 | def _fmt_config(self, config_items): | ||
911 | 645 | res = {} | ||
912 | 646 | for item, item_confs in config_items.items(): | ||
913 | 647 | version = item_confs['version'] | ||
914 | 648 | res[item] = {'version': version} | ||
915 | 649 | if version == 1: | ||
916 | 650 | res[item]['config'] = [self.test_config[item][version][i] | ||
917 | 651 | for i in item_confs['items']] | ||
918 | 652 | elif version == 2 and item == 'network': | ||
919 | 653 | for cfg_item in item_confs['items']: | ||
920 | 654 | res[item].update(self.test_config[item][version][cfg_item]) | ||
921 | 655 | else: | ||
922 | 656 | raise NotImplementedError | ||
923 | 657 | return res | ||
924 | 658 | |||
925 | 659 | def _test_req_mappings(self, req_mappings): | ||
926 | 660 | for (config_items, expected_reqs) in req_mappings: | ||
927 | 661 | cfg = self._fmt_config(config_items) | ||
928 | 662 | actual_reqs = curthooks.detect_required_packages(cfg) | ||
929 | 663 | self.assertEqual(set(actual_reqs), set(expected_reqs), | ||
930 | 664 | 'failed for config: {}'.format(config_items)) | ||
931 | 665 | |||
932 | 666 | def test_storage_v1_detect(self): | ||
933 | 667 | self._test_req_mappings(( | ||
934 | 668 | ({'storage': { | ||
935 | 669 | 'version': 1, | ||
936 | 670 | 'items': ('lvm_partition', 'lvm_volgroup', 'btrfs', 'xfs')}}, | ||
937 | 671 | ('lvm2', 'xfsprogs', 'btrfs-tools')), | ||
938 | 672 | ({'storage': { | ||
939 | 673 | 'version': 1, | ||
940 | 674 | 'items': ('raid', 'bcache', 'ext3', 'xfs')}}, | ||
941 | 675 | ('mdadm', 'bcache-tools', 'e2fsprogs', 'xfsprogs')), | ||
942 | 676 | ({'storage': { | ||
943 | 677 | 'version': 1, | ||
944 | 678 | 'items': ('raid', 'lvm_volgroup', 'lvm_partition', 'ext3', | ||
945 | 679 | 'ext4', 'btrfs')}}, | ||
946 | 680 | ('lvm2', 'mdadm', 'e2fsprogs', 'btrfs-tools')), | ||
947 | 681 | ({'storage': { | ||
948 | 682 | 'version': 1, | ||
949 | 683 | 'items': ('bcache', 'lvm_volgroup', 'lvm_partition', 'ext2')}}, | ||
950 | 684 | ('bcache-tools', 'lvm2', 'e2fsprogs')), | ||
951 | 685 | )) | ||
952 | 686 | |||
953 | 687 | def test_network_v1_detect(self): | ||
954 | 688 | self._test_req_mappings(( | ||
955 | 689 | ({'network': { | ||
956 | 690 | 'version': 1, | ||
957 | 691 | 'items': ('bridge',)}}, | ||
958 | 692 | ('bridge-utils',)), | ||
959 | 693 | ({'network': { | ||
960 | 694 | 'version': 1, | ||
961 | 695 | 'items': ('vlan', 'bond')}}, | ||
962 | 696 | ('vlan', 'ifenslave')), | ||
963 | 697 | ({'network': { | ||
964 | 698 | 'version': 1, | ||
965 | 699 | 'items': ('bond', 'bridge')}}, | ||
966 | 700 | ('ifenslave', 'bridge-utils')), | ||
967 | 701 | ({'network': { | ||
968 | 702 | 'version': 1, | ||
969 | 703 | 'items': ('vlan', 'bridge', 'bond')}}, | ||
970 | 704 | ('ifenslave', 'bridge-utils', 'vlan')), | ||
971 | 705 | )) | ||
972 | 706 | |||
973 | 707 | def test_mixed_v1_detect(self): | ||
974 | 708 | self._test_req_mappings(( | ||
975 | 709 | ({'storage': { | ||
976 | 710 | 'version': 1, | ||
977 | 711 | 'items': ('raid', 'bcache', 'ext4')}, | ||
978 | 712 | 'network': { | ||
979 | 713 | 'version': 1, | ||
980 | 714 | 'items': ('vlan',)}}, | ||
981 | 715 | ('mdadm', 'bcache-tools', 'e2fsprogs', 'vlan')), | ||
982 | 716 | ({'storage': { | ||
983 | 717 | 'version': 1, | ||
984 | 718 | 'items': ('lvm_partition', 'lvm_volgroup', 'xfs')}, | ||
985 | 719 | 'network': { | ||
986 | 720 | 'version': 1, | ||
987 | 721 | 'items': ('bridge', 'bond')}}, | ||
988 | 722 | ('lvm2', 'xfsprogs', 'bridge-utils', 'ifenslave')), | ||
989 | 723 | ({'storage': { | ||
990 | 724 | 'version': 1, | ||
991 | 725 | 'items': ('ext3', 'ext4', 'btrfs')}, | ||
992 | 726 | 'network': { | ||
993 | 727 | 'version': 1, | ||
994 | 728 | 'items': ('bond', 'vlan')}}, | ||
995 | 729 | ('e2fsprogs', 'btrfs-tools', 'vlan', 'ifenslave')), | ||
996 | 730 | )) | ||
997 | 731 | |||
998 | 732 | def test_network_v2_detect(self): | ||
999 | 733 | self._test_req_mappings(( | ||
1000 | 734 | ({'network': { | ||
1001 | 735 | 'version': 2, | ||
1002 | 736 | 'items': ('bridge',)}}, | ||
1003 | 737 | ('bridge-utils',)), | ||
1004 | 738 | ({'network': { | ||
1005 | 739 | 'version': 2, | ||
1006 | 740 | 'items': ('vlan',)}}, | ||
1007 | 741 | ('vlan',)), | ||
1008 | 742 | ({'network': { | ||
1009 | 743 | 'version': 2, | ||
1010 | 744 | 'items': ('vlan', 'bridge')}}, | ||
1011 | 745 | ('vlan', 'bridge-utils')), | ||
1012 | 746 | )) | ||
1013 | 747 | |||
1014 | 748 | def test_mixed_storage_v1_network_v2_detect(self): | ||
1015 | 749 | self._test_req_mappings(( | ||
1016 | 750 | ({'network': { | ||
1017 | 751 | 'version': 2, | ||
1018 | 752 | 'items': ('bridge', 'vlan')}, | ||
1019 | 753 | 'storage': { | ||
1020 | 754 | 'version': 1, | ||
1021 | 755 | 'items': ('raid', 'bcache', 'ext4')}}, | ||
1022 | 756 | ('vlan', 'bridge-utils', 'mdadm', 'bcache-tools', 'e2fsprogs')), | ||
1023 | 757 | )) | ||
1024 | 758 | |||
1025 | 759 | def test_invalid_version_in_config(self): | ||
1026 | 760 | with self.assertRaises(ValueError): | ||
1027 | 761 | curthooks.detect_required_packages({'network': {'version': 3}}) | ||
1028 | 762 | |||
1029 | 763 | |||
1030 | 580 | # vi: ts=4 expandtab syntax=python | 764 | # vi: ts=4 expandtab syntax=python |
1031 | 581 | 765 | ||
1032 | === modified file 'tests/unittests/test_net.py' | |||
1033 | --- tests/unittests/test_net.py 2017-02-09 16:58:23 +0000 | |||
1034 | +++ tests/unittests/test_net.py 2017-06-19 16:35:41 +0000 | |||
1035 | @@ -1,10 +1,11 @@ | |||
1036 | 1 | from unittest import TestCase | 1 | from unittest import TestCase |
1037 | 2 | import mock | ||
1038 | 2 | import os | 3 | import os |
1039 | 3 | import shutil | 4 | import shutil |
1040 | 4 | import tempfile | 5 | import tempfile |
1041 | 5 | import yaml | 6 | import yaml |
1042 | 6 | 7 | ||
1044 | 7 | from curtin import net | 8 | from curtin import config, net, util |
1045 | 8 | import curtin.net.network_state as network_state | 9 | import curtin.net.network_state as network_state |
1046 | 9 | from textwrap import dedent | 10 | from textwrap import dedent |
1047 | 10 | 11 | ||
1048 | @@ -654,6 +655,141 @@ | |||
1049 | 654 | self.assertEqual(sorted(ifaces.split('\n')), | 655 | self.assertEqual(sorted(ifaces.split('\n')), |
1050 | 655 | sorted(net_ifaces.split('\n'))) | 656 | sorted(net_ifaces.split('\n'))) |
1051 | 656 | 657 | ||
1052 | 658 | @mock.patch('curtin.util.load_file') | ||
1053 | 659 | @mock.patch('curtin.util.subp') | ||
1054 | 660 | @mock.patch('curtin.util.which') | ||
1055 | 661 | @mock.patch.object(util.ChrootableTarget, "__enter__", new=lambda a: a) | ||
1056 | 662 | def test_netconfig_passthrough_available(self, mock_which, mock_subp, | ||
1057 | 663 | mock_load_file): | ||
1058 | 664 | cloud_init = '/usr/bin/cloud-init' | ||
1059 | 665 | python = '/usr/bin/python3' | ||
1060 | 666 | mock_which.return_value = cloud_init | ||
1061 | 667 | mock_load_file.return_value = "#! %s" % python | ||
1062 | 668 | mock_subp.return_value = ('True', '') | ||
1063 | 669 | feature = 'NETWORK_CONFIG_V2' | ||
1064 | 670 | expected_cmd = ( | ||
1065 | 671 | "from cloudinit import version;" | ||
1066 | 672 | "print('%s' in getattr(version, 'FEATURES', []))" % feature) | ||
1067 | 673 | |||
1068 | 674 | available = net.netconfig_passthrough_available(self.target) | ||
1069 | 675 | |||
1070 | 676 | self.assertEqual(True, available, | ||
1071 | 677 | "netconfig passthrough was NOT available") | ||
1072 | 678 | mock_which.assert_called_with('cloud-init', target=self.target) | ||
1073 | 679 | mock_load_file.assert_called_with(self.target + cloud_init) | ||
1074 | 680 | mock_subp.assert_called_with([python, '-c', expected_cmd], | ||
1075 | 681 | capture=True, target=self.target) | ||
1076 | 682 | |||
1077 | 683 | @mock.patch('curtin.util.load_file') | ||
1078 | 684 | @mock.patch('curtin.util.subp') | ||
1079 | 685 | @mock.patch('curtin.util.which') | ||
1080 | 686 | @mock.patch.object(util.ChrootableTarget, "__enter__", new=lambda a: a) | ||
1081 | 687 | def test_netconfig_passthrough_available_no_py3(self, mock_which, | ||
1082 | 688 | mock_subp, mock_load_file): | ||
1083 | 689 | cloud_init = '/usr/bin/cloud-init' | ||
1084 | 690 | python = '/usr/bin/python' | ||
1085 | 691 | mock_which.return_value = cloud_init | ||
1086 | 692 | mock_load_file.return_value = "#! %s" % python | ||
1087 | 693 | mock_subp.return_value = ('True', '') | ||
1088 | 694 | feature = 'NETWORK_CONFIG_V2' | ||
1089 | 695 | expected_cmd = ( | ||
1090 | 696 | "from cloudinit import version;" | ||
1091 | 697 | "print('%s' in getattr(version, 'FEATURES', []))" % feature) | ||
1092 | 698 | |||
1093 | 699 | available = net.netconfig_passthrough_available(self.target) | ||
1094 | 700 | |||
1095 | 701 | self.assertEqual(True, available, | ||
1096 | 702 | "netconfig passthrough was available") | ||
1097 | 703 | mock_which.assert_called_with('cloud-init', target=self.target) | ||
1098 | 704 | mock_load_file.assert_called_with(self.target + cloud_init) | ||
1099 | 705 | mock_subp.assert_called_with([python, '-c', expected_cmd], | ||
1100 | 706 | capture=True, target=self.target) | ||
1101 | 707 | |||
1102 | 708 | @mock.patch('curtin.net.LOG') | ||
1103 | 709 | @mock.patch('curtin.util.subp') | ||
1104 | 710 | @mock.patch('curtin.util.which') | ||
1105 | 711 | @mock.patch.object(util.ChrootableTarget, "__enter__", new=lambda a: a) | ||
1106 | 712 | def test_netconfig_passthrough_available_no_cloudinit(self, mock_which, | ||
1107 | 713 | mock_subp, mock_log): | ||
1108 | 714 | mock_which.return_value = None | ||
1109 | 715 | |||
1110 | 716 | available = net.netconfig_passthrough_available(self.target) | ||
1111 | 717 | |||
1112 | 718 | self.assertEqual(False, available, | ||
1113 | 719 | "netconfig passthrough was available") | ||
1114 | 720 | self.assertTrue(mock_log.warning.called) | ||
1115 | 721 | self.assertFalse(mock_subp.called) | ||
1116 | 722 | |||
1117 | 723 | @mock.patch('curtin.util.load_file') | ||
1118 | 724 | @mock.patch('curtin.util.subp') | ||
1119 | 725 | @mock.patch('curtin.util.which') | ||
1120 | 726 | @mock.patch.object(util.ChrootableTarget, "__enter__", new=lambda a: a) | ||
1121 | 727 | def test_netconfig_passthrough_available_feature_not_found(self, | ||
1122 | 728 | mock_which, | ||
1123 | 729 | mock_subp, | ||
1124 | 730 | mock_load_file): | ||
1125 | 731 | cloud_init = '/usr/bin/cloud-init' | ||
1126 | 732 | python = '/usr/bin/python3' | ||
1127 | 733 | mock_which.return_value = cloud_init | ||
1128 | 734 | mock_load_file.return_value = "#! %s" % python | ||
1129 | 735 | mock_subp.return_value = ('False', '') | ||
1130 | 736 | feature = 'NETWORK_CONFIG_V2' | ||
1131 | 737 | expected_cmd = ( | ||
1132 | 738 | "from cloudinit import version;" | ||
1133 | 739 | "print('%s' in getattr(version, 'FEATURES', []))" % feature) | ||
1134 | 740 | |||
1135 | 741 | available = net.netconfig_passthrough_available(self.target) | ||
1136 | 742 | |||
1137 | 743 | self.assertEqual(False, available, | ||
1138 | 744 | "netconfig passthrough was available") | ||
1139 | 745 | mock_which.assert_called_with('cloud-init', target=self.target) | ||
1140 | 746 | mock_load_file.assert_called_with(self.target + cloud_init) | ||
1141 | 747 | mock_subp.assert_called_with([python, '-c', expected_cmd], | ||
1142 | 748 | capture=True, target=self.target) | ||
1143 | 749 | |||
1144 | 750 | @mock.patch('curtin.util.load_file') | ||
1145 | 751 | @mock.patch('curtin.net.LOG') | ||
1146 | 752 | @mock.patch('curtin.util.subp') | ||
1147 | 753 | @mock.patch('curtin.util.which') | ||
1148 | 754 | @mock.patch.object(util.ChrootableTarget, "__enter__", new=lambda a: a) | ||
1149 | 755 | def test_netconfig_passthrough_available_exc(self, mock_which, mock_subp, | ||
1150 | 756 | mock_log, mock_load_file): | ||
1151 | 757 | cloud_init = '/usr/bin/cloud-init' | ||
1152 | 758 | python = '/usr/bin/python3' | ||
1153 | 759 | mock_which.return_value = cloud_init | ||
1154 | 760 | mock_load_file.return_value = "#! %s" % python | ||
1155 | 761 | mock_subp.side_effect = util.ProcessExecutionError | ||
1156 | 762 | feature = 'NETWORK_CONFIG_V2' | ||
1157 | 763 | expected_cmd = ( | ||
1158 | 764 | "from cloudinit import version;" | ||
1159 | 765 | "print('%s' in getattr(version, 'FEATURES', []))" % feature) | ||
1160 | 766 | |||
1161 | 767 | available = net.netconfig_passthrough_available(self.target) | ||
1162 | 768 | |||
1163 | 769 | self.assertEqual(False, available, | ||
1164 | 770 | "netconfig passthrough was available") | ||
1165 | 771 | mock_which.assert_called_with('cloud-init', target=self.target) | ||
1166 | 772 | mock_subp.assert_called_with([python, '-c', expected_cmd], | ||
1167 | 773 | capture=True, target=self.target) | ||
1168 | 774 | self.assertTrue(mock_log.exception.called) | ||
1169 | 775 | |||
1170 | 776 | @mock.patch('curtin.util.write_file') | ||
1171 | 777 | def test_render_netconfig_passthrough(self, mock_writefile): | ||
1172 | 778 | netcfg = yaml.safe_load(self.config) | ||
1173 | 779 | pt_config = 'etc/cloud/cloud.cfg.d/curtin-networking.cfg' | ||
1174 | 780 | target_config = os.path.sep.join((self.target, pt_config),) | ||
1175 | 781 | |||
1176 | 782 | net.render_netconfig_passthrough(self.target, netconfig=netcfg) | ||
1177 | 783 | |||
1178 | 784 | content = config.dump_config(netcfg) | ||
1179 | 785 | mock_writefile.assert_called_with(target_config, content=content) | ||
1180 | 786 | |||
1181 | 787 | def test_render_netconfig_passthrough_nonetcfg(self): | ||
1182 | 788 | netcfg = None | ||
1183 | 789 | self.assertRaises(ValueError, | ||
1184 | 790 | net.render_netconfig_passthrough, | ||
1185 | 791 | self.target, netconfig=netcfg) | ||
1186 | 792 | |||
1187 | 657 | def test_routes_rendered(self): | 793 | def test_routes_rendered(self): |
1188 | 658 | # as reported in bug 1649652 | 794 | # as reported in bug 1649652 |
1189 | 659 | conf = [ | 795 | conf = [ |
1190 | 660 | 796 | ||
1191 | === modified file 'tests/vmtests/test_network.py' | |||
1192 | --- tests/vmtests/test_network.py 2017-05-19 21:40:48 +0000 | |||
1193 | +++ tests/vmtests/test_network.py 2017-06-19 16:35:41 +0000 | |||
1194 | @@ -1,7 +1,12 @@ | |||
1195 | 1 | from . import VMBaseClass, logger, helpers | 1 | from . import VMBaseClass, logger, helpers |
1196 | 2 | from .releases import base_vm_classes as relbase | 2 | from .releases import base_vm_classes as relbase |
1197 | 3 | 3 | ||
1198 | 4 | from unittest import SkipTest | ||
1199 | 5 | from curtin import config | ||
1200 | 6 | |||
1201 | 7 | import glob | ||
1202 | 4 | import ipaddress | 8 | import ipaddress |
1203 | 9 | import os | ||
1204 | 5 | import re | 10 | import re |
1205 | 6 | import textwrap | 11 | import textwrap |
1206 | 7 | import yaml | 12 | import yaml |
1207 | @@ -14,26 +19,41 @@ | |||
1208 | 14 | collect_scripts = [textwrap.dedent(""" | 19 | collect_scripts = [textwrap.dedent(""" |
1209 | 15 | cd OUTPUT_COLLECT_D | 20 | cd OUTPUT_COLLECT_D |
1210 | 16 | echo "waiting for ipv6 to settle" && sleep 5 | 21 | echo "waiting for ipv6 to settle" && sleep 5 |
1214 | 17 | ifconfig -a > ifconfig_a | 22 | route -n | tee first_route_n |
1215 | 18 | ip link show > ip_link_show | 23 | ifconfig -a | tee ifconfig_a |
1216 | 19 | ip a > ip_a | 24 | ip link show | tee ip_link_show |
1217 | 25 | ip a | tee ip_a | ||
1218 | 20 | find /etc/network/interfaces.d > find_interfacesd | 26 | find /etc/network/interfaces.d > find_interfacesd |
1219 | 21 | cp -av /etc/network/interfaces . | 27 | cp -av /etc/network/interfaces . |
1220 | 22 | cp -av /etc/network/interfaces.d . | 28 | cp -av /etc/network/interfaces.d . |
1221 | 23 | cp /etc/resolv.conf . | 29 | cp /etc/resolv.conf . |
1227 | 24 | cp -av /etc/udev/rules.d/70-persistent-net.rules . | 30 | cp -av /etc/udev/rules.d/70-persistent-net.rules . ||: |
1228 | 25 | ip -o route show > ip_route_show | 31 | ip -o route show | tee ip_route_show |
1229 | 26 | ip -6 -o route show > ip_6_route_show | 32 | ip -6 -o route show | tee ip_6_route_show |
1230 | 27 | route -n > route_n | 33 | route -n |tee route_n |
1231 | 28 | route -6 -n > route_6_n | 34 | route -6 -n |tee route_6_n |
1232 | 29 | cp -av /run/network ./run_network | 35 | cp -av /run/network ./run_network |
1233 | 30 | cp -av /var/log/upstart ./upstart ||: | 36 | cp -av /var/log/upstart ./upstart ||: |
1235 | 31 | sleep 10 && ip a > ip_a | 37 | cp -av /etc/cloud ./etc_cloud |
1236 | 38 | cp -av /var/log/cloud*.log ./ | ||
1237 | 39 | dpkg-query -W -f '${Version}' cloud-init |tee dpkg_cloud-init_version | ||
1238 | 40 | dpkg-query -W -f '${Version}' nplan |tee dpkg_nplan_version | ||
1239 | 41 | dpkg-query -W -f '${Version}' systemd |tee dpkg_systemd_version | ||
1240 | 42 | V=/usr/lib/python*/dist-packages/cloudinit/version.py; | ||
1241 | 43 | grep -c NETWORK_CONFIG_V2 $V > cloudinit_passthrough_available | ||
1242 | 44 | mkdir -p etc_netplan | ||
1243 | 45 | cp -av /etc/netplan/* ./etc_netplan/ ||: | ||
1244 | 46 | networkctl |tee networkctl | ||
1245 | 47 | mkdir -p run_systemd_network | ||
1246 | 48 | cp -a /run/systemd/network/* ./run_systemd_network/ ||: | ||
1247 | 49 | cp -a /run/systemd/netif ./run_systemd_netif ||: | ||
1248 | 50 | cp -a /run/systemd/resolve ./run_systemd_resolve ||: | ||
1249 | 51 | cp -a /etc/systemd ./etc_systemd ||: | ||
1250 | 52 | journalctl --no-pager -b -x > journalctl_out | ||
1251 | 32 | """)] | 53 | """)] |
1252 | 33 | 54 | ||
1253 | 34 | def test_output_files_exist(self): | 55 | def test_output_files_exist(self): |
1254 | 35 | self.output_files_exist([ | 56 | self.output_files_exist([ |
1255 | 36 | "70-persistent-net.rules", | ||
1256 | 37 | "find_interfacesd", | 57 | "find_interfacesd", |
1257 | 38 | "ifconfig_a", | 58 | "ifconfig_a", |
1258 | 39 | "interfaces", | 59 | "interfaces", |
1259 | @@ -44,17 +64,109 @@ | |||
1260 | 44 | "route_n", | 64 | "route_n", |
1261 | 45 | ]) | 65 | ]) |
1262 | 46 | 66 | ||
1264 | 47 | def test_etc_network_interfaces(self): | 67 | def read_eni(self): |
1265 | 68 | eni = "" | ||
1266 | 69 | eni_cfg = "" | ||
1267 | 70 | |||
1268 | 48 | eni = self.load_collect_file("interfaces") | 71 | eni = self.load_collect_file("interfaces") |
1269 | 49 | logger.debug('etc/network/interfaces:\n{}'.format(eni)) | 72 | logger.debug('etc/network/interfaces:\n{}'.format(eni)) |
1270 | 50 | 73 | ||
1271 | 74 | # we don't use collect_path as we're building a glob | ||
1272 | 75 | eni_dir = os.path.join(self.td.collect, "interfaces.d", "*.cfg") | ||
1273 | 76 | for cfg in glob.glob(eni_dir): | ||
1274 | 77 | with open(cfg) as fp: | ||
1275 | 78 | eni_cfg += fp.read() | ||
1276 | 79 | |||
1277 | 80 | return (eni, eni_cfg) | ||
1278 | 81 | |||
1279 | 82 | def _network_renderer(self): | ||
1280 | 83 | """ Determine if target uses eni/ifupdown or netplan/networkd """ | ||
1281 | 84 | |||
1282 | 85 | etc_netplan = self.collect_path('etc_netplan') | ||
1283 | 86 | networkd = self.collect_path('run_systemd_network') | ||
1284 | 87 | |||
1285 | 88 | if len(os.listdir(etc_netplan)) > 0 and len(os.listdir(networkd)) > 0: | ||
1286 | 89 | print('Network Renderer: systemd-networkd') | ||
1287 | 90 | return 'systemd-networkd' | ||
1288 | 91 | |||
1289 | 92 | print('Network Renderer: ifupdown') | ||
1290 | 93 | return 'ifupdown' | ||
1291 | 94 | |||
1292 | 95 | def test_etc_network_interfaces(self): | ||
1293 | 96 | if self._network_renderer() != "ifupdown": | ||
1294 | 97 | reason = ("{}: using net-passthrough; " | ||
1295 | 98 | "deferring to cloud-init".format(self.__class__)) | ||
1296 | 99 | raise SkipTest(reason) | ||
1297 | 100 | |||
1298 | 101 | eni, eni_cfg = self.read_eni() | ||
1299 | 51 | expected_eni = self.get_expected_etc_network_interfaces() | 102 | expected_eni = self.get_expected_etc_network_interfaces() |
1303 | 52 | eni_lines = eni.split('\n') | 103 | |
1304 | 53 | for line in expected_eni.split('\n'): | 104 | eni_lines = eni.split('\n') + eni_cfg.split('\n') |
1305 | 54 | self.assertTrue(line in eni_lines, msg="missing line: %s" % line) | 105 | print("\n".join(eni_lines)) |
1306 | 106 | for line in [l for l in expected_eni.split('\n') if len(l) > 0]: | ||
1307 | 107 | if line.startswith("#"): | ||
1308 | 108 | continue | ||
1309 | 109 | if "hwaddress ether" in line: | ||
1310 | 110 | continue | ||
1311 | 111 | print('expected line:\n%s' % line) | ||
1312 | 112 | self.assertTrue(line in eni_lines, "not in eni: %s" % line) | ||
1313 | 113 | |||
1314 | 114 | def test_cloudinit_network_passthrough(self): | ||
1315 | 115 | cc_passthrough = "cloud.cfg.d/curtin-networking.cfg" | ||
1316 | 116 | |||
1317 | 117 | avail_str = self.load_collect_file('cloudinit_passthrough_available') | ||
1318 | 118 | available = int(avail_str) == 1 | ||
1319 | 119 | print('avail_str=%s available=%s' % (avail_str, available)) | ||
1320 | 120 | |||
1321 | 121 | if not available: | ||
1322 | 122 | raise SkipTest('not available on %s' % self.__class__) | ||
1323 | 123 | |||
1324 | 124 | print('passthrough was available') | ||
1325 | 125 | pt_file = os.path.join(self.td.collect, 'etc_cloud', | ||
1326 | 126 | cc_passthrough) | ||
1327 | 127 | print('checking if passthrough file written: %s' % pt_file) | ||
1328 | 128 | self.assertTrue(os.path.exists(pt_file)) | ||
1329 | 129 | |||
1330 | 130 | # compare | ||
1331 | 131 | original = {'network': | ||
1332 | 132 | config.load_config(self.conf_file).get('network')} | ||
1333 | 133 | intarget = config.load_config(pt_file) | ||
1334 | 134 | self.assertEqual(original, intarget) | ||
1335 | 135 | |||
1336 | 136 | def test_cloudinit_network_disabled(self): | ||
1337 | 137 | cc_disabled = 'cloud.cfg.d/curtin-disable-cloudinit-networking.cfg' | ||
1338 | 138 | |||
1339 | 139 | avail_str = self.load_collect_file('cloudinit_passthrough_available') | ||
1340 | 140 | available = int(avail_str) == 1 | ||
1341 | 141 | print('avail_str=%s available=%s' % (avail_str, available)) | ||
1342 | 142 | |||
1343 | 143 | if available: | ||
1344 | 144 | raise SkipTest('passthrough available on %s' % self.__class__) | ||
1345 | 145 | |||
1346 | 146 | print('passthrough not available') | ||
1347 | 147 | cc_disable_file = os.path.join(self.td.collect, 'etc_cloud', | ||
1348 | 148 | cc_disabled) | ||
1349 | 149 | print('checking if network:disable file written: %s' % | ||
1350 | 150 | cc_disable_file) | ||
1351 | 151 | self.assertTrue(os.path.exists(cc_disable_file)) | ||
1352 | 152 | |||
1353 | 153 | # compare | ||
1354 | 154 | original = {'network': {'config': 'disabled'}} | ||
1355 | 155 | intarget = config.load_config(cc_disable_file) | ||
1356 | 156 | |||
1357 | 157 | print('checking cloud-init network-cfg content') | ||
1358 | 158 | self.assertEqual(original, intarget) | ||
1359 | 55 | 159 | ||
1360 | 56 | def test_etc_resolvconf(self): | 160 | def test_etc_resolvconf(self): |
1362 | 57 | resolvconf = self.load_collect_file("resolv.conf") | 161 | render2resolvconf = { |
1363 | 162 | 'ifupdown': "resolv.conf", | ||
1364 | 163 | 'systemd-networkd': "run_systemd_resolve/resolv.conf" | ||
1365 | 164 | } | ||
1366 | 165 | resolvconfpath = render2resolvconf.get(self._network_renderer(), None) | ||
1367 | 166 | self.assertTrue(resolvconfpath is not None) | ||
1368 | 167 | logger.debug('Selected path to resolvconf: %s', resolvconfpath) | ||
1369 | 168 | |||
1370 | 169 | resolvconf = self.load_collect_file(resolvconfpath) | ||
1371 | 58 | logger.debug('etc/resolv.conf:\n{}'.format(resolvconf)) | 170 | logger.debug('etc/resolv.conf:\n{}'.format(resolvconf)) |
1372 | 59 | 171 | ||
1373 | 60 | resolv_lines = resolvconf.split('\n') | 172 | resolv_lines = resolvconf.split('\n') |
1374 | @@ -111,12 +223,21 @@ | |||
1375 | 111 | def test_static_routes(self): | 223 | def test_static_routes(self): |
1376 | 112 | '''check routing table''' | 224 | '''check routing table''' |
1377 | 113 | network_state = self.get_network_state() | 225 | network_state = self.get_network_state() |
1378 | 226 | |||
1379 | 227 | # if we're using passthrough then we can't load state | ||
1380 | 228 | cc_passthrough = "cloud.cfg.d/curtin-networking.cfg" | ||
1381 | 229 | pt_file = os.path.join(self.td.collect, 'etc_cloud', cc_passthrough) | ||
1382 | 230 | print('checking if passthrough file written: %s' % pt_file) | ||
1383 | 231 | if not network_state and os.path.exists(pt_file): | ||
1384 | 232 | raise SkipTest('passthrough enabled, skipping %s' % self.__class__) | ||
1385 | 233 | |||
1386 | 114 | ip_route_show = self.load_collect_file("ip_route_show") | 234 | ip_route_show = self.load_collect_file("ip_route_show") |
1387 | 115 | route_n = self.load_collect_file("route_n") | 235 | route_n = self.load_collect_file("route_n") |
1388 | 116 | 236 | ||
1389 | 117 | print("ip route show:\n%s" % ip_route_show) | 237 | print("ip route show:\n%s" % ip_route_show) |
1390 | 118 | print("route -n:\n%s" % route_n) | 238 | print("route -n:\n%s" % route_n) |
1392 | 119 | routes = network_state.get('routes') | 239 | routes = network_state.get('routes', []) |
1393 | 240 | print("found routes: [%s]" % routes) | ||
1394 | 120 | for route in routes: | 241 | for route in routes: |
1395 | 121 | print('Checking static route: %s' % route) | 242 | print('Checking static route: %s' % route) |
1396 | 122 | destnet = ( | 243 | destnet = ( |
1397 | @@ -144,6 +265,12 @@ | |||
1398 | 144 | print('parsed ip_a dict:\n{}'.format( | 265 | print('parsed ip_a dict:\n{}'.format( |
1399 | 145 | yaml.dump(ip_dict, default_flow_style=False, indent=4))) | 266 | yaml.dump(ip_dict, default_flow_style=False, indent=4))) |
1400 | 146 | 267 | ||
1401 | 268 | route_n = self.load_collect_file("route_n") | ||
1402 | 269 | logger.debug("route -n:\n{}".format(route_n)) | ||
1403 | 270 | |||
1404 | 271 | route_6_n = self.load_collect_file("route_6_n") | ||
1405 | 272 | logger.debug("route -6 -n:\n{}".format(route_6_n)) | ||
1406 | 273 | |||
1407 | 147 | ip_route_show = self.load_collect_file("ip_route_show") | 274 | ip_route_show = self.load_collect_file("ip_route_show") |
1408 | 148 | logger.debug("ip route show:\n{}".format(ip_route_show)) | 275 | logger.debug("ip route show:\n{}".format(ip_route_show)) |
1409 | 149 | for line in [line for line in ip_route_show.split('\n') | 276 | for line in [line for line in ip_route_show.split('\n') |
1410 | @@ -156,12 +283,6 @@ | |||
1411 | 156 | route_info = m.groupdict('') | 283 | route_info = m.groupdict('') |
1412 | 157 | logger.debug(route_info) | 284 | logger.debug(route_info) |
1413 | 158 | 285 | ||
1414 | 159 | route_n = self.load_collect_file("route_n") | ||
1415 | 160 | logger.debug("route -n:\n{}".format(route_n)) | ||
1416 | 161 | |||
1417 | 162 | route_6_n = self.load_collect_file("route_6_n") | ||
1418 | 163 | logger.debug("route -6 -n:\n{}".format(route_6_n)) | ||
1419 | 164 | |||
1420 | 165 | routes = { | 286 | routes = { |
1421 | 166 | '4': route_n, | 287 | '4': route_n, |
1422 | 167 | '6': route_6_n, | 288 | '6': route_6_n, |
1423 | @@ -170,9 +291,10 @@ | |||
1424 | 170 | for iface in interfaces.values(): | 291 | for iface in interfaces.values(): |
1425 | 171 | print("\nnetwork_state iface: %s" % ( | 292 | print("\nnetwork_state iface: %s" % ( |
1426 | 172 | yaml.dump(iface, default_flow_style=False, indent=4))) | 293 | yaml.dump(iface, default_flow_style=False, indent=4))) |
1427 | 294 | ipcfg = ip_dict.get(iface['name'], {}) | ||
1428 | 173 | self.check_interface(iface['name'], | 295 | self.check_interface(iface['name'], |
1429 | 174 | iface, | 296 | iface, |
1431 | 175 | ip_dict.get(iface['name']), | 297 | ipcfg, |
1432 | 176 | routes) | 298 | routes) |
1433 | 177 | 299 | ||
1434 | 178 | def check_interface(self, ifname, iface, ipcfg, routes): | 300 | def check_interface(self, ifname, iface, ipcfg, routes): |
1435 | @@ -182,8 +304,9 @@ | |||
1436 | 182 | # FIXME: remove check? | 304 | # FIXME: remove check? |
1437 | 183 | # initial check, do we have the correct iface ? | 305 | # initial check, do we have the correct iface ? |
1438 | 184 | print('ifname={}'.format(ifname)) | 306 | print('ifname={}'.format(ifname)) |
1439 | 307 | self.assertTrue(type(ipcfg) == dict, "%s is not dict" % (ipcfg)) | ||
1440 | 308 | print("ipcfg['interface']={}".format(ipcfg['interface'])) | ||
1441 | 185 | self.assertEqual(ifname, ipcfg['interface']) | 309 | self.assertEqual(ifname, ipcfg['interface']) |
1442 | 186 | print("ipcfg['interface']={}".format(ipcfg['interface'])) | ||
1443 | 187 | 310 | ||
1444 | 188 | # check physical interface attributes (skip bond members, macs change) | 311 | # check physical interface attributes (skip bond members, macs change) |
1445 | 189 | if iface['type'] in ['physical'] and 'bond-master' not in iface: | 312 | if iface['type'] in ['physical'] and 'bond-master' not in iface: |
1446 | 190 | 313 | ||
1447 | === modified file 'tests/vmtests/test_network_alias.py' | |||
1448 | --- tests/vmtests/test_network_alias.py 2017-04-26 16:14:04 +0000 | |||
1449 | +++ tests/vmtests/test_network_alias.py 2017-06-19 16:35:41 +0000 | |||
1450 | @@ -1,5 +1,6 @@ | |||
1451 | 1 | from .releases import base_vm_classes as relbase | 1 | from .releases import base_vm_classes as relbase |
1452 | 2 | from .test_network import TestNetworkBaseTestsAbs | 2 | from .test_network import TestNetworkBaseTestsAbs |
1453 | 3 | from unittest import SkipTest | ||
1454 | 3 | 4 | ||
1455 | 4 | 5 | ||
1456 | 5 | class TestNetworkAliasAbs(TestNetworkBaseTestsAbs): | 6 | class TestNetworkAliasAbs(TestNetworkBaseTestsAbs): |
1457 | @@ -7,6 +8,11 @@ | |||
1458 | 7 | """ | 8 | """ |
1459 | 8 | conf_file = "examples/tests/network_alias.yaml" | 9 | conf_file = "examples/tests/network_alias.yaml" |
1460 | 9 | 10 | ||
1461 | 11 | def test_etc_network_interfaces(self): | ||
1462 | 12 | reason = ("%s: cloud-init and curtin eni rendering" | ||
1463 | 13 | " differ" % (self.__class__)) | ||
1464 | 14 | raise SkipTest(reason) | ||
1465 | 15 | |||
1466 | 10 | 16 | ||
1467 | 11 | class PreciseHWETTestNetworkAlias(relbase.precise_hwe_t, TestNetworkAliasAbs): | 17 | class PreciseHWETTestNetworkAlias(relbase.precise_hwe_t, TestNetworkAliasAbs): |
1468 | 12 | # FIXME: off due to hang at test: Starting execute cloud user/final scripts | 18 | # FIXME: off due to hang at test: Starting execute cloud user/final scripts |
1469 | 13 | 19 | ||
1470 | === modified file 'tests/vmtests/test_network_bridging.py' | |||
1471 | --- tests/vmtests/test_network_bridging.py 2017-05-19 21:40:48 +0000 | |||
1472 | +++ tests/vmtests/test_network_bridging.py 2017-06-19 16:35:41 +0000 | |||
1473 | @@ -111,7 +111,6 @@ | |||
1474 | 111 | self.assertEqual('install ok installed', status) | 111 | self.assertEqual('install ok installed', status) |
1475 | 112 | 112 | ||
1476 | 113 | def test_bridge_params(self): | 113 | def test_bridge_params(self): |
1477 | 114 | """ Test if configure bridge params match values on the device """ | ||
1478 | 115 | 114 | ||
1479 | 116 | def _load_sysfs_bridge_data(): | 115 | def _load_sysfs_bridge_data(): |
1480 | 117 | sysfs_br0 = sysfs_to_dict(self.collect_path("sysfs_br0")) | 116 | sysfs_br0 = sysfs_to_dict(self.collect_path("sysfs_br0")) |
1481 | @@ -138,6 +137,7 @@ | |||
1482 | 138 | p not in bridge_params_uncheckable)] | 137 | p not in bridge_params_uncheckable)] |
1483 | 139 | 138 | ||
1484 | 140 | def _check_bridge_param(sysfs_vals, p, br): | 139 | def _check_bridge_param(sysfs_vals, p, br): |
1485 | 140 | print('Checking bridge %s param %s' % (br, p)) | ||
1486 | 141 | value = br.get(param) | 141 | value = br.get(param) |
1487 | 142 | if param in ['bridge_stp']: | 142 | if param in ['bridge_stp']: |
1488 | 143 | if value in ['off', '0']: | 143 | if value in ['off', '0']: |
1489 | @@ -146,25 +146,35 @@ | |||
1490 | 146 | value = 1 | 146 | value = 1 |
1491 | 147 | else: | 147 | else: |
1492 | 148 | print('bridge_stp not in known val list') | 148 | print('bridge_stp not in known val list') |
1493 | 149 | elif param in ['bridge_portprio']: | ||
1494 | 150 | if self._network_renderer() == "systemd-networkd": | ||
1495 | 151 | reason = ("%s: skip until lp#1668347" | ||
1496 | 152 | " is fixed" % self.__class__) | ||
1497 | 153 | logger.warn('Skipping: %s', reason) | ||
1498 | 154 | print(reason) | ||
1499 | 155 | return | ||
1500 | 149 | 156 | ||
1501 | 150 | print('key=%s value=%s' % (param, value)) | 157 | print('key=%s value=%s' % (param, value)) |
1502 | 151 | if type(value) == list: | 158 | if type(value) == list: |
1503 | 152 | for subval in value: | 159 | for subval in value: |
1504 | 153 | (port, pval) = subval.split(" ") | 160 | (port, pval) = subval.split(" ") |
1506 | 154 | print('key=%s port=%s pval=%s' % (param, port, pval)) | 161 | print('param=%s port=%s pval=%s' % (param, port, pval)) |
1507 | 155 | sys_file_val = _get_sysfs_value(sysfs_vals, br0['name'], | 162 | sys_file_val = _get_sysfs_value(sysfs_vals, br0['name'], |
1508 | 156 | param, port) | 163 | param, port) |
1509 | 157 | 164 | ||
1511 | 158 | self.assertEqual(int(pval), int(sys_file_val)) | 165 | msg = "Source cfg: %s=%s on port %s" % (param, value, port) |
1512 | 166 | self.assertEqual(int(pval), int(sys_file_val), msg) | ||
1513 | 159 | else: | 167 | else: |
1514 | 160 | sys_file_val = _get_sysfs_value(sysfs_vals, br0['name'], | 168 | sys_file_val = _get_sysfs_value(sysfs_vals, br0['name'], |
1515 | 161 | param, port=None) | 169 | param, port=None) |
1517 | 162 | self.assertEqual(int(value), int(sys_file_val)) | 170 | self.assertEqual(int(value), int(sys_file_val), |
1518 | 171 | "Source cfg: %s=%s" % (param, value)) | ||
1519 | 163 | 172 | ||
1520 | 164 | sysfs_vals = _load_sysfs_bridge_data() | 173 | sysfs_vals = _load_sysfs_bridge_data() |
1522 | 165 | print(sysfs_vals) | 174 | # print(sysfs_vals) |
1523 | 166 | br0 = _get_bridge_config() | 175 | br0 = _get_bridge_config() |
1524 | 167 | for param in _get_bridge_params(br0): | 176 | for param in _get_bridge_params(br0): |
1525 | 177 | print('Checking param %s' % param) | ||
1526 | 168 | _check_bridge_param(sysfs_vals, param, br0) | 178 | _check_bridge_param(sysfs_vals, param, br0) |
1527 | 169 | 179 | ||
1528 | 170 | 180 | ||
1529 | 171 | 181 | ||
1530 | === modified file 'tests/vmtests/test_network_ipv6_enisource.py' | |||
1531 | --- tests/vmtests/test_network_ipv6_enisource.py 2017-04-26 16:14:04 +0000 | |||
1532 | +++ tests/vmtests/test_network_ipv6_enisource.py 2017-06-19 16:35:41 +0000 | |||
1533 | @@ -1,10 +1,16 @@ | |||
1534 | 1 | from .releases import base_vm_classes as relbase | 1 | from .releases import base_vm_classes as relbase |
1535 | 2 | from .test_network_enisource import TestNetworkENISource | 2 | from .test_network_enisource import TestNetworkENISource |
1536 | 3 | 3 | ||
1537 | 4 | import unittest | ||
1538 | 5 | |||
1539 | 4 | 6 | ||
1540 | 5 | class TestNetworkIPV6ENISource(TestNetworkENISource): | 7 | class TestNetworkIPV6ENISource(TestNetworkENISource): |
1541 | 6 | conf_file = "examples/tests/network_source_ipv6.yaml" | 8 | conf_file = "examples/tests/network_source_ipv6.yaml" |
1542 | 7 | 9 | ||
1543 | 10 | @unittest.skip("FIXME: cloud-init.net needs update") | ||
1544 | 11 | def test_etc_network_interfaces(self): | ||
1545 | 12 | pass | ||
1546 | 13 | |||
1547 | 8 | 14 | ||
1548 | 9 | class PreciseTestNetworkIPV6ENISource(relbase.precise, | 15 | class PreciseTestNetworkIPV6ENISource(relbase.precise, |
1549 | 10 | TestNetworkIPV6ENISource): | 16 | TestNetworkIPV6ENISource): |
PASSED: Continuous integration, rev:466 /jenkins. ubuntu. com/server/ job/curtin- ci/526/ /jenkins. ubuntu. com/server/ job/curtin- ci/nodes= metal-amd64/ 526 /jenkins. ubuntu. com/server/ job/curtin- ci/nodes= metal-arm64/ 526 /jenkins. ubuntu. com/server/ job/curtin- ci/nodes= metal-ppc64el/ 526 /jenkins. ubuntu. com/server/ job/curtin- ci/nodes= metal-s390x/ 526 /jenkins. ubuntu. com/server/ job/curtin- ci/nodes= vm-i386/ 526
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild: /jenkins. ubuntu. com/server/ job/curtin- ci/526/ rebuild
https:/