Skip to content

Commit

Permalink
bugfix for next-available (#250)
Browse files Browse the repository at this point in the history
* bugfix for next-available

* fix for:NPA-198: unable to set enable_dns field in hostRecord

* updating unit and e2e testcases for a, aaaa and host records
  • Loading branch information
Aish-sp authored Oct 22, 2024
1 parent 12d4e15 commit 4114f9a
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 45 deletions.
11 changes: 7 additions & 4 deletions e2e_tests/wapi_framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@ var _ = Describe("DNS Forward Zone", func() {
})
})

var _ = Describe("Allocate next available network", func() {
var _ = Describe("Allocate next available using EA", func() {
var connector *ConnectorFacadeE2E

BeforeEach(func() {
Expand Down Expand Up @@ -2725,7 +2725,8 @@ var _ = Describe("Allocate next available network", func() {
comment := "Test next_available_ip for record:host with ipv6"
eaMap := map[string]string{"*Site": "Norway"}
name := "testhost1.wapi.com"
recordHost := ibclient.NewIpNextAvailable(name, "record:host", eaMap, nil, false, ea, comment, false, nil, "IPV6")
recordHost := ibclient.NewIpNextAvailable(name, "record:host", eaMap, nil, false, ea, comment, false, nil, "IPV6",
false, false, "", "", "", "", false, 0, nil)

recordHost.SetObjectType("record:host")
ref, err := connector.CreateObject(recordHost)
Expand All @@ -2739,7 +2740,8 @@ var _ = Describe("Allocate next available network", func() {
comment := "Test next_available_ip for record:host with ipv4"
eaMap := map[string]string{"*Site": "Namibia"}
name := "testhost2.wapi.com"
recordHost := ibclient.NewIpNextAvailable(name, "record:host", eaMap, nil, false, ea, comment, false, nil, "IPV4")
recordHost := ibclient.NewIpNextAvailable(name, "record:host", eaMap, nil, false, ea, comment, false, nil, "IPV4",
false, false, "", "", "", "", false, 0, nil)

recordHost.SetObjectType("record:host")
ref, err := connector.CreateObject(recordHost)
Expand All @@ -2753,7 +2755,8 @@ var _ = Describe("Allocate next available network", func() {
comment := "Test next_available_ip for record:host with ipv4 and ipv6"
eaMap := map[string]string{"*Site": "Japan"}
name := "testhost3.wapi.com"
recordHost := ibclient.NewIpNextAvailable(name, "record:host", eaMap, nil, false, ea, comment, false, nil, "Both")
recordHost := ibclient.NewIpNextAvailable(name, "record:host", eaMap, nil, false, ea, comment, false, nil, "Both",
false, false, "", "", "", "", false, 0, nil)

recordHost.SetObjectType("record:host")
ref, err := connector.CreateObject(recordHost)
Expand Down
4 changes: 2 additions & 2 deletions object_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type IBObjectManager interface {
CreateDefaultNetviews(globalNetview string, localNetview string) (globalNetviewRef string, localNetviewRef string, err error)
CreateZoneForward(comment string, disable bool, eas EA, forwardTo NullableNameServers, forwardersOnly bool, forwardingServers *NullableForwardingServers, fqdn string, nsGroup string, view string, zoneFormat string, externalNsGroup string) (*ZoneForward, error)
CreateEADefinition(eadef EADefinition) (*EADefinition, error)
CreateHostRecord(enabledns bool, enabledhcp bool, recordName string, netview string, dnsview string, ipv4cidr string, ipv6cidr string, ipv4Addr string, ipv6Addr string, macAddr string, duid string, useTtl bool, ttl uint32, comment string, eas EA, aliases []string) (*HostRecord, error)
CreateHostRecord(enabledns bool, enabledhcp bool, recordName string, netview string, dnsview string, ipv4cidr string, ipv6cidr string, ipv4Addr string, ipv6Addr string, macAddr string, duid string, useTtl bool, ttl uint32, comment string, eas EA, aliases []string, disable bool) (*HostRecord, error)
CreateMXRecord(dnsView string, fqdn string, mx string, preference uint32, ttl uint32, useTtl bool, comment string, eas EA) (*RecordMX, error)
CreateNetwork(netview string, cidr string, isIPv6 bool, comment string, eas EA) (*Network, error)
CreateNetworkContainer(netview string, cidr string, isIPv6 bool, comment string, eas EA) (*NetworkContainer, error)
Expand Down Expand Up @@ -94,7 +94,7 @@ type IBObjectManager interface {
UpdateAAAARecord(ref string, netView string, recordName string, cidr string, ipAddr string, useTtl bool, ttl uint32, comment string, setEas EA) (*RecordAAAA, error)
UpdateCNAMERecord(ref string, canonical string, recordName string, useTtl bool, ttl uint32, comment string, setEas EA) (*RecordCNAME, error)
UpdateFixedAddress(fixedAddrRef string, netview string, name string, cidr string, ipAddr string, matchclient string, macOrDuid string, comment string, eas EA) (*FixedAddress, error)
UpdateHostRecord(hostRref string, enabledns bool, enabledhcp bool, name string, netview string, dnsView string, ipv4cidr string, ipv6cidr string, ipv4Addr string, ipv6Addr string, macAddress string, duid string, useTtl bool, ttl uint32, comment string, eas EA, aliases []string) (*HostRecord, error)
UpdateHostRecord(hostRref string, enabledns bool, enabledhcp bool, name string, netview string, dnsView string, ipv4cidr string, ipv6cidr string, ipv4Addr string, ipv6Addr string, macAddress string, duid string, useTtl bool, ttl uint32, comment string, eas EA, aliases []string, disable bool) (*HostRecord, error)
UpdateMXRecord(ref string, dnsView string, fqdn string, mx string, preference uint32, ttl uint32, useTtl bool, comment string, eas EA) (*RecordMX, error)
UpdateNetwork(ref string, setEas EA, comment string) (*Network, error)
UpdateNetworkContainer(ref string, setEas EA, comment string) (*NetworkContainer, error)
Expand Down
6 changes: 4 additions & 2 deletions object_manager_a-record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ var _ = Describe("Object Manager: A-record", func() {
recordName,
netviewName)

objectForCreation := NewIpNextAvailable(netviewName, objectType, nil, params, false, eas, comment, false, nil, ipAddrType)
objectForCreation := NewIpNextAvailable(recordName, objectType, nil, params, false, eas, comment, false, nil, ipAddrType,
false, false, "", "", netviewName, "", false, 0, nil)
objectAsResult := NewRecordA(
dnsView, "", recordName, "53.0.0.1", 5, true, comment, eas, fakeRefReturn)

Expand All @@ -91,7 +92,8 @@ var _ = Describe("Object Manager: A-record", func() {

It("should create A record with next available IP", func() {
// Call the function to allocate next available IP and create A record
result, err := objMgr.AllocateNextAvailableIp(netviewName, objectType, nil, params, false, eas, comment, false, nil, ipAddrType)
result, err := objMgr.AllocateNextAvailableIp(recordName, objectType, nil, params, false, eas, comment, false, nil, ipAddrType,
false, false, "", "", netviewName, "", false, 0, nil)

// Assert no error occurred
Expect(err).To(BeNil())
Expand Down
6 changes: 4 additions & 2 deletions object_manager_aaaa-record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ var _ = Describe("Object Manager: AAAA-record", func() {

fakeRefReturn := fmt.Sprintf("record:aaaa/ZG5zLmJpbmRfY25h:%s/%20%20", recordName)

objectForCreation := NewIpNextAvailable("", objectType, nil, params, false, ea, comment, false, nil, ipAddrType)
objectForCreation := NewIpNextAvailable(recordName, objectType, nil, params, false, ea, comment, false, nil, ipAddrType,
false, false, "", "", "", "", false, 0, nil)
objectAsResult := NewRecordAAAA(
dnsView, recordName, "2001:db8:abcd:14::1", false, 0, comment, ea, fakeRefReturn)

Expand All @@ -113,7 +114,8 @@ var _ = Describe("Object Manager: AAAA-record", func() {

It("should allocate next available IP and create AAAA record", func() {
// Call AllocateNextAvailableIp for AAAA record
result, err := objMgr.AllocateNextAvailableIp("", objectType, nil, params, false, ea, comment, false, nil, ipAddrType)
result, err := objMgr.AllocateNextAvailableIp(recordName, objectType, nil, params, false, ea, comment, false, nil, ipAddrType,
false, false, "", "", "", "", false, 0, nil)

// Assert no error occurred
Expect(err).To(BeNil())
Expand Down
9 changes: 5 additions & 4 deletions object_manager_host_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func (objMgr *ObjectManager) CreateHostRecord(
ttl uint32,
comment string,
eas EA,
aliases []string) (*HostRecord, error) {
aliases []string,
disable bool) (*HostRecord, error) {

if ipv4Addr == "" && ipv4cidr != "" {
if netview == "" {
Expand Down Expand Up @@ -56,7 +57,7 @@ func (objMgr *ObjectManager) CreateHostRecord(
}
recordHost = NewHostRecord(
netview, recordName, "", "", recordHostIpv4AddrSlice, recordHostIpv6AddrSlice,
eas, enabledns, dnsview, "", "", useTtl, ttl, comment, aliases)
eas, enabledns, dnsview, "", "", useTtl, ttl, comment, aliases, disable)
ref, err := objMgr.connector.CreateObject(recordHost)
if err != nil {
return nil, err
Expand Down Expand Up @@ -166,7 +167,7 @@ func (objMgr *ObjectManager) UpdateHostRecord(
ttl uint32,
comment string,
eas EA,
aliases []string) (*HostRecord, error) {
aliases []string, disable bool) (*HostRecord, error) {

recordHostIpv4AddrSlice := []HostRecordIpv4Addr{}
recordHostIpv6AddrSlice := []HostRecordIpv6Addr{}
Expand Down Expand Up @@ -243,7 +244,7 @@ func (objMgr *ObjectManager) UpdateHostRecord(
}
updateHostRecord := NewHostRecord(
"", name, "", "", recordHostIpv4AddrSlice, recordHostIpv6AddrSlice,
eas, enabledns, dnsView, "", hostRref, useTtl, ttl, comment, aliases)
eas, enabledns, dnsView, "", hostRref, useTtl, ttl, comment, aliases, disable)
ref, err := objMgr.connector.UpdateObject(updateHostRecord, hostRref)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 4114f9a

Please sign in to comment.