def build_file(self): self.build_ip_maps() registry = Registry(config, self.conn) entries = self.conn.zk.get_children(self.registry.zk_ip_map_path) bundles = registry._ips_from_entries(entries) builder = IPtables(config, is_vpc=False, dry_run=True) builder.build(bundles)
def test_register_in_VPC(self): registry = Registry(config, self.conn) ip = registry.register() self.assertEquals(IPv4Network(unicode(self.conn.overlay_subnet)), self.conn.network) self.assertIn(IPv4Address(unicode(ip)), self.conn.network) ip_to_id = self.conn.zk.get(registry._zk_ip_path(ip))[0] id_to_ip = self.conn.zk.get(registry._zk_id_path)[0] self.assertEquals(self.conn.instance_id, ip_to_id) self.assertEquals(ip, id_to_ip)
def build_ip_maps(self): self.tempfiles = {} self.registry = Registry(config, self.conn) entries = [ "acf847a7c6804f6e8e3346a93386a654-32.32.32.32|10.8.2.1|192.168.0.1|0", "4d8e8617c68a46f89ceaef5bba33b3c0-32.32.32.33|10.8.2.2|192.168.0.2|0", "46a30a0bd5a44e7899a87f08ad79e6ff-32.32.32.34|10.8.2.3|192.168.0.3|1" ] self.conn.zk.ensure_path(self.registry.zk_ip_map_path) for entry in entries: self.conn.zk.create("%s/%s" % (self.registry.zk_ip_map_path, entry)) def return_ipset_temp(temp): temp.seek(0) self.tempfiles["ipset"] = temp.read() def return_iptables_temp(table, temp): temp.seek(0) self.tempfiles[table] = temp.read() IPtables._push_iptables_live = Mock(side_effect=return_iptables_temp) IPtables._push_ipset_live = Mock(side_effect=return_ipset_temp)