def test_peer(self): ''' Test if it adds another node into the peer list. ''' # Peers can be added successfully, already present, be the localhost, or not be connected. mock = MagicMock(return_value=xml_peer_probe_success) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('salt'), { 'exitval': '0', 'output': None }) mock = MagicMock(return_value=xml_peer_probe_fail_already_member) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual( glusterfs.peer('salt'), { 'exitval': '0', 'output': 'Host salt port 24007 already in peer list' }) mock = MagicMock(return_value=xml_peer_probe_fail_localhost) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('salt'), { 'exitval': '0', 'output': 'Probe on localhost not needed' }) mock = MagicMock(return_value=xml_peer_probe_fail_cant_connect) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertRaises(CommandExecutionError, glusterfs.peer, 'salt') mock = MagicMock(return_value=True) with patch.object(suc, 'check_name', mock): self.assertRaises(SaltInvocationError, glusterfs.peer, 'a')
def test_peer(self): ''' Test if it add another node into the peer list. ''' mock = MagicMock(return_value='') with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('salt'), '') mock = MagicMock(return_value=True) with patch.object(suc, 'check_name', mock): self.assertEqual(glusterfs.peer('a'), 'Invalid characters in peer name')
def test_peer(self): ''' Test if gluster peer call is successful. ''' mock_run = MagicMock() with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}): mock_run.return_value = xml_peer_probe_already_member self.assertTrue(glusterfs.peer('salt')) mock_run.return_value = xml_peer_probe_localhost self.assertTrue(glusterfs.peer('salt')) mock_run.return_value = xml_peer_probe_fail_cant_connect self.assertFalse(glusterfs.peer('salt'))
def test_peer(self): ''' Test if it adds another node into the peer list. ''' mock = MagicMock(return_value=xml_command_success) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertTrue(glusterfs.peer('salt')) mock = MagicMock(return_value=True) with patch.object(suc, 'check_name', mock): self.assertRaises(SaltInvocationError, glusterfs.peer, 'a')
def test_peer(self): ''' Test if it adds another node into the peer list. ''' # invalid characters mock = MagicMock(return_value=True) with patch.object(suc, 'check_name', mock): self.assertRaises(SaltInvocationError, glusterfs.peer, 'a') # version 3.4 # by hostname # peer failed unknown hostname # peer failed can't connect mock = MagicMock( return_value=GlusterResults.v34.peer_probe.fail_cant_connect) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertRaises(CommandExecutionError, glusterfs.peer, 'server2') # peer self mock = MagicMock( return_value=GlusterResults.v34.peer_probe.success_self) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('server1'), {'exitval': '1', 'output': 'success: on localhost not needed'}) # peer added mock = MagicMock( return_value=GlusterResults.v34.peer_probe.success_other) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('server2'), {'exitval': '0', 'output': 'success'}) # peer already member mock = MagicMock( return_value=GlusterResults.v34.peer_probe.success_already_peer['hostname']) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('server2'), {'exitval': '2', 'output': 'success: host server2 port 24007 already in peer list'}) mock = MagicMock( return_value=GlusterResults.v34.peer_probe.success_already_peer['ip']) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('10.0.0.2'), {'exitval': '2', 'output': 'success: host 10.0.0.2 port 24007 already in peer list'}) # peer in reverse (probe server1 from server2) mock = MagicMock( return_value=GlusterResults.v34.peer_probe.success_first_hostname_from_second_first_time) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('server1'), {'exitval': '0', 'output': 'success'}) mock = MagicMock( return_value=GlusterResults.v34.peer_probe.success_first_hostname_from_second_second_time) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('server1'), {'exitval': '2', 'output': 'success: host server1 port 24007 already in peer list'}) # peer in reverse using ip address instead of hostname mock = MagicMock( return_value=GlusterResults.v34.peer_probe.success_reverse_already_peer['ip']) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('10.0.0.1'), {'exitval': '2', 'output': 'success: host 10.0.0.1 port 24007 already in peer list'}) # by ip address # peer self mock = MagicMock( return_value=GlusterResults.v34.peer_probe.success_self) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('10.0.0.1'), {'exitval': '1', 'output': 'success: on localhost not needed'}) # peer added mock = MagicMock( return_value=GlusterResults.v34.peer_probe.success_other) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('10.0.0.2'), {'exitval': '0', 'output': 'success'}) # peer already member mock = MagicMock( return_value=GlusterResults.v34.peer_probe.success_already_peer['ip']) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('10.0.0.2'), {'exitval': '2', 'output': 'success: host 10.0.0.2 port 24007 already in peer list'}) # version 3.7 # peer failed unknown hostname # peer failed can't connect mock = MagicMock( return_value=GlusterResults.v37.peer_probe.fail_cant_connect) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertRaises(CommandExecutionError, glusterfs.peer, 'server2') # peer self mock = MagicMock( return_value=GlusterResults.v37.peer_probe.success_self) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('server1'), {'exitval': '1', 'output': 'Probe on localhost not needed'}) # peer added mock = MagicMock( return_value=GlusterResults.v37.peer_probe.success_other) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('server2'), {'exitval': '0', 'output': None}) # peer already member mock = MagicMock( return_value=GlusterResults.v37.peer_probe.success_already_peer['hostname']) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('server2'), {'exitval': '2', 'output': 'Host server2 port 24007 already in peer list'}) # peer in reverse # by ip address # peer added mock = MagicMock( return_value=GlusterResults.v37.peer_probe.success_other) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('10.0.0.2'), {'exitval': '0', 'output': None}) # peer already member mock = MagicMock( return_value=GlusterResults.v37.peer_probe.success_already_peer['ip']) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('10.0.0.2'), {'exitval': '2', 'output': 'Host 10.0.0.2 port 24007 already in peer list'}) # peer self mock = MagicMock( return_value=GlusterResults.v37.peer_probe.success_self) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('10.0.0.1'), {'exitval': '1', 'output': 'Probe on localhost not needed'}) # peer in reverse (probe server1 from server2) mock = MagicMock( return_value=GlusterResults.v37.peer_probe.success_first_hostname_from_second_first_time) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('server1'), {'exitval': '2', 'output': 'Host server1 port 24007 already in peer list'}) # peer in reverse using ip address instead of hostname first time mock = MagicMock( return_value=GlusterResults.v37.peer_probe.success_first_ip_from_second_first_time) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('10.0.0.1'), {'exitval': '0', 'output': None}) mock = MagicMock( return_value=GlusterResults.v37.peer_probe.success_first_ip_from_second_second_time) with patch.dict(glusterfs.__salt__, {'cmd.run': mock}): self.assertEqual(glusterfs.peer('10.0.0.1'), {'exitval': '2', 'output': 'Host 10.0.0.1 port 24007 already in peer list'})