Skip to content

Commit

Permalink
Fix vm status transition check bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-github-robot authored Oct 30, 2024
2 parents 5f5a332 + c60906c commit b85ba26
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/core/infra/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func HandleMciVmAction(nsId string, mciId string, vmId string, action string, fo
return err.Error(), err
}

log.Debug().Msg("[VM action: " + action)
log.Info().Msg("[VM control request] " + action)

mci, err := GetMciStatus(nsId, mciId)
if err != nil {
Expand Down Expand Up @@ -517,7 +517,9 @@ func CheckAllowedTransition(nsId string, mciId string, vmId model.OptionalParame

// duplicated action
if strings.EqualFold(vm.Status, targetStatus) {
return errors.New(action + " is not allowed for VM under " + vm.Status)
if !strings.EqualFold(action, model.ActionReboot) {
return errors.New(action + " is not allowed for VM under " + vm.Status)
}
}
// redundant action
if strings.EqualFold(vm.Status, model.StatusTerminated) {
Expand Down
6 changes: 3 additions & 3 deletions src/core/infra/manageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func ListSubGroupId(nsId string, mciId string) ([]string, error) {
return nil, err
}

log.Debug().Msg("[ListSubGroupId]")
//log.Debug().Msg("[ListSubGroupId]")
key := common.GenMciKey(nsId, mciId, "")
key += "/"

Expand Down Expand Up @@ -608,7 +608,7 @@ func ListVmInfo(nsId string, mciId string, vmId string) (*model.TbVmInfo, error)
vmKeyValue, err := kvstore.GetKv(vmKey)
if err != nil {
log.Error().Err(err).Msg("")
err = fmt.Errorf("In CoreGetMciVmInfo(); kvstore.GetKv() returned an error.")
err = fmt.Errorf("kvstore.GetKv() returned an error.")
log.Error().Err(err).Msg("")
// return nil, err
}
Expand All @@ -635,7 +635,7 @@ func ListVmInfo(nsId string, mciId string, vmId string) (*model.TbVmInfo, error)

// GetMciObject is func to retrieve MCI object from database (no current status update)
func GetMciObject(nsId string, mciId string) (model.TbMciInfo, error) {
log.Debug().Msg("[GetMciObject]" + mciId)
//log.Debug().Msg("[GetMciObject]" + mciId)
key := common.GenMciKey(nsId, mciId, "")
keyValue, err := kvstore.GetKv(key)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/core/infra/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func CheckVm(nsId string, mciId string, vmId string) (bool, error) {
log.Error().Err(err).Msg("")
return false, err
}
log.Debug().Msg("[Check vm] " + mciId + ", " + vmId)
//log.Debug().Msg("[Check vm] " + mciId + ", " + vmId)

key := common.GenMciKey(nsId, mciId, vmId)

Expand Down
4 changes: 2 additions & 2 deletions src/core/resource/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ func ListResource(nsId string, resourceType string, filterKey string, filterVal
return nil, err
}

log.Debug().Msg("[Get] " + resourceType + " list")
//log.Debug().Msg("[Get] " + resourceType + " list")
key := "/ns/" + nsId + "/resources/" + resourceType
log.Debug().Msg(key)
//log.Debug().Msg(key)

keyValue, err := kvstore.GetKvList(key)
keyValue = kvutil.FilterKvListBy(keyValue, key, 1)
Expand Down
6 changes: 3 additions & 3 deletions src/core/resource/k8scluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,17 +1028,17 @@ func ListK8sClusterId(nsId string) ([]string, error) {

// ListK8sCluster returns the list of TB K8sCluster objects of given nsId
func ListK8sCluster(nsId string, filterKey string, filterVal string) (interface{}, error) {
log.Info().Msg("ListK8sCluster")
//log.Info().Msg("ListK8sCluster")

err := common.CheckString(nsId)
if err != nil {
log.Err(err).Msg("Failed to List K8sCluster")
return nil, err
}

log.Debug().Msg("[Get] K8sCluster list")
//log.Debug().Msg("[Get] K8sCluster list")
k := fmt.Sprintf("/ns/%s/k8scluster", nsId)
log.Debug().Msg(k)
//log.Debug().Msg(k)

/*
* Get model.TbK8sClusterInfo objects from kvstore
Expand Down

0 comments on commit b85ba26

Please sign in to comment.