Skip to content

Commit

Permalink
fix: add script name to past activity
Browse files Browse the repository at this point in the history
  • Loading branch information
jahzielv committed Nov 19, 2024
1 parent 368f93c commit 8f0388a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion server/datastore/mysql/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (ds *Datastore) ListHostUpcomingActivities(ctx context.Context, hostID uint
JSON_OBJECT(
'host_id', hsr.host_id,
'host_display_name', COALESCE(hdn.display_name, ''),
'script_name', COALESCE(scr.name, ''),
'script_name', COALESCE(ses.name, COALESCE(scr.name, '')),
'script_execution_id', hsr.execution_id,
'async', NOT hsr.sync_request,
'policy_id', hsr.policy_id,
Expand All @@ -330,6 +330,8 @@ func (ds *Datastore) ListHostUpcomingActivities(ctx context.Context, hostID uint
scripts scr ON scr.id = hsr.script_id
LEFT OUTER JOIN
host_software_installs hsi ON hsi.execution_id = hsr.execution_id
LEFT OUTER JOIN
setup_experience_scripts ses ON ses.id = hsr.setup_experience_script_id
WHERE
hsr.host_id = :host_id AND
hsr.exit_code IS NULL AND
Expand Down
25 changes: 18 additions & 7 deletions server/datastore/mysql/activities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,14 @@ func testListHostUpcomingActivities(t *testing.T, ds *Datastore) {
h2SelfService, err := ds.InsertSoftwareInstallRequest(noUserCtx, h2.ID, sw1Meta.InstallerID, true, nil)
require.NoError(t, err)

setupExpScript := &fleet.Script{Name: "setup_experience_script", ScriptContents: "setup_experience"}
err = ds.SetSetupExperienceScript(ctx, setupExpScript)

Check failure on line 545 in server/datastore/mysql/activities_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

ineffectual assignment to err (ineffassign)

Check failure on line 545 in server/datastore/mysql/activities_test.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

ineffectual assignment to err (ineffassign)
ses, err := ds.GetSetupExperienceScript(ctx, h2.TeamID)
require.NoError(t, err)
hsr, err = ds.NewHostScriptExecutionRequest(ctx, &fleet.HostScriptRequestPayload{HostID: h2.ID, ScriptContents: "setup_experience", SetupExperienceScriptID: &ses.ID})
require.NoError(t, err)
h2SetupExp := hsr.ExecutionID

// create pending install and uninstall requests for h3 that will be deleted
_, err = ds.InsertSoftwareInstallRequest(ctx, h3.ID, sw3Meta.InstallerID, false, nil)
require.NoError(t, err)
Expand All @@ -560,7 +568,8 @@ func testListHostUpcomingActivities(t *testing.T, ds *Datastore) {
endTime = SetOrderedCreatedAtTimestamps(t, ds, endTime, "host_software_installs", "execution_id", h2SelfService)
endTime = SetOrderedCreatedAtTimestamps(t, ds, endTime, "host_software_installs", "execution_id", h2Bar)
endTime = SetOrderedCreatedAtTimestamps(t, ds, endTime, "host_script_results", "execution_id", h2A, h2F)
SetOrderedCreatedAtTimestamps(t, ds, endTime, "host_vpp_software_installs", "command_uuid", vppCommand1, vppCommand2)
endTime = SetOrderedCreatedAtTimestamps(t, ds, endTime, "host_vpp_software_installs", "command_uuid", vppCommand1, vppCommand2)
SetOrderedCreatedAtTimestamps(t, ds, endTime, "host_script_results", "execution_id", h2SetupExp)

execIDsWithUser := map[string]bool{
h1A: true,
Expand All @@ -576,11 +585,13 @@ func testListHostUpcomingActivities(t *testing.T, ds *Datastore) {
h2Bar: true,
vppCommand1: true,
vppCommand2: false,
h2SetupExp: false,
}
execIDsScriptName := map[string]string{
h1A: scr1.Name,
h1B: scr2.Name,
h2A: scr1.Name,
h1A: scr1.Name,
h1B: scr2.Name,
h2A: scr1.Name,
h2SetupExp: setupExpScript.Name,
}
execIDsSoftwareTitle := map[string]string{
h1Fleet: "foo",
Expand Down Expand Up @@ -641,10 +652,10 @@ func testListHostUpcomingActivities(t *testing.T, ds *Datastore) {
wantMeta: &fleet.PaginationMetadata{HasNextResults: false, HasPreviousResults: true, TotalResults: 8},
},
{
opts: fleet.ListOptions{PerPage: 4},
opts: fleet.ListOptions{PerPage: 5},
hostID: h2.ID,
wantExecs: []string{h2SelfService, h2Bar, h2A, vppCommand2},
wantMeta: &fleet.PaginationMetadata{HasNextResults: false, HasPreviousResults: false, TotalResults: 4},
wantExecs: []string{h2SelfService, h2Bar, h2A, vppCommand2, h2SetupExp},
wantMeta: &fleet.PaginationMetadata{HasNextResults: false, HasPreviousResults: false, TotalResults: 5},
},
{
opts: fleet.ListOptions{},
Expand Down

0 comments on commit 8f0388a

Please sign in to comment.