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_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_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_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_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_delete(dhcp_server, subnet): try: from spoke.lib.dhcp import SpokeDHCPSubnet subnet = SpokeDHCPSubnet(dhcp_server) result = subnet.delete(subnet) except error.SpokeError as e: result = common.handle_error(e) return result
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_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)