Skip to content

Only create a tempdir when needed#564

Merged
slyon merged 1 commit intocanonical:mainfrom
Cellebyte:fix/configmanager
Dec 16, 2025
Merged

Only create a tempdir when needed#564
slyon merged 1 commit intocanonical:mainfrom
Cellebyte:fix/configmanager

Conversation

@Cellebyte
Copy link
Contributor

@Cellebyte Cellebyte commented Dec 15, 2025

Description

During early boot the configmanager needs to be initialized before /tmp is mounted.
This causes the __init__ of configmanager to fail.

I moved tempdir into a property and only create a directory when restore or backup is called.

Traceback (most recent call last):
  File "/usr/sbin/netplan", line 23, in <module>
    netplan.main()
  File "/usr/share/netplan/netplan_cli/cli/core.py", line 58, in main
    self.run_command()
  File "/usr/share/netplan/netplan_cli/cli/utils.py", line 332, in run_command
    self.func()
  File "/usr/share/netplan/netplan_cli/cli/commands/apply.py", line 62, in run
    self.run_command()
  File "/usr/share/netplan/netplan_cli/cli/utils.py", line 332, in run_command
    self.func()
  File "/usr/share/netplan/netplan_cli/cli/commands/apply.py", line 65, in command_apply
    config_manager = ConfigManager()
                     ^^^^^^^^^^^^^^^
  File "/usr/share/netplan/netplan_cli/configmanager.py", line 33, in __init__
    self.tempdir = tempfile.mkdtemp(prefix='netplan_')
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/tempfile.py", line 512, in mkdtemp
    prefix, suffix, dir, output_type = _sanitize_params(prefix, suffix, dir)
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/tempfile.py", line 265, in _sanitize_params
    dir = gettempdir()
          ^^^^^^^^^^^^
  File "/usr/lib/python3.12/tempfile.py", line 454, in gettempdir
    return _os.fsdecode(_gettempdir())
                        ^^^^^^^^^^^^^
  File "/usr/lib/python3.12/tempfile.py", line 447, in _gettempdir
    tempdir = _get_default_tempdir()
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/tempfile.py", line 362, in _get_default_tempdir
    raise FileNotFoundError(_errno.ENOENT,
FileNotFoundError: [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/']
Exception ignored in: <function ConfigManager.__del__ at 0x7de98f6af380>
Traceback (most recent call last):
  File "/usr/share/netplan/netplan_cli/configmanager.py", line 146, in __del__
    self.cleanup()
  File "/usr/share/netplan/netplan_cli/configmanager.py", line 142, in cleanup
    shutil.rmtree(self.tempdir)
                  ^^^^^^^^^^^^
  File "/usr/share/netplan/netplan_cli/configmanager.py", line 41, in __getattr__
    assert self.np_state is not None, "Must call parse() before accessing the config."
           ^^^^^^^^^^^^^
  File "/usr/share/netplan/netplan_cli/configmanager.py", line 41, in __getattr__
    assert self.np_state is not None, "Must call parse() before accessing the config."
           ^^^^^^^^^^^^^
  File "/usr/share/netplan/netplan_cli/configmanager.py", line 41, in __getattr__
    assert self.np_state is not None, "Must call parse() before accessing the config."
           ^^^^^^^^^^^^^
  [Previous line repeated 995 more times]
RecursionError: maximum recursion depth exceeded

Checklist

  • Runs make check successfully.
  • Retains code coverage (make check-coverage).
  • New/changed keys in YAML format are documented.
  • (Optional) Adds example YAML for new feature.
  • (Optional) Closes an open bug in Launchpad.

Copy link
Contributor

@slyon slyon left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, LGTM!

@slyon slyon merged commit b0fdccf into canonical:main Dec 16, 2025
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants