Skip to content

Commit

Permalink
fixing IBObjectManager.UpdateHostRecord()
Browse files Browse the repository at this point in the history
Additional argument added to specify DNS view,
otherwise there is an error when searching a host
record which is not in the default DNS view.

Plus some of minor fixes.
  • Loading branch information
skudriavtsev committed Nov 9, 2022
1 parent fe67681 commit 92ee29d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
3 changes: 1 addition & 2 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func getHTTPResponseError(resp *http.Response) error {
defer resp.Body.Close()
content, _ := ioutil.ReadAll(resp.Body)
msg := fmt.Sprintf("WAPI request error: %d('%s')\nContents:\n%s\n", resp.StatusCode, resp.Status, content)
log.Printf(msg)
if resp.StatusCode == http.StatusNotFound {
return NewNotFoundError(msg)
}
Expand Down Expand Up @@ -296,7 +295,7 @@ func (wrb *WapiRequestBuilder) BuildRequest(t RequestType, obj IBObject, ref str

req, err = http.NewRequest(t.toMethod(), urlStr, bytes.NewBuffer(bodyStr))
if err != nil {
log.Printf("err1: '%s'", err)
log.Printf("cannot build request: '%s'", err)
return
}
req.Header.Set("Content-Type", "application/json")
Expand Down
2 changes: 1 addition & 1 deletion object_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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, 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) (*HostRecord, error)
UpdateNetwork(ref string, setEas EA, comment string) (*Network, error)
UpdateNetworkContainer(ref string, setEas EA, comment string) (*NetworkContainer, error)
UpdateNetworkView(ref string, name string, comment string, setEas EA) (*NetworkView, error)
Expand Down
6 changes: 5 additions & 1 deletion object_manager_host_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (objMgr *ObjectManager) UpdateHostRecord(
enableDhcp bool,
name string,
netView string,
dnsView string,
ipv4cidr string,
ipv6cidr string,
ipv4Addr string,
Expand Down Expand Up @@ -237,9 +238,12 @@ func (objMgr *ObjectManager) UpdateHostRecord(
recordHostIpAddr := NewHostRecordIpv6Addr(ipv6Addr, duid, enableDhcpv6, "")
recordHostIpv6AddrSlice = []HostRecordIpv6Addr{*recordHostIpAddr}
}
if !enabledns {
dnsView = ""
}
updateHostRecord := NewHostRecord(
"", name, "", "", recordHostIpv4AddrSlice, recordHostIpv6AddrSlice,
eas, enabledns, "", "", hostRref, useTtl, ttl, comment, aliases)
eas, enabledns, dnsView, "", hostRref, useTtl, ttl, comment, aliases)
ref, err := objMgr.connector.UpdateObject(updateHostRecord, hostRref)
if err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions object_manager_host_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ var _ = Describe("Object Manager: host record", func() {
"ea5": "ea5_old_value"}
initialAliases := []string{"abc.test.com", "xyz.test.com"}
initObj := NewHostRecord("", hostName, "", "", []HostRecordIpv4Addr{},
[]HostRecordIpv6Addr{}, initialEas, enableDNS, "", "", "", useTtl, ttl, "old comment", initialAliases)
[]HostRecordIpv6Addr{}, initialEas, enableDNS, "someDNSview", "", "", useTtl, ttl, "old comment", initialAliases)
initObj.Ref = ref

setEas := EA{
Expand All @@ -398,11 +398,11 @@ var _ = Describe("Object Manager: host record", func() {
updateUseTtl := false
updateTtl := uint32(0)
updateObjIn := NewHostRecord("", "host1.test.com", "", "", []HostRecordIpv4Addr{},
[]HostRecordIpv6Addr{}, expectedEas, enableDNS, "", "", "", updateUseTtl, updateTtl, comment, expectedAliases)
[]HostRecordIpv6Addr{}, expectedEas, enableDNS, "someDNSview", "", "", updateUseTtl, updateTtl, comment, expectedAliases)
updateObjIn.Ref = ref

expectedObj := NewHostRecord("", "host1.test.com", "", "", []HostRecordIpv4Addr{},
[]HostRecordIpv6Addr{}, expectedEas, enableDNS, "", "", "", updateUseTtl, updateTtl, comment, expectedAliases)
[]HostRecordIpv6Addr{}, expectedEas, enableDNS, "someDNSview", "", "", updateUseTtl, updateTtl, comment, expectedAliases)
expectedObj.Ref = ref

conn = &fakeConnector{
Expand All @@ -421,7 +421,7 @@ var _ = Describe("Object Manager: host record", func() {
objMgr = NewObjectManager(conn, cmpType, tenantID)

actualObj, err = objMgr.UpdateHostRecord(ref, true, false, "host1.test.com", "",
"", "", "", "", "", "", updateUseTtl, updateTtl, comment, setEas, expectedAliases)
"someDNSview", "", "", "", "", "", "", updateUseTtl, updateTtl, comment, setEas, expectedAliases)
Expect(err).To(BeNil())
Expect(*actualObj).To(BeEquivalentTo(*expectedObj))
})
Expand Down Expand Up @@ -458,7 +458,7 @@ var _ = Describe("Object Manager: host record", func() {
}
objMgr = NewObjectManager(conn, cmpType, tenantID)

actualObj, err = objMgr.UpdateHostRecord(ref, enableDNS, false, hostName, "", "",
actualObj, err = objMgr.UpdateHostRecord(ref, enableDNS, false, hostName, "", "", "",
"", ipv4Addr, ipv6Addr, macAddr, duid, useTtl, ttl, "", nil, []string{})
Expect(err).To(BeNil())
Expect(*actualObj).To(BeEquivalentTo(*expectedObj))
Expand Down

0 comments on commit 92ee29d

Please sign in to comment.