Skip to content

Commit

Permalink
debug summary add (RedHatInsights#2639)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Holloway <jholloway@redhat.com>
  • Loading branch information
loadtheaccumulator authored Jul 12, 2024
1 parent fd3e5ba commit e79295d
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 97 deletions.
49 changes: 49 additions & 0 deletions pkg/services/repobuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@ func (rb *RepoBuilder) RepoPullLocalStaticDeltas(u *models.Commit, o *models.Com
return err
}

var output []byte

// pull the local repo at the exact rev (which was HEAD of o.OSTreeRef)
cmd := BuildCommand("/usr/bin/ostree", "pull-local", "--repo", uprepo, oldrepo, oldRevParse)
if output, err := cmd.CombinedOutput(); err != nil {
Expand All @@ -565,6 +567,13 @@ func (rb *RepoBuilder) RepoPullLocalStaticDeltas(u *models.Commit, o *models.Com
).Error("error occurred while running pull-local command")
return err
}
rb.log.WithFields(log.Fields{
"command": cmd,
"output": string(output),
"to_repo": uprepo,
"from_repo": oldrepo,
"from_revparse": oldRevParse,
}).Info("pull local from_commit into to_commit")

// generate static delta
cmd = BuildCommand("/usr/bin/ostree", "static-delta", "generate", "--repo", uprepo, "--from", oldRevParse, "--to", updateRevParse)
Expand All @@ -574,6 +583,27 @@ func (rb *RepoBuilder) RepoPullLocalStaticDeltas(u *models.Commit, o *models.Com
).Error("error occurred while running static-delta command")
return err
}
rb.log.WithFields(log.Fields{
"command": cmd,
"output": string(output),
"to_repo": uprepo,
"from_revparse": oldRevParse,
"to_revparse": updateRevParse,
}).Info("generate static delta")

// confirm static delta
cmd = BuildCommand("/usr/bin/ostree", "static-delta", "list", "--repo", uprepo)
if output, err := cmd.CombinedOutput(); err != nil {
rb.log.WithFields(
log.Fields{"error": err.Error(), "OSTreeCommit": oldRevParse, "output": string(output)},
).Error("error occurred while running static-delta command")
return err
}
rb.log.WithFields(log.Fields{
"command": cmd,
"output": string(output),
"to_repo": uprepo,
}).Info("confirm static delta")

// update ostree summary
cmd = BuildCommand("/usr/bin/ostree", "summary", "--repo", uprepo, "-u")
Expand All @@ -583,6 +613,25 @@ func (rb *RepoBuilder) RepoPullLocalStaticDeltas(u *models.Commit, o *models.Com
).Error("error occurred while running summary update command")
return err
}
rb.log.WithFields(log.Fields{
"command": cmd,
"output": string(output),
"to_repo": uprepo,
}).Info("update ostree summary")

// confirm ostree summary
cmd = BuildCommand("/usr/bin/ostree", "summary", "--repo", uprepo, "-v")
if output, err := cmd.CombinedOutput(); err != nil {
rb.log.WithFields(
log.Fields{"error": err.Error(), "OSTreeSummary": uprepo, "output": string(output)},
).Error("error occurred while running summary view command")
return err
}
rb.log.WithFields(log.Fields{
"command": cmd,
"output": string(output),
"to_repo": uprepo,
}).Info("confirm ostree summary")

return nil
}
Expand Down
229 changes: 132 additions & 97 deletions pkg/services/repobuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,47 +741,61 @@ func TestBuildUpdateRepoWithOldCommits(t *testing.T) {
updateCommitRevision := update.Commit.OSTreeCommit

expectedExecCalls := []struct {
name string
TestHelper MockTestExecHelper
ExpectedOutput string
ExpectedExistStatus int
ExpectedCommand string
ExpectExecuted bool
name string
TestHelper MockTestExecHelper
ExpectedOutput string
ExpectedExitStatus int
ExpectedCommand string
ExpectExecuted bool
}{
{
name: "run ostree command rev-parse for update commit successfully",
TestHelper: NewMockTestExecHelper(t, updateCommitRevision, 0),
ExpectedOutput: updateCommitRevision,
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("ostree rev-parse --repo %s %s", updateRepoPath, update.Commit.OSTreeRef),
name: "run ostree command rev-parse for update commit successfully",
TestHelper: NewMockTestExecHelper(t, updateCommitRevision, 0),
ExpectedOutput: updateCommitRevision,
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("ostree rev-parse --repo %s %s", updateRepoPath, update.Commit.OSTreeRef),
},
{
name: "run ostree command rev-parse for old commit successfully",
TestHelper: NewMockTestExecHelper(t, oldCommitRevision, 0),
ExpectedOutput: oldCommitRevision,
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("ostree rev-parse --repo %s %s", updateOldCommitRepoPath, update.OldCommits[0].OSTreeRef),
name: "run ostree command rev-parse for old commit successfully",
TestHelper: NewMockTestExecHelper(t, oldCommitRevision, 0),
ExpectedOutput: oldCommitRevision,
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("ostree rev-parse --repo %s %s", updateOldCommitRepoPath, update.OldCommits[0].OSTreeRef),
},
{
name: "run ostree command pull-local successfully",
TestHelper: NewMockTestExecHelper(t, "pull-local", 0),
ExpectedOutput: "pull-local",
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree pull-local --repo %s %s %s", updateRepoPath, updateOldCommitRepoPath, oldCommitRevision),
name: "run ostree command pull-local successfully",
TestHelper: NewMockTestExecHelper(t, "pull-local", 0),
ExpectedOutput: "pull-local",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree pull-local --repo %s %s %s", updateRepoPath, updateOldCommitRepoPath, oldCommitRevision),
},
{
name: "run ostree command static-delta successfully",
TestHelper: NewMockTestExecHelper(t, "static-delta", 0),
ExpectedOutput: "static-delta",
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree static-delta generate --repo %s --from %s --to %s", updateRepoPath, oldCommitRevision, updateCommitRevision),
name: "run ostree command static-delta successfully",
TestHelper: NewMockTestExecHelper(t, "static-delta", 0),
ExpectedOutput: "static-delta",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree static-delta generate --repo %s --from %s --to %s", updateRepoPath, oldCommitRevision, updateCommitRevision),
},
{
name: "run ostree command summary successfully",
TestHelper: NewMockTestExecHelper(t, "summary", 0),
ExpectedOutput: "summary",
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree summary --repo %s -u", updateRepoPath),
name: "should run ostree command static-delta list successfully",
TestHelper: NewMockTestExecHelper(t, "static-delta", 0),
ExpectedOutput: "static-delta",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree static-delta list --repo %s", updateRepoPath),
},
{
name: "run ostree command summary successfully",
TestHelper: NewMockTestExecHelper(t, "summary", 0),
ExpectedOutput: "summary",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree summary --repo %s -u", updateRepoPath),
},
{
name: "run ostree command summary view successfully",
TestHelper: NewMockTestExecHelper(t, "summary", 0),
ExpectedOutput: "summary",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree summary --repo %s -v", updateRepoPath),
},
}
// chain TestExecHelper, so that each mock can initiate the next exec command helper
Expand All @@ -803,7 +817,7 @@ func TestBuildUpdateRepoWithOldCommits(t *testing.T) {
for _, testCase := range expectedExecCalls {
t.Run(testCase.name, func(t *testing.T) {
g.Expect(testCase.TestHelper.Executed).To(BeTrue())
g.Expect(testCase.TestHelper.ExistStatus).To(Equal(testCase.ExpectedExistStatus))
g.Expect(testCase.TestHelper.ExistStatus).To(Equal(testCase.ExpectedExitStatus))
g.Expect(testCase.TestHelper.Output).To(Equal(testCase.ExpectedOutput))
g.Expect(testCase.TestHelper.Command).To(Equal(testCase.ExpectedCommand))
})
Expand Down Expand Up @@ -1286,47 +1300,61 @@ func TestRepoPullLocalStaticDeltas(t *testing.T) {
oldCommitRevision := faker.UUIDHyphenated()

expectedCallsCases := []struct {
name string
TestHelper MockTestExecHelper
ExpectedOutput string
ExpectedExistStatus int
ExpectedCommand string
ExpectExecuted bool
name string
TestHelper MockTestExecHelper
ExpectedOutput string
ExpectedExitStatus int
ExpectedCommand string
ExpectExecuted bool
}{
{
name: "should run ostree command rev-parse for update commit successfully",
TestHelper: NewMockTestExecHelper(t, updateCommitRevision, 0),
ExpectedOutput: updateCommitRevision,
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("ostree rev-parse --repo %s %s", updateRepoPath, updateCommit.OSTreeRef),
name: "should run ostree command rev-parse for update commit successfully",
TestHelper: NewMockTestExecHelper(t, updateCommitRevision, 0),
ExpectedOutput: updateCommitRevision,
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("ostree rev-parse --repo %s %s", updateRepoPath, updateCommit.OSTreeRef),
},
{
name: "should run ostree command rev-parse for old commit successfully",
TestHelper: NewMockTestExecHelper(t, oldCommitRevision, 0),
ExpectedOutput: oldCommitRevision,
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("ostree rev-parse --repo %s %s", oldRepoPath, oldCommit.OSTreeRef),
name: "should run ostree command rev-parse for old commit successfully",
TestHelper: NewMockTestExecHelper(t, oldCommitRevision, 0),
ExpectedOutput: oldCommitRevision,
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("ostree rev-parse --repo %s %s", oldRepoPath, oldCommit.OSTreeRef),
},
{
name: "should run ostree command pull-local successfully",
TestHelper: NewMockTestExecHelper(t, "pull-local", 0),
ExpectedOutput: "pull-local",
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree pull-local --repo %s %s %s", updateRepoPath, oldRepoPath, oldCommitRevision),
name: "should run ostree command pull-local successfully",
TestHelper: NewMockTestExecHelper(t, "pull-local", 0),
ExpectedOutput: "pull-local",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree pull-local --repo %s %s %s", updateRepoPath, oldRepoPath, oldCommitRevision),
},
{
name: "should run ostree command static-delta successfully",
TestHelper: NewMockTestExecHelper(t, "static-delta", 0),
ExpectedOutput: "static-delta",
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree static-delta generate --repo %s --from %s --to %s", updateRepoPath, oldCommitRevision, updateCommitRevision),
name: "should run ostree command static-delta successfully",
TestHelper: NewMockTestExecHelper(t, "static-delta", 0),
ExpectedOutput: "static-delta",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree static-delta generate --repo %s --from %s --to %s", updateRepoPath, oldCommitRevision, updateCommitRevision),
},
{
name: "run ostree command summary successfully",
TestHelper: NewMockTestExecHelper(t, "summary", 0),
ExpectedOutput: "summary",
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree summary --repo %s -u", updateRepoPath),
name: "should run ostree command static-delta list successfully",
TestHelper: NewMockTestExecHelper(t, "static-delta", 0),
ExpectedOutput: "static-delta",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree static-delta list --repo %s", updateRepoPath),
},
{
name: "run ostree command summary successfully",
TestHelper: NewMockTestExecHelper(t, "summary", 0),
ExpectedOutput: "summary",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree summary --repo %s -u", updateRepoPath),
},
{
name: "run ostree command summary view successfully",
TestHelper: NewMockTestExecHelper(t, "summary", 0),
ExpectedOutput: "summary",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree summary --repo %s -v", updateRepoPath),
},
}
// chain TestHelper, so that each mock can initiate the next exec command helper
Expand All @@ -1344,7 +1372,7 @@ func TestRepoPullLocalStaticDeltas(t *testing.T) {
for _, testCase := range expectedCallsCases {
t.Run(testCase.name, func(t *testing.T) {
g.Expect(testCase.TestHelper.Executed).To(BeTrue())
g.Expect(testCase.TestHelper.ExistStatus).To(Equal(testCase.ExpectedExistStatus))
g.Expect(testCase.TestHelper.ExistStatus).To(Equal(testCase.ExpectedExitStatus))
g.Expect(testCase.TestHelper.Output).To(Equal(testCase.ExpectedOutput))
if testCase.ExpectedCommand != "" {
g.Expect(testCase.TestHelper.Command).To(Equal(testCase.ExpectedCommand))
Expand Down Expand Up @@ -1696,47 +1724,54 @@ func TestRepoPullLocalStaticDeltasFailsWhenSummaryFails(t *testing.T) {
oldCommitRevision := faker.UUIDHyphenated()

expectedCallsCases := []struct {
name string
TestHelper MockTestExecHelper
ExpectedOutput string
ExpectedExistStatus int
ExpectedCommand string
ExpectExecuted bool
name string
TestHelper MockTestExecHelper
ExpectedOutput string
ExpectedExitStatus int
ExpectedCommand string
ExpectExecuted bool
}{
{
name: "should run ostree command rev-parse for update commit successfully",
TestHelper: NewMockTestExecHelper(t, updateCommitRevision, 0),
ExpectedOutput: updateCommitRevision,
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("ostree rev-parse --repo %s %s", updateRepoPath, updateCommit.OSTreeRef),
name: "should run ostree command rev-parse for update commit successfully",
TestHelper: NewMockTestExecHelper(t, updateCommitRevision, 0),
ExpectedOutput: updateCommitRevision,
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("ostree rev-parse --repo %s %s", updateRepoPath, updateCommit.OSTreeRef),
},
{
name: "should run ostree command rev-parse for old commit successfully",
TestHelper: NewMockTestExecHelper(t, oldCommitRevision, 0),
ExpectedOutput: oldCommitRevision,
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("ostree rev-parse --repo %s %s", oldRepoPath, oldCommit.OSTreeRef),
name: "should run ostree command rev-parse for old commit successfully",
TestHelper: NewMockTestExecHelper(t, oldCommitRevision, 0),
ExpectedOutput: oldCommitRevision,
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("ostree rev-parse --repo %s %s", oldRepoPath, oldCommit.OSTreeRef),
},
{
name: "should run ostree command pull-local successfully",
TestHelper: NewMockTestExecHelper(t, "pull-local", 0),
ExpectedOutput: "pull-local",
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree pull-local --repo %s %s %s", updateRepoPath, oldRepoPath, oldCommitRevision),
name: "should run ostree command pull-local successfully",
TestHelper: NewMockTestExecHelper(t, "pull-local", 0),
ExpectedOutput: "pull-local",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree pull-local --repo %s %s %s", updateRepoPath, oldRepoPath, oldCommitRevision),
},
{
name: "should run ostree command static-delta successfully",
TestHelper: NewMockTestExecHelper(t, "static-delta", 0),
ExpectedOutput: "static-delta",
ExpectedExistStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree static-delta generate --repo %s --from %s --to %s", updateRepoPath, oldCommitRevision, updateCommitRevision),
name: "should run ostree command static-delta successfully",
TestHelper: NewMockTestExecHelper(t, "static-delta", 0),
ExpectedOutput: "static-delta",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree static-delta generate --repo %s --from %s --to %s", updateRepoPath, oldCommitRevision, updateCommitRevision),
},
{
name: "run ostree command summary with fail",
TestHelper: NewMockTestExecHelper(t, "summary", 4),
ExpectedOutput: "summary",
ExpectedExistStatus: 4,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree summary --repo %s -u", updateRepoPath),
name: "should run ostree command static-delta list successfully",
TestHelper: NewMockTestExecHelper(t, "static-delta", 0),
ExpectedOutput: "static-delta",
ExpectedExitStatus: 0,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree static-delta list --repo %s", updateRepoPath),
},
{
name: "run ostree command summary with fail",
TestHelper: NewMockTestExecHelper(t, "summary", 4),
ExpectedOutput: "summary",
ExpectedExitStatus: 4,
ExpectedCommand: fmt.Sprintf("/usr/bin/ostree summary --repo %s -u", updateRepoPath),
},
}
// chain TestHelper, so that each mock can initiate the next exec command helper
Expand All @@ -1747,7 +1782,7 @@ func TestRepoPullLocalStaticDeltasFailsWhenSummaryFails(t *testing.T) {
}
// set the first exec command helper mock
services.BuildCommand = expectedCallsCases[0].TestHelper.MockExecCommand
expectedErrorMessage := fmt.Sprintf("exit status %d", expectedCallsCases[4].TestHelper.ExistStatus)
expectedErrorMessage := fmt.Sprintf("exit status %d", expectedCallsCases[5].TestHelper.ExistStatus)

err = RepoBuilder.RepoPullLocalStaticDeltas(&updateCommit, &oldCommit, updateRepoPath, oldRepoPath)
g.Expect(err).To(HaveOccurred())
Expand All @@ -1756,7 +1791,7 @@ func TestRepoPullLocalStaticDeltasFailsWhenSummaryFails(t *testing.T) {
for _, testCase := range expectedCallsCases {
t.Run(testCase.name, func(t *testing.T) {
g.Expect(testCase.TestHelper.Executed).To(BeTrue())
g.Expect(testCase.TestHelper.ExistStatus).To(Equal(testCase.ExpectedExistStatus))
g.Expect(testCase.TestHelper.ExistStatus).To(Equal(testCase.ExpectedExitStatus))
g.Expect(testCase.TestHelper.Output).To(Equal(testCase.ExpectedOutput))
if testCase.ExpectedCommand != "" {
g.Expect(testCase.TestHelper.Command).To(Equal(testCase.ExpectedCommand))
Expand Down

0 comments on commit e79295d

Please sign in to comment.