Skip to content

Commit 4d0e11d

Browse files
michaellee1019jgeaso1266
authored andcommitted
RSDK-12450: Fix --cloud-config arg in reload command (#5507)
1 parent 59a6eab commit 4d0e11d

File tree

2 files changed

+76
-3
lines changed

2 files changed

+76
-3
lines changed

cli/module_build.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,13 +825,13 @@ func (c *viamClient) triggerCloudReloadBuild(
825825
return "", err
826826
}
827827

828-
part, err := c.getRobotPart(args.PartID)
828+
part, err := c.getRobotPart(partID)
829829
if err != nil {
830830
return "", err
831831
}
832832

833833
if part.Part == nil {
834-
return "", fmt.Errorf("part with id=%s not found", args.PartID)
834+
return "", fmt.Errorf("part with id=%s not found", partID)
835835
}
836836

837837
if part.Part.UserSuppliedInfo == nil {
@@ -1596,7 +1596,12 @@ func ModuleRestartAction(c *cli.Context, args moduleRestartArgs) error {
15961596
return err
15971597
}
15981598

1599-
part, err := client.getRobotPart(args.PartID)
1599+
partID, err := resolvePartID(args.PartID, args.CloudConfig)
1600+
if err != nil {
1601+
return err
1602+
}
1603+
1604+
part, err := client.getRobotPart(partID)
16001605
if err != nil {
16011606
return err
16021607
}

cli/module_reload_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,74 @@ func TestFullReloadFlow(t *testing.T) {
205205
})
206206
}
207207

208+
func TestReloadWithCloudConfig(t *testing.T) {
209+
logger := logging.NewTestLogger(t)
210+
211+
manifestPath := createTestManifest(t, "", nil)
212+
confStruct, err := structpb.NewStruct(map[string]any{
213+
"modules": []any{},
214+
})
215+
test.That(t, err, test.ShouldBeNil)
216+
217+
// Create a temporary cloud config file
218+
cloudConfigPath := filepath.Join(t.TempDir(), "viam.json")
219+
cloudConfigFile, err := os.Create(cloudConfigPath)
220+
test.That(t, err, test.ShouldBeNil)
221+
_, err = cloudConfigFile.WriteString(`{"cloud":{"app_address":"https://app.viam.com:443","id":"cloud-config-part-id","secret":"SECRET"}}`)
222+
test.That(t, err, test.ShouldBeNil)
223+
test.That(t, cloudConfigFile.Close(), test.ShouldBeNil)
224+
225+
t.Run("reloadWithCloudConfigLocal", func(t *testing.T) {
226+
updateCount := 0
227+
cCtx, vc, _, _ := setup(
228+
mockFullAppServiceClient(confStruct, nil, &updateCount),
229+
nil,
230+
&inject.BuildServiceClient{},
231+
map[string]any{
232+
moduleFlagPath: manifestPath,
233+
moduleBuildFlagCloudConfig: cloudConfigPath,
234+
moduleBuildFlagNoBuild: true,
235+
moduleFlagLocal: true,
236+
generalFlagNoProgress: true, // Disable progress spinner to avoid race conditions in tests
237+
},
238+
"token",
239+
)
240+
test.That(t, vc.loginAction(cCtx), test.ShouldBeNil)
241+
242+
// Test that reloadModuleActionInner correctly uses cloud-config to resolve part ID
243+
err = reloadModuleActionInner(cCtx, vc, parseStructFromCtx[reloadModuleArgs](cCtx), logger, false)
244+
test.That(t, err, test.ShouldBeNil)
245+
test.That(t, updateCount, test.ShouldEqual, 1)
246+
})
247+
248+
t.Run("verifyPartIDResolution", func(t *testing.T) {
249+
// Test that the part ID is correctly resolved from cloud-config
250+
// and that args.PartID remains empty when only cloud-config is provided
251+
cCtx, _, _, _ := setup(
252+
mockFullAppServiceClient(confStruct, nil, nil),
253+
nil,
254+
&inject.BuildServiceClient{},
255+
map[string]any{
256+
moduleFlagPath: manifestPath,
257+
moduleBuildFlagCloudConfig: cloudConfigPath,
258+
moduleBuildFlagNoBuild: true,
259+
moduleFlagLocal: true,
260+
},
261+
"token",
262+
)
263+
264+
args := parseStructFromCtx[reloadModuleArgs](cCtx)
265+
// Verify that args.PartID is empty (not set via --part-id flag) and CloudConfig is set
266+
test.That(t, args.PartID, test.ShouldBeEmpty)
267+
test.That(t, args.CloudConfig, test.ShouldEqual, cloudConfigPath)
268+
269+
// Verify that resolvePartID correctly extracts the part ID from the cloud config
270+
partID, err := resolvePartID(args.PartID, args.CloudConfig)
271+
test.That(t, err, test.ShouldBeNil)
272+
test.That(t, partID, test.ShouldEqual, "cloud-config-part-id")
273+
})
274+
}
275+
208276
func TestRestartModule(t *testing.T) {
209277
t.Skip("restartModule test requires fake robot client")
210278
}

0 commit comments

Comments
 (0)