def test_get_missing_dhcp_subnet(self): """Fetch missing DHCP subnet; return empty list.""" subnet = "192.168.0.0" sub = SpokeDHCPSubnet(self.dhcp_server) result = sub.get(subnet)["data"] expected_result = [] self.assertEqual(result, expected_result)
def test_delete_dhcp_subnet(self): """Delete DHCP subnet, return True.""" subnet = '172.16.1.0' mask = '8' sub = SpokeDHCPSubnet(self.dhcp_server) sub.create(subnet, mask) self.assertTrue(sub.delete(subnet))
def test_get_missing_dhcp_subnet(self): """Fetch missing DHCP subnet; return empty list.""" subnet = '192.168.0.0' sub = SpokeDHCPSubnet(self.dhcp_server) result = sub.get(subnet)['data'] expected_result = [] self.assertEqual(result, expected_result)
def test_delete_dhcp_subnet(self): """Delete DHCP subnet, return True.""" subnet = "172.16.1.0" mask = "8" sub = SpokeDHCPSubnet(self.dhcp_server) sub.create(subnet, mask) self.assertTrue(sub.delete(subnet))
def subnet_search(dhcp_server, subnet): try: from spoke.lib.dhcp import SpokeDHCPSubnet subnet = SpokeDHCPSubnet(dhcp_server) result = subnet.get(subnet) except error.SpokeError as e: result = common.handle_error(e) return result
def subnet_create(dhcp_server, subnet, mask, start_ip=None, stop_ip=None): try: from spoke.lib.dhcp import SpokeDHCPSubnet subnet = SpokeDHCPSubnet(dhcp_server) result = subnet.create(subnet, mask, start_ip, stop_ip) except error.SpokeError as e: result = common.handle_error(e) return result
def test_create_dhcp_subnet_twice(self): """Create DHCP subnet twice; raise AlreadyExists.""" subnet = "10.0.0.0" subnet_mask = "16" sub = SpokeDHCPSubnet(self.dhcp_server) sub.create(subnet, subnet_mask) self.assertRaises(error.AlreadyExists, sub.create, subnet, subnet_mask) sub.delete(subnet)
def subnet_create(dhcp_server, subnet, mask, start_ip=None, stop_ip=None): try: from spoke.lib.dhcp import SpokeDHCPSubnet subnet= SpokeDHCPSubnet(dhcp_server) result = subnet.create(subnet, mask, start_ip, stop_ip) except error.SpokeError as e: result = common.handle_error(e) return result
def test_delete_dhcp_service_before_subnet(self): """Delete DHCP service while subnet present, raise SaveTheBabies.""" dhcp_server = "deletechildren.dhcp.service.local" dhcp = SpokeDHCPService() dhcp.create(dhcp_server) subnet = "10.0.0.0" mask = "16" sub = SpokeDHCPSubnet(dhcp_server) sub.create(subnet, mask) self.assertRaises(error.SaveTheBabies, dhcp.delete, dhcp_server) sub.delete(subnet) dhcp.delete(dhcp_server)
def test_create_dhcp_subnet_with_integer_mask(self): """Create DHCP subnet with integer mask; return True.""" subnet = "10.0.0.0" subnet_mask = 16 sub = SpokeDHCPSubnet(self.dhcp_server) result = sub.create(subnet, subnet_mask)["data"] service_name = self.dhcp_server + self.dhcp_conf_suffix service_dn = "cn=%s,%s" % (service_name, self.base_dn) dn = "cn=%s,%s" % (subnet, service_dn) dn_info = {"objectClass": ["top", self.dhcp_subnet_class], "cn": [subnet], "dhcpNetMask": [str(subnet_mask)]} expected_result = [(dn, dn_info)] self.assertEqual(result, expected_result) sub.delete(subnet)
def test_create_dhcp_subnet_with_integer_mask(self): """Create DHCP subnet with integer mask; return True.""" subnet = '10.0.0.0' subnet_mask = 16 sub = SpokeDHCPSubnet(self.dhcp_server) result = sub.create(subnet, subnet_mask)['data'] service_name = self.dhcp_server + self.dhcp_conf_suffix service_dn = 'cn=%s,%s' % (service_name, self.base_dn) dn = 'cn=%s,%s' % (subnet, service_dn) dn_info = {'objectClass': ['top', self.dhcp_subnet_class], 'cn': [subnet], 'dhcpNetMask': [str(subnet_mask)]} expected_result = [(dn, dn_info)] self.assertEqual(result, expected_result) sub.delete(subnet)
def test_create_dhcp_subnet_with_missing_stop_ip(self): """Create DHCP subnet with no stop IP; raise InputError.""" subnet = '10.0.0.0' subnet_mask = '16' start_ip = '10.0.0.1' sub = SpokeDHCPSubnet(self.dhcp_server) self.assertRaises(error.InputError, sub.create, subnet, subnet_mask, start_ip)
def test_create_dhcp_subnet_with_integer_mask(self): """Create DHCP subnet with integer mask; return True.""" subnet = '10.0.0.0' subnet_mask = 16 sub = SpokeDHCPSubnet(self.dhcp_server) result = sub.create(subnet, subnet_mask)['data'] service_name = self.dhcp_server + self.dhcp_conf_suffix service_dn = 'cn=%s,%s' % (service_name, self.base_dn) dn = 'cn=%s,%s' % (subnet, service_dn) dn_info = { 'objectClass': ['top', self.dhcp_subnet_class], 'cn': [subnet], 'dhcpNetMask': [str(subnet_mask)] } expected_result = [(dn, dn_info)] self.assertEqual(result, expected_result) sub.delete(subnet)
def test_create_dhcp_subnet_with_non_ip_range(self): """Create DHCP subnet with non IP range; raise InputError.""" subnet = '10.0.0.0' subnet_mask = '16' start_ip = '10.0.0' stop_ip = '10.0.0.254' sub = SpokeDHCPSubnet(self.dhcp_server) self.assertRaises(error.InputError, sub.create, subnet, subnet_mask, start_ip, stop_ip)
def test_create_dhcp_subnet_with_stop_ip_preceding_start_ip(self): """Create DHCP subnet with the stop IP preceding the start ip; \ raise InputError.""" subnet = '10.0.0.0' subnet_mask = '16' start_ip = '10.0.2.25' stop_ip = '10.0.1.250' sub = SpokeDHCPSubnet(self.dhcp_server) self.assertRaises(error.InputError, sub.create, subnet, subnet_mask, start_ip, stop_ip)
def test_get_dhcp_subnet(self): """Fetch DHCP subnet; return True.""" subnet = '10.0.0.0' mask = '16' start_ip = '10.0.0.1' stop_ip = '10.0.0.254' subnet_range = start_ip + ' ' + stop_ip sub = SpokeDHCPSubnet(self.dhcp_server) result = sub.create(subnet, mask, start_ip, stop_ip)['data'] service_name = self.dhcp_server + self.dhcp_conf_suffix service_dn = 'cn=%s,%s' % (service_name, self.base_dn) dn = 'cn=%s,%s' % (subnet, service_dn) dn_info = {'objectClass': ['top', self.dhcp_subnet_class], 'cn': [subnet], 'dhcpNetMask': [str(mask)], 'dhcpRange': [subnet_range]} expected_result = [(dn, dn_info)] self.assertEqual(result, expected_result) sub.delete(subnet)
def test_get_dhcp_subnet(self): """Fetch DHCP subnet; return True.""" subnet = "10.0.0.0" mask = "16" start_ip = "10.0.0.1" stop_ip = "10.0.0.254" subnet_range = start_ip + " " + stop_ip sub = SpokeDHCPSubnet(self.dhcp_server) result = sub.create(subnet, mask, start_ip, stop_ip)["data"] service_name = self.dhcp_server + self.dhcp_conf_suffix service_dn = "cn=%s,%s" % (service_name, self.base_dn) dn = "cn=%s,%s" % (subnet, service_dn) dn_info = { "objectClass": ["top", self.dhcp_subnet_class], "cn": [subnet], "dhcpNetMask": [str(mask)], "dhcpRange": [subnet_range], } expected_result = [(dn, dn_info)] self.assertEqual(result, expected_result) sub.delete(subnet)
def test_get_dhcp_subnet(self): """Fetch DHCP subnet; return True.""" subnet = '10.0.0.0' mask = '16' start_ip = '10.0.0.1' stop_ip = '10.0.0.254' subnet_range = start_ip + ' ' + stop_ip sub = SpokeDHCPSubnet(self.dhcp_server) result = sub.create(subnet, mask, start_ip, stop_ip)['data'] service_name = self.dhcp_server + self.dhcp_conf_suffix service_dn = 'cn=%s,%s' % (service_name, self.base_dn) dn = 'cn=%s,%s' % (subnet, service_dn) dn_info = { 'objectClass': ['top', self.dhcp_subnet_class], 'cn': [subnet], 'dhcpNetMask': [str(mask)], 'dhcpRange': [subnet_range] } expected_result = [(dn, dn_info)] self.assertEqual(result, expected_result) sub.delete(subnet)
def test_create_dhcp_subnet_twice(self): """Create DHCP subnet twice; raise AlreadyExists.""" subnet = '10.0.0.0' subnet_mask = '16' sub = SpokeDHCPSubnet(self.dhcp_server) sub.create(subnet, subnet_mask) self.assertRaises(error.AlreadyExists, sub.create, subnet, subnet_mask) sub.delete(subnet)
def test_delete_dhcp_service_before_subnet(self): """Delete DHCP service while subnet present, raise SaveTheBabies.""" dhcp_server = 'deletechildren.dhcp.service.local' dhcp = SpokeDHCPService() dhcp.create(dhcp_server) subnet = '10.0.0.0' mask = '16' sub = SpokeDHCPSubnet(dhcp_server) sub.create(subnet, mask) self.assertRaises(error.SaveTheBabies, dhcp.delete, dhcp_server) sub.delete(subnet) dhcp.delete(dhcp_server)
def test_create_dhcp_subnet_with_invalid_mask(self): """Create DHCP subnet with non-integer mask; raise InputError.""" subnet = '10.0.0.0' subnet_mask = '255.0.0.0' sub = SpokeDHCPSubnet(self.dhcp_server) self.assertRaises(error.InputError, sub.create, subnet, subnet_mask)
def test_get_invalid_dhcp_subnet(self): """Fetch DHCP invalid subnet; raise InputError.""" subnet = '10.0.0' sub = SpokeDHCPSubnet(self.dhcp_server) self.assertRaises(error.InputError, sub.get, subnet)
def test_delete_missing_dhcp_subnet(self): """Delete missing DHCP subnet; raise NotFound.""" # This should be deleted when the instantiation raises the error. subnet = '172.16.2.0' sub = SpokeDHCPSubnet(self.dhcp_server) self.assertRaises(error.NotFound, sub.delete, subnet)