Remove unused render_template_to_file method

In a filesystem access code audit I found the method render_template_to_file is not used in the code. This patch removes it and it's tests.

Change-Id: I0264349176763f9aa4a87750aca270a6acd2c529
This commit is contained in:
Michael Johnson
2022-05-12 21:26:56 +00:00
parent cc8f5a5ede
commit e1b92ab37c
2 changed files with 0 additions and 53 deletions
-38
View File
@@ -213,44 +213,6 @@ class TestUtils(oslotest.base.BaseTestCase):
self.assertEqual('Hello World', result)
@mock.patch('builtins.open', new_callable=mock.mock_open)
@mock.patch('os.path.exists')
def test_render_template_to_file(self, mock_exists, mock_open):
mock_exists.return_value = True
output_path = '/tmp/designate/resources/templates/hello.jinja2'
template = jinja2.Template('Hello {{name}}')
utils.render_template_to_file(
template, makedirs=False, output_path=output_path, name='World'
)
mock_open.assert_called_once_with(output_path, 'w')
mock_open().write.assert_called_once_with('Hello World')
@mock.patch('builtins.open', new_callable=mock.mock_open)
@mock.patch('os.path.exists')
@mock.patch('os.makedirs')
def test_render_template_to_file_with_makedirs(self, mock_makedirs,
mock_exists,
mock_open):
mock_exists.return_value = False
output_path = '/tmp/designate/resources/templates/hello.jinja2'
template = jinja2.Template('Hello {{name}}')
utils.render_template_to_file(
template, makedirs=True, output_path=output_path, name='World'
)
mock_makedirs.assert_called_once_with(
'/tmp/designate/resources/templates'
)
mock_open.assert_called_once_with(output_path, 'w')
mock_open().write.assert_called_once_with('Hello World')
@mock.patch.object(timeutils, 'utcnow_ts')
def test_increment_serial_lower_than_ts(self, mock_utcnow_ts):
mock_utcnow_ts.return_value = 1561698354
-15
View File
@@ -110,21 +110,6 @@ def render_template(template, **template_context):
return template.render(**template_context)
def render_template_to_file(template_name, output_path, makedirs=True,
**template_context):
output_folder = os.path.dirname(output_path)
# Create the output folder tree if necessary
if makedirs and not os.path.exists(output_folder):
os.makedirs(output_folder)
# Render the template
content = render_template(template_name, **template_context)
with open(output_path, 'w') as output_fh:
output_fh.write(content)
def execute(*cmd, **kw):
"""Execute a command in a subprocess, blocking.
"""