Merge "Bash variable workaround"
This commit is contained in:
commit
6d25971d4c
|
@ -12,6 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from copy import deepcopy
|
||||
import os
|
||||
|
||||
from devops.helpers import subprocess_runner
|
||||
|
@ -77,11 +78,16 @@ def generate_cloud_image_settings(cloud_image_settings_path, meta_data_path,
|
|||
" - sudo route add default gw "
|
||||
"{gateway} {interface_name}")
|
||||
|
||||
logger.debug("user_data contains next data: \n{}".format(
|
||||
user_data_content.format(**data_context)))
|
||||
|
||||
# FIXME this hack should be rewrited!
|
||||
# Workaround to be able pass bash-style variables ${}
|
||||
fmt_user_data_content = deepcopy(user_data_content)
|
||||
for _key in data_context.keys():
|
||||
logger.warning("Searching key:{} in user_data".format(_key))
|
||||
_repl = "{{{0}}}".format(_key)
|
||||
fmt_user_data_content = \
|
||||
fmt_user_data_content.replace(_repl, data_context[_key])
|
||||
with open(user_data_path, 'w') as f:
|
||||
f.write(user_data_content.format(**data_context))
|
||||
f.write(fmt_user_data_content)
|
||||
|
||||
# Generate cloud_ISO
|
||||
cmd = "genisoimage -output {} " \
|
||||
|
@ -89,5 +95,4 @@ def generate_cloud_image_settings(cloud_image_settings_path, meta_data_path,
|
|||
"-rock {} {}".format(cloud_image_settings_path,
|
||||
user_data_path,
|
||||
meta_data_path)
|
||||
|
||||
subprocess_runner.Subprocess.check_call(cmd)
|
||||
|
|
|
@ -57,7 +57,6 @@ class TestCloudImageSettings(unittest.TestCase):
|
|||
interface_name=u'enp0s3')
|
||||
|
||||
self.os_mock.makedirs.assert_called_once_with('/mydir')
|
||||
|
||||
self.open_mock.assert_has_calls((
|
||||
mock.call('/mydir/meta-data', 'w'),
|
||||
mock.call().__enter__(),
|
||||
|
@ -72,7 +71,8 @@ class TestCloudImageSettings(unittest.TestCase):
|
|||
' gateway 10.109.0.1\n'
|
||||
' dns-nameservers 8.8.8.8\n'
|
||||
'local-hostname: nailgun.domain.local'),
|
||||
mock.call().__exit__(None, None, None),
|
||||
mock.call().__exit__(None, None, None)))
|
||||
self.open_mock.assert_has_calls((
|
||||
mock.call('/mydir/user-data', 'w'),
|
||||
mock.call().__enter__(),
|
||||
mock.call().write(
|
||||
|
|
Loading…
Reference in New Issue