Simplify validate_args_environment_dir
Make the method a function since it does not need the class properties. Use list comprehension, and a shorter more descriptive variable name. Change-Id: Ieda25ce82808276461c74944befa96faccd95301
This commit is contained in:
parent
f44c7e25ed
commit
bf03fe4a9c
|
@ -1528,8 +1528,7 @@ class TestArgumentValidation(fakes.TestDeployOvercloud):
|
|||
|
||||
app_args = mock.Mock()
|
||||
app_args.verbose_level = 1
|
||||
self.validate = overcloud_deploy.DeployOvercloud(
|
||||
self.app, app_args)._validate_args_environment_directory
|
||||
self.validate = overcloud_deploy._validate_args_environment_dir
|
||||
|
||||
def test_validate_env_dir(self):
|
||||
self.assertIsNone(self.validate(['/tmp/real_dir']))
|
||||
|
|
|
@ -43,6 +43,16 @@ from tripleoclient.workflows import parameters as workflow_params
|
|||
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):
|
||||
"""Deploy Overcloud"""
|
||||
|
||||
|
@ -406,21 +416,7 @@ class DeployOvercloud(command.Command):
|
|||
"used when using --baremetal-deployment")
|
||||
|
||||
if parsed_args.environment_directories:
|
||||
self._validate_args_environment_directory(
|
||||
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)))
|
||||
_validate_args_environment_dir(parsed_args.environment_directories)
|
||||
|
||||
def _provision_baremetal(self, parsed_args, tht_root):
|
||||
|
||||
|
|
Loading…
Reference in New Issue