openwisp-controller
openwisp-controller copied to clipboard
[bug] Deleting VPN template does not delete VpnClient objects
How to replicate
- Open Django shell (in command line) and check the number of VpnClient objects using this query
VpnClient.objects.count() - Create a VPN server object with OpenVPN backend
- Create a VPN template for this VPN server
- Add the VPN template to a device
- Go to the VPN template page and delete the Template
- Open Django shell (in command line) and check the number of VpnClient objects using this query
VpnClient.objects.count()
Expected outcome The number of VpnClients is different in Step 1 and Step 6 should be same.
Actual outcome
The number of VpnClients is different in Step 1 and Step 6 (increased by one). It is because the deletion of VPN template didn't trigger deletion of related VpnClient objects (there is no direct relation).
I found that it is possible to have two different VPN templates for the same VPN server object. But, it is not possible to apply both the templates on the same device, as the JSONSchema generates the following error
There is a conflict with the specified templates. Invalid configuration triggered by "#/files", validator says:
I think we should discourage using different templates for the same VPN server object on the same device using validation (we can create a separate issue for this).
We should double check the working of the following code. I think, it is not getting triggered when the template object is deleted.
https://github.com/openwisp/openwisp-controller/blob/226442c47be5031e64033ae44c8b00aaf2623c68/openwisp_controller/config/base/config.py#L229-L275