Skip to content

Commit

Permalink
Improving func names and conditions
Browse files Browse the repository at this point in the history
Signed-off-by: Tejaswi Bondila <bondila.venkatatejaswi@progress.com>
  • Loading branch information
bvtejaswi committed Jul 17, 2023
1 parent ab13195 commit 7e3986b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
32 changes: 10 additions & 22 deletions components/automate-cli/cmd/chef-automate/certRotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ func (c *certRotateFlow) patchConfig(param *patchFnParameters, concurrent bool,
return err
}
} else {
err = c.copyAndExecuteConcurrently(nodeOpUtils, filteredIps, param.sshUtil, param.timestamp, param.remoteService, param.fileName, scriptCommands, param.flagsObj, printCertRotateOutput)
err = c.copyAndExecuteConcurrentlyToFrontEndNodes(nodeOpUtils, filteredIps, param.sshUtil, param.timestamp, param.remoteService, param.fileName, scriptCommands, param.flagsObj, printCertRotateOutput)
if err != nil {
return err
}
Expand Down Expand Up @@ -647,37 +647,25 @@ func (c *certRotateFlow) copyAndExecute(ips []string, sshUtil SSHUtil, timestamp
return nil
}

// copyAndExecute will copy the toml file to each required node and then execute the set of commands.
func (c *certRotateFlow) copyAndExecuteConcurrently(nu NodeOpUtils, ips []string, sshUtil SSHUtil, timestamp string, remoteService string, fileName string, scriptCommands string, flagsObj *certRotateFlags, printCertRotateOutput func(CertRotateCmdResult, string, *cli.Writer)) error {
//var err error
var tomlFilePath string
// copyAndExecuteConcurrently will copy the toml file to each required nodes concurrently and then execute the set of commands.
func (c *certRotateFlow) copyAndExecuteConcurrentlyToFrontEndNodes(nu NodeOpUtils, ips []string, sshUtil SSHUtil, timestamp string, remoteService string, fileName string, scriptCommands string, flagsObj *certRotateFlags, printCertRotateOutput func(CertRotateCmdResult, string, *cli.Writer)) error {

responseChan := make(chan CertRotateCmdResult, len(ips))
defer close(responseChan)
infra, _, err := nu.getHaInfraDetails()
if err != nil {
return err
}
for i := 0; i < len(ips); i++ {
infra, _, err := nu.getHaInfraDetails()
if err != nil {
return err
}
SSHConfig := c.getSshDetails(infra)
SSHUtils := NewSSHUtil(SSHConfig)
SSHConfig.timeout = flagsObj.timeout
SSHUtils.setSSHConfig(SSHConfig)
go func(hostIP string, responseChan chan CertRotateCmdResult) {
rc := CertRotateCmdResult{hostIP, "", nil, writer, remoteService}
SSHUtils.getSSHConfig().hostIP = hostIP
if (flagsObj.postgres || flagsObj.opensearch) && remoteService != "frontend" {
tomlFilePath, err = c.getMerger(fileName, timestamp, remoteService, GET_USER_CONFIG, SSHUtils)
if err != nil {
rc.err = err
responseChan <- rc
return
}
// Copying the new toml file which includes both old and new configurations (for backend nodes).
err = SSHUtils.copyFileToRemote(tomlFilePath, remoteService+timestamp, false)
} else {
// Copying the new toml file which includes new configurations (for frontend nodes).
err = SSHUtils.copyFileToRemote(fileName, remoteService+timestamp, false)
}
// Copying the new toml file which includes new configurations (for frontend nodes).
err = SSHUtils.copyFileToRemote(fileName, remoteService+timestamp, false)
if err != nil {
writer.Errorf("%v", err)
rc.err = err
Expand Down
4 changes: 2 additions & 2 deletions components/automate-cli/cmd/chef-automate/certRotate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ func TestGetFrontIpsToSkipRootCAPatchingForPg(t *testing.T) {
}
}

func TestCopyAndExecuteConCurrently(t *testing.T) {
func TestCopyAndExecuteConcurrentlyToFrontEndNodes(t *testing.T) {
c := certRotateFlow{FileUtils: mockFS()}
infra := &AutomateHAInfraDetails{}
fmt.Println(infra)
Expand Down Expand Up @@ -1247,7 +1247,7 @@ func TestCopyAndExecuteConCurrently(t *testing.T) {
fmt.Println("remote service : ", testCase.remoteService)
fmt.Println("commands : ", testCase.scriptCommands)
fmt.Println("flags: ", testCase.flagsObj)
err := c.copyAndExecuteConcurrently(testCase.mockPatchCmdHelper, testCase.ips, testCase.sshUtil, testCase.timestamp, testCase.remoteService, testCase.fileName, testCase.scriptCommands, testCase.flagsObj, printCertRotateOutput)
err := c.copyAndExecuteConcurrentlyToFrontEndNodes(testCase.mockPatchCmdHelper, testCase.ips, testCase.sshUtil, testCase.timestamp, testCase.remoteService, testCase.fileName, testCase.scriptCommands, testCase.flagsObj, printCertRotateOutput)
fmt.Println("msg: ", err)
if err != nil {
assert.EqualError(t, err, testCase.errorWant.Error())
Expand Down

0 comments on commit 7e3986b

Please sign in to comment.