def setUp(self): super(TestConfigureCorosync, self).setUp() from chroma_agent.lib.corosync import CorosyncRingInterface def get_ring0(): return CorosyncRingInterface('eth0.1.1?1b34*430') mock.patch('chroma_agent.lib.corosync.get_ring0', get_ring0).start() self.interfaces = { 'eth0.1.1?1b34*430': { 'device': 'eth0.1.1?1b34*430', 'mac_address': 'de:ad:be:ef:ca:fe', 'ipv4_address': '192.168.1.1', 'ipv4_netmask': '255.255.255.0', 'link_up': True }, 'eth1': { 'device': 'eth1', 'mac_address': 'ba:db:ee:fb:aa:af', 'ipv4_address': None, 'ipv4_netmask': 0, 'link_up': True } } # Just mock out the entire module ... This will make the tests # run on OS X or on Linux without the python-ethtool package. self.old_ethtool = sys.modules.get("ethtool", None) ethtool = fake_ethtool(self.interfaces) sys.modules['ethtool'] = ethtool self.write_ifcfg = mock.patch( 'chroma_agent.lib.node_admin.write_ifcfg').start() self.unmanage_network = mock.patch( 'chroma_agent.lib.node_admin.unmanage_network').start() self.write_config_to_file = mock.patch( 'chroma_agent.action_plugins.manage_corosync.write_config_to_file' ).start() mock.patch( 'chroma_agent.action_plugins.manage_pacemaker.unconfigure_pacemaker' ).start() old_set_address = CorosyncRingInterface.set_address def set_address(obj, address, prefix): if self.interfaces[obj.name]['ipv4_address'] is None: self.interfaces[obj.name]['ipv4_address'] = address self.interfaces[obj.name]['ipv4_netmask'] = prefix old_set_address(obj, address, prefix) mock.patch( 'chroma_agent.lib.corosync.CorosyncRingInterface.set_address', set_address).start() @property def has_link(obj): return self.interfaces[obj.name]['link_up'] self.link_patcher = mock.patch( 'chroma_agent.lib.corosync.CorosyncRingInterface.has_link', has_link) self.link_patcher.start() mock.patch('chroma_agent.lib.corosync.find_unused_port', return_value=4242).start() mock.patch( 'chroma_agent.lib.corosync.discover_existing_mcastport').start() self.conf_template = env.get_template('corosync.conf') # mock out firewall control calls and check with assert_has_calls in tests self.mock_add_port = mock.patch.object(FirewallControlEL7, '_add_port', return_value=None).start() self.mock_remove_port = mock.patch.object(FirewallControlEL7, '_remove_port', return_value=None).start() # mock out service control objects with ServiceControlEL7 spec and check with assert_has_calls in tests # this assumes, quite rightly, that manage_corosync and manage_corosync2 will not both be used in the same test self.mock_corosync_service = mock.create_autospec(ServiceControlEL7) self.mock_corosync_service.enable.return_value = None self.mock_corosync_service.disable.return_value = None mock.patch( 'chroma_agent.action_plugins.manage_corosync.corosync_service', self.mock_corosync_service).start() mock.patch( 'chroma_agent.action_plugins.manage_corosync2.corosync_service', self.mock_corosync_service).start() self.mock_pcsd_service = mock.create_autospec(ServiceControlEL7) self.mock_pcsd_service.enable.return_value = None self.mock_pcsd_service.start.return_value = None mock.patch('chroma_agent.action_plugins.manage_corosync2.pcsd_service', self.mock_pcsd_service).start() mock.patch( 'chroma_agent.action_plugins.manage_corosync.firewall_control', FirewallControlEL7()).start() mock.patch( 'chroma_agent.action_plugins.manage_corosync2.firewall_control', FirewallControlEL7()).start() # Guaranteed cleanup with unittest2 self.addCleanup(mock.patch.stopall)
def setUp(self): super(TestConfigureCorosync, self).setUp() from chroma_agent.lib.corosync import CorosyncRingInterface from chroma_agent.lib.corosync import env def get_shared_ring(): return CorosyncRingInterface("eth0.1.1?1b34*430") mock.patch("chroma_agent.lib.corosync.get_shared_ring", get_shared_ring).start() self.interfaces = { "eth0.1.1?1b34*430": { "device": "eth0.1.1?1b34*430", "mac_address": "de:ad:be:ef:ca:fe", "ipv4_address": "192.168.1.1", "ipv4_netmask": "255.255.255.0", "link_up": True, }, "eth1": { "device": "eth1", "mac_address": "ba:db:ee:fb:aa:af", "ipv4_address": None, "ipv4_netmask": 0, "link_up": True, }, } # Just mock out the entire module ... This will make the tests # run on OS X or on Linux without the python-ethtool package. self.old_ethtool = sys.modules.get("ethtool", None) ethtool = fake_ethtool(self.interfaces) sys.modules["ethtool"] = ethtool self.write_ifcfg = mock.patch( "chroma_agent.lib.node_admin.write_ifcfg").start() self.unmanage_network = mock.patch( "chroma_agent.lib.node_admin.unmanage_network").start() self.write_config_to_file = mock.patch( "chroma_agent.action_plugins.manage_corosync.write_config_to_file" ).start() mock.patch( "chroma_agent.action_plugins.manage_pacemaker.unconfigure_pacemaker" ).start() old_set_address = CorosyncRingInterface.set_address def set_address(obj, address, prefix): if self.interfaces[obj.name]["ipv4_address"] is None: self.interfaces[obj.name]["ipv4_address"] = address self.interfaces[obj.name]["ipv4_netmask"] = prefix old_set_address(obj, address, prefix) mock.patch( "chroma_agent.lib.corosync.CorosyncRingInterface.set_address", set_address).start() @property def has_link(obj): return self.interfaces[obj.name]["link_up"] self.link_patcher = mock.patch( "chroma_agent.lib.corosync.CorosyncRingInterface.has_link", has_link) self.link_patcher.start() mock.patch("chroma_agent.lib.corosync.find_unused_port", return_value=4242).start() mock.patch( "chroma_agent.lib.corosync.discover_existing_mcastport").start() self.conf_template = env.get_template("corosync.conf") # mock out firewall control calls and check with assert_has_calls in tests self.mock_add_port = mock.patch.object(FirewallControlEL7, "_add_port", return_value=None).start() self.mock_remove_port = mock.patch.object(FirewallControlEL7, "_remove_port", return_value=None).start() # mock out service control objects with ServiceControlEL7 spec and check with assert_has_calls in tests # this assumes, quite rightly, that manage_corosync and manage_corosync2 will not both be used in the same test self.mock_corosync_service = mock.create_autospec(ServiceControlEL7) self.mock_corosync_service.enable.return_value = None self.mock_corosync_service.disable.return_value = None mock.patch( "chroma_agent.action_plugins.manage_corosync.corosync_service", self.mock_corosync_service, ).start() mock.patch( "chroma_agent.action_plugins.manage_corosync2.corosync_service", self.mock_corosync_service, ).start() self.mock_pcsd_service = mock.create_autospec(ServiceControlEL7) self.mock_pcsd_service.enable.return_value = None self.mock_pcsd_service.start.return_value = None mock.patch( "chroma_agent.action_plugins.manage_corosync2.pcsd_service", self.mock_pcsd_service, ).start() mock.patch( "chroma_agent.action_plugins.manage_corosync.firewall_control", FirewallControlEL7(), ).start() mock.patch( "chroma_agent.action_plugins.manage_corosync2.firewall_control", FirewallControlEL7(), ).start() # Guaranteed cleanup with unittest2 self.addCleanup(mock.patch.stopall)