Merge "Simplify validate_args_environment_dir"

This commit is contained in:
Zuul 2021-06-11 08:49:37 +00:00 committed by Gerrit Code Review
commit 1627680daf
2 changed files with 12 additions and 17 deletions

View File

@ -1528,8 +1528,7 @@ class TestArgumentValidation(fakes.TestDeployOvercloud):
app_args = mock.Mock() app_args = mock.Mock()
app_args.verbose_level = 1 app_args.verbose_level = 1
self.validate = overcloud_deploy.DeployOvercloud( self.validate = overcloud_deploy._validate_args_environment_dir
self.app, app_args)._validate_args_environment_directory
def test_validate_env_dir(self): def test_validate_env_dir(self):
self.assertIsNone(self.validate(['/tmp/real_dir'])) self.assertIsNone(self.validate(['/tmp/real_dir']))

View File

@ -43,6 +43,16 @@ from tripleoclient.workflows import parameters as workflow_params
CONF = cfg.CONF CONF = cfg.CONF
def _validate_args_environment_dir(dirs):
default = os.path.expanduser(constants.DEFAULT_ENV_DIRECTORY)
not_found = [d for d in dirs if not os.path.isdir(d) and d != default]
if not_found:
raise oscexc.CommandError(
"Error: The following environment directories were not found"
": {0}".format(", ".join(not_found)))
class DeployOvercloud(command.Command): class DeployOvercloud(command.Command):
"""Deploy Overcloud""" """Deploy Overcloud"""
@ -406,21 +416,7 @@ class DeployOvercloud(command.Command):
"used when using --baremetal-deployment") "used when using --baremetal-deployment")
if parsed_args.environment_directories: if parsed_args.environment_directories:
self._validate_args_environment_directory( _validate_args_environment_dir(parsed_args.environment_directories)
parsed_args.environment_directories)
def _validate_args_environment_directory(self, directories):
default = os.path.expanduser(constants.DEFAULT_ENV_DIRECTORY)
nonexisting_dirs = []
for d in directories:
if not os.path.isdir(d) and d != default:
nonexisting_dirs.append(d)
if nonexisting_dirs:
raise oscexc.CommandError(
"Error: The following environment directories were not found"
": {0}".format(", ".join(nonexisting_dirs)))
def _provision_baremetal(self, parsed_args, tht_root): def _provision_baremetal(self, parsed_args, tht_root):