cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #01728
[Merge] ~smoser/cloud-init:render-network-state-change into cloud-init:master
Scott Moser has proposed merging ~smoser/cloud-init:render-network-state-change into cloud-init:master.
Commit message:
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.
Requested reviews:
cloud init development team (cloud-init-dev)
For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/320212
--
Your team cloud init development team is requested to review the proposed merge of ~smoser/cloud-init:render-network-state-change into cloud-init:master.
diff --git a/cloudinit/net/eni.py b/cloudinit/net/eni.py
index 5b249f1..5ed4cb1 100644
--- a/cloudinit/net/eni.py
+++ b/cloudinit/net/eni.py
@@ -444,14 +444,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))
@@ -461,7 +461,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 06de660..633371a 100644
--- a/cloudinit/net/sysconfig.py
+++ b/cloudinit/net/sysconfig.py
@@ -387,19 +387,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 5515335..337be66 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 8d25310..7123d41 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -689,7 +689,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:
@@ -717,7 +717,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())
@@ -746,7 +746,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')))
@@ -928,7 +928,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):
References