Looks good.  Could we add unittests for distro using apply_network, including 
one without a _write_network so we can test that fallback logic?


Diff comments:

> 
> === modified file 'tests/unittests/test_net.py'
> --- tests/unittests/test_net.py       2016-06-15 23:11:24 +0000
> +++ tests/unittests/test_net.py       2016-07-14 02:45:33 +0000
> @@ -323,6 +634,53 @@
>          self.assertEqual(found, self.simple_cfg)
>  
>  
> +class TestEniRoundTrip(TestCase):

Nice!

> +    def setUp(self):
> +        super(TestCase, self).setUp()
> +        self.tmp_dir = tempfile.mkdtemp()
> +        self.addCleanup(shutil.rmtree, self.tmp_dir)
> +
> +    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 testsimple_convert_and_render(self):
> +        network_config = eni.convert_eni_data(EXAMPLE_ENI)
> +        files = self._render_and_read(network_config=network_config)
> +        self.assertEqual(
> +            RENDERED_ENI.splitlines(),
> +            files['/etc/network/interfaces'].splitlines())
> +
> +    def testsimple_render_all(self):
> +        entry = NETWORK_CONFIGS['all']
> +        files = 
> self._render_and_read(network_config=yaml.load(entry['yaml']))
> +        self.assertEqual(
> +            entry['expected_eni'].splitlines(),
> +            files['/etc/network/interfaces'].splitlines())
> +
> +    def testsimple_render_small(self):
> +        entry = NETWORK_CONFIGS['small']
> +        files = 
> self._render_and_read(network_config=yaml.load(entry['yaml']))
> +        self.assertEqual(
> +            entry['expected_eni'].splitlines(),
> +            files['/etc/network/interfaces'].splitlines())
> +
> +
>  def _gzip_data(data):
>      with io.BytesIO() as iobuf:
>          gzfp = gzip.GzipFile(mode="wb", fileobj=iobuf)


-- 
https://code.launchpad.net/~smoser/cloud-init/trunk.net-improve-lo-dns/+merge/298035
Your team cloud init development team is requested to review the proposed merge 
of lp:~smoser/cloud-init/trunk.net-improve-lo-dns into lp:cloud-init.

_______________________________________________
Mailing list: https://launchpad.net/~cloud-init-dev
Post to     : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to