summaryrefslogtreecommitdiff
path: root/ironic_python_agent/hardware.py
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-11-18 17:38:00 +0000
committerGerrit Code Review <review@openstack.org>2020-11-18 17:38:00 +0000
commit4762aca0779af8a256170d97abe1dd3a91d5bea0 (patch)
treee93f9e7623f512829df51a0c83d440a75228f10d /ironic_python_agent/hardware.py
parent3761a448009467dd342bc0cb3ca3b182969def42 (diff)
parent92e26b01e97418f3f491216eb193124703befd3d (diff)
downloadironic-python-agent-4762aca0779af8a256170d97abe1dd3a91d5bea0.tar.gz
Merge "Add clean step 'erase_pstore'"
Diffstat (limited to 'ironic_python_agent/hardware.py')
-rw-r--r--ironic_python_agent/hardware.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py
index ecc9fba2..cb8e34fc 100644
--- a/ironic_python_agent/hardware.py
+++ b/ironic_python_agent/hardware.py
@@ -22,6 +22,7 @@ from multiprocessing.pool import ThreadPool
import os
import re
import shlex
+import shutil
import time
from ironic_lib import disk_utils
@@ -1318,6 +1319,37 @@ class GenericHardwareManager(HardwareManager):
for k, v in erase_errors.items()]))
raise errors.BlockDeviceEraseError(excpt_msg)
+ def _find_pstore_mount_point(self):
+ """Find the pstore mount point by scanning /proc/mounts.
+
+ :returns: The pstore mount if existing, none otherwise.
+ """
+ with open("/proc/mounts", "r") as mounts:
+ for line in mounts:
+ # /proc/mounts format is: "device mountpoint fstype ..."
+ m = re.match(r'^pstore (\S+) pstore', line)
+ if m:
+ return m.group(1)
+
+ def erase_pstore(self, node, ports):
+ """Attempt to erase the kernel pstore.
+
+ :param node: Ironic node object
+ :param ports: list of Ironic port objects
+ """
+ pstore_path = self._find_pstore_mount_point()
+ if not pstore_path:
+ LOG.debug("No pstore found")
+ return
+
+ LOG.info("Cleaning up pstore in %s", pstore_path)
+ for file in os.listdir(pstore_path):
+ filepath = os.path.join(pstore_path, file)
+ try:
+ shutil.rmtree(filepath)
+ except OSError:
+ os.remove(filepath)
+
def _shred_block_device(self, node, block_device):
"""Erase a block device using shred.
@@ -1685,6 +1717,13 @@ class GenericHardwareManager(HardwareManager):
'abortable': True
},
{
+ 'step': 'erase_pstore',
+ 'priority': 0,
+ 'interface': 'deploy',
+ 'reboot_requested': False,
+ 'abortable': True
+ },
+ {
'step': 'delete_configuration',
'priority': 0,
'interface': 'raid',