def test_manual_ring1_config_corosync2(self): ring0_name = 'eth0.1.1?1b34*430' ring1_name = 'eth1' ring1_ipaddr = '10.42.42.42' ring1_netmask = '255.255.255.0' mcast_port = '4242' new_node_fqdn = 'servera.somewhere.org' pcs_password = '******' # add shell commands to be expected self.add_commands( CommandCaptureCommand( ("/sbin/ip", "link", "set", "dev", ring1_name, "up")), CommandCaptureCommand( ("/sbin/ip", "addr", "add", '/'.join([ring1_ipaddr, ring1_netmask]), "dev", ring1_name)), CommandCaptureCommand( ("bash", "-c", "echo bondJAMESbond | passwd --stdin hacluster")), CommandCaptureCommand( tuple(["pcs", "cluster", "auth"] + [new_node_fqdn] + ["-u", "hacluster", "-p", "bondJAMESbond"]))) # now a two-step process! first network... self.assertEqual( agent_result_ok, configure_network(ring0_name, ring1_name=ring1_name, ring1_ipaddr=ring1_ipaddr, ring1_prefix=ring1_netmask)) self.write_ifcfg.assert_called_with(ring1_name, 'ba:db:ee:fb:aa:af', '10.42.42.42', '255.255.255.0') # fetch ring info r0, r1 = self._ring_iface_info(mcast_port) # add shell commands to be expected populated with ring interface info self.add_command( ("pcs", "cluster", "setup", "--name", "lustre-ha-cluster", "--force", new_node_fqdn, "--transport", "udp", "--rrpmode", "passive", "--addr0", str(r0.bindnetaddr), "--mcast0", str(r0.mcastaddr), "--mcastport0", str(r0.mcastport), "--addr1", str(r1.bindnetaddr), "--mcast1", str(r1.mcastaddr), "--mcastport1", str(r1.mcastport), "--token", "17000", "--fail_recv_const", "10")) # ...then corosync / pcsd self.assertEqual(agent_result_ok, configure_corosync2_stage_1(mcast_port, pcs_password)) self.assertEqual( agent_result_ok, configure_corosync2_stage_2(ring0_name, ring1_name, new_node_fqdn, mcast_port, pcs_password, True)) # check correct firewall and service calls were made self.mock_add_port.assert_has_calls( [mock.call(mcast_port, 'udp'), mock.call(PCS_TCP_PORT, 'tcp')]) self.mock_remove_port.assert_not_called() self.mock_pcsd_service.start.assert_called_once_with() self.mock_corosync_service.enable.assert_called_once_with() self.mock_pcsd_service.enable.assert_called_once_with() self.mock_remove_port.reset_mock() self.mock_add_port.reset_mock() self.mock_corosync_service.reset_mock() # ...now change corosync mcast port old_mcast_port = '4242' new_mcast_port = '4246' # add shell command to be expected when updating corosync.conf file with new mcast port value self.add_command(('sed', '-i.bak', 's/mcastport:.*/mcastport: %s/g' % new_mcast_port, '/etc/corosync/corosync.conf')) self.assertEqual(agent_result_ok, change_mcast_port(old_mcast_port, new_mcast_port)) # check correct firewall and service calls were made self.mock_add_port.assert_has_calls([mock.call(new_mcast_port, 'udp')]) self.mock_remove_port.assert_has_calls( [mock.call(old_mcast_port, 'udp')]) with self.assertRaises(AssertionError): self.mock_corosync_service.enable.assert_any_call() self.assertRanAllCommandsInOrder()
def _test_manual_ring1_config_corosync2(self, fqdn=False): import socket from chroma_agent.action_plugins.manage_corosync2 import ( configure_corosync2_stage_1, ) from chroma_agent.action_plugins.manage_corosync2 import ( configure_corosync2_stage_2, ) from chroma_agent.action_plugins.manage_corosync2 import PCS_TCP_PORT from chroma_agent.action_plugins.manage_corosync_common import configure_network ring0_name = "eth0.1.1?1b34*430" ring1_name = "eth1" ring1_ipaddr = "10.42.42.42" ring1_netmask = "255.255.255.0" mcast_port = "4242" new_node_fqdn = "servera.somewhere.org" pcs_password = "******" # add shell commands to be expected self.add_commands( CommandCaptureCommand( ("/sbin/ip", "link", "set", "dev", ring1_name, "up")), CommandCaptureCommand(( "/sbin/ip", "addr", "add", "/".join([ring1_ipaddr, ring1_netmask]), "dev", ring1_name, )), ) if fqdn: self.add_commands( CommandCaptureCommand( ("hostnamectl", "set-hostname", new_node_fqdn))) self.add_commands( CommandCaptureCommand( ("bash", "-c", "echo bondJAMESbond | passwd --stdin hacluster")), CommandCaptureCommand( tuple(["pcs", "cluster", "auth"] + [new_node_fqdn] + ["-u", "hacluster", "-p", "bondJAMESbond"])), ) # now a two-step process! first network... self.assertEqual( agent_result_ok, configure_network( ring0_name, ring1_name=ring1_name, ring1_ipaddr=ring1_ipaddr, ring1_prefix=ring1_netmask, ), ) self.write_ifcfg.assert_called_with(ring1_name, "ba:db:ee:fb:aa:af", "10.42.42.42", "255.255.255.0") # fetch ring info r0, r1 = self._ring_iface_info(mcast_port) # add shell commands to be expected populated with ring interface info self.add_command(( "pcs", "cluster", "setup", "--name", "lustre-ha-cluster", "--force", new_node_fqdn, "--transport", "udp", "--rrpmode", "passive", "--addr0", str(r0.bindnetaddr), "--mcast0", str(r0.mcastaddr), "--mcastport0", str(r0.mcastport), "--addr1", str(r1.bindnetaddr), "--mcast1", str(r1.mcastaddr), "--mcastport1", str(r1.mcastport), "--token", "17000", "--fail_recv_const", "10", )) # ...then corosync / pcsd if fqdn: self.assertEqual( agent_result_ok, configure_corosync2_stage_1(mcast_port, pcs_password, new_node_fqdn), ) else: self.assertEqual( agent_result_ok, configure_corosync2_stage_1(mcast_port, pcs_password)) self.assertEqual( agent_result_ok, configure_corosync2_stage_2(ring0_name, ring1_name, new_node_fqdn, mcast_port, pcs_password, True), ) # check correct firewall and service calls were made self.mock_add_port.assert_has_calls( [mock.call(mcast_port, "udp"), mock.call(PCS_TCP_PORT, "tcp")]) self.mock_remove_port.assert_not_called() self.mock_pcsd_service.start.assert_called_once_with() self.mock_corosync_service.enable.assert_called_once_with() self.mock_pcsd_service.enable.assert_called_once_with() self.mock_remove_port.reset_mock() self.mock_add_port.reset_mock() self.mock_corosync_service.reset_mock() self.assertRanAllCommandsInOrder()
def test_manual_ring1_config(self): ring0_name = 'eth0.1.1?1b34*430' ring1_name = 'eth1' ring1_ipaddr = '10.42.42.42' ring1_netmask = '255.255.255.0' old_mcast_port = None new_mcast_port = '4242' # add shell commands to be expected self.add_commands( CommandCaptureCommand( ('/sbin/ip', 'link', 'set', 'dev', ring1_name, 'up')), CommandCaptureCommand( ('/sbin/ip', 'addr', 'add', '%s/%s' % (ring1_ipaddr, ring1_netmask), 'dev', ring1_name))) # now a two-step process! first network... self.assertEqual( agent_result_ok, configure_network(ring0_name, ring1_name=ring1_name, ring1_ipaddr=ring1_ipaddr, ring1_prefix=ring1_netmask)) self.write_ifcfg.assert_called_with(ring1_name, 'ba:db:ee:fb:aa:af', '10.42.42.42', '255.255.255.0') self.unmanage_network.assert_called_with(ring1_name, 'ba:db:ee:fb:aa:af') # ...then corosync self.assertEqual( agent_result_ok, configure_corosync(ring0_name, ring1_name, old_mcast_port, new_mcast_port)) test_config = self._render_test_config(new_mcast_port) self.write_config_to_file.assert_called_with( '/etc/corosync/corosync.conf', test_config) # check correct firewall and service calls were made self.mock_add_port.assert_has_calls([mock.call(new_mcast_port, 'udp')]) self.mock_remove_port.assert_not_called() self.mock_corosync_service.enable.assert_called_once_with() self.assertRanAllCommandsInOrder() self.mock_remove_port.reset_mock() self.mock_add_port.reset_mock() self.mock_corosync_service.reset_mock() # ...now change corosync mcast port old_mcast_port = '4242' new_mcast_port = '4246' self.assertEqual( agent_result_ok, configure_corosync(ring0_name, ring1_name, old_mcast_port, new_mcast_port)) test_config = self._render_test_config(new_mcast_port) # check we try to write template with new_mcast_port value self.write_config_to_file.assert_called_with( '/etc/corosync/corosync.conf', test_config) # check correct firewall and service calls were made self.mock_remove_port.assert_has_calls( [mock.call(old_mcast_port, 'udp')]) self.mock_add_port.assert_has_calls([mock.call(new_mcast_port, 'udp')]) self.mock_corosync_service.enable.assert_called_once_with()
def test_manual_ring1_config(self): from chroma_agent.action_plugins.manage_corosync_common import configure_network from chroma_agent.action_plugins.manage_corosync import configure_corosync ring0_name = "eth0.1.1?1b34*430" ring1_name = "eth1" ring1_ipaddr = "10.42.42.42" ring1_netmask = "255.255.255.0" old_mcast_port = None new_mcast_port = "4242" # add shell commands to be expected self.add_commands( CommandCaptureCommand( ("/sbin/ip", "link", "set", "dev", ring1_name, "up")), CommandCaptureCommand(( "/sbin/ip", "addr", "add", "%s/%s" % (ring1_ipaddr, ring1_netmask), "dev", ring1_name, )), ) # now a two-step process! first network... self.assertEqual( agent_result_ok, configure_network( ring0_name, ring1_name=ring1_name, ring1_ipaddr=ring1_ipaddr, ring1_prefix=ring1_netmask, ), ) self.write_ifcfg.assert_called_with(ring1_name, "ba:db:ee:fb:aa:af", "10.42.42.42", "255.255.255.0") self.unmanage_network.assert_called_with(ring1_name, "ba:db:ee:fb:aa:af") # ...then corosync self.assertEqual( agent_result_ok, configure_corosync(ring0_name, ring1_name, old_mcast_port, new_mcast_port), ) test_config = self._render_test_config(new_mcast_port) self.write_config_to_file.assert_called_with( "/etc/corosync/corosync.conf", test_config) # check correct firewall and service calls were made self.mock_add_port.assert_has_calls([mock.call(new_mcast_port, "udp")]) self.mock_remove_port.assert_not_called() self.mock_corosync_service.enable.assert_called_once_with() self.assertRanAllCommandsInOrder() self.mock_remove_port.reset_mock() self.mock_add_port.reset_mock() self.mock_corosync_service.reset_mock() # ...now change corosync mcast port old_mcast_port = "4242" new_mcast_port = "4246" self.assertEqual( agent_result_ok, configure_corosync(ring0_name, ring1_name, old_mcast_port, new_mcast_port), ) test_config = self._render_test_config(new_mcast_port) # check we try to write template with new_mcast_port value self.write_config_to_file.assert_called_with( "/etc/corosync/corosync.conf", test_config) # check correct firewall and service calls were made self.mock_remove_port.assert_has_calls( [mock.call(old_mcast_port, "udp")]) self.mock_add_port.assert_has_calls([mock.call(new_mcast_port, "udp")]) self.mock_corosync_service.enable.assert_called_once_with()