Skip to content

Commit

Permalink
Use Eden.Root from configuration instead of viper in InitVarsFromConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Abramov <[email protected]>
  • Loading branch information
uncleDecart committed Nov 21, 2023
1 parent b0386ac commit 66f750b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
11 changes: 5 additions & 6 deletions pkg/openevec/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func InitVarsFromConfig(cfg *EdenSetupArgs) (*utils.ConfigVars, error) {
cv.AdamIP = cfg.Adam.CertsIP
cv.AdamPort = strconv.Itoa(cfg.Adam.Port)
cv.AdamDomain = cfg.Adam.CertsDomain
cv.AdamDir = utils.ResolveAbsPath(cfg.Adam.Dist)
cv.AdamDir = utils.ResolveAbsPathWithRoot(cfg.Eden.Root, cfg.Adam.Dist)
cv.AdamCA = caCertPath
cv.AdamRedisURLEden = cfg.Adam.Redis.RemoteURL
cv.AdamRemote = cfg.Adam.Remote.Enabled
Expand All @@ -53,25 +53,24 @@ func InitVarsFromConfig(cfg *EdenSetupArgs) (*utils.ConfigVars, error) {
cv.AdamCachingPrefix = cfg.Adam.Caching.Prefix
cv.AdamCachingRedis = cfg.Adam.Caching.Redis

cv.SSHKey = utils.ResolveAbsPath(cfg.Eden.SSHKey)
cv.SSHKey = utils.ResolveAbsPathWithRoot(cfg.Eden.Root, cfg.Eden.SSHKey)
cv.EdenBinDir = cfg.Eden.BinDir
cv.EdenProg = cfg.Eden.EdenBin
cv.TestProg = cfg.Eden.TestBin
cv.TestScenario = cfg.Eden.TestScenario
cv.EServerImageDist = utils.ResolveAbsPath(cfg.Eden.Images.EServerImageDist)
cv.EServerImageDist = utils.ResolveAbsPathWithRoot(cfg.Eden.Root, cfg.Eden.Images.EServerImageDist)
cv.EServerPort = strconv.Itoa(cfg.Eden.EServer.Port)
cv.EServerIP = cfg.Eden.EServer.IP

cv.EveCert = utils.ResolveAbsPath(cfg.Eve.Cert)
cv.EveDeviceCert = utils.ResolveAbsPath(cfg.Eve.DeviceCert)
cv.EveCert = utils.ResolveAbsPathWithRoot(cfg.Eden.Root, cfg.Eve.Cert)
cv.EveDeviceCert = utils.ResolveAbsPathWithRoot(cfg.Eden.Root, cfg.Eve.DeviceCert)
cv.EveSerial = cfg.Eve.Serial
cv.EveDist = cfg.Eve.Dist
cv.EveQemuConfig = cfg.Eve.QemuFileToSave
cv.ZArch = cfg.Eve.Arch
cv.EveSSID = cfg.Eve.Ssid
cv.EveHV = cfg.Eve.HV
cv.DevModel = cfg.Eve.DevModel
cv.DevModelFIle = cfg.Eve.DevModelFile
cv.EveName = cfg.Eve.Name
cv.EveUUID = cfg.Eve.CertsUUID
cv.AdamLogLevel = cfg.Eve.AdamLogLevel
Expand Down
31 changes: 18 additions & 13 deletions pkg/utils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/spf13/viper"
)

//SHA256SUM calculates sha256 of file
// SHA256SUM calculates sha256 of file
func SHA256SUM(filePath string) string {
file, err := os.Open(filePath)
if err != nil {
Expand All @@ -30,7 +30,7 @@ func SHA256SUM(filePath string) string {
return hex.EncodeToString(hash.Sum(nil))
}

//CopyFileNotExists copy file from src to dst with same permission if not exists
// CopyFileNotExists copy file from src to dst with same permission if not exists
func CopyFileNotExists(src string, dst string) (err error) {
if _, err = os.Lstat(dst); os.IsNotExist(err) {
if err = CopyFile(src, dst); err != nil {
Expand All @@ -40,7 +40,7 @@ func CopyFileNotExists(src string, dst string) (err error) {
return nil
}

//CopyFile copy file from src to dst with same permission
// CopyFile copy file from src to dst with same permission
func CopyFile(src string, dst string) (err error) {
info, err := os.Lstat(src)
if err != nil {
Expand Down Expand Up @@ -81,7 +81,7 @@ func CopyFile(src string, dst string) (err error) {
return
}

//TouchFile create empty file
// TouchFile create empty file
func TouchFile(src string) (err error) {
if _, err := os.Stat(src); os.IsNotExist(err) {
file, err := os.Create(src)
Expand All @@ -99,23 +99,28 @@ func TouchFile(src string) (err error) {
return nil
}

//FileNameWithoutExtension trim file extension and path
// FileNameWithoutExtension trim file extension and path
func FileNameWithoutExtension(fileName string) string {
return filepath.Base(strings.TrimSuffix(fileName, filepath.Ext(fileName)))
}

//ResolveAbsPath use eden.root parameter to resolve path
// ResolveAbsPath use eden.root parameter to resolve path
func ResolveAbsPath(curPath string) string {
return ResolveAbsPathWithRoot(viper.GetString("eden.root"), curPath)
}

// ResolveAbsPathWithRoot use rootPath parameter to resolve path
func ResolveAbsPathWithRoot(rootPath, curPath string) string {
if strings.TrimSpace(curPath) == "" {
return ""
}
if !filepath.IsAbs(curPath) {
return filepath.Join(viper.GetString("eden.root"), strings.TrimSpace(curPath))
return filepath.Join(rootPath, strings.TrimSpace(curPath))
}
return curPath
}

//GetFileFollowLinks resolve file by walking through symlinks
// GetFileFollowLinks resolve file by walking through symlinks
func GetFileFollowLinks(filePath string) (string, error) {
log.Debugf("GetFileFollowLinks %s", filePath)
filePath = ResolveHomeDir(filePath)
Expand All @@ -137,7 +142,7 @@ func GetFileFollowLinks(filePath string) (string, error) {
return filepath.Join(filepath.Dir(filePath), fileInfo.Name()), nil
}

//GetFileSize returns file size
// GetFileSize returns file size
func GetFileSize(filePath string) int64 {
fi, err := os.Stat(filePath)
if err != nil {
Expand All @@ -146,7 +151,7 @@ func GetFileSize(filePath string) int64 {
return fi.Size()
}

//ResolveHomeDir resolve ~ in path
// ResolveHomeDir resolve ~ in path
func ResolveHomeDir(filePath string) string {
usr, err := user.Current()
if err != nil {
Expand All @@ -161,7 +166,7 @@ func ResolveHomeDir(filePath string) string {
return filePath
}

//CopyFolder from source to destination
// CopyFolder from source to destination
func CopyFolder(source, destination string) error {
var err = filepath.Walk(source, func(path string, info os.FileInfo, err error) error {
var relPath = strings.Replace(path, source, "", 1)
Expand All @@ -182,7 +187,7 @@ func IsInputFromPipe() bool {
return fileInfo.Mode()&os.ModeCharDevice == 0
}

//SHA256SUMAll calculates sha256 of directory
// SHA256SUMAll calculates sha256 of directory
func SHA256SUMAll(dir string) (string, error) {
hash := sha256.New()
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
Expand All @@ -207,7 +212,7 @@ func SHA256SUMAll(dir string) (string, error) {
return hex.EncodeToString(hash.Sum(nil)), nil
}

//CreateDisk creates empty disk with defined format on diskFile with size bytes capacity
// CreateDisk creates empty disk with defined format on diskFile with size bytes capacity
func CreateDisk(diskFile, format string, size uint64) error {
if err := os.MkdirAll(filepath.Dir(diskFile), 0755); err != nil {
return err
Expand Down

0 comments on commit 66f750b

Please sign in to comment.