From 768ba19dd908b4f41d0c7b1ad9d4d43f89269a81 Mon Sep 17 00:00:00 2001 From: Ghislain Bourgeois Date: Wed, 22 Nov 2023 17:16:18 -0500 Subject: [PATCH 1/2] fix: Ignore NRF URI containing a specific IP on registration --- service/init.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/service/init.go b/service/init.go index 2f9b614..a8a2fee 100644 --- a/service/init.go +++ b/service/init.go @@ -387,7 +387,7 @@ func (udm *UDM) BuildAndSendRegisterNFInstance() (models.NfProfile, error) { return profile, err } -//UpdateNF is the callback function, this is called when keepalivetimer elapsed +// UpdateNF is the callback function, this is called when keepalivetimer elapsed func (udm *UDM) UpdateNF() { KeepAliveTimerMutex.Lock() defer KeepAliveTimerMutex.Unlock() @@ -435,16 +435,14 @@ func (udm *UDM) registerNF() { if err != nil { logger.InitLog.Errorln(err.Error()) } else { - var newNrfUri string var err1 error var prof models.NfProfile - prof, newNrfUri, self.NfId, err1 = consumer.SendRegisterNFInstance(self.NrfUri, self.NfId, proflie) + prof, _, self.NfId, err1 = consumer.SendRegisterNFInstance(self.NrfUri, self.NfId, proflie) if err1 != nil { logger.InitLog.Errorln(err1.Error()) } else { udm.StartKeepAliveTimer(prof) logger.CfgLog.Infof("Sent Register NF Instance with updated profile") - self.NrfUri = newNrfUri } } } From be89e02bf13ea1d20cbb8408412a46bed85713f3 Mon Sep 17 00:00:00 2001 From: Ghislain Bourgeois Date: Thu, 23 Nov 2023 16:49:22 -0500 Subject: [PATCH 2/2] fix: Add test for unchanging NRF URI --- service/init.go | 9 ++++----- service/init_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 service/init_test.go diff --git a/service/init.go b/service/init.go index d18fa01..e9e76fe 100644 --- a/service/init.go +++ b/service/init.go @@ -429,15 +429,14 @@ func (udm *UDM) registerNF() { self := context.UDM_Self() for msg := range ConfigPodTrigger { initLog.Infof("Minimum configuration from config pod available %v", msg) - proflie, err := consumer.BuildNFInstance(self) + profile, err := consumer.BuildNFInstance(self) if err != nil { logger.InitLog.Errorln(err.Error()) } else { - var err1 error var prof models.NfProfile - prof, _, self.NfId, err1 = consumer.SendRegisterNFInstance(self.NrfUri, self.NfId, proflie) - if err1 != nil { - logger.InitLog.Errorln(err1.Error()) + prof, _, self.NfId, err = consumer.SendRegisterNFInstance(self.NrfUri, self.NfId, profile) + if err != nil { + logger.InitLog.Errorln(err.Error()) } else { udm.StartKeepAliveTimer(prof) logger.CfgLog.Infof("Sent Register NF Instance with updated profile") diff --git a/service/init_test.go b/service/init_test.go new file mode 100644 index 0000000..f2139d2 --- /dev/null +++ b/service/init_test.go @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2023 Open Networking Foundation +// + +package service + +import ( + "fmt" + "net/http" + "net/http/httptest" + "testing" + "time" + + "github.com/omec-project/udm/context" +) + +func Test_nrf_url_is_not_overwritten_when_registering(t *testing.T) { + svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "banana") + })) + svr.EnableHTTP2 = true + svr.StartTLS() + defer svr.Close() + self := context.UDM_Self() + self.NrfUri = svr.URL + self.RegisterIPv4 = "127.0.0.2" + var udm *UDM + go udm.registerNF() + ConfigPodTrigger <- true + + time.Sleep(1 * time.Second) + if self.NrfUri != svr.URL { + t.Errorf("Expected NRF URL to stay %v, but was %v", svr.URL, self.NrfUri) + } +}