On delete category request, Delete category related files
@@ -1182,7 +1182,7 @@ class ConfigurationManager(ConfigurationManagerSingleton):
payload = PayloadBuilder().WHERE(["child", "=", cat]).payload()
result = await self._storage.delete_from_tbl("category_children", payload)
if result['response'] == 'deleted':
- _logger.info('Deleted parent in catgory_children: %s', cat)
+ _logger.info('Deleted parent in category_children: %s', cat)
# Remove category.
payload = PayloadBuilder().WHERE(["key", "=", cat]).payload()
@@ -1194,9 +1194,14 @@ class ConfigurationManager(ConfigurationManagerSingleton):
# FIXME: FOGL-2140
await audit.information('CONCH', audit_details)
+ # delete_category_script_files is a better name in today's context. But in future there can be more stuff
+ # related to the category; the definition of method should be extended as required
+ self.delete_category_related_things(cat)
+
# Remove cat from cache
if cat in self._cacheManager.cache:
self._cacheManager.remove(cat)
+
except KeyError as ex:
raise ValueError(ex)
except StorageServerError as ex:
@@ -1205,6 +1210,27 @@ class ConfigurationManager(ConfigurationManagerSingleton):
else:
return {cat: result}
+ def delete_category_related_things(self, category_name):
+ """ On delete category request
+
+ - Delete category related files
+
+ :param category_name:
+ :return:
+ """
+ import glob
+ uploaded_scripts_dir = '{}/data/scripts/'.format(_FOGLAMP_ROOT)
+ if _FOGLAMP_DATA:
+ uploaded_scripts_dir = '{}/scripts/'.format(_FOGLAMP_DATA)
+ files = "{}/{}*".format(uploaded_scripts_dir, category_name.lower())
+ try:
+ for f in glob.glob(files):
+ _logger.info("Removing file %s for category %s", f, category_name)
+ os.remove(f)
+ except Exception as ex:
+ _logger.error('Failed to delete file(s) for category %s. Exception %s', category_name, str(ex))
+ # raise ex
+
def register_interest(self, category_name, callback):
"""Registers an interest in any changes to the category_value associated with category_name
