Beispiel #1
0
    def test_default_generation(self, mock_get_devicelist,
                                mock_sys_netdev_info, mock_sys_dev_path):
        tmp_dir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, tmp_dir)
        _setup_test(tmp_dir, mock_get_devicelist, mock_sys_netdev_info,
                    mock_sys_dev_path)

        network_cfg = net.generate_fallback_config()
        ns = network_state.parse_net_config_data(network_cfg,
                                                 skip_broken=False)

        render_dir = os.path.join(tmp_dir, "render")
        os.makedirs(render_dir)

        renderer = eni.Renderer({
            'links_path_prefix': None,
            'eni_path': 'interfaces',
            'netrules_path': None,
        })
        renderer.render_network_state(render_dir, ns)

        self.assertTrue(os.path.exists(os.path.join(render_dir, 'interfaces')))
        with open(os.path.join(render_dir, 'interfaces')) as fh:
            contents = fh.read()

        expected = """
auto lo
iface lo inet loopback

auto eth1000
iface eth1000 inet dhcp
"""
        self.assertEqual(expected.lstrip(), contents.lstrip())
Beispiel #2
0
    def _render_and_read(self,
                         network_config=None,
                         state=None,
                         eni_path=None,
                         links_prefix=None,
                         netrules_path=None):
        if network_config:
            ns = network_state.parse_net_config_data(network_config)
        elif state:
            ns = state
        else:
            raise ValueError("Expected data or state, got neither")

        if eni_path is None:
            eni_path = 'etc/network/interfaces'

        renderer = eni.Renderer(
            config={
                'eni_path': eni_path,
                'links_path_prefix': links_prefix,
                'netrules_path': netrules_path
            })

        renderer.render_network_state(self.tmp_dir, ns)
        return dir2dict(self.tmp_dir)
    def test_bond_conversion(self):
        # light testing of bond conversion and eni rendering of bond
        ncfg = openstack.convert_net_json(NETWORK_DATA_BOND,
                                          known_macs=KNOWN_MACS)
        eni_renderer = eni.Renderer()

        eni_renderer.render_network_state(
            network_state.parse_net_config_data(ncfg), target=self.tmp)
        with open(os.path.join(self.tmp, "etc", "network", "interfaces"),
                  'r') as f:
            eni_rendering = f.read()

        # Verify there are expected interfaces in the net config.
        interfaces = sorted([
            i['name'] for i in ncfg['config']
            if i['type'] in ('vlan', 'bond', 'physical')
        ])
        self.assertEqual(
            sorted(["oeth0", "oeth1", "bond0", "bond0.602", "bond0.612"]),
            interfaces)

        words = eni_rendering.split()
        # 'eth0' and 'eth1' are the ids. because their mac adresses
        # map to other names, we should not see them in the ENI
        self.assertNotIn('eth0', words)
        self.assertNotIn('eth1', words)

        # oeth0 and oeth1 are the interface names for eni.
        # bond0 will be generated for the bond. Each should be auto.
        self.assertIn("auto oeth0", eni_rendering)
        self.assertIn("auto oeth1", eni_rendering)
        self.assertIn("auto bond0", eni_rendering)
Beispiel #4
0
 def __init__(self, name, cfg, paths):
     distros.Distro.__init__(self, name, cfg, paths)
     # This will be used to restrict certain
     # calls from repeatly happening (when they
     # should only happen say once per instance...)
     self._runner = helpers.Runners(paths)
     self.osfamily = 'debian'
     self._net_renderer = eni.Renderer({
         'eni_path': self.network_conf_fn,
         'eni_header': ENI_HEADER,
         'links_path_prefix': None,
         'netrules_path': None,
     })
    def test_vlan(self):
        # light testing of vlan config conversion and eni rendering
        ncfg = openstack.convert_net_json(NETWORK_DATA_VLAN,
                                          known_macs=KNOWN_MACS)
        eni_renderer = eni.Renderer()
        eni_renderer.render_network_state(
            network_state.parse_net_config_data(ncfg), target=self.tmp)
        with open(os.path.join(self.tmp, "etc",
                               "network", "interfaces"), 'r') as f:
            eni_rendering = f.read()

        self.assertIn("iface enp0s1", eni_rendering)
        self.assertIn("address 10.0.1.5", eni_rendering)
        self.assertIn("auto enp0s1.602", eni_rendering)
Beispiel #6
0
    def test_config_with_explicit_loopback(self):
        tmp_dir = self.tmp_dir()
        ns = network_state.parse_net_config_data(CONFIG_V1_EXPLICIT_LOOPBACK)
        renderer = eni.Renderer()
        renderer.render_network_state(ns, tmp_dir)
        expected = """\
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
"""
        self.assertEqual(expected,
                         dir2dict(tmp_dir)['/etc/network/interfaces'])
 def test_conversion_with_route(self):
     ncfg = openstack.convert_net_json(NETWORK_DATA_2,
                                       known_macs=KNOWN_MACS)
     # not the best test, but see that we get a route in the
     # network config and that it gets rendered to an ENI file
     routes = []
     for n in ncfg['config']:
         for s in n.get('subnets', []):
             routes.extend(s.get('routes', []))
     self.assertIn(
         {'network': '0.0.0.0', 'netmask': '0.0.0.0', 'gateway': '2.2.2.9'},
         routes)
     eni_renderer = eni.Renderer()
     eni_renderer.render_network_state(
         network_state.parse_net_config_data(ncfg), target=self.tmp)
     with open(os.path.join(self.tmp, "etc",
                            "network", "interfaces"), 'r') as f:
         eni_rendering = f.read()
         self.assertIn("route add default gw 2.2.2.9", eni_rendering)