From f3765fa420138cfde2842c5447ab2a4751c2cfb3 Mon Sep 17 00:00:00 2001 From: "Shah, Viram" Date: Thu, 10 Feb 2022 12:09:38 -0800 Subject: [PATCH] SNC-15879 No error "% Error: Invalid image URL" when attempt to "image set-default" with an invalid image (#51) * Assigning timestamp values and ifnot present then returning empty * Retracking data type for timestamp and using dbmaps for fetching values --- .../openconfig-image-management-annot.yang | 8 +- translib/transformer/xfmr_image_mgmt.go | 77 +++++++++++++++++++ 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/models/yang/annotations/openconfig-image-management-annot.yang b/models/yang/annotations/openconfig-image-management-annot.yang index 45c85f072..4a62d2072 100644 --- a/models/yang/annotations/openconfig-image-management-annot.yang +++ b/models/yang/annotations/openconfig-image-management-annot.yang @@ -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"; } } diff --git a/translib/transformer/xfmr_image_mgmt.go b/translib/transformer/xfmr_image_mgmt.go index 1f539db04..bba68ac58 100644 --- a/translib/transformer/xfmr_image_mgmt.go +++ b/translib/transformer/xfmr_image_mgmt.go @@ -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) { @@ -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