From 04ccc91a15e33051872c82b2c7a5189a13a6a978 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 24 Feb 2016 10:36:24 -0700 Subject: [PATCH] Set network-related hostvars if necessary Specifically, monitor_interface and public_network Signed-off-by: Zack Cerza --- teuthology/task/ceph_ansible.py | 7 +++ teuthology/test/task/test_ceph_ansible.py | 55 +++++++++++++++++++++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/teuthology/task/ceph_ansible.py b/teuthology/task/ceph_ansible.py index bd3258958..f402b2b9e 100644 --- a/teuthology/task/ceph_ansible.py +++ b/teuthology/task/ceph_ansible.py @@ -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 diff --git a/teuthology/test/task/test_ceph_ansible.py b/teuthology/test/task/test_ceph_ansible.py index 8e71465b5..669ab1ebc 100644 --- a/teuthology/test/task/test_ceph_ansible.py +++ b/teuthology/test/task/test_ceph_ansible.py @@ -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'", + ]) -- 2.47.3