Use cli-container-image-prepare.yaml playbook

Depends-On: https://review.opendev.org/#/c/746476/
Change-Id: Ic5b9c532fdfdadb4a34c54f05a03a334b69afec9
This commit is contained in:
Rabi Mishra 2020-08-17 12:26:30 +05:30
parent 094bbc657c
commit 8b41b26630
3 changed files with 46 additions and 53 deletions

View File

@ -44,7 +44,7 @@ STANDALONE_NETWORKS_FILE = "/dev/null"
UNDERCLOUD_NETWORKS_FILE = "network_data_undercloud.yaml"
ANSIBLE_HOSTS_FILENAME = "hosts.yaml"
ANSIBLE_CWL = "tripleo_dense,tripleo_profile_tasks,tripleo_states"
CONTAINER_IMAGE_PREPARE_LOG_FILE = "container_image_prepare.log"
# The name of the file which holds the plan environment contents
PLAN_ENVIRONMENT = 'plan-environment.yaml'
USER_ENVIRONMENT = 'user-environment.yaml'

View File

@ -773,7 +773,8 @@ class TestTripleoImagePrepare(TestPluginV1):
super(TestTripleoImagePrepare, self).setUp()
# Get the command object to test
self.cmd = container_image.TripleOImagePrepare(self.app, None)
self.cmd.app_args = mock.Mock()
self.cmd.app_args.verbose_level = 3
self.temp_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.temp_dir)
self.prepare_default_file = os.path.join(
@ -810,14 +811,10 @@ class TestTripleoImagePrepare(TestPluginV1):
with open(self.roles_data_file, 'w') as f:
f.write(self.roles_yaml)
@mock.patch('tripleo_common.utils.locks.processlock.'
'ProcessLock')
@mock.patch('tripleo_common.image.kolla_builder.'
'container_images_prepare_multi')
def test_tripleo_container_image_prepare(self, prepare_multi, mock_lock):
@mock.patch('tripleoclient.utils.run_ansible_playbook',
autospec=True)
def test_tripleo_container_image_prepare(self, mock_playbook):
mock_lockobj = mock.MagicMock()
mock_lock.return_value = mock_lockobj
env_file = os.path.join(self.temp_dir, 'containers_env.yaml')
arglist = [
@ -831,34 +828,21 @@ class TestTripleoImagePrepare(TestPluginV1):
'tripleo', 'container', 'image', 'prepare', 'default'
] + arglist
prepare_multi.return_value = {
'DockerAodhApiImage':
'192.0.2.0:8787/t/os-aodh-apifoo:passed-ci',
'DockerAodhConfigImage':
'192.0.2.0:8787/t/os-aodh-apifoo:passed-ci',
}
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
e_vars = {'roles_file': self.roles_data_file,
'environment_directories': [mock.ANY],
'environment_files': [self.temp_dir + '/prepare_env.yaml'],
'cleanup': 'full', 'dry_run': False,
'log_file': 'container_image_prepare.log', 'debug': True,
'output_env_file': self.temp_dir + '/containers_env.yaml'}
prepare_multi.assert_called_once_with(
self.default_env,
yaml.safe_load(self.roles_yaml),
dry_run=False,
cleanup='full',
lock=mock_lockobj)
with open(env_file) as f:
result = yaml.safe_load(f)
self.assertEqual({
'parameter_defaults': {
'DockerAodhApiImage':
'192.0.2.0:8787/t/os-aodh-apifoo:passed-ci',
'DockerAodhConfigImage':
'192.0.2.0:8787/t/os-aodh-apifoo:passed-ci',
}
}, result)
mock_playbook.assert_called_with(
extra_vars=e_vars,
inventory='localhost,',
playbook='cli-container-image-prepare.yaml',
playbook_dir='/usr/share/ansible/tripleo-playbooks',
verbosity=3, workdir=mock.ANY)
class TestTripleoImagePrepareDefault(TestPluginV1):

View File

@ -35,6 +35,7 @@ from tripleo_common.image.builder import buildah
from tripleo_common.image import image_uploader
from tripleo_common.image import kolla_builder
from tripleo_common.utils.locks import processlock
from tripleoclient import utils as oooutils
from tripleoclient import command
from tripleoclient import constants
@ -1037,6 +1038,14 @@ class TripleOImagePrepare(command.Command):
"images. 'partial' will leave images required for "
"deployment on this host. 'none' will do no cleanup.")
)
parser.add_argument(
"--log-file",
dest="log_file",
default=constants.CONTAINER_IMAGE_PREPARE_LOG_FILE,
help=_("Log file to be used for python logging. "
"By default it would be logged to "
"$HOME/container_image_prepare.log.")
)
return parser
def take_action(self, parsed_args):
@ -1045,25 +1054,25 @@ class TripleOImagePrepare(command.Command):
if parsed_args.cleanup not in image_uploader.CLEANUP:
raise oscexc.CommandError('--cleanup must be one of: %s' %
', '.join(image_uploader.CLEANUP))
extra_vars = {
"roles_file": parsed_args.roles_file,
"environment_directories": parsed_args.environment_directories,
"environment_files": parsed_args.environment_files,
"cleanup": parsed_args.cleanup,
"dry_run": parsed_args.dry_run,
"log_file": parsed_args.log_file}
roles_data = utils.fetch_roles_file(parsed_args.roles_file)
if self.app_args.verbose_level >= 3:
extra_vars["debug"] = True
env = utils.build_prepare_env(
parsed_args.environment_files,
parsed_args.environment_directories
)
lock = processlock.ProcessLock()
params = kolla_builder.container_images_prepare_multi(
env, roles_data, dry_run=parsed_args.dry_run,
cleanup=parsed_args.cleanup, lock=lock)
env_data = build_env_file(params, self.app.command_options)
if parsed_args.output_env_file:
if os.path.exists(parsed_args.output_env_file):
self.log.warning("Output env file exists, "
"moving it to backup.")
shutil.move(parsed_args.output_env_file,
parsed_args.output_env_file + ".backup")
utils.safe_write(parsed_args.output_env_file, env_data)
else:
self.app.stdout.write(env_data)
extra_vars["output_env_file"] = parsed_args.output_env_file
with oooutils.TempDirs() as tmp:
oooutils.run_ansible_playbook(
playbook='cli-container-image-prepare.yaml',
inventory='localhost,',
workdir=tmp,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=oooutils.playbook_verbosity(self=self),
extra_vars=extra_vars)