summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-03-16 14:30:15 -0400
committerScott Moser <smoser@brickies.net>2017-03-17 14:41:50 -0400
commita33447344eed897010603b3e8ea1fd122052de76 (patch)
treef155a381238e06fcb412d488951fc3a72c19f455
parent1a2ca7530518d819cbab7287b12f942743427e38 (diff)
downloadvyos-cloud-init-a33447344eed897010603b3e8ea1fd122052de76.tar.gz
vyos-cloud-init-a33447344eed897010603b3e8ea1fd122052de76.zip
render_network_state: switch arguments around, do not require target
render_network_state should default to rendering on /. The changes here just make it so render_network_state does not require a target, but defaults to None, and uses target_path to handle that.
-rw-r--r--cloudinit/net/eni.py8
-rw-r--r--cloudinit/net/sysconfig.py8
-rw-r--r--tests/unittests/test_datasource/test_configdrive.py7
-rw-r--r--tests/unittests/test_net.py12
4 files changed, 18 insertions, 17 deletions
diff --git a/cloudinit/net/eni.py b/cloudinit/net/eni.py
index 69ecbb5d..efa034bf 100644
--- a/cloudinit/net/eni.py
+++ b/cloudinit/net/eni.py
@@ -448,14 +448,14 @@ class Renderer(renderer.Renderer):
return '\n\n'.join(['\n'.join(s) for s in sections]) + "\n"
- def render_network_state(self, target, network_state):
- fpeni = os.path.join(target, self.eni_path)
+ def render_network_state(self, network_state, target=None):
+ fpeni = util.target_path(target, self.eni_path)
util.ensure_dir(os.path.dirname(fpeni))
header = self.eni_header if self.eni_header else ""
util.write_file(fpeni, header + self._render_interfaces(network_state))
if self.netrules_path:
- netrules = os.path.join(target, self.netrules_path)
+ netrules = util.target_path(target, self.netrules_path)
util.ensure_dir(os.path.dirname(netrules))
util.write_file(netrules,
self._render_persistent_net(network_state))
@@ -465,7 +465,7 @@ class Renderer(renderer.Renderer):
links_prefix=self.links_path_prefix)
def _render_systemd_links(self, target, network_state, links_prefix):
- fp_prefix = os.path.join(target, links_prefix)
+ fp_prefix = util.target_path(target, links_prefix)
for f in glob.glob(fp_prefix + "*"):
os.unlink(f)
for iface in network_state.iter_interfaces():
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
index 7f52db4a..4eeaaa8a 100644
--- a/cloudinit/net/sysconfig.py
+++ b/cloudinit/net/sysconfig.py
@@ -389,19 +389,19 @@ class Renderer(renderer.Renderer):
contents[iface_cfg.routes.path] = iface_cfg.routes.to_string()
return contents
- def render_network_state(self, target, network_state):
- base_sysconf_dir = os.path.join(target, self.sysconf_dir)
+ def render_network_state(self, network_state, target=None):
+ base_sysconf_dir = util.target_path(target, self.sysconf_dir)
for path, data in self._render_sysconfig(base_sysconf_dir,
network_state).items():
util.write_file(path, data)
if self.dns_path:
- dns_path = os.path.join(target, self.dns_path)
+ dns_path = util.target_path(target, self.dns_path)
resolv_content = self._render_dns(network_state,
existing_dns_path=dns_path)
util.write_file(dns_path, resolv_content)
if self.netrules_path:
netrules_content = self._render_persistent_net(network_state)
- netrules_path = os.path.join(target, self.netrules_path)
+ netrules_path = util.target_path(target, self.netrules_path)
util.write_file(netrules_path, netrules_content)
# vi: ts=4 expandtab
diff --git a/tests/unittests/test_datasource/test_configdrive.py b/tests/unittests/test_datasource/test_configdrive.py
index 55153357..337be667 100644
--- a/tests/unittests/test_datasource/test_configdrive.py
+++ b/tests/unittests/test_datasource/test_configdrive.py
@@ -645,7 +645,7 @@ class TestConvertNetworkData(TestCase):
routes)
eni_renderer = eni.Renderer()
eni_renderer.render_network_state(
- self.tmp, network_state.parse_net_config_data(ncfg))
+ network_state.parse_net_config_data(ncfg), self.tmp)
with open(os.path.join(self.tmp, "etc",
"network", "interfaces"), 'r') as f:
eni_rendering = f.read()
@@ -665,8 +665,9 @@ class TestConvertNetworkData(TestCase):
ncfg = openstack.convert_net_json(NETWORK_DATA_BOND,
known_macs=KNOWN_MACS)
eni_renderer = eni.Renderer()
+
eni_renderer.render_network_state(
- self.tmp, network_state.parse_net_config_data(ncfg))
+ network_state.parse_net_config_data(ncfg), self.tmp)
with open(os.path.join(self.tmp, "etc",
"network", "interfaces"), 'r') as f:
eni_rendering = f.read()
@@ -697,7 +698,7 @@ class TestConvertNetworkData(TestCase):
known_macs=KNOWN_MACS)
eni_renderer = eni.Renderer()
eni_renderer.render_network_state(
- self.tmp, network_state.parse_net_config_data(ncfg))
+ network_state.parse_net_config_data(ncfg), self.tmp)
with open(os.path.join(self.tmp, "etc",
"network", "interfaces"), 'r') as f:
eni_rendering = f.read()
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index c6535e1c..dca44b37 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -697,7 +697,7 @@ class TestSysConfigRendering(CiTestCase):
os.makedirs(render_dir)
renderer = sysconfig.Renderer()
- renderer.render_network_state(render_dir, ns)
+ renderer.render_network_state(ns, render_dir)
render_file = 'etc/sysconfig/network-scripts/ifcfg-eth1000'
with open(os.path.join(render_dir, render_file)) as fh:
@@ -725,7 +725,7 @@ USERCTL=no
ns = network_state.parse_net_config_data(network_cfg,
skip_broken=False)
renderer = sysconfig.Renderer()
- renderer.render_network_state(render_dir, ns)
+ renderer.render_network_state(ns, render_dir)
for fn, expected_content in os_sample.get('out_sysconfig', []):
with open(os.path.join(render_dir, fn)) as fh:
self.assertEqual(expected_content, fh.read())
@@ -735,7 +735,7 @@ USERCTL=no
render_dir = self.tmp_path("render")
os.makedirs(render_dir)
renderer = sysconfig.Renderer()
- renderer.render_network_state(render_dir, ns)
+ renderer.render_network_state(ns, render_dir)
found = dir2dict(render_dir)
nspath = '/etc/sysconfig/network-scripts/'
self.assertNotIn(nspath + 'ifcfg-lo', found.keys())
@@ -775,7 +775,7 @@ class TestEniNetRendering(CiTestCase):
{'links_path_prefix': None,
'eni_path': 'interfaces', 'netrules_path': None,
})
- renderer.render_network_state(render_dir, ns)
+ renderer.render_network_state(ns, render_dir)
self.assertTrue(os.path.exists(os.path.join(render_dir,
'interfaces')))
@@ -795,7 +795,7 @@ iface eth1000 inet dhcp
tmp_dir = self.tmp_dir()
ns = network_state.parse_net_config_data(CONFIG_V1_EXPLICIT_LOOPBACK)
renderer = eni.Renderer()
- renderer.render_network_state(tmp_dir, ns)
+ renderer.render_network_state(ns, tmp_dir)
expected = """\
auto lo
iface lo inet loopback
@@ -972,7 +972,7 @@ class TestEniRoundTrip(CiTestCase):
config={'eni_path': eni_path, 'links_path_prefix': links_prefix,
'netrules_path': netrules_path})
- renderer.render_network_state(dir, ns)
+ renderer.render_network_state(ns, dir)
return dir2dict(dir)
def testsimple_convert_and_render(self):