コード例 #1
0
    def testGetCandidatesYesMemcache(self):
        sliver_tool_list = [
            MockSliverTool(status_ipv4=message.STATUS_ONLINE,
                           status_ipv6=message.STATUS_OFFLINE),
            MockSliverTool(status_ipv4=message.STATUS_OFFLINE,
                           status_ipv6=message.STATUS_ONLINE),
            MockSliverTool(status_ipv4=message.STATUS_OFFLINE,
                           status_ipv6=message.STATUS_ONLINE),
            MockSliverTool(status_ipv4=message.STATUS_ONLINE,
                           status_ipv6=message.STATUS_ONLINE),
            MockSliverTool(status_ipv4=message.STATUS_OFFLINE,
                           status_ipv6=message.STATUS_OFFLINE)
        ]
        memcache.set('valid_tool_id',
                     sliver_tool_list,
                     namespace=constants.MEMCACHE_NAMESPACE_TOOLS)

        base_resolver = resolver.ResolverBase()
        mock_query = mock.Mock(tool_id='valid_tool_id')
        self.assertEqual(
            2,
            len(
                base_resolver._get_candidates(mock_query,
                                              message.ADDRESS_FAMILY_IPv4)))
        self.assertEqual(
            3,
            len(
                base_resolver._get_candidates(mock_query,
                                              message.ADDRESS_FAMILY_IPv6)))
コード例 #2
0
    def testGetCandidatesFromSitesNoMemcacheNoDatastore(self):
        sliver_tool_list = [
            MockSliverTool('s1', message.STATUS_OFFLINE,
                           message.STATUS_OFFLINE)
        ]
        memcache.set('tool_id2',
                     sliver_tool_list,
                     namespace=constants.MEMCACHE_NAMESPACE_TOOLS)

        root = TestEntityGroupRoot(key_name='root')
        st1 = model.SliverTool(parent=root.key())
        st1.tool_id = 'valid_tool_id'
        st1.site_id = 's1'
        st1.status_ipv4 = message.STATUS_OFFLINE
        st1.status_ipv6 = message.STATUS_OFFLINE
        st1.put()

        base_resolver = resolver.ResolverBase()
        mock_query = mock.Mock(tool_id='valid_tool_id')
        self.assertEqual(
            0,
            len(
                base_resolver._get_candidates_from_sites(
                    mock_query, message.ADDRESS_FAMILY_IPv4, ['s1'])))
        self.assertEqual(
            0,
            len(
                base_resolver._get_candidates_from_sites(
                    mock_query, message.ADDRESS_FAMILY_IPv6, ['s1'])))
コード例 #3
0
    def testGetCandidatesYesMemcacheButOffline(self):
        sliver_tool_list = [
            MockSliverTool(status_ipv4=message.STATUS_OFFLINE,
                           status_ipv6=message.STATUS_OFFLINE)
        ]
        memcache.set('valid_tool_id',
                     sliver_tool_list,
                     namespace=constants.MEMCACHE_NAMESPACE_TOOLS)

        root = TestEntityGroupRoot(key_name='root')
        st1 = model.SliverTool(parent=root.key())
        st1.tool_id = 'valid_tool_id'
        st1.status_ipv4 = message.STATUS_ONLINE
        st1.status_ipv6 = message.STATUS_ONLINE
        st1.put()

        base_resolver = resolver.ResolverBase()
        mock_query = mock.Mock(tool_id='valid_tool_id')
        self.assertEqual(
            0,
            len(
                base_resolver._get_candidates(mock_query,
                                              message.ADDRESS_FAMILY_IPv4)))
        self.assertEqual(
            0,
            len(
                base_resolver._get_candidates(mock_query,
                                              message.ADDRESS_FAMILY_IPv6)))
コード例 #4
0
    def testGetCandidatesFromSitesNoMemcacheYesDatastore(self):
        root = TestEntityGroupRoot(key_name='root')
        st1 = model.SliverTool(parent=root.key())
        st1.tool_id = 'valid_tool_id'
        st1.site_id = 's1'
        st1.status_ipv4 = message.STATUS_ONLINE
        st1.status_ipv6 = message.STATUS_ONLINE
        st1.put()
        st2 = model.SliverTool(parent=root.key())
        st2.tool_id = 'valid_tool_id'
        st2.site_id = 's1'
        st2.status_ipv4 = message.STATUS_ONLINE
        st2.status_ipv6 = message.STATUS_OFFLINE
        st2.put()
        st3 = model.SliverTool(parent=root.key())
        st3.tool_id = 'valid_tool_id'
        st3.site_id = 's1'
        st3.status_ipv4 = message.STATUS_OFFLINE
        st3.status_ipv6 = message.STATUS_ONLINE
        st3.put()
        st4 = model.SliverTool(parent=root.key())
        st4.tool_id = 'valid_tool_id'
        st4.site_id = 's2'
        st4.status_ipv4 = message.STATUS_OFFLINE
        st4.status_ipv6 = message.STATUS_ONLINE
        st4.put()
        st5 = model.SliverTool(parent=root.key())
        st5.tool_id = 'valid_tool_id'
        st5.site_id = 's1'
        st5.status_ipv4 = message.STATUS_OFFLINE
        st5.status_ipv6 = message.STATUS_OFFLINE
        st5.put()

        base_resolver = resolver.ResolverBase()
        mock_query = mock.Mock(tool_id='valid_tool_id')
        self.assertEqual(
            2,
            len(
                base_resolver._get_candidates_from_sites(
                    mock_query, message.ADDRESS_FAMILY_IPv4, ['s1'])))
        self.assertEqual(
            2,
            len(
                base_resolver._get_candidates_from_sites(
                    mock_query, message.ADDRESS_FAMILY_IPv6, ['s1'])))