Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-39322: [release-4.18]fix ts2phc leap window check #357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,11 @@ func (p *ptpProcess) processPTPMetrics(output string) {
logEntry := synce.ParseLog(output)
p.ProcessSynceEvents(logEntry)

} else if p.name == ts2phcProcessName && (strings.Contains(output, NMEASourceDisabledIndicator) ||
strings.Contains(output, InvalidMasterTimestampIndicator) ||
(strings.Contains(output, NMEASourceDisabledIndicator2) &&
(!leap.LeapMgr.IsLeapInWindow(time.Now().UTC(), -2*time.Second, time.Second)))) { //TODO identify which interface lost nmea or 1pps
} else if p.name == ts2phcProcessName &&
!leap.LeapMgr.IsLeapInWindow(time.Now().UTC(), -2*time.Second, time.Second) &&
(strings.Contains(output, NMEASourceDisabledIndicator) ||
strings.Contains(output, InvalidMasterTimestampIndicator) ||
strings.Contains(output, NMEASourceDisabledIndicator2)) { //TODO identify which interface lost nmea or 1pps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't nmea lost indicator always for GM interface ? GM interface will give the nmea interface , until we support two GNSS

Copy link
Contributor Author

@vitus133 vitus133 Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, only for GM interface. I only extended the condition for declaring "nmea string lost", that we are not in the leap event right now to all nmea failure kinds, because I noticed they could be different while I was checking the 4.14 backport

iface := p.ifaces.GetGMInterface().Name
p.ProcessTs2PhcEvents(faultyOffset, ts2phcProcessName, iface, map[event.ValueType]interface{}{event.NMEA_STATUS: int64(0)})
glog.Error("nmea string lost") //TODO: add for 1pps lost
Expand Down
29 changes: 2 additions & 27 deletions pkg/daemon/daemon_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import (
"github.com/openshift/linuxptp-daemon/pkg/leap"
ptpv1 "github.com/openshift/ptp-operator/api/v1"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fake "k8s.io/client-go/kubernetes/fake"
"sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -42,7 +39,8 @@ func clean(t *testing.T) {
func applyProfileSyncE(t *testing.T, profile *ptpv1.PtpProfile) {

stopCh := make(<-chan struct{})
mockLeap()
assert.NoError(t, leap.MockLeapFile())
defer close(leap.LeapMgr.Close)
dn := New(
"test-node-name",
"openshift-ptp",
Expand All @@ -62,8 +60,6 @@ func applyProfileSyncE(t *testing.T, profile *ptpv1.PtpProfile) {
assert.NotNil(t, dn)
err := dn.applyNodePtpProfile(0, profile)
assert.NoError(t, err)
close(leap.LeapMgr.Close)

}

func testRequirements(t *testing.T, profile *ptpv1.PtpProfile) {
Expand Down Expand Up @@ -102,24 +98,3 @@ func Test_applyProfile_synce(t *testing.T) {
clean(t)
}
}

func mockLeap() error {
cm := &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Namespace: "openshift-ptp", Name: "leap-configmap"},
Data: map[string]string{
"test-node-name": `# Do not edit
# This file is generated automatically by linuxptp-daemon
#$ 3927775672
#@ 4291747200
3692217600 37 # 1 Jan 2017`,
},
}
os.Setenv("NODE_NAME", "test-node-name")
client := fake.NewSimpleClientset(cm)
lm, err := leap.New(client, "openshift-ptp")
if err != nil {
return err
}
go lm.Run()
return nil
}
4 changes: 3 additions & 1 deletion pkg/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/openshift/linuxptp-daemon/pkg/event"
"github.com/openshift/linuxptp-daemon/pkg/leap"
"github.com/openshift/linuxptp-daemon/pkg/synce"
ptpv1 "github.com/openshift/ptp-operator/api/v1"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -220,7 +221,6 @@ func setup() {
var logLevel string
flag.StringVar(&logLevel, "logLevel", "4", "test")
flag.Lookup("v").Value.Set(logLevel)

daemon.InitializeOffsetMaps()
pm = daemon.NewProcessManager()
daemon.RegisterMetrics(MYNODE)
Expand All @@ -236,6 +236,8 @@ func TestMain(m *testing.M) {
os.Exit(code)
}
func Test_ProcessPTPMetrics(t *testing.T) {
leap.MockLeapFile()
defer close(leap.LeapMgr.Close)

assert := assert.New(t)
for _, tc := range testCases {
Expand Down
27 changes: 2 additions & 25 deletions pkg/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import (
"github.com/openshift/linuxptp-daemon/pkg/leap"
"github.com/openshift/linuxptp-daemon/pkg/protocol"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fake "k8s.io/client-go/kubernetes/fake"
)

var (
Expand Down Expand Up @@ -207,7 +204,8 @@ func TestEventHandler_ProcessEvents(t *testing.T) {
eventManager := event.Init("node", true, "/tmp/go.sock", eChannel, closeChn, nil, nil, nil)
eventManager.MockEnable()
go eventManager.ProcessEvents()
assert.NoError(t, mockLeap())
assert.NoError(t, leap.MockLeapFile())
defer close(leap.LeapMgr.Close)
time.Sleep(1 * time.Second)
for _, test := range tests {
select {
Expand Down Expand Up @@ -341,24 +339,3 @@ func sendEvents(cfgName string, processName event.EventSource, state event.PTPSt
Reset: false,
}
}

func mockLeap() error {
cm := &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Namespace: "openshift-ptp", Name: "leap-configmap"},
Data: map[string]string{
"test-node-name": `# Do not edit
# This file is generated automatically by linuxptp-daemon
#$ 3927775672
#@ 4291747200
3692217600 37 # 1 Jan 2017`,
},
}
os.Setenv("NODE_NAME", "test-node-name")
client := fake.NewSimpleClientset(cm)
lm, err := leap.New(client, "openshift-ptp")
if err != nil {
return err
}
go lm.Run()
return nil
}
23 changes: 23 additions & 0 deletions pkg/leap/leap-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
"github.com/golang/glog"
"github.com/openshift/linuxptp-daemon/pkg/pmc"
"github.com/openshift/linuxptp-daemon/pkg/ublox"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
fake "k8s.io/client-go/kubernetes/fake"
)

const (
Expand Down Expand Up @@ -434,3 +436,24 @@ func (l *LeapManager) IsLeapInWindow(now time.Time, startOffset, endOffset time.
}
return false
}

func MockLeapFile() error {
cm := &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Namespace: "openshift-ptp", Name: "leap-configmap"},
Data: map[string]string{
"test-node-name": `# Do not edit
# This file is generated automatically by linuxptp-daemon
#$ 3927775672
#@ 4291747200
3692217600 37 # 1 Jan 2017`,
},
}
os.Setenv("NODE_NAME", "test-node-name")
client := fake.NewSimpleClientset(cm)
lm, err := New(client, "openshift-ptp")
if err != nil {
return err
}
go lm.Run()
return nil
}