Пример #1
0
    def test_finds_all_ring_files(self):
        devices = [
            dict(ip='1.2.3.4',
                 port='6001',
                 device='/sdb',
                 replication_port='6021',
                 replication_ip='1.2.3.4'),
            dict(ip='1.2.3.5',
                 port='6001',
                 device='/sdb',
                 replication_port='6021',
                 replication_ip='1.2.3.5')
        ]

        for f in ('object.ring.gz', 'object-1.ring.gz', 'account.ring.gz',
                  'container.ring.gz', 'junk'):
            open(os.path.join(self.testdir, f), 'wb')
        with mock.patch('swiftlm.utils.utility.RingData.load') as mock_load:
            with mock.patch('swiftlm.utils.utility.SWIFT_PATH', self.testdir):
                mock_load.return_value = mock.MagicMock(devs=devices)
                results = utility.get_ring_hosts()
        self.assertEqual(8, len(results))
        # 2 devs per ring file
        expected = [
            RingDeviceEntry(dev['ip'], dev['port'], dev['device'])
            for dev in devices
        ] * 4
        self.assertEqual(expected, results, results)
Пример #2
0
    def _get_devices(cls, ring_type):
        """
        Get a list of hosts compatible with Scout

        :param ring_type: Type of the ring, such as 'object'
        :returns: a set of tuples containing the ip and port of hosts
        """
        ring_data = get_ring_hosts(ring_type=ring_type)
        ips = set((n.ip, n.port) for n in ring_data)
        return ips
Пример #3
0
    def test_finds_all_ring_files(self):
        devices = [
            dict(ip="1.2.3.4", port="6001", device="/sdb", replication_port="6021", replication_ip="1.2.3.4"),
            dict(ip="1.2.3.5", port="6001", device="/sdb", replication_port="6021", replication_ip="1.2.3.5"),
        ]

        for f in ("object.ring.gz", "object-1.ring.gz", "account.ring.gz", "container.ring.gz", "junk"):
            open(os.path.join(self.testdir, f), "wb")
        with mock.patch("swiftlm.utils.utility.RingData.load") as mock_load:
            with mock.patch("swiftlm.utils.utility.SWIFT_PATH", self.testdir):
                mock_load.return_value = mock.MagicMock(devs=devices)
                results = utility.get_ring_hosts()
        self.assertEqual(8, len(results))
        # 2 devs per ring file
        expected = [RingDeviceEntry(dev["ip"], dev["port"], dev["device"]) for dev in devices] * 4
        self.assertEqual(expected, results, results)
Пример #4
0
 def test_no_swift_dir(self):
     non_existent_dir = os.path.join(self.testdir, "not_here")
     with mock.patch("swiftlm.utils.utility.SWIFT_PATH", non_existent_dir):
         results = utility.get_ring_hosts()
     self.assertEqual([], results)
Пример #5
0
 def test_no_ring_files(self):
     for f in "junk":
         open(os.path.join(self.testdir, f), "wb")
     with mock.patch("swiftlm.utils.utility.SWIFT_PATH", self.testdir):
         results = utility.get_ring_hosts()
     self.assertEqual([], results)
Пример #6
0
 def test_no_swift_dir(self):
     non_existent_dir = os.path.join(self.testdir, 'not_here')
     with mock.patch('swiftlm.utils.utility.SWIFT_PATH', non_existent_dir):
         results = utility.get_ring_hosts()
     self.assertEqual([], results)
Пример #7
0
 def test_no_ring_files(self):
     for f in ('junk'):
         open(os.path.join(self.testdir, f), 'wb')
     with mock.patch('swiftlm.utils.utility.SWIFT_PATH', self.testdir):
         results = utility.get_ring_hosts()
     self.assertEqual([], results)
Пример #8
0
def main():
    """Checks connectivity to memcache and object servers."""
    results = []

    if server_type(ServerType.proxy):
        cp = configparser.ConfigParser()
        cp.read(os.path.join(MEMCACHE_CONF_PATH, 'memcache.conf'))

        try:
            memcache_servers = [
                HostPort.from_string(s)
                for s in cp.get('memcache', 'memcache_servers').split(',')
            ]
        except configparser.NoSectionError:
            memcache_servers = []

        check(memcache_servers, memcache_check, results)

        # Check Keystone token-validation endpoint
        scheme = 'http'
        cp.read(os.path.join(SWIFT_PROXY_PATH, 'proxy-server.conf'))
        try:
            ise = cp.get('filter:authtoken', 'auth_url')
            parsed = urlparse.urlparse(ise)
            endpoint_servers = [HostPort(parsed.hostname, str(parsed.port))]
            scheme = parsed.scheme
        except configparser.NoSectionError:
            endpoint_servers = []

        check(endpoint_servers, connect_check, results, scheme=scheme)

    # rsync is required for ACO servers so filter on these server_type()
    if (server_type(ServerType.account) or server_type(ServerType.container)
            or server_type(ServerType.object)):
        # swiftlm-scan.conf is the ansible-generated source of truth
        # default in the case of ansible not laying down the rsync-target port
        cp = configparser.ConfigParser()
        cp.read(os.path.join(SWIFTLM_SCAN_PATH, 'swiftlm-scan.conf'))

        # this assumes (rightfully so) that all nodes will be using
        # the same rsync_bind_port as opposed to querying each node
        # for its possibly uniquely-configured port
        try:
            rsync_bind_port = cp.get('rsync-target', 'rsync_bind_port')
        except (configparser.NoSectionError, configparser.NoOptionError):
            rsync_bind_port = '873'

        try:
            # retrieve unique list of nodes in the ring using the ring file
            # and utilizing the configured replication network IP
            rsync_targets = []
            devices = get_ring_hosts(ring_type=None)
            rsync_set = set()
            for device in devices:
                if device.replication_ip not in rsync_set:
                    rsync_host = socket.gethostbyaddr(device.replication_ip)
                    rsync_targets.append(
                        HostPort(rsync_host[0], rsync_bind_port))
                    rsync_set.add(device.replication_ip)
        except Exception:
            pass

        check(rsync_targets, rsync_check, results)

    # TODO -- rewrite this as a connect_check
    # try:
    #     ping_targets = []
    #     devices = get_ring_hosts(ring_type=None)
    #     ip_set = set()
    #
    #     for device in devices:
    #         if device.ip not in ip_set:
    #             # Port not relevant for ping_check. (Empty string is an
    #             # invalid dimension value, Hence '_' used for target_port)
    #             ping_targets.append(HostPort(device.ip, '_'))
    #             ip_set.add(device.ip)
    #
    # except Exception:  # noqa
    #   # may be some problem loading ring files, but not concern of this check
    #     # to diagnose any further.
    #     pass
    #
    # check(ping_targets, ping_check, results)

    return results