Generate undercloud_parameters in output_dir

Help undercloud_parameters.yaml to find way out
of /tmp box.

Move write_env_file into tripleoclient utils for
better unit testing.

Change-Id: Ibe4e1d8f683a02d55fee86bbf0f057f41f93b72e
Signed-off-by: Bogdan Dobrelya <bdobreli@redhat.com>
This commit is contained in:
Bogdan Dobrelya 2018-04-19 14:27:55 +02:00 committed by Emilien Macchi
parent 240728f525
commit 00169d46f6
3 changed files with 64 additions and 44 deletions

View File

@ -37,6 +37,7 @@ class TestUndercloudInstall(TestPluginV1):
self.conf = self.useFixture(oslo_fixture.Config(cfg.CONF))
self.conf.config(container_images_file='/home/stack/foo.yaml')
self.conf.set_default('output_dir', '/home/stack')
# Get the command object to test
app_args = mock.Mock()
app_args.verbose_level = 1
@ -53,9 +54,14 @@ class TestUndercloudInstall(TestPluginV1):
mock_subprocess.assert_called_with(['instack-install-undercloud'])
@mock.patch('os.mkdir')
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)
@mock.patch('os.getcwd', return_value='/tmp')
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_install_with_heat(self, mock_subprocess, mock_cwd):
def test_undercloud_install_with_heat_custom_output(self, mock_subprocess,
mock_cwd, mock_wr,
mock_os):
self.conf.config(output_dir='/foo')
arglist = ['--use-heat', '--no-validations']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -63,6 +69,7 @@ class TestUndercloudInstall(TestPluginV1):
# DisplayCommandBase.take_action() returns two tuples
self.cmd.take_action(parsed_args)
mock_os.assert_called_with('/foo')
mock_subprocess.assert_called_with(
['sudo', 'openstack', 'undercloud',
'deploy', '--local-domain=localdomain',
@ -99,13 +106,17 @@ class TestUndercloudInstall(TestPluginV1):
'/usr/share/openstack-tripleo-heat-templates/environments/'
'config-download-environment.yaml', '-e',
'/usr/share/openstack-tripleo-heat-templates/environments/'
'undercloud.yaml', '-e', '/tmp/undercloud_parameters.yaml',
mock.ANY, '--log-file=/tmp/install-undercloud.log'])
'undercloud.yaml', '--output-dir=/foo',
'-e', '/foo/undercloud_parameters.yaml',
'--log-file=/tmp/install-undercloud.log'])
@mock.patch('os.mkdir')
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)
@mock.patch('os.getcwd', return_value='/tmp')
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_install_with_heat_and_debug(self, mock_subprocess,
mock_cwd):
mock_cwd, mock_wr,
mock_os):
arglist = ['--use-heat', '--no-validations']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -152,13 +163,17 @@ class TestUndercloudInstall(TestPluginV1):
'/usr/share/openstack-tripleo-heat-templates/environments/'
'config-download-environment.yaml', '-e',
'/usr/share/openstack-tripleo-heat-templates/environments/'
'undercloud.yaml', '-e', '/tmp/undercloud_parameters.yaml',
mock.ANY, '--debug', '--log-file=/tmp/install-undercloud.log'])
'undercloud.yaml', '--output-dir=/home/stack',
'-e', '/home/stack/undercloud_parameters.yaml',
'--debug', '--log-file=/tmp/install-undercloud.log'])
@mock.patch('os.mkdir')
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)
@mock.patch('os.getcwd', return_value='/tmp')
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_install_with_swift_encryption(self, mock_subprocess,
mock_cwd):
mock_cwd, mock_wr,
mock_os):
arglist = ['--use-heat', '--no-validations']
verifylist = []
self.conf.set_default('enable_swift_encryption', True)
@ -207,23 +222,27 @@ class TestUndercloudInstall(TestPluginV1):
'/usr/share/openstack-tripleo-heat-templates/environments/'
'config-download-environment.yaml', '-e',
'/usr/share/openstack-tripleo-heat-templates/environments/'
'undercloud.yaml', '-e', '/tmp/undercloud_parameters.yaml',
mock.ANY, '--log-file=/tmp/install-undercloud.log'])
'undercloud.yaml', '--output-dir=/home/stack',
'-e', '/home/stack/undercloud_parameters.yaml',
'--log-file=/tmp/install-undercloud.log'])
class TestUndercloudUpgrade(TestPluginV1):
def setUp(self):
super(TestUndercloudUpgrade, self).setUp()
conf = self.useFixture(oslo_fixture.Config(cfg.CONF))
conf.config(container_images_file='/home/stack/foo.yaml')
self.conf = self.useFixture(oslo_fixture.Config(cfg.CONF))
self.conf.config(container_images_file='/home/stack/foo.yaml')
self.conf.set_default('output_dir', '/home/stack')
# Get the command object to test
app_args = mock.Mock()
app_args.verbose_level = 1
self.cmd = undercloud.UpgradeUndercloud(self.app, app_args)
@mock.patch('os.mkdir')
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_upgrade(self, mock_subprocess):
def test_undercloud_upgrade(self, mock_subprocess, mock_wr, mock_os):
arglist = []
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -242,9 +261,12 @@ class TestUndercloudUpgrade(TestPluginV1):
]
)
@mock.patch('os.mkdir')
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)
@mock.patch('os.getcwd', return_value='/tmp')
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_upgrade_with_heat(self, mock_subprocess, mock_cwd):
def test_undercloud_upgrade_with_heat(self, mock_subprocess,
mock_cwd, mock_wr, mock_os):
arglist = ['--use-heat', '--no-validations']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -291,13 +313,17 @@ class TestUndercloudUpgrade(TestPluginV1):
'/usr/share/openstack-tripleo-heat-templates/environments/'
'config-download-environment.yaml', '-e',
'/usr/share/openstack-tripleo-heat-templates/environments/'
'undercloud.yaml', '-e', '/tmp/undercloud_parameters.yaml',
mock.ANY, '--log-file=/tmp/install-undercloud.log'])
'undercloud.yaml', '--output-dir=/home/stack',
'-e', '/home/stack/undercloud_parameters.yaml',
'--log-file=/tmp/install-undercloud.log'])
@mock.patch('os.mkdir')
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)
@mock.patch('os.getcwd', return_value='/tmp')
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_upgrade_with_heat_and_debug(self, mock_subprocess,
mock_cwd):
mock_cwd, mock_wr,
mock_os):
arglist = ['--use-heat', '--no-validations']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -347,5 +373,6 @@ class TestUndercloudUpgrade(TestPluginV1):
'/usr/share/openstack-tripleo-heat-templates/environments/'
'config-download-environment.yaml', '-e',
'/usr/share/openstack-tripleo-heat-templates/environments/'
'undercloud.yaml', '-e', '/tmp/undercloud_parameters.yaml',
mock.ANY, '--debug', '--log-file=/tmp/install-undercloud.log'])
'undercloud.yaml', '--output-dir=/home/stack',
'-e', '/home/stack/undercloud_parameters.yaml',
'--debug', '--log-file=/tmp/install-undercloud.log'])

View File

@ -54,6 +54,18 @@ def bracket_ipv6(address):
return address
def write_env_file(env_data, env_file, registry_overwrites):
"""Write the tht env file as yaml"""
data = {'parameter_defaults': env_data}
if registry_overwrites:
data['resource_registry'] = registry_overwrites
with open(env_file, "w") as f:
dumper = yaml.dumper.SafeDumper
dumper.ignore_aliases = lambda self, data: True
yaml.dump(data, f, default_flow_style=False, Dumper=dumper)
def write_overcloudrc(stack_name, overcloudrcs, config_directory='.'):
"""Write the overcloudrc files"""

View File

@ -796,14 +796,14 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=False,
"environments/config-download-environment.yaml"),
"-e", os.path.join(tht_templates, "environments/undercloud.yaml")]
env_file = _write_env_file(
env_data, registry_overwrites=registry_overwrites)
deploy_args += ['-e', env_file]
params_file = os.path.abspath(os.path.join(CONF['output_dir'],
'undercloud_parameters.yaml'))
deploy_args += ['--output-dir=%s' % CONF['output_dir']]
if not os.path.isdir(CONF['output_dir']):
os.mkdir(CONF['output_dir'])
if CONF.get('output_dir'):
deploy_args += ['--output-dir=%s' % CONF['output_dir']]
if not os.path.isdir(CONF['output_dir']):
os.mkdir(CONF['output_dir'])
deploy_args += ['-e', params_file]
utils.write_env_file(env_data, params_file, registry_overwrites)
if CONF.get('cleanup'):
deploy_args.append('--cleanup')
@ -879,25 +879,6 @@ def _get_public_tls_resource_registry_overwrites(enable_tls_yaml_path):
'registry.' % enable_tls_yaml_path)
def _write_env_file(env_data,
env_file="/tmp/undercloud_parameters.yaml",
registry_overwrites={}):
"""Write the undercloud parameters to yaml"""
data = {'parameter_defaults': env_data}
if registry_overwrites:
data['resource_registry'] = registry_overwrites
env_file = os.path.abspath(env_file)
with open(env_file, "w") as f:
try:
dumper = yaml.dumper.SafeDumper
dumper.ignore_aliases = lambda self, data: True
yaml.dump(data, f, default_flow_style=False, Dumper=dumper)
except yaml.YAMLError as exc:
raise exc
return env_file
def _container_images_config(conf, deploy_args, env_data):
if conf.container_images_file:
deploy_args += ['-e', conf.container_images_file]