Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions cloudinit/net/netplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ def _clean_default(target=None):
os.unlink(f)


def netplan_api_write_yaml_file(net_config_content: str) -> bool:
def netplan_api_write_yaml_file(
net_config_content: str, target: Optional[str] = None
) -> bool:
"""Use netplan.State._write_yaml_file to write netplan config

Where netplan python API exists, prefer to use of the private
Expand Down Expand Up @@ -281,9 +283,11 @@ def netplan_api_write_yaml_file(net_config_content: str) -> bool:
# determine default root-dir /etc/netplan and/or specialized
# filenames or read permissions based on whether this config
# contains secrets.
state_output_file._write_yaml_file(
os.path.basename(CLOUDINIT_NETPLAN_FILE)
)
if not target:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good solution and correct assessment of the issue, though additionally tox's py3 virtual environment also doesn't have visibility to cleanly download netplan's python API, so unittest from within tox will not find the netplan python API even in environments which provide such an API. This is only exposed to external admin users running pytest directly and relying on python system packages.

file = os.path.basename(CLOUDINIT_NETPLAN_FILE)
else:
file = target
state_output_file._write_yaml_file(file)
except Exception as e:
LOG.warning(
"Unable to render network config using netplan python module."
Expand Down Expand Up @@ -392,7 +396,7 @@ def render_network_state(
content = header + content

netplan_config_changed = has_netplan_config_changed(fpnplan, content)
if not netplan_api_write_yaml_file(content):
if not netplan_api_write_yaml_file(content, target=fpnplan):
fallback_write_netplan_yaml(fpnplan, content)

if self.clean_default:
Expand Down
2 changes: 1 addition & 1 deletion packages/bddeb
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def main():
"release_suffix": get_release_suffix(args.release),
}

with temp_utils.tempdir() as tdir:
with temp_utils.tempdir(needs_exe=True) as tdir:

# output like 0.7.6-1022-g36e92d3
ver_data = read_version()
Expand Down