Skip to content

Commit

Permalink
one more change to plan layout
Browse files Browse the repository at this point in the history
  • Loading branch information
bsamuels453 committed Jan 10, 2024
1 parent c23befd commit b5acf03
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 71 deletions.
75 changes: 75 additions & 0 deletions pkg/plan/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package plan

import (
"fmt"
"github.com/kurtosis-tech/stacktrace"
"os"
"path/filepath"
)

func preparePaths(testName string) (netRefPath, netConfigPath, planConfigPath string, err error) {
dir, err := os.Getwd()
// initialize to empty string for error cases
netConfigPath = ""
planConfigPath = ""
if err != nil {
return
}

netRefPath = fmt.Sprintf("plan/%s.yaml", testName)
networkConfigName := fmt.Sprintf("network-configs/%s", netRefPath)
netConfigPath = filepath.Join(dir, networkConfigName)
if _, err = os.Stat(netConfigPath); err == nil {
// delete file
err = os.Remove(netConfigPath)
if err != nil {
err = stacktrace.Propagate(err, "unable to remove file")
return
}
}

suiteName := fmt.Sprintf("test-suites/plan/%s.yaml", testName)
planConfigPath = filepath.Join(dir, suiteName)
if _, err = os.Stat(planConfigPath); err == nil {
// delete file
err = os.Remove(planConfigPath)
if err != nil {
err = stacktrace.Propagate(err, "unable to remove file")
return
}
}
err = nil
return
}

func writePlans(netConfigPath, suiteConfigPath string, netConfig, suiteConfig []byte) error {
f, err := os.Create(netConfigPath)
if err != nil {
return stacktrace.Propagate(err, "cannot open network types path %s", netConfigPath)
}
_, err = f.Write(netConfig)
if err != nil {
return stacktrace.Propagate(err, "could not write network types to file")
}

err = f.Close()
if err != nil {
return stacktrace.Propagate(err, "could not close network types file")
}

f, err = os.Create(suiteConfigPath)
if err != nil {
return stacktrace.Propagate(err, "cannot open suite types path %s", suiteConfigPath)
}
_, err = f.Write(suiteConfig)
if err != nil {
return stacktrace.Propagate(err, "could not write suite types to file")
}

err = f.Close()
if err != nil {
return stacktrace.Propagate(err, "could not close suite types file")
}

return nil
}
71 changes: 0 additions & 71 deletions pkg/plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,80 +4,9 @@ import (
"attacknet/cmd/pkg/plan/network"
"attacknet/cmd/pkg/plan/suite"
types "attacknet/cmd/pkg/types"
"fmt"
"github.com/kurtosis-tech/stacktrace"
"gopkg.in/yaml.v3"
"os"
"path/filepath"
)

func preparePaths(testName string) (netRefPath, netConfigPath, planConfigPath string, err error) {
dir, err := os.Getwd()
// initialize to empty string for error cases
netConfigPath = ""
planConfigPath = ""
if err != nil {
return
}

netRefPath = fmt.Sprintf("plan/%s.yaml", testName)
networkConfigName := fmt.Sprintf("network-configs/%s", netRefPath)
netConfigPath = filepath.Join(dir, networkConfigName)
if _, err = os.Stat(netConfigPath); err == nil {
// delete file
err = os.Remove(netConfigPath)
if err != nil {
err = stacktrace.Propagate(err, "unable to remove file")
return
}
}

suiteName := fmt.Sprintf("test-suites/plan/%s.yaml", testName)
planConfigPath = filepath.Join(dir, suiteName)
if _, err = os.Stat(planConfigPath); err == nil {
// delete file
err = os.Remove(planConfigPath)
if err != nil {
err = stacktrace.Propagate(err, "unable to remove file")
return
}
}
err = nil
return
}

func writePlans(netConfigPath, suiteConfigPath string, netConfig, suiteConfig []byte) error {
f, err := os.Create(netConfigPath)
if err != nil {
return stacktrace.Propagate(err, "cannot open network types path %s", netConfigPath)
}
_, err = f.Write(netConfig)
if err != nil {
return stacktrace.Propagate(err, "could not write network types to file")
}

err = f.Close()
if err != nil {
return stacktrace.Propagate(err, "could not close network types file")
}

f, err = os.Create(suiteConfigPath)
if err != nil {
return stacktrace.Propagate(err, "cannot open suite types path %s", suiteConfigPath)
}
_, err = f.Write(suiteConfig)
if err != nil {
return stacktrace.Propagate(err, "could not write suite types to file")
}

err = f.Close()
if err != nil {
return stacktrace.Propagate(err, "could not close suite types file")
}

return nil
}

func BuildPlan(planName string, config *PlannerConfig) error {

netRefPath, netConfigPath, suiteConfigPath, err := preparePaths(planName)
Expand Down

0 comments on commit b5acf03

Please sign in to comment.