Loading utility.go 0 → 100644 +33 −0 Original line number Diff line number Diff line package kinetic import ( "fmt" "io" "io/ioutil" "os" ) // UpdateFirmware is the utility function to update drive firmware. // conn is BlockConnection to drive, and file is the full path to the firmware file. func UpdateFirmware(conn *BlockConnection, file string) error { _, err := os.Stat(file) if err != nil { if os.IsNotExist(err) { klog.Errorf("Update firmware fail, file %s not exist", file) } return err } data, err := ioutil.ReadFile(file) if err != nil { klog.Errorf("Update firmware fail, file %s can't read", file) return err } status, err := conn.UpdateFirmware(data) if err != nil || status.Code != OK { klog.Errorf("Update firmware fail : %s\n", status.Error()) } return err } utility_test.go 0 → 100644 +14 −0 Original line number Diff line number Diff line package kinetic import ( "testing" ) func TestUpdateFirmware(t *testing.T) { // file not exist, expected to fail file := "not/exist/firmare/unknown-version.slod" err := UpdateFirmware(blockConn, file) if err != nil { t.Fatal("Firmware update fail: ", file) } } Loading
utility.go 0 → 100644 +33 −0 Original line number Diff line number Diff line package kinetic import ( "fmt" "io" "io/ioutil" "os" ) // UpdateFirmware is the utility function to update drive firmware. // conn is BlockConnection to drive, and file is the full path to the firmware file. func UpdateFirmware(conn *BlockConnection, file string) error { _, err := os.Stat(file) if err != nil { if os.IsNotExist(err) { klog.Errorf("Update firmware fail, file %s not exist", file) } return err } data, err := ioutil.ReadFile(file) if err != nil { klog.Errorf("Update firmware fail, file %s can't read", file) return err } status, err := conn.UpdateFirmware(data) if err != nil || status.Code != OK { klog.Errorf("Update firmware fail : %s\n", status.Error()) } return err }
utility_test.go 0 → 100644 +14 −0 Original line number Diff line number Diff line package kinetic import ( "testing" ) func TestUpdateFirmware(t *testing.T) { // file not exist, expected to fail file := "not/exist/firmare/unknown-version.slod" err := UpdateFirmware(blockConn, file) if err != nil { t.Fatal("Firmware update fail: ", file) } }