From 541d891bb9875a79ec36cb71ce4172beef256f7d Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 19 Oct 2017 12:38:57 -0600 Subject: [PATCH] ansible: Optional suffix for inventory filenames So we can support e.g. YAML inventories. Signed-off-by: Zack Cerza --- teuthology/task/ansible.py | 9 ++++++--- teuthology/test/task/test_ansible.py | 22 +++++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/teuthology/task/ansible.py b/teuthology/task/ansible.py index ac8f0ce187..3a2c1d9bca 100644 --- a/teuthology/task/ansible.py +++ b/teuthology/task/ansible.py @@ -203,12 +203,15 @@ class Ansible(Task): self.inventory = self._write_hosts_file(hosts_str) self.generated_inventory = True - def _write_hosts_file(self, content): + def _write_hosts_file(self, content, suffix=''): """ Actually write the hosts file """ - hosts_file = NamedTemporaryFile(prefix="teuth_ansible_hosts_", - delete=False) + hosts_file = NamedTemporaryFile( + prefix="teuth_ansible_hosts_", + suffix=suffix, + delete=False, + ) hosts_file.write(content) hosts_file.flush() return hosts_file.name diff --git a/teuthology/test/task/test_ansible.py b/teuthology/test/task/test_ansible.py index 33739f6030..f8b2829fa7 100644 --- a/teuthology/test/task/test_ansible.py +++ b/teuthology/test/task/test_ansible.py @@ -227,8 +227,11 @@ class TestAnsibleTask(TestTask): with patch.object(ansible, 'NamedTemporaryFile') as m_NTF: m_NTF.return_value = hosts_file_obj task.generate_hosts_file() - m_NTF.assert_called_once_with(prefix="teuth_ansible_hosts_", - delete=False) + m_NTF.assert_called_once_with( + prefix="teuth_ansible_hosts_", + delete=False, + suffix='', + ) assert task.generated_inventory is True assert task.inventory == hosts_file_path hosts_file_obj.seek(0) @@ -255,9 +258,11 @@ class TestAnsibleTask(TestTask): task.find_repo() task.get_playbook() task.generate_playbook() - m_NTF.assert_called_once_with(prefix="teuth_ansible_playbook_", - dir=task.repo_path, - delete=False) + m_NTF.assert_called_once_with( + prefix="teuth_ansible_playbook_", + dir=task.repo_path, + delete=False, + ) assert task.generated_playbook is True assert task.playbook_file == playbook_file_obj playbook_file_obj.seek(0) @@ -483,8 +488,11 @@ class TestCephLabTask(TestTask): with patch.object(ansible, 'NamedTemporaryFile') as m_NTF: m_NTF.return_value = hosts_file_obj task.generate_hosts_file() - m_NTF.assert_called_once_with(prefix="teuth_ansible_hosts_", - delete=False) + m_NTF.assert_called_once_with( + prefix="teuth_ansible_hosts_", + delete=False, + suffix='', + ) assert task.generated_inventory is True assert task.inventory == hosts_file_path hosts_file_obj.seek(0) -- 2.39.5