~curtin-dev/curtin/bionic

« back to all changes in this revision

Viewing changes to curtin/commands/apply_net.py

  • Committer: Scott Moser
  • Date: 2017-08-03 19:51:16 UTC
  • mfrom: (1.1.50)
  • Revision ID: smoser@ubuntu.com-20170803195116-0xc6onji18peerm5
* New upstream snapshot.
  - tests: Add CiTestCase common parent for all curtin tests.
  - vmtests: Remove force flag for centos curthooks
  - tools/jenkins-runner: improve tgtd cleanup logic
  - tests: Drop EOL Wily Vivid and Yakkety tests.
  - Disable yum plugins when installing packages, update ca-certs for https
  - Rename centos_network_curthooks -> centos_apply_network_config.
  - tests: in centos_defaults use write_files for grub serial.
  - write_files: write files after extract, change write_files signature.
  - pass network configuration through to target for ubuntu and centos
  - tests: disable yakkety tests.
  - tools/launch: automatically pass on proxy settings to curtin
  - Add top level 'proxy' to config, deprecate top level http_proxy.
  - tools/curtainer: fix to enable deb-src for -proposed.
  - Use unshare to put chroot commands in own pid namespace.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from .. import log
22
22
import curtin.net as net
23
23
import curtin.util as util
 
24
from curtin import config
24
25
from . import populate_one_subcmd
25
26
 
26
27
 
89
90
        sys.stderr.write(msg + "\n")
90
91
        raise Exception(msg)
91
92
 
 
93
    passthrough = False
92
94
    if network_state:
 
95
        # NB: we cannot support passthrough until curtin can convert from
 
96
        # network_state to network-config yaml
93
97
        ns = net.network_state.from_state_file(network_state)
 
98
        raise ValueError('Not Supported; curtin lacks a network_state to '
 
99
                         'network_config converter.')
94
100
    elif network_config:
95
 
        ns = net.parse_net_config(network_config)
96
 
 
97
 
    net.render_network_state(target=target, network_state=ns)
 
101
        netcfg = config.load_config(network_config)
 
102
 
 
103
        # curtin will pass-through the netconfig into the target
 
104
        # for rendering at runtime unless the target OS does not
 
105
        # support NETWORK_CONFIG_V2 feature.
 
106
        LOG.info('Checking cloud-init in target [%s] for network '
 
107
                 'configuration passthrough support.', target)
 
108
        try:
 
109
            passthrough = net.netconfig_passthrough_available(target)
 
110
        except util.ProcessExecutionError:
 
111
            LOG.warning('Failed to determine if passthrough is available')
 
112
 
 
113
        if passthrough:
 
114
            LOG.info('Passing network configuration through to target: %s',
 
115
                     target)
 
116
            net.render_netconfig_passthrough(target, netconfig=netcfg)
 
117
        else:
 
118
            ns = net.parse_net_config_data(netcfg.get('network', {}))
 
119
 
 
120
    if not passthrough:
 
121
        LOG.info('Rendering network configuration in target')
 
122
        net.render_network_state(target=target, network_state=ns)
98
123
 
99
124
    _maybe_remove_legacy_eth0(target)
100
 
    LOG.info('Attempting to remove ipv6 privacy extensions')
101
125
    _disable_ipv6_privacy_extensions(target)
102
126
    _patch_ifupdown_ipv6_mtu_hook(target)
103
127
 
130
154
       by default; this races with the cloud-image desire to disable them.
131
155
       Resolve this by allowing the cloud-image setting to win. """
132
156
 
 
157
    LOG.debug('Attempting to remove ipv6 privacy extensions')
133
158
    cfg = util.target_path(target, path=path)
134
159
    if not os.path.exists(cfg):
135
160
        LOG.warn('Failed to find ipv6 privacy conf file %s', cfg)
143
168
        lines = [f.strip() for f in contents.splitlines()
144
169
                 if not f.startswith("#")]
145
170
        if lines == known_contents:
146
 
            LOG.info('deleting file: %s', cfg)
 
171
            LOG.info('Removing ipv6 privacy extension config file: %s', cfg)
147
172
            util.del_file(cfg)
148
173
            msg = "removed %s with known contents" % cfg
149
174
            curtin_contents = '\n'.join(
153
178
                 "# net.ipv6.conf.default.use_tempaddr = 2"])
154
179
            util.write_file(cfg, curtin_contents)
155
180
        else:
156
 
            LOG.info('skipping, content didnt match')
157
 
            LOG.debug("found content:\n%s", lines)
158
 
            LOG.debug("expected contents:\n%s", known_contents)
 
181
            LOG.debug('skipping removal of %s, expected content not found',
 
182
                      cfg)
 
183
            LOG.debug("Found content in file %s:\n%s", cfg, lines)
 
184
            LOG.debug("Expected contents in file %s:\n%s", cfg, known_contents)
159
185
            msg = (bmsg + " '%s' exists with user configured content." % cfg)
160
186
    except Exception as e:
161
187
        msg = bmsg + " %s exists, but could not be read. %s" % (cfg, e)