Add --config-file option to tempest cleanup command

As `--config-file` option exists in tempest run command, tempest cleanup command also needs the `--config-file` option.
Without the option, tempest cleanup command always run with default config path(/etc/tempest.conf).
This commit allows tempest cleanup command to run with the exact config file.

Closes-Bug: 2111889
Change-Id: I4fa889bd89aa62ceed080fc59f45320613739384
Signed-off-by: eunkyung <ek121.kim@samsung.com>
This commit is contained in:
Eunkyung99
2025-05-28 17:27:50 +09:00
parent cbb2eff6c7
commit f720d15bf1
3 changed files with 22 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
features:
- |
A new argument ``--config-file`` has been added to the
``tempest cleanup`` CLI to allow specifying a config file.
Without this argument, it will use the default configuration file.

View File

@@ -124,6 +124,7 @@ Runtime Arguments
complicated logic.
"""
import os
import sys
import traceback
@@ -148,7 +149,17 @@ class TempestCleanup(command.Command):
GOT_EXCEPTIONS = []
def _set_conf(self, config_file=None):
if config_file:
if os.path.exists(os.path.abspath(config_file)):
CONF.set_config_path(os.path.abspath(config_file))
else:
raise FileNotFoundError(
"Config file: %s doesn't exist" % config_file)
def take_action(self, parsed_args):
if parsed_args.config_file:
self._set_conf(parsed_args.config_file)
try:
self.init(parsed_args)
if not parsed_args.init_saved_state:
@@ -339,6 +350,8 @@ class TempestCleanup(command.Command):
"state - all resources present at that moment. "
"This option will be ignored if passed with "
"--prefix.")
parser.add_argument('--config-file', default=None, dest='config_file',
help='Configuration file to cleanup tempest with')
return parser
def get_description(self):

View File

@@ -56,8 +56,10 @@ class TestTempestCleanup(base.TestCase):
c.GOT_EXCEPTIONS.append('exception')
mock_cleanup.return_value = True
mock_init.return_value = True
parsed_args = mock.Mock()
parsed_args.config_file = []
try:
c.take_action(mock.Mock())
c.take_action(parsed_args)
except Exception as exc:
self.assertEqual(str(exc), '[\'exception\']')
return