def test_revision(self, sock=None): myset = WiSet(name=self.name, attr_type="hash:net", sock=sock) myset.create() assert load_ipset(self.name, sock=sock).revision >= 6 myset.destroy()
def test_force_attr_revision(self): sock = get_ipset_socket(attr_revision=2) myset = WiSet(name=self.name, attr_type="hash:net", sock=sock) myset.create() assert load_ipset(self.name, sock=sock).revision >= 2 myset.destroy() sock.close()
def test_physdev(self): myset = WiSet(name=self.name, attr_type="hash:net,iface") myset.create() myset.add("192.168.0.0/24,eth0", physdev=False) myset.add("192.168.1.0/24,eth0", physdev=True) content = myset.content myset.destroy() assert content["192.168.0.0/24,eth0"].physdev is False assert content["192.168.1.0/24,eth0"].physdev is True
def test_wildcard_entries(self): require_kernel(5, 5) myset = WiSet(name=self.name, attr_type="hash:net,iface") myset.create() myset.add("192.168.0.0/24,eth", wildcard=True) myset.add("192.168.1.0/24,wlan0", wildcard=False) content = myset.content myset.destroy() assert content["192.168.0.0/24,eth"].wildcard is True assert content["192.168.1.0/24,wlan0"].wildcard is False
def test_replace(content_a, content_b): myset = WiSet(name=self.name, sock=sock) myset.create() myset.insert_list(content_a) myset.update_content() for value in content_a: assert value in myset.content myset.replace_entries(content_b) myset.update_content() for (old, new) in zip(content_a, content_b): assert old not in myset.content assert new in myset.content myset.destroy()
def test_add_ipstats(self, sock=None): data = IPStats(packets=10, bytes=1000, comment="hello world", skbmark="0x10/0x10", timeout=None) myset = WiSet(name=self.name, attr_type="hash:net", comment=True, skbinfo=True, counters=True, sock=sock) myset.create() myset.add("198.51.100.0/24", **data._asdict()) assert "198.51.100.0/24" in myset.content assert data == myset.content["198.51.100.0/24"] myset.destroy()
def test_basic_attribute_reads(self, sock=None): for value in [True, False]: myset = WiSet(name=self.name, sock=sock, counters=value, comment=value) if sock is None: myset.open_netlink() myset.create() from_netlink = load_ipset(self.name, sock=sock) assert value == from_netlink.comment assert value == from_netlink.counters myset.destroy() if sock is None: myset.close_netlink()
def test_stats_consistency(self, sock=None): """ Test several way to fill the statistics of one IPSet """ entries = ["1.2.3.4", "1.2.3.5", "1.2.3.6"] myset = WiSet(name=self.name, sock=sock) myset.create() myset.insert_list(entries) myset_lists = load_all_ipsets(sock=sock, content=True)[self.name] for value in entries: assert value in myset_lists.content myset_list = load_ipset(self.name, sock=sock, content=True) for value in entries: assert value in myset_list.content myset.destroy()
def test_hashnet_with_comment(self, sock=None): comment = "abcdef" myset = WiSet(name=self.name, attr_type="hash:net", comment=True, sock=sock) myset.create() inherit_sock = sock is not None myset = load_ipset(self.name, sock=sock, inherit_sock=inherit_sock) assert myset.comment myset.add("192.168.1.1", comment=comment) myset.update_content() assert myset.content["192.168.1.1/32"].comment == comment myset.destroy()
def test_replace(content_a, content_b): myset = WiSet(name=self.name, sock=sock, comment=True) myset.create() myset.insert_list(content_a) myset.update_content() for value in content_a: assert value['entry'] in myset.content assert value['comment'] == ( myset.content[value['entry']].comment) myset.replace_entries(content_b) myset.update_content() for value in content_a: assert value['entry'] not in myset.content for value in content_b: assert value['entry'] in myset.content assert value['comment'] == ( myset.content[value['entry']].comment) myset.destroy()
def test_replace(content_a, content_b): myset = WiSet(name=self.name, sock=sock, comment=True) myset.create() myset.insert_list(content_a) myset.update_content() for value in content_a: assert value['entry'] in myset.content assert value['comment'] == (myset .content[value['entry']] .comment) myset.replace_entries(content_b) myset.update_content() for value in content_a: assert value['entry'] not in myset.content for value in content_b: assert value['entry'] in myset.content assert value['comment'] == (myset .content[value['entry']] .comment) myset.destroy()