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,
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
)
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)
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'
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'
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)
'[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'",
+ ])