]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Set network-related hostvars if necessary 791/head
authorZack Cerza <zack@redhat.com>
Wed, 24 Feb 2016 17:36:24 +0000 (10:36 -0700)
committerZack Cerza <zack@redhat.com>
Fri, 26 Feb 2016 17:01:45 +0000 (10:01 -0700)
Specifically, monitor_interface and public_network

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

index bd32589581ede58982d518064a296560f7c4e5a5..f402b2b9e05fb1f8d7a662c8e04936301f85436a 100644 (file)
@@ -52,6 +52,9 @@ class CephAnsible(ansible.Ansible):
     It will optionally do the following automatically based on ``vars`` that
     are passed in:
         * Set ``devices`` for each host if ``osd_auto_discovery`` is not True
+        * Set ``monitor_interface`` for each host if ``monitor_interface`` is
+          unset
+        * Set ``public_network`` for each host if ``public_network`` is unset
     """.format(
         git_base=teuth_config.ceph_git_base_url,
         playbook=_default_playbook,
@@ -118,6 +121,10 @@ class CephAnsible(ansible.Ansible):
         host_vars = dict()
         if not extra_vars.get('osd_auto_discovery', False):
             host_vars['devices'] = get_scratch_devices(remote)
+        if 'monitor_interface' not in extra_vars:
+            host_vars['monitor_interface'] = remote.interface
+        if 'public_network' not in extra_vars:
+            host_vars['public_network'] = remote.cidr
         return host_vars
 
 task = CephAnsible
index 8e71465b5c65a83293ca5e588ed5990dc3e244e8..669ab1ebcb66ce7dc22af158b7806cfb2012acc0 100644 (file)
@@ -46,10 +46,21 @@ class TestCephAnsibleTask(TestAnsibleTask):
         )
         self.patcher_get_scratch_devices.start()
 
+        def fake_set_iface_and_cidr(self):
+            self._interface = 'eth0'
+            self._cidr = '172.21.0.0/20'
+
+        self.patcher_remote = patch.multiple(
+            Remote,
+            _set_iface_and_cidr=fake_set_iface_and_cidr,
+        )
+        self.patcher_remote.start()
+
     def stop_patchers(self):
         super(TestCephAnsibleTask, self).stop_patchers()
         self.patcher_fetch_repo.stop()
         self.patcher_get_scratch_devices.stop()
+        self.patcher_remote.stop()
 
     def test_playbook_none(self):
         skip(SKIP_IRRELEVANT)
@@ -66,7 +77,11 @@ class TestCephAnsibleTask(TestAnsibleTask):
     def test_generate_hosts_file(self):
         self.task_config.update(dict(
             playbook=[],
-            vars=dict(osd_auto_discovery=True),
+            vars=dict(
+                osd_auto_discovery=True,
+                monitor_interface='eth0',
+                public_network='172.21.0.0/20',
+            ),
         ))
         task = self.klass(self.ctx, self.task_config)
         hosts_file_path = '/my/hosts/file'
@@ -93,7 +108,11 @@ class TestCephAnsibleTask(TestAnsibleTask):
 
     def test_generate_hosts_file_with_devices(self):
         self.task_config.update(dict(
-            playbook=[]
+            playbook=[],
+            vars=dict(
+                monitor_interface='eth0',
+                public_network='172.21.0.0/20',
+            ),
         ))
         task = self.klass(self.ctx, self.task_config)
         hosts_file_path = '/my/hosts/file'
@@ -103,7 +122,7 @@ class TestCephAnsibleTask(TestAnsibleTask):
             m_NTF.return_value = hosts_file_obj
             task.generate_hosts_file()
             m_NTF.assert_called_once_with(prefix="teuth_ansible_hosts_",
-                                            delete=False)
+                                          delete=False)
         assert task.generated_inventory is True
         assert task.inventory == hosts_file_path
         hosts_file_obj.seek(0)
@@ -117,3 +136,33 @@ class TestCephAnsibleTask(TestAnsibleTask):
             '[osds]',
             'remote3 devices=\'["/dev/remote3"]\'',
         ])
+
+    def test_generate_hosts_file_with_network(self):
+        self.task_config.update(dict(
+            playbook=[],
+            vars=dict(
+                osd_auto_discovery=True,
+            ),
+        ))
+        task = self.klass(self.ctx, self.task_config)
+        hosts_file_path = '/my/hosts/file'
+        hosts_file_obj = StringIO()
+        hosts_file_obj.name = hosts_file_path
+        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)
+        assert task.generated_inventory is True
+        assert task.inventory == hosts_file_path
+        hosts_file_obj.seek(0)
+        assert hosts_file_obj.read() == '\n'.join([
+            '[mdss]',
+            "remote2 monitor_interface='eth0' public_network='172.21.0.0/20'",
+            '',
+            '[mons]',
+            "remote1 monitor_interface='eth0' public_network='172.21.0.0/20'",
+            '',
+            '[osds]',
+            "remote3 monitor_interface='eth0' public_network='172.21.0.0/20'",
+        ])