Skip to content

Commit e9f7a10

Browse files
committed
Add additional test cases
Signed-off-by: Evan Lezar <[email protected]>
1 parent 71d46ed commit e9f7a10

File tree

1 file changed

+216
-0
lines changed

1 file changed

+216
-0
lines changed

pkg/mig/reconfigure/reconfigure_test.go

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,222 @@ func TestReconfigure(t *testing.T) {
127127
},
128128
expectedError: fmt.Errorf(`unable to get the value of the "example.com/config.state" label: error getting label`),
129129
},
130+
{
131+
description: "reconfigure exits if config is applied",
132+
options: reconfigureMIGOptions{
133+
NodeName: "NodeName",
134+
MIGPartedConfigFile: "/path/to/config/file.yaml",
135+
SelectedMIGConfig: "selected-mig-config",
136+
DriverLibraryPath: "/path/to/libnvidia-ml.so.1",
137+
HostRootMount: "/host/",
138+
ConfigStateLabel: "example.com/config.state",
139+
},
140+
migParted: &migPartedMock{
141+
assertValidMIGConfigFunc: func() error {
142+
return nil
143+
},
144+
assertMIGConfigFunc: func() error {
145+
return nil
146+
},
147+
},
148+
checkMigParted: func(mpm *migPartedMock) {
149+
require.Len(t, mpm.calls.assertValidMIGConfig, 1)
150+
require.Len(t, mpm.calls.assertMIGConfig, 1)
151+
require.Len(t, mpm.calls.applyMIGConfig, 0)
152+
require.Len(t, mpm.calls.assertMIGModeOnly, 0)
153+
require.Len(t, mpm.calls.applyMIGModeOnly, 0)
154+
},
155+
nodeLabeller: &nodeWithLabels{
156+
mock: &nodeLabellerMock{
157+
getNodeLabelValueFunc: func(s string) (string, error) {
158+
return "current-state", nil
159+
},
160+
},
161+
},
162+
checkNodeLabeller: func(nwl *nodeWithLabels) {
163+
calls := nwl.mock.getNodeLabelValueCalls()
164+
require.Len(t, calls, 1)
165+
require.EqualValues(t, []struct{ S string }{{"example.com/config.state"}}, calls)
166+
},
167+
expectedError: nil,
168+
},
169+
{
170+
description: "reconfigure exists if config is applied",
171+
options: reconfigureMIGOptions{
172+
NodeName: "NodeName",
173+
MIGPartedConfigFile: "/path/to/config/file.yaml",
174+
SelectedMIGConfig: "selected-mig-config",
175+
DriverLibraryPath: "/path/to/libnvidia-ml.so.1",
176+
HostRootMount: "/host/",
177+
ConfigStateLabel: "example.com/config.state",
178+
},
179+
migParted: &migPartedMock{
180+
assertValidMIGConfigFunc: func() error {
181+
return nil
182+
},
183+
assertMIGConfigFunc: func() error {
184+
return nil
185+
},
186+
},
187+
checkMigParted: func(mpm *migPartedMock) {
188+
require.Len(t, mpm.calls.assertValidMIGConfig, 1)
189+
require.Len(t, mpm.calls.assertMIGConfig, 1)
190+
require.Len(t, mpm.calls.applyMIGConfig, 0)
191+
require.Len(t, mpm.calls.assertMIGModeOnly, 0)
192+
require.Len(t, mpm.calls.applyMIGModeOnly, 0)
193+
},
194+
nodeLabeller: &nodeWithLabels{
195+
mock: &nodeLabellerMock{
196+
getNodeLabelValueFunc: func(s string) (string, error) {
197+
return "current-state", nil
198+
},
199+
},
200+
},
201+
checkNodeLabeller: func(nwl *nodeWithLabels) {
202+
calls := nwl.mock.getNodeLabelValueCalls()
203+
require.Len(t, calls, 1)
204+
require.EqualValues(t, []struct{ S string }{{"example.com/config.state"}}, calls)
205+
},
206+
expectedError: nil,
207+
},
208+
{
209+
description: "mode change required after reboot is error",
210+
options: reconfigureMIGOptions{
211+
NodeName: "NodeName",
212+
MIGPartedConfigFile: "/path/to/config/file.yaml",
213+
SelectedMIGConfig: "selected-mig-config",
214+
DriverLibraryPath: "/path/to/libnvidia-ml.so.1",
215+
HostRootMount: "/host/",
216+
ConfigStateLabel: "example.com/config.state",
217+
},
218+
migParted: &migPartedMock{
219+
assertValidMIGConfigFunc: func() error {
220+
return nil
221+
},
222+
assertMIGConfigFunc: func() error {
223+
return fmt.Errorf("config needs updating")
224+
},
225+
assertMIGModeOnlyFunc: func() error {
226+
return fmt.Errorf("mode needs updating")
227+
},
228+
},
229+
checkMigParted: func(mpm *migPartedMock) {
230+
require.Len(t, mpm.calls.assertValidMIGConfig, 1)
231+
require.Len(t, mpm.calls.assertMIGConfig, 1)
232+
require.Len(t, mpm.calls.assertMIGModeOnly, 1)
233+
require.Len(t, mpm.calls.applyMIGConfig, 0)
234+
require.Len(t, mpm.calls.applyMIGModeOnly, 0)
235+
},
236+
nodeLabeller: &nodeWithLabels{
237+
mock: &nodeLabellerMock{
238+
getNodeLabelValueFunc: func(s string) (string, error) {
239+
return "rebooting", nil
240+
},
241+
},
242+
},
243+
checkNodeLabeller: func(nwl *nodeWithLabels) {
244+
calls := nwl.mock.getNodeLabelValueCalls()
245+
require.Len(t, calls, 1)
246+
require.EqualValues(t, []struct{ S string }{{"example.com/config.state"}}, calls)
247+
},
248+
expectedError: fmt.Errorf("MIG mode change failed after reboot: mode needs updating"),
249+
},
250+
{
251+
description: "mode does not need updating; apply config error is returned",
252+
options: reconfigureMIGOptions{
253+
NodeName: "NodeName",
254+
MIGPartedConfigFile: "/path/to/config/file.yaml",
255+
SelectedMIGConfig: "selected-mig-config",
256+
DriverLibraryPath: "/path/to/libnvidia-ml.so.1",
257+
HostRootMount: "/host/",
258+
ConfigStateLabel: "example.com/config.state",
259+
},
260+
migParted: &migPartedMock{
261+
assertValidMIGConfigFunc: func() error {
262+
return nil
263+
},
264+
assertMIGConfigFunc: func() error {
265+
return fmt.Errorf("config needs updating")
266+
},
267+
assertMIGModeOnlyFunc: func() error {
268+
return nil
269+
},
270+
applyMIGModeOnlyFunc: func() error {
271+
return nil
272+
},
273+
applyMIGConfigFunc: func() error {
274+
return fmt.Errorf("failed to apply config")
275+
},
276+
},
277+
checkMigParted: func(mpm *migPartedMock) {
278+
require.Len(t, mpm.calls.assertValidMIGConfig, 1)
279+
require.Len(t, mpm.calls.assertMIGConfig, 1)
280+
require.Len(t, mpm.calls.assertMIGModeOnly, 2)
281+
require.Len(t, mpm.calls.applyMIGModeOnly, 1)
282+
require.Len(t, mpm.calls.applyMIGConfig, 1)
283+
},
284+
nodeLabeller: &nodeWithLabels{
285+
mock: &nodeLabellerMock{
286+
getNodeLabelValueFunc: func(s string) (string, error) {
287+
return "current-state", nil
288+
},
289+
},
290+
},
291+
checkNodeLabeller: func(nwl *nodeWithLabels) {
292+
calls := nwl.mock.getNodeLabelValueCalls()
293+
require.Len(t, calls, 1)
294+
require.EqualValues(t, []struct{ S string }{{"example.com/config.state"}}, calls)
295+
},
296+
expectedError: fmt.Errorf("failed to apply config"),
297+
},
298+
{
299+
description: "mode does not need updating; apply config succeeds",
300+
options: reconfigureMIGOptions{
301+
NodeName: "NodeName",
302+
MIGPartedConfigFile: "/path/to/config/file.yaml",
303+
SelectedMIGConfig: "selected-mig-config",
304+
DriverLibraryPath: "/path/to/libnvidia-ml.so.1",
305+
HostRootMount: "/host/",
306+
ConfigStateLabel: "example.com/config.state",
307+
},
308+
migParted: &migPartedMock{
309+
assertValidMIGConfigFunc: func() error {
310+
return nil
311+
},
312+
assertMIGConfigFunc: func() error {
313+
return fmt.Errorf("config needs updating")
314+
},
315+
assertMIGModeOnlyFunc: func() error {
316+
return nil
317+
},
318+
applyMIGModeOnlyFunc: func() error {
319+
return nil
320+
},
321+
applyMIGConfigFunc: func() error {
322+
return nil
323+
},
324+
},
325+
checkMigParted: func(mpm *migPartedMock) {
326+
require.Len(t, mpm.calls.assertValidMIGConfig, 1)
327+
require.Len(t, mpm.calls.assertMIGConfig, 1)
328+
require.Len(t, mpm.calls.assertMIGModeOnly, 2)
329+
require.Len(t, mpm.calls.applyMIGModeOnly, 1)
330+
require.Len(t, mpm.calls.applyMIGConfig, 1)
331+
},
332+
nodeLabeller: &nodeWithLabels{
333+
mock: &nodeLabellerMock{
334+
getNodeLabelValueFunc: func(s string) (string, error) {
335+
return "current-state", nil
336+
},
337+
},
338+
},
339+
checkNodeLabeller: func(nwl *nodeWithLabels) {
340+
calls := nwl.mock.getNodeLabelValueCalls()
341+
require.Len(t, calls, 1)
342+
require.EqualValues(t, []struct{ S string }{{"example.com/config.state"}}, calls)
343+
},
344+
expectedError: nil,
345+
},
130346
}
131347

132348
for _, tc := range testCases {

0 commit comments

Comments
 (0)