netplan pollutes /tmp with temporary directories
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/
```
class ConfigManager(
def __init__(self, prefix="/", extra_files={}):
self.prefix = prefix
...
def cleanup(self):
...
```
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.
/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.