def test_missing_subnet(self): ip_address, _ = get_free_ip((self.subnet, )) ip = host.IP(interface=self.interface, address=ip_address) with self.assertRaises(IntegrityError): self.session.add(ip) self.session.commit()
def test_0040_wrong_subnet(self): subnets = Subnet.q.all() interface = host.Interface.q.first() ip_address, _ = get_free_ip((subnets[0], )) ip = host.IP(interface=interface, address=ip_address) with self.assertRaises(ValueError): ip.subnet = subnets[1] ip = host.IP(interface=interface, subnet=subnets[1]) with self.assertRaises(ValueError): ip.address = ip_address with self.assertRaises(ValueError): host.IP(interface=interface, subnet=subnets[1], address=ip_address)
def pick_ip(self): ip, _ = get_free_ip((self.subnet, )) addr = host.IP(interface=self.interface, address=ip, subnet=self.subnet) self.session.add(addr) self.session.commit() return addr
def test_wrong_subnet(self): ip_address, _ = get_free_ip((self.subnets[0], )) ip = host.IP(interface=self.interface, address=ip_address) with self.assertRaises(ValueError): ip.subnet = self.subnets[1] ip = host.IP(interface=self.interface, subnet=self.subnets[1]) with self.assertRaises(ValueError): ip.address = ip_address with self.assertRaises(ValueError): host.IP(interface=self.interface, subnet=self.subnets[1], address=ip_address)
def test_correct_subnet_and_ip(self): ip_address, _ = get_free_ip((self.subnet, )) ip = host.IP(interface=self.interface, address=ip_address, subnet=self.subnet) self.session.add(ip) self.session.commit() ip_address, _ = get_free_ip((self.subnet, )) ip = host.IP(address=ip_address, subnet=self.subnet, interface=self.interface) self.session.add(ip) self.session.commit() host.IP.q.filter(host.IP.interface == self.interface).delete() self.session.commit()
def test_0010_correct_subnet_and_ip(self): subnet = Subnet.q.first() interface = host.Interface.q.first() ip_address, _ = get_free_ip((subnet, )) ip = host.IP(interface=interface) ip.address = ip_address ip.subnet = subnet session.session.add(ip) session.session.commit() interface = host.Interface.q.first() ip_address, _ = get_free_ip((subnet, )) ip = host.IP(address=ip_address, subnet=subnet, interface=interface) session.session.add(ip) session.session.commit() host.IP.q.filter(host.IP.interface == interface).delete() session.session.commit()
def test_0030_missing_ip(self): subnet = Subnet.q.first() interface = host.Interface.q.first() ip = host.IP(interface=interface) ip.subnet = subnet def commit(): session.session.add(ip) session.session.commit() self.assertRaises(IntegrityError, commit)
def test_0020_missing_subnet(self): subnet = Subnet.q.first() interface = host.Interface.q.first() ip_address, _ = get_free_ip((subnet, )) ip = host.IP(interface=interface) ip.address = ip_address def commit(): session.session.add(ip) session.session.commit() self.assertRaises(IntegrityError, commit)
def test_0040_delete_subnet(self): subnet = Subnet.q.first() interface = host.Interface.q.first() ip, _ = get_free_ip((subnet, )) ip_addr = host.IP(interface=interface, address=ip, subnet=subnet) session.session.add(ip_addr) session.session.commit() with self.assertRaises(IntegrityError): ip_addr.subnet = None self.assertIsNone(ip_addr.subnet) session.session.commit()
def test_missing_ip(self): ip = host.IP(interface=self.interface, subnet=self.subnet) with self.assertRaises(IntegrityError): self.session.add(ip) self.session.commit()