]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
ansible: Optional suffix for inventory filenames
authorZack Cerza <zack@redhat.com>
Thu, 19 Oct 2017 18:38:57 +0000 (12:38 -0600)
committerZack Cerza <zack@redhat.com>
Fri, 20 Oct 2017 19:44:16 +0000 (13:44 -0600)
So we can support e.g. YAML inventories.

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/task/ansible.py
teuthology/test/task/test_ansible.py

index ac8f0ce1873191e155047c0de636a8a7424da1a5..3a2c1d9bcae6510637f28c993fc69b1e0b882365 100644 (file)
@@ -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
index 33739f603080bcf29199cf46cb25e7d896e7d7cb..f8b2829fa7190b691ae31a2f3a6d2a416cd81b38 100644 (file)
@@ -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)