示例#1
0
 def testGetPeer(self, _peer_list):
     existing_peers = [
         peer.Peer(uuid=uuid.UUID("663bbc5b-c9b4-4a02-8b56-85e05e1b01c8"),
                   hostname=ip_address("172.31.12.7"),
                   status=peer.State.PeerInCluster),
         peer.Peer(uuid=uuid.UUID("15af92ad-ae64-4aba-89db-73730f2ca6ec"),
                   hostname=ip_address("172.31.21.242"),
                   status=peer.State.PeerInCluster)
     ]
     _peer_list.return_value = Ok(existing_peers)
     result = peer.get_peer(hostname=ip_address('172.31.21.242'))
     self.assertIs(result, existing_peers[1])
示例#2
0
 def testPeerProbe(self, _run_command, _peer_list):
     existing_peers = [
         peer.Peer(uuid=uuid.UUID("663bbc5b-c9b4-4a02-8b56-85e05e1b01c8"),
                   hostname=ip_address("172.31.12.7"),
                   status=peer.State.PeerInCluster),
         peer.Peer(uuid=uuid.UUID("15af92ad-ae64-4aba-89db-73730f2ca6ec"),
                   hostname=ip_address("172.31.21.242"),
                   status=peer.State.PeerInCluster)
     ]
     _peer_list.return_value = Ok(existing_peers)
     peer.peer_probe(hostname='172.31.21.243')
     # print("Peer probe result: {}".format(result.value))
     _run_command.assert_called_with("gluster",
                                     ["peer", "probe", "172.31.21.243"],
                                     True, False)
示例#3
0
 def testParsePeerStatus(self):
     expected_peers = [
         peer.Peer(uuid=uuid.UUID("663bbc5b-c9b4-4a02-8b56-85e05e1b01c8"),
                   hostname=ip_address("172.31.12.7"),
                   status=peer.State.PeerInCluster),
         peer.Peer(uuid=uuid.UUID("15af92ad-ae64-4aba-89db-73730f2ca6ec"),
                   hostname=ip_address("172.31.21.242"),
                   status=peer.State.PeerInCluster)
     ]
     with open('unit_tests/peer_status.xml', 'r') as xml_output:
         lines = xml_output.readlines()
         result_list = peer.parse_peer_status("".join(lines))
         self.assertTrue(result_list.is_ok())
         peer_list = result_list.value
         for status in peer_list:
             self.assertIn(member=status, container=expected_peers)
         self.assertEqual(2, len(result_list.value),
                          "Expected 2 peer objects")
示例#4
0
 def testParsePeerList(self, _resolve_to_ip):
     _resolve_to_ip.return_value = Ok("172.31.21.243")
     expected_peers = [
         peer.Peer(uuid=uuid.UUID("663bbc5b-c9b4-4a02-8b56-85e05e1b01c8"),
                   hostname=ip_address("172.31.12.7"),
                   status=peer.State.PeerInCluster),
         peer.Peer(uuid=uuid.UUID("15af92ad-ae64-4aba-89db-73730f2ca6ec"),
                   hostname=ip_address("172.31.21.242"),
                   status=peer.State.PeerInCluster),
         peer.Peer(uuid=uuid.UUID("cebf02bb-a304-4058-986e-375e2e1e5313"),
                   hostname=ip_address("172.31.21.243"),
                   status=None)
     ]
     with open('unit_tests/pool_list.xml', 'r') as xml_output:
         lines = xml_output.readlines()
         result_list = peer.parse_peer_list("".join(lines))
         self.assertTrue(result_list.is_ok())
         peer_list = result_list.value
         for peer_object in peer_list:
             self.assertIn(member=peer_object, container=expected_peers)
import sys
import unittest
import uuid

import mock
from result import Ok

from lib.gluster import peer, volume

mock_apt = mock.MagicMock()
sys.modules['apt'] = mock_apt
mock_apt.apt_pkg = mock.MagicMock()

peer_1 = peer.Peer(uuid=uuid.UUID("39bdbbd6-5271-4c23-b405-cc0b67741ebc"),
                   hostname="172.20.21.231",
                   status=None)
peer_2 = peer.Peer(uuid=uuid.UUID("a51b28e8-6f06-4563-9a5f-48f3f31a6713"),
                   hostname="172.20.21.232",
                   status=None)
peer_3 = peer.Peer(uuid=uuid.UUID("57dd0230-50d9-452a-be8b-8f9dd9fe0264"),
                   hostname="172.20.21.233",
                   status=None)

brick_list = [
    volume.Brick(brick_uuid=uuid.UUID("12d4bd98-e102-4174-b99a-ef76f849474e"),
                 peer=peer_1,
                 path="/mnt/sdb",
                 is_arbiter=False),
    volume.Brick(brick_uuid=uuid.UUID("a563d73c-ef3c-47c6-b50d-ddc800ef5dae"),
                 peer=peer_2,