def queryset(self, request, queryset): if self.value(): result = OutdatedServerManager().filter( servers=queryset, outdated=(self.value() == 'outdated')) return queryset.filter(id__in=[server.id for server, _ in result]) return queryset
def test_should_filter_outdated_servers(self, m): outdated = self._create_varnish_server('127.0.0.1', 8080, 6082) coherent = self._create_varnish_server('127.0.0.2', 8080, 6082) m.get('http://127.0.0.1:8080/vaas/', json={"vcl_version": "outdated_version"}) m.get('http://127.0.0.2:8080/vaas/', json={"vcl_version": "current_version"}) self.assertEqual([(outdated, "outdated_version")], OutdatedServerManager().filter([outdated, coherent]))
def test_should_not_load_outdated_disabled_servers(self, m): outdated_disabled = self._create_varnish_server('127.0.0.1', 8080, 6082, status='disabled') outdated = self._create_varnish_server('127.0.0.2', 8080, 6082) m.get('http://127.0.0.1:8080/vaas/', json={"vcl_version": "outdated_version"}) m.get('http://127.0.0.2:8080/vaas/', json={"vcl_version": "outdated_version"}) expected_server = OutdatedServer( outdated.pk, u'127.0.0.2', 6082, u'dc1-coh', u'cluster-coherency', u'outdated_version' ) self.assertEqual([expected_server], OutdatedServerManager().load('cluster-coherency'))
def test_should_load_outdated_servers_and_map_to_dto(self, m): outdated = self._create_varnish_server('127.0.0.1', 8080, 6082) coherent = self._create_varnish_server('127.0.0.2', 8080, 6082) m.get('http://127.0.0.1:8080/vaas/', json={"vcl_version": "outdated_version"}) m.get('http://127.0.0.2:8080/vaas/', json={"vcl_version": "current_version"}) expected_server = OutdatedServer( outdated.pk, u'127.0.0.1', 6082, u'dc1-coh', u'cluster-coherency', u'outdated_version' ) self.assertEqual([expected_server], OutdatedServerManager().load('cluster-coherency'))
def get_object_list(self, request): cluster = None if request: cluster = request.GET.get('cluster', None) return OutdatedServerManager().load(cluster)