@@ -16,6 +16,11 @@ type AnalyzeHostOS struct {
1616 hostAnalyzer * troubleshootv1beta2.HostOSAnalyze
1717}
1818
19+ type NodeOSInfo struct {
20+ NodeName string
21+ collect.HostOSInfo
22+ }
23+
1924func (a * AnalyzeHostOS ) Title () string {
2025 return hostAnalyzerTitleOrDefault (a .hostAnalyzer .AnalyzeMeta , "Host OS Info" )
2126}
@@ -27,30 +32,93 @@ func (a *AnalyzeHostOS) IsExcluded() (bool, error) {
2732func (a * AnalyzeHostOS ) Analyze (
2833 getCollectedFileContents func (string ) ([]byte , error ), findFiles getChildCollectedFileContents ,
2934) ([]* AnalyzeResult , error ) {
30-
35+ var nodesOSInfo [] NodeOSInfo
3136 result := AnalyzeResult {}
3237 result .Title = a .Title ()
3338
39+ // check if the host os info file exists (local mode)
3440 contents , err := getCollectedFileContents (collect .HostOSInfoPath )
3541 if err != nil {
36- return []* AnalyzeResult {& result }, errors .Wrap (err , "failed to get collected file" )
42+ //check if the node list file exists (remote mode)
43+ contents , err := getCollectedFileContents (collect .NODE_LIST_FILE )
44+ if err != nil {
45+ return []* AnalyzeResult {& result }, errors .Wrap (err , "failed to get collected file" )
46+ }
47+
48+ var nodes collect.HostOSInfoNodes
49+ if err := json .Unmarshal (contents , & nodes ); err != nil {
50+ return []* AnalyzeResult {& result }, errors .Wrap (err , "failed to unmarshal host os info nodes" )
51+ }
52+
53+ // iterate over each node and analyze the host os info
54+ for _ , node := range nodes .Nodes {
55+ contents , err := getCollectedFileContents (collect .NodeInfoBaseDir + "/" + node + "/" + collect .HostInfoFileName )
56+ if err != nil {
57+ return []* AnalyzeResult {& result }, errors .Wrap (err , "failed to get collected file" )
58+ }
59+
60+ var osInfo collect.HostOSInfo
61+ if err := json .Unmarshal (contents , & osInfo ); err != nil {
62+ return []* AnalyzeResult {& result }, errors .Wrap (err , "failed to unmarshal host os info" )
63+ }
64+
65+ nodesOSInfo = append (nodesOSInfo , NodeOSInfo {NodeName : node , HostOSInfo : osInfo })
66+ }
67+
68+ results , err := analyzeOSVersionResult (nodesOSInfo , a .hostAnalyzer .Outcomes , a .Title ())
69+ if err != nil {
70+ return []* AnalyzeResult {& result }, errors .Wrap (err , "failed to analyze os version result" )
71+ }
72+ return results , nil
3773 }
3874
3975 var osInfo collect.HostOSInfo
4076 if err := json .Unmarshal (contents , & osInfo ); err != nil {
4177 return []* AnalyzeResult {& result }, errors .Wrap (err , "failed to unmarshal host os info" )
4278 }
79+ nodesOSInfo = append (nodesOSInfo , NodeOSInfo {NodeName : "" , HostOSInfo : osInfo })
80+ return analyzeOSVersionResult (nodesOSInfo , a .hostAnalyzer .Outcomes , a .Title ())
81+ }
82+
83+ func analyzeOSVersionResult (nodesOSInfo []NodeOSInfo , outcomes []* troubleshootv1beta2.Outcome , title string ) ([]* AnalyzeResult , error ) {
84+ var results []* AnalyzeResult
85+ for _ , osInfo := range nodesOSInfo {
86+ if title == "" {
87+ title = "Host OS Info"
88+ }
89+
90+ analyzeResult , err := analyzeByOutcomes (outcomes , osInfo , title )
91+ if err != nil {
92+ return nil , errors .Wrap (err , "failed to analyze condition" )
93+ }
94+ results = append (results , analyzeResult ... )
95+ }
4396
44- return analyzeOSVersionResult ( osInfo , a . hostAnalyzer . Outcomes , a . Title ())
97+ return results , nil
4598}
4699
47- func analyzeOSVersionResult ( osInfo collect. HostOSInfo , outcomes [] * troubleshootv1beta2. Outcome , title string ) ([] * AnalyzeResult , error ) {
100+ var rx = regexp . MustCompile ( `^[0-9]+\.?[0-9]*\.?[0-9]*` )
48101
49- if title == "" {
50- title = "Host OS Info"
102+ func fixVersion (versionStr string ) string {
103+
104+ splitStr := strings .Split (versionStr , "." )
105+ for i := 0 ; i < len (splitStr ); i ++ {
106+ if splitStr [i ] != "0" {
107+ splitStr [i ] = strings .TrimPrefix (splitStr [i ], "0" )
108+ }
51109 }
110+ fixTrailZero := strings .Join (splitStr , "." )
111+ version := rx .FindString (fixTrailZero )
112+ version = strings .TrimRight (version , "." )
113+ return version
114+ }
52115
116+ func analyzeByOutcomes (outcomes []* troubleshootv1beta2.Outcome , osInfo NodeOSInfo , title string ) ([]* AnalyzeResult , error ) {
117+ var results []* AnalyzeResult
53118 for _ , outcome := range outcomes {
119+ if osInfo .NodeName != "" {
120+ title = fmt .Sprintf ("%s - Node %s" , title , osInfo .NodeName )
121+ }
54122
55123 result := AnalyzeResult {
56124 Title : title ,
@@ -82,7 +150,8 @@ func analyzeOSVersionResult(osInfo collect.HostOSInfo, outcomes []*troubleshootv
82150 result .URI = uri
83151 // When is usually empty as the final case and should be treated as true
84152 if when == "" {
85- return []* AnalyzeResult {& result }, nil
153+ results = append (results , & result )
154+ return results , nil
86155 }
87156
88157 parts := strings .Split (when , " " )
@@ -109,7 +178,8 @@ func analyzeOSVersionResult(osInfo collect.HostOSInfo, outcomes []*troubleshootv
109178 return []* AnalyzeResult {}, errors .Wrapf (err , "failed to parse tolerant: %v" , fixedKernelVer )
110179 }
111180 if whenRange (toleratedKernelVer ) {
112- return []* AnalyzeResult {& result }, nil
181+ results = append (results , & result )
182+ return results , nil
113183 }
114184 }
115185
@@ -125,7 +195,8 @@ func analyzeOSVersionResult(osInfo collect.HostOSInfo, outcomes []*troubleshootv
125195 return []* AnalyzeResult {& result }, errors .Wrapf (err , "failed to parse tolerant: %v" , fixedKernelVer )
126196 }
127197 if whenRange (toleratedKernelVer ) {
128- return []* AnalyzeResult {& result }, nil
198+ results = append (results , & result )
199+ return results , nil
129200 }
130201 }
131202 // Match the platform version
@@ -137,26 +208,10 @@ func analyzeOSVersionResult(osInfo collect.HostOSInfo, outcomes []*troubleshootv
137208 return []* AnalyzeResult {& result }, errors .Wrapf (err , "failed to parse tolerant: %v" , fixedDistVer )
138209 }
139210 if whenRange (toleratedDistVer ) {
140- return []* AnalyzeResult {& result }, nil
211+ results = append (results , & result )
212+ return results , nil
141213 }
142214 }
143215 }
144-
145- return []* AnalyzeResult {}, nil
146- }
147-
148- var rx = regexp .MustCompile (`^[0-9]+\.?[0-9]*\.?[0-9]*` )
149-
150- func fixVersion (versionStr string ) string {
151-
152- splitStr := strings .Split (versionStr , "." )
153- for i := 0 ; i < len (splitStr ); i ++ {
154- if splitStr [i ] != "0" {
155- splitStr [i ] = strings .TrimPrefix (splitStr [i ], "0" )
156- }
157- }
158- fixTrailZero := strings .Join (splitStr , "." )
159- version := rx .FindString (fixTrailZero )
160- version = strings .TrimRight (version , "." )
161- return version
216+ return results , nil
162217}
0 commit comments