@@ -2,6 +2,7 @@ package daemon_test
22
33import (
44 "context"
5+ "fmt"
56 "os"
67 "sync"
78 "time"
@@ -689,6 +690,90 @@ var _ = Describe("Daemon Controller", Ordered, func() {
689690 })
690691})
691692
693+ var _ = Describe ("Daemon CheckSystemdStatus" , func () {
694+ var (
695+ myMockCtrl * gomock.Controller
696+ myHostHelper * mock_helper.MockHostHelpersInterface
697+ reconciler * daemon.NodeReconciler
698+ )
699+
700+ BeforeEach (func () {
701+ myMockCtrl = gomock .NewController (GinkgoT ())
702+ myHostHelper = mock_helper .NewMockHostHelpersInterface (myMockCtrl )
703+ reconciler = daemon .New (nil , myHostHelper , nil , nil , nil )
704+
705+ originalUsingSystemdMode := vars .UsingSystemdMode
706+ vars .UsingSystemdMode = true
707+ DeferCleanup (func () {
708+ vars .UsingSystemdMode = originalUsingSystemdMode
709+ })
710+ })
711+
712+ Context ("when systemd services are enabled" , func () {
713+ BeforeEach (func () {
714+ myHostHelper .EXPECT ().IsServiceEnabled (constants .SriovServicePath ).Return (true , nil )
715+ myHostHelper .EXPECT ().IsServiceEnabled (constants .SriovPostNetworkServicePath ).Return (true , nil )
716+ })
717+
718+ It ("should return exist=true if sriov result file exists" , func () {
719+ myHostHelper .EXPECT ().ReadSriovResult ().Return (& hostTypes.SriovResult {}, nil )
720+ result , exist , err := reconciler .CheckSystemdStatus ()
721+ Expect (err ).ToNot (HaveOccurred ())
722+ Expect (exist ).To (BeTrue ())
723+ Expect (result ).ToNot (BeNil ())
724+ })
725+
726+ It ("should return exist=false if sriov result file does not exist" , func () {
727+ myHostHelper .EXPECT ().ReadSriovResult ().Return (nil , nil )
728+ result , exist , err := reconciler .CheckSystemdStatus ()
729+ Expect (err ).ToNot (HaveOccurred ())
730+ Expect (exist ).To (BeFalse ())
731+ Expect (result ).To (BeNil ())
732+ })
733+
734+ It ("should return error if ReadSriovResult fails" , func () {
735+ myHostHelper .EXPECT ().ReadSriovResult ().Return (nil , fmt .Errorf ("read error" ))
736+ result , exist , err := reconciler .CheckSystemdStatus ()
737+ Expect (err ).To (HaveOccurred ())
738+ Expect (exist ).To (BeFalse ())
739+ Expect (result ).To (BeNil ())
740+ })
741+ })
742+
743+ Context ("when systemd services are NOT enabled" , func () {
744+ It ("should return exist=false if first service is disabled" , func () {
745+ myHostHelper .EXPECT ().IsServiceEnabled (constants .SriovServicePath ).Return (false , nil )
746+ myHostHelper .EXPECT ().IsServiceEnabled (constants .SriovPostNetworkServicePath ).Return (true , nil )
747+ result , exist , err := reconciler .CheckSystemdStatus ()
748+ Expect (err ).ToNot (HaveOccurred ())
749+ Expect (exist ).To (BeFalse ())
750+ Expect (result .SyncStatus ).To (Equal (constants .SyncStatusFailed ))
751+ })
752+
753+ It ("should return exist=false if second service is disabled" , func () {
754+ myHostHelper .EXPECT ().IsServiceEnabled (constants .SriovServicePath ).Return (true , nil )
755+ myHostHelper .EXPECT ().IsServiceEnabled (constants .SriovPostNetworkServicePath ).Return (false , nil )
756+ result , exist , err := reconciler .CheckSystemdStatus ()
757+ Expect (err ).ToNot (HaveOccurred ())
758+ Expect (exist ).To (BeFalse ())
759+ Expect (result .SyncStatus ).To (Equal (constants .SyncStatusFailed ))
760+ })
761+ })
762+
763+ Context ("when not in systemd mode" , func () {
764+ BeforeEach (func () {
765+ vars .UsingSystemdMode = false
766+ })
767+
768+ It ("should return exist=false and no error" , func () {
769+ result , exist , err := reconciler .CheckSystemdStatus ()
770+ Expect (err ).ToNot (HaveOccurred ())
771+ Expect (exist ).To (BeFalse ())
772+ Expect (result ).To (BeNil ())
773+ })
774+ })
775+ })
776+
692777func patchAnnotation (nodeState * sriovnetworkv1.SriovNetworkNodeState , key , value string ) {
693778 originalNodeState := nodeState .DeepCopy ()
694779 nodeState .Annotations [key ] = value
0 commit comments