netplan pollutes /tmp with temporary directories

Bug #1767464 reported by Serapheim Dimitropoulos
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Netplan
Fix Released
Undecided
Unassigned

Bug Description

After running netplan a bunch of times I realized that it had created way too many directories in /tmp.

```
$ ls /tmp/ | grep netplan | head
netplan_00uzmp8z
netplan_011c9ofi
netplan_03xpdqj8
netplan_04s2svfx
netplan_07s073t8
netplan_07u8ii29
netplan__08g5ij8
netplan_08v9itfy
netplan_0c4o2erm
netplan_0cpstwx5
$ ls /tmp/ | grep netplan | wc -l
2056
```

It seems like every time that the netplan command is invoked regardless the operation it generates a directory like that:

```
$ ls /tmp/ | grep netplan | wc -l
2056
$ sudo netplan apply
$ ls /tmp/ | grep netplan | wc -l
2057
$ sudo netplan generate
$ ls /tmp/ | grep netplan | wc -l
2058
```

Looking at the source under netplan/netplan/configmanager.py, I found the places where we create and destroy the temporary directories:

```
class ConfigManager(object):

    def __init__(self, prefix="/", extra_files={}):
        self.prefix = prefix
        self.tempdir = tempfile.mkdtemp(prefix='netplan_')
    ...

    def cleanup(self):
        shutil.rmtree(self.tempdir)
...
```

Doing a quick test in my host with both Python2 and 3 it seems like shutil.rmtree does not get rid of the tempdir itself.

Even though the directories are empty, their existence can lead to problems.

Revision history for this message
Ryan Harper (raharper) wrote :

/tmp is going to get pruned by systemd-tempfiles but there's no reason to leave those around. There's some indirection going on where when the netplan cli loads, it's getting instances of all of the commands, but when apply or generate run, the try_config handler doesn't get to run, and subsequently the cleanup method is never called.

Revision history for this message
Ryan Harper (raharper) wrote :

I've put up a PR to address this.

https://github.com/CanonicalLtd/netplan/pull/23

Revision history for this message
Daniel Axtens (daxtens) wrote :

That has been merged, marking as Fix Committed.

Changed in netplan:
status: New → Fix Committed
Revision history for this message
Lukas Märdian (slyon) wrote :

This has been released as of 0.38 and a similar issue is currently being worked on in LP: #1959729

=> I'm marking this one "Fix released".

Changed in netplan:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.