Skip to content

Commit

Permalink
Restoring prior behavior on bpm stop on non existent processes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ops Manager committed Oct 6, 2021
1 parent 9976a21 commit 8ead4d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
24 changes: 12 additions & 12 deletions src/bpm/commands/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,6 @@ func stop(cmd *cobra.Command, _ []string) error {
logger.Info("starting")
defer logger.Info("complete")

jobCfg, err := bpmCfg.ParseJobConfig()
if err != nil {
logger.Error("failed-to-parse-config", err)
return fmt.Errorf("failed to parse job configuration: %s", err)
}

procCfg, err := processByNameFromJobConfig(jobCfg, procName)
if err != nil {
logger.Error("process-not-defined", err)
return fmt.Errorf("process %q not present in job configuration (%s)", procName, bpmCfg.JobConfig())
}

runcLifecycle, err := newRuncLifecycle()
if err != nil {
return err
Expand All @@ -86,6 +74,18 @@ func stop(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("failed to get job-process status: %s", err)
}

jobCfg, err := bpmCfg.ParseJobConfig()
if err != nil {
logger.Error("failed-to-parse-config", err)
return fmt.Errorf("failed to parse job configuration: %s", err)
}

procCfg, err := processByNameFromJobConfig(jobCfg, procName)
if err != nil {
logger.Error("process-not-defined", err)
return fmt.Errorf("process %q not present in job configuration (%s)", procName, bpmCfg.JobConfig())
}

if err := runcLifecycle.StopProcess(logger, bpmCfg, procCfg, DefaultStopTimeout); err != nil {
logger.Error("failed-to-stop", err)
}
Expand Down
9 changes: 4 additions & 5 deletions src/bpm/integration/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,21 @@ var _ = Describe("stop", func() {
})
})

Context("when the job-process doesn't not exist and has no config", func() {
Context("when the job-process doesn't not exist", func() {
BeforeEach(func() {
bpmLog = filepath.Join(boshRoot, "sys", "log", "non-existent", "bpm.log")
})

It("complaints that the config cannot be found", func() {
It("ignores that and is successful", func() {
command := exec.Command(bpmPath, "stop", "non-existent")
command.Env = append(command.Env, fmt.Sprintf("BPM_BOSH_ROOT=%s", boshRoot))

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
<-session.Exited

Expect(session).To(gexec.Exit(1))
Expect(fileContents(bpmLog)()).To(ContainSubstring("failed-to-parse-config"))
Expect(fileContents(bpmLog)()).To(ContainSubstring("no such file or directory"))
Expect(session).To(gexec.Exit(0))
Expect(fileContents(bpmLog)()).To(ContainSubstring("job-already-stopped"))
})
})

Expand Down

0 comments on commit 8ead4d3

Please sign in to comment.