Match-id-ca6c163b9b73228a9cdee8044427156acb258fc4

This commit is contained in:
BianTanggui
2022-10-18 17:18:34 +08:00
parent f5ae8e3a13
commit d6252eb43e
2 changed files with 16 additions and 22 deletions

View File

@@ -62,11 +62,10 @@ func main() {
err = process() err = process()
if err != nil { if err != nil {
hwlog.OpLog.Infof("%v run %s failed", logPrefixWords, os.Args) hwlog.OpLog.Errorf("%v run install failed: %v", logPrefixWords, err)
log.Fatal(fmt.Errorf("error in installation")) log.Fatal(fmt.Errorf("error in installation"))
} else {
hwlog.OpLog.Infof("%v run %s success", logPrefixWords, os.Args)
} }
hwlog.OpLog.Infof("%v run install success", logPrefixWords)
} }
func initLogModule(ctx context.Context) error { func initLogModule(ctx context.Context) error {

View File

@@ -10,7 +10,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"main/dcmi"
"os" "os"
"os/exec" "os/exec"
"path" "path"
@@ -19,8 +18,9 @@ import (
"syscall" "syscall"
"github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-spec/specs-go"
"huawei.com/mindx/common/hwlog" "huawei.com/mindx/common/hwlog"
"main/dcmi"
"mindxcheckutils" "mindxcheckutils"
) )
@@ -165,10 +165,10 @@ func addHook(spec *specs.Spec) error {
} }
vdevice, err := dcmi.CreateVDevice(&dcmi.NpuWorker{}, spec) vdevice, err := dcmi.CreateVDevice(&dcmi.NpuWorker{}, spec)
hwlog.RunLog.Infof("vnpu split done: vdevice: %v err: %v", vdevice.VdeviceID, err)
if err != nil { if err != nil {
return err return err
} }
hwlog.RunLog.Infof("vnpu split done: vdevice: %v", vdevice.VdeviceID)
if vdevice.VdeviceID != -1 { if vdevice.VdeviceID != -1 {
updateEnvAndPostHook(spec, vdevice) updateEnvAndPostHook(spec, vdevice)
@@ -217,7 +217,7 @@ func modifySpecFile(path string) error {
if err != nil { if err != nil {
return fmt.Errorf("spec file doesnt exist %s: %v", path, err) return fmt.Errorf("spec file doesnt exist %s: %v", path, err)
} }
if _, err := mindxcheckutils.RealFileChecker(path, true, true, mindxcheckutils.DefaultSize); err != nil { if _, err = mindxcheckutils.RealFileChecker(path, true, true, mindxcheckutils.DefaultSize); err != nil {
return err return err
} }
@@ -234,11 +234,11 @@ func modifySpecFile(path string) error {
} }
var spec specs.Spec var spec specs.Spec
if err := json.Unmarshal(jsonContent, &spec); err != nil { if err = json.Unmarshal(jsonContent, &spec); err != nil {
return fmt.Errorf("failed to unmarshal oci spec file %s: %v", path, err) return fmt.Errorf("failed to unmarshal oci spec file %s: %v", path, err)
} }
if err := addHook(&spec); err != nil { if err = addHook(&spec); err != nil {
return fmt.Errorf("failed to inject hook: %v", err) return fmt.Errorf("failed to inject hook: %v", err)
} }
@@ -247,7 +247,7 @@ func modifySpecFile(path string) error {
return fmt.Errorf("failed to marshal OCI spec file: %v", err) return fmt.Errorf("failed to marshal OCI spec file: %v", err)
} }
if _, err := jsonFile.WriteAt(jsonOutput, 0); err != nil { if _, err = jsonFile.WriteAt(jsonOutput, 0); err != nil {
return fmt.Errorf("failed to write OCI spec file: %v", err) return fmt.Errorf("failed to write OCI spec file: %v", err)
} }
@@ -273,7 +273,7 @@ func doProcess() error {
specFilePath := args.bundleDirPath + "/config.json" specFilePath := args.bundleDirPath + "/config.json"
if err := modifySpecFile(specFilePath); err != nil { if err = modifySpecFile(specFilePath); err != nil {
return fmt.Errorf("failed to modify spec file %s: %v", specFilePath, err) return fmt.Errorf("failed to modify spec file %s: %v", specFilePath, err)
} }
@@ -295,7 +295,7 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
defer func() { defer func() {
if err := mindxcheckutils.ChangeRuntimeLogMode("runtime-run-", "runtime-operate-"); err != nil { if err = mindxcheckutils.ChangeRuntimeLogMode("runtime-run-", "runtime-operate-"); err != nil {
fmt.Println("defer changeFileMode function failed") fmt.Println("defer changeFileMode function failed")
} }
}() }()
@@ -303,18 +303,13 @@ func main() {
hwlog.OpLog.Infof("%v ascend docker runtime starting, try to setup container", logPrefixWords) hwlog.OpLog.Infof("%v ascend docker runtime starting, try to setup container", logPrefixWords)
if !mindxcheckutils.StringChecker(strings.Join(os.Args, " "), 0, if !mindxcheckutils.StringChecker(strings.Join(os.Args, " "), 0,
maxCommandLength, mindxcheckutils.DefaultWhiteList+" ") { maxCommandLength, mindxcheckutils.DefaultWhiteList+" ") {
hwlog.RunLog.Infof("%v ascend docker runtime failed", logPrefixWords) hwlog.RunLog.Errorf("%v ascend docker runtime args check failed", logPrefixWords)
hwlog.OpLog.Errorf("%v ascend docker runtime failed", logPrefixWords) hwlog.OpLog.Errorf("%v ascend docker runtime args check failed", logPrefixWords)
log.Fatal("command error") log.Fatal("command error")
} }
logWords := fmt.Sprintf("%v running %v", logPrefixWords, os.Args) if err = doProcess(); err != nil {
if len(logWords) > maxLogLength { hwlog.RunLog.Errorf("%v docker runtime failed: %v", logPrefixWords, err)
logWords = logWords[0:maxLogLength-1] + "..." hwlog.OpLog.Errorf("%v docker runtime failed: %v", logPrefixWords, err)
}
hwlog.OpLog.Infof(logWords)
if err := doProcess(); err != nil {
hwlog.RunLog.Errorf("%v ascend docker runtime failed", logPrefixWords)
hwlog.OpLog.Errorf("%v %v failed", logPrefixWords, logWords)
log.Fatal(err) log.Fatal(err)
} }
} }