Skip to content

Commit

Permalink
SNC-15879 No error "% Error: Invalid image URL" when attempt to "imag…
Browse files Browse the repository at this point in the history
…e set-default" with an invalid image (sonic-net#51)

* Assigning timestamp values and ifnot present then returning empty

* Retracking data type for timestamp and using dbmaps for fetching values
  • Loading branch information
ViramShah91 authored and GitHub Enterprise committed Feb 10, 2022
1 parent 7385672 commit f3765fa
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,22 @@ module openconfig-image-management-annot {

deviation /oc-img-mgmt:image-management/oc-img-mgmt:install/oc-img-mgmt:state/oc-img-mgmt:transfer-start-time {
deviate add {
sonic-ext:field-name "transfer_task_start_time";
sonic-ext:field-transformer "transfer_start_time_xfmr";
}
}
deviation /oc-img-mgmt:image-management/oc-img-mgmt:install/oc-img-mgmt:state/oc-img-mgmt:transfer-end-time {
deviate add {
sonic-ext:field-name "transfer_task_end_time";
sonic-ext:field-transformer "transfer_end_time_xfmr";
}
}
deviation /oc-img-mgmt:image-management/oc-img-mgmt:install/oc-img-mgmt:state/oc-img-mgmt:install-start-time {
deviate add {
sonic-ext:field-name "install_task_start_time";
sonic-ext:field-transformer "install_start_time_xfmr";
}
}
deviation /oc-img-mgmt:image-management/oc-img-mgmt:install/oc-img-mgmt:state/oc-img-mgmt:install-end-time {
deviate add {
sonic-ext:field-name "install_task_end_time";
sonic-ext:field-transformer "install_end_time_xfmr";
}
}

Expand Down
77 changes: 77 additions & 0 deletions translib/transformer/xfmr_image_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func init() {
XlateFuncBind("DbToYang_image_table_key_xfmr", DbToYang_image_table_key_xfmr)
XlateFuncBind("YangToDb_image_global_key_xfmr", YangToDb_image_global_key_xfmr)
XlateFuncBind("DbToYang_image_name_xfmr", DbToYang_image_name_xfmr)
XlateFuncBind("DbToYang_transfer_start_time_xfmr", DbToYang_transfer_start_time_xfmr)
XlateFuncBind("DbToYang_transfer_end_time_xfmr", DbToYang_transfer_end_time_xfmr)
XlateFuncBind("DbToYang_install_start_time_xfmr", DbToYang_install_start_time_xfmr)
XlateFuncBind("DbToYang_install_end_time_xfmr", DbToYang_install_end_time_xfmr)
}

var DbToYang_image_name_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) {
Expand All @@ -51,6 +55,79 @@ var DbToYang_image_name_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[
return res_map, nil
}

func getDBValuesTime(inParams XfmrParams, varName string) (string, error) {
if varName == "" {
return "", errors.New("Invalid inParams")
}
data := (*inParams.dbDataMap)[inParams.curDb]
imgTbl := data["IMAGE_GLOBAL"]
if _, ok := imgTbl[inParams.key]; !ok {
return "", errors.New("Key not present in Image Global table")
}
imgKey := imgTbl[inParams.key]
timeStamp, ok := imgKey.Field[varName]
if !ok {
return "", errors.New("Field not present in Image Global Table")
}
return timeStamp, nil
}

var DbToYang_transfer_start_time_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) {

res_map := make(map[string]interface{})
value, err := getDBValuesTime(inParams, "transfer_task_start_time")
if err != nil {
return nil, err
}
if value == "0" {
return nil, err
}
res_map["transfer-start-time"] = value
return res_map, nil
}

var DbToYang_transfer_end_time_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) {

res_map := make(map[string]interface{})
value, err := getDBValuesTime(inParams, "transfer_task_end_time")
if err != nil {
return nil, err
}
if value == "0" {
return nil, err
}
res_map["transfer-end-time"] = value
return res_map, nil
}

var DbToYang_install_start_time_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) {

res_map := make(map[string]interface{})
value, err := getDBValuesTime(inParams, "install_task_start_time")
if err != nil {
return nil, err
}
if value == "0" {
return nil, err
}
res_map["install-start-time"] = value
return res_map, nil
}

var DbToYang_install_end_time_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) {

res_map := make(map[string]interface{})
value, err := getDBValuesTime(inParams, "install_task_end_time")
if err != nil {
return nil, err
}
if value == "0" {
return nil, err
}
res_map["install-end-time"] = value
return res_map, nil
}

var YangToDb_image_table_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) {

var err error
Expand Down

0 comments on commit f3765fa

Please sign in to comment.