Mechanism to cleanup all ImageCaches¶
This spec talks about creating a mechanism to cleanup all the image caches (leveraging most of the code that is already in pxe driver)
The cleanup method for cleaning up ImageCache (or its subclasses)
_cleanup_caches_if_required is situated inside pxe driver. Hence, any
other subclass of ImageCache situated in any other file, cannot use this
This code was introduced in this commit: https://review.openstack.org/#/c/92625
The reason why the cleanup method is placed in pxe driver is because it needs
to know other subclasses of ImageCache to do efficient cleaning to make up for
the required space in the cache. Other ImageCaches which are situated in the
same filesystem are also cleaned up if enough space is not available after
cleaning up the current cache. This method hardcodes
TFTPImageCache to be cleaned up for any cache cleanup.
The problem could be solved as follows:
Each of the subclasses of ImageCache that wishes to be used in cleanup of other caches (currently
TFTPImageCache) add a decorator
@image_cache.cleanup(priority=N). N should be a positive integer which signifies the priority in which the cache should be cleaned up when extra free space is required after cleaning up the provided cache. Higher value of N means higher priority. If two caches have same value of N (probably at different places in code), then the order of cleanup of those two caches is not predictable (it will depend on which of the two module is loaded first).
InstanceImageCachebeing large, should be cleaned up before
TFTPImageCache. Hence they will have it as below:
@image_cache.cleanup(priority=50) class InstanceImageCache(...) ... @image_cache.cleanup(priority=25) class TFTPImageCache(...) ...
There would be list
cache_cleanup_listin image_cache.py which would contain a sorted list of instances of
ImageCacheto be considered for cleanup. The decorator function
cleanupadds an instance of the subclass of
ImageCacheinto list. This list will be kept sorted in non-increasing order of
priorityafter adding the entry.
_cleanup_caches_if_requiredwill be moved to ironic.common.image_cache and renamed to
clean_up_caches. The method
_cleanup_caches_if_requiredcurrently uses a hardcoded list of caches to be cleaned for extra space. Instead of that, the newly proposed method will just use the list
PXEImageCachewill not have decorator
The code to cleanup can continue to exist in the pxe driver and pxe driver can import and maintain the hardcoded list of all the caches across the source tree. This is hard to maintain and not logical.
Another alternative is that the method can be moved to a common place, but the cleanup may be initiated on the caches that the module would know about. This would not be as efficient as the proposed solution, as proposed solution can consider more caches for cleaning up and making up the required space.
Data model impact¶
REST API impact¶
Driver API impact¶
Nova driver impact¶
Other end user impact¶
Other deployer impact¶
Developers wishing to introduce a new subclass of
ImageCachecan add the decorator
@image_cache.cleanupand assign an
priorityin interest of overall ironic.
The subclass of ImageCache that wishes to be cleaned up should not take any parameters in the constructor.
_cleanup_caches_if_requiredfrom ironic.drivers.modules.pxe to ironic.common.image_cache.
Modify the unit tests for fetch_images() method in ironic.tests.drivers.test_pxe
Currently existing unit tests will be modified in accordance with the proposed behavior.