Skip to content

[specific ci=Group11-Upgrade] Add UpgradeInProgress flag for VCH upgrade#4847

Merged
chengwang86 merged 11 commits intovmware:masterfrom
chengwang86:cheng-detectupgrade-4069
Apr 25, 2017
Merged

[specific ci=Group11-Upgrade] Add UpgradeInProgress flag for VCH upgrade#4847
chengwang86 merged 11 commits intovmware:masterfrom
chengwang86:cheng-detectupgrade-4069

Conversation

@chengwang86
Copy link
Contributor

@chengwang86 chengwang86 commented Apr 21, 2017

Fixes #4069

This PR adds a flag UpgradeInProgress to the VCH's ExtraConfig.

  • during VCH upgrade, if UpgradeInProgress==true, the current upgrade operation will fail since there might be another upgrade operation running.

  • I also add vic-machine upgrade --resetInProgressFlag so that the user could reset the flag to false in case the flag is polluted by previous operations that do not finish properly.

  • test cases are added

upgrading, err := vch.GetVCHUpdateStatus(ctx)
if err != nil {
log.Errorf("Unable to determine if upgrade is in progress: %s", err)
log.Errorf("Unable to determine if upgrade/update is in progress: %s", err)
Copy link
Contributor

@emlin emlin Apr 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/update/configure/g

}
if upgrading {
log.Info("Upgrade in progress")
log.Info("Upgrade/update in progress")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

},
cli.BoolFlag{
Name: "resetInProgressFlag",
Usage: "Reset the UpdateInProgress flag",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is upgrade command, name the flag as UpgradeInProgress.

return errors.New("upgrade failed")
}
if upgrading {
log.Error("Upgrade failed: another upgrade/update operation is in progress")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention how to fix it using option --resetInProgressFlag

}

// GetVCHUpdateStatus tells if an upgrade/update has already been started based on the UpdateInProgress flag in ExtraConfig
// If error != nil, VCH upgrade/update will exit; so the value of the VCH upgrade/update status is not important
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method help should not talk about the behavior of callers
here should describe while any error happens in vm operation, will return error

if v, ok := info[UpdateInProgress]; ok {
updateStatus, err := strconv.ParseBool(v)
if err != nil {
// If error occurs, return true to cancel VCH upgrade. The user can reset the UpdateInProgress flag later.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if error happens, the bool return value should not matter for the caller.
again do not comment caller's behavior

Copy link
Contributor

@mhagen-vmware mhagen-vmware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple small changes, otherwise lgtm

[Arguments] ${expected}
${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux inspect --name=%{VCH-NAME} --target=%{TEST_URL} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} --compute-resource=%{TEST_RESOURCE}
Should Be Equal As Integers ${rc} 0
Should Contain ${output} ${expected}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull this into VCH-Util.robot please.

[Arguments] ${expected}
${rc} ${output}= Run And Return Rc And Output govc vm.info -e %{VCH-NAME} | grep UpdateInProgress
Should Be Equal As Integers ${rc} 0
Should Contain ${output} ${expected}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one too


// GetVCHUpdateStatus tells if an upgrade/update has already been started based on the UpdateInProgress flag in ExtraConfig
// If error != nil, VCH upgrade/update will exit; so the value of the VCH upgrade/update status is not important
func (vm *VirtualMachine) GetVCHUpdateStatus(ctx context.Context) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetVCHUpdateStatus => VCHUpdateStatus

}

// SetVCHUpdateStatus sets the "UpdateInProgress" flag in ExtraConfig
func (vm *VirtualMachine) SetVCHUpdateStatus(ctx context.Context, updateStatus string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get set method should use same type of value, all string or bool

@chengwang86 chengwang86 changed the title [specific ci=Group11-Upgrade] Add UpdateInProgress flag for VCH upgrade [specific ci=Group11-Upgrade] Add UpgradeInProgress flag for VCH upgrade Apr 24, 2017
if upgrading {
log.Error("Upgrade failed: another upgrade/update operation is in progress")
log.Error("Upgrade failed: another upgrade/configure operation is in progress")
log.Error("Use --resetInProgressFlag to reset the VCH upgrade/configure status")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still need to mention, if there is no other upgrade or configure process running, use ...

func (vm *VirtualMachine) GetVCHUpdateStatus(ctx context.Context) (bool, error) {
// VCHUpgradeStatus tells if an upgrade/configure has already been started based on the UpgradeInProgress flag in ExtraConfig
// It returns the error if the vm operation does not succeed
func (vm *VirtualMachine) VCHUpgradeStatus(ctx context.Context) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method will be reused by upgrade and configure, so might still use update as name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add unit test for these two methods

},
cli.BoolFlag{
Name: "resetInProgressFlag",
Usage: "Reset the UpgradeInProgress flag",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels like here should have a warning message as well. to make sure user does not reset flag during other process is actually running

updateStatus, err := strconv.ParseBool(v)
if err != nil {
// If error occurs, the bool return value does not matter for the caller.
return true, fmt.Errorf("failed to parse %s to bool: %s", v, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here should return false

return false, err
}

if v, ok := info[UpgradeInProgress]; ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name is still inconsistent

Copy link
Contributor

@mhagen-vmware mhagen-vmware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@chengwang86 chengwang86 force-pushed the cheng-detectupgrade-4069 branch from e074906 to 43925ad Compare April 25, 2017 14:16
@chengwang86 chengwang86 merged commit 3d35d84 into vmware:master Apr 25, 2017
matthewavery pushed a commit to matthewavery/vic that referenced this pull request May 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants