Exemple #1
0
 def test_ip_cmdline_read_kernel_cmdline_ip6(self):
     content = {'net6-eno1.conf': DHCP6_CONTENT_1}
     populate_dir(self.tmp, content)
     files = [os.path.join(self.tmp, k) for k in content.keys()]
     found = cmdline.read_kernel_cmdline_config(
         files=files,
         cmdline='foo ip6=dhcp root=/dev/sda',
         mac_addrs=self.macs)
     self.assertEqual(
         found, {
             'version':
             1,
             'config': [{
                 'type':
                 'physical',
                 'name':
                 'eno1',
                 'mac_address':
                 self.macs['eno1'],
                 'subnets': [{
                     'dns_nameservers': ['2001:67c:1562:8010::2:1'],
                     'control': 'manual',
                     'type': 'dhcp6',
                     'netmask': '64'
                 }]
             }]
         })
Exemple #2
0
 def test_ip_cmdline_read_kernel_cmdline_none(self):
     # if there is no ip= or ip6= on cmdline, return value should be None
     content = {'net6-eno1.conf': DHCP6_CONTENT_1}
     files = sorted(populate_dir(self.tmp_dir(), content))
     found = cmdline.read_kernel_cmdline_config(
         files=files, cmdline='foo root=/dev/sda', mac_addrs=self.macs)
     self.assertEqual(found, None)
Exemple #3
0
 def test_ip_cmdline_read_kernel_cmdline_none(self):
     # if there is no ip= or ip6= on cmdline, return value should be None
     content = {'net6-eno1.conf': DHCP6_CONTENT_1}
     populate_dir(self.tmp, content)
     files = [os.path.join(self.tmp, k) for k in content.keys()]
     found = cmdline.read_kernel_cmdline_config(
         files=files, cmdline='foo root=/dev/sda', mac_addrs=self.macs)
     self.assertEqual(found, None)
Exemple #4
0
 def test_ip_cmdline_read_kernel_cmdline_ip(self):
     content = {'net-eth0.conf': DHCP_CONTENT_1}
     files = sorted(populate_dir(self.tmp_dir(), content))
     found = cmdline.read_kernel_cmdline_config(
         files=files, cmdline='foo ip=dhcp', mac_addrs=self.macs)
     exp1 = copy.deepcopy(DHCP_EXPECTED_1)
     exp1['mac_address'] = self.macs['eth0']
     self.assertEqual(found['version'], 1)
     self.assertEqual(found['config'], [exp1])
Exemple #5
0
 def test_ip_cmdline_read_kernel_cmdline_ip(self):
     content = {'net-eth0.conf': DHCP_CONTENT_1}
     populate_dir(self.tmp, content)
     files = [os.path.join(self.tmp, k) for k in content.keys()]
     found = cmdline.read_kernel_cmdline_config(
         files=files, cmdline='foo ip=dhcp', mac_addrs=self.macs)
     exp1 = copy.deepcopy(DHCP_EXPECTED_1)
     exp1['mac_address'] = self.macs['eth0']
     self.assertEqual(found['version'], 1)
     self.assertEqual(found['config'], [exp1])
Exemple #6
0
 def test_ip_cmdline_read_kernel_cmdline_ip6(self):
     content = {'net6-eno1.conf': DHCP6_CONTENT_1}
     populate_dir(self.tmp, content)
     files = [os.path.join(self.tmp, k) for k in content.keys()]
     found = cmdline.read_kernel_cmdline_config(
         files=files, cmdline='foo ip6=dhcp root=/dev/sda',
         mac_addrs=self.macs)
     self.assertEqual(
         found,
         {'version': 1, 'config': [
          {'type': 'physical', 'name': 'eno1',
           'mac_address': self.macs['eno1'],
           'subnets': [
               {'dns_nameservers': ['2001:67c:1562:8010::2:1'],
                'control': 'manual', 'type': 'dhcp6', 'netmask': '64'}]}]})
Exemple #7
0
    def test_ip_cmdline_both_ip_ip6(self):
        content = {'net-eth0.conf': DHCP_CONTENT_1,
                   'net6-eth0.conf': DHCP6_CONTENT_1.replace('eno1', 'eth0')}
        files = sorted(populate_dir(self.tmp_dir(), content))
        found = cmdline.read_kernel_cmdline_config(
            files=files, cmdline='foo ip=dhcp ip6=dhcp', mac_addrs=self.macs)

        eth0 = copy.deepcopy(DHCP_EXPECTED_1)
        eth0['mac_address'] = self.macs['eth0']
        eth0['subnets'].append(
            {'control': 'manual', 'type': 'dhcp6',
             'netmask': '64', 'dns_nameservers': ['2001:67c:1562:8010::2:1']})
        expected = [eth0]
        self.assertEqual(found['version'], 1)
        self.assertEqual(found['config'], expected)
Exemple #8
0
    def test_ip_cmdline_both_ip_ip6(self):
        content = {'net-eth0.conf': DHCP_CONTENT_1,
                   'net6-eth0.conf': DHCP6_CONTENT_1.replace('eno1', 'eth0')}
        populate_dir(self.tmp, content)
        files = [os.path.join(self.tmp, k) for k in sorted(content.keys())]
        found = cmdline.read_kernel_cmdline_config(
            files=files, cmdline='foo ip=dhcp ip6=dhcp', mac_addrs=self.macs)

        eth0 = copy.deepcopy(DHCP_EXPECTED_1)
        eth0['mac_address'] = self.macs['eth0']
        eth0['subnets'].append(
            {'control': 'manual', 'type': 'dhcp6',
             'netmask': '64', 'dns_nameservers': ['2001:67c:1562:8010::2:1']})
        expected = [eth0]
        self.assertEqual(found['version'], 1)
        self.assertEqual(found['config'], expected)
    def _find_networking_config(self):
        disable_file = os.path.join(
            self.paths.get_cpath("data"), "upgraded-network"
        )
        if os.path.exists(disable_file):
            return (None, disable_file)

        available_cfgs = {
            NetworkConfigSource.cmdline: cmdline.read_kernel_cmdline_config(),
            NetworkConfigSource.initramfs: cmdline.read_initramfs_config(),
            NetworkConfigSource.ds: None,
            NetworkConfigSource.system_cfg: self.cfg.get("network"),
        }

        if self.datasource and hasattr(self.datasource, "network_config"):
            available_cfgs[
                NetworkConfigSource.ds
            ] = self.datasource.network_config

        if self.datasource:
            order = self.datasource.network_config_sources
        else:
            order = sources.DataSource.network_config_sources
        for cfg_source in order:
            if not hasattr(NetworkConfigSource, cfg_source):
                LOG.warning(
                    "data source specifies an invalid network cfg_source: %s",
                    cfg_source,
                )
                continue
            if cfg_source not in available_cfgs:
                LOG.warning(
                    "data source specifies an unavailable network"
                    " cfg_source: %s",
                    cfg_source,
                )
                continue
            ncfg = available_cfgs[cfg_source]
            if net.is_disabled_cfg(ncfg):
                LOG.debug("network config disabled by %s", cfg_source)
                return (None, cfg_source)
            if ncfg:
                return (ncfg, cfg_source)
        return (
            self.distro.generate_fallback_config(),
            NetworkConfigSource.fallback,
        )
Exemple #10
0
    def _find_networking_config(self):
        disable_file = os.path.join(self.paths.get_cpath("data"),
                                    "upgraded-network")
        if os.path.exists(disable_file):
            return (None, disable_file)

        available_cfgs = {
            NetworkConfigSource.CMD_LINE: cmdline.read_kernel_cmdline_config(),
            NetworkConfigSource.INITRAMFS: cmdline.read_initramfs_config(),
            NetworkConfigSource.DS: None,
            NetworkConfigSource.SYSTEM_CFG: self.cfg.get("network"),
        }

        if self.datasource and hasattr(self.datasource, "network_config"):
            available_cfgs[
                NetworkConfigSource.DS] = self.datasource.network_config

        if self.datasource:
            order = self.datasource.network_config_sources
        else:
            order = sources.DataSource.network_config_sources
        for cfg_source in order:
            if not isinstance(cfg_source, NetworkConfigSource):
                LOG.warning(
                    "data source specifies an invalid network cfg_source: %s",
                    cfg_source,
                )
                continue
            if cfg_source not in available_cfgs:
                LOG.warning(
                    "data source specifies an unavailable network"
                    " cfg_source: %s",
                    cfg_source,
                )
                continue
            ncfg = self._remove_top_level_network_key(
                available_cfgs[cfg_source])
            if net.is_disabled_cfg(ncfg):
                LOG.debug("network config disabled by %s", cfg_source)
                return (None, cfg_source)
            if ncfg:
                return (ncfg, cfg_source)
        return (
            self.distro.generate_fallback_config(),
            NetworkConfigSource.FALLBACK,
        )
Exemple #11
0
    def network_config(self):
        """Network config is read from initramfs provided files
        If none is present, then we fall back to fallback configuration.

        One thing to note here is that this method is not currently
        considered at all if there is is kernel/initramfs provided
        data.  In that case, stages considers that the cmdline data
        overrides datasource provided data and does not consult here.

        We nonetheless return cmdline provided config if present
        and fallback to generate fallback."""
        if self._network_config == sources.UNSET:
            cmdline_cfg = cmdline.read_kernel_cmdline_config()
            if cmdline_cfg:
                self._network_config = cmdline_cfg
            else:
                self._network_config = self.distro.generate_fallback_config()
        return self._network_config
Exemple #12
0
    def _find_networking_config(self):
        disable_file = os.path.join(self.paths.get_cpath('data'),
                                    'upgraded-network')
        if os.path.exists(disable_file):
            return (None, disable_file)

        cmdline_cfg = ('cmdline', cmdline.read_kernel_cmdline_config())
        dscfg = ('ds', None)
        if self.datasource and hasattr(self.datasource, 'network_config'):
            dscfg = ('ds', self.datasource.network_config)
        sys_cfg = ('system_cfg', self.cfg.get('network'))

        for loc, ncfg in (cmdline_cfg, sys_cfg, dscfg):
            if net.is_disabled_cfg(ncfg):
                LOG.debug("network config disabled by %s", loc)
                return (None, loc)
            if ncfg:
                return (ncfg, loc)
        return (net.generate_fallback_config(), "fallback")
Exemple #13
0
    def _find_networking_config(self):
        disable_file = os.path.join(
            self.paths.get_cpath('data'), 'upgraded-network')
        if os.path.exists(disable_file):
            return (None, disable_file)

        cmdline_cfg = ('cmdline', cmdline.read_kernel_cmdline_config())
        dscfg = ('ds', None)
        if self.datasource and hasattr(self.datasource, 'network_config'):
            dscfg = ('ds', self.datasource.network_config)
        sys_cfg = ('system_cfg', self.cfg.get('network'))

        for loc, ncfg in (cmdline_cfg, sys_cfg, dscfg):
            if net.is_disabled_cfg(ncfg):
                LOG.debug("network config disabled by %s", loc)
                return (None, loc)
            if ncfg:
                return (ncfg, loc)
        return (net.generate_fallback_config(), "fallback")
Exemple #14
0
 def test_cmdline_with_b64_gz(self):
     data = _gzip_data(json.dumps(self.simple_cfg).encode())
     encoded_text = base64.b64encode(data).decode()
     raw_cmdline = 'ro network-config=' + encoded_text + ' root=foo'
     found = cmdline.read_kernel_cmdline_config(cmdline=raw_cmdline)
     self.assertEqual(found, self.simple_cfg)
Exemple #15
0
 def test_cmdline_with_b64_gz(self):
     data = _gzip_data(json.dumps(self.simple_cfg).encode())
     encoded_text = base64.b64encode(data).decode()
     raw_cmdline = 'ro network-config=' + encoded_text + ' root=foo'
     found = cmdline.read_kernel_cmdline_config(cmdline=raw_cmdline)
     self.assertEqual(found, self.simple_cfg)
Exemple #16
0
def _is_iscsi_root():
    return bool(cmdline.read_kernel_cmdline_config())