feat: add shutdownVMOnMigrationFailure to the upgrade-config setting (#1218) (#1265)

* feat: add shutdownVMOnMigrationFailure to the upgrade-config setting

Add a control for the new field, which decides whether a VM that fails
to live migrate during the node pre-drain phase is shut down so that the
upgrade can continue. The field is only shown and defaulted on v1.10.0
or later clusters.




* fix: name the upgrade-config radio groups for screen readers

Pass the labels of the Restore VM and Shut Down VM on Migration Failure
radio groups as their aria-label, so that screen readers can tell them
apart. Select the value through the radio group in the tests, so that
they catch a group that isn't bound to its field.




---------

Signed-off-by: Tim Liou <tim.liou@suse.com>
Co-authored-by: Tim Liou <tim.liou@suse.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mergify[bot]
2026-11-18 09:15:15 +08:00
committed by GitHub
co-authored by Tim Liou Claude Opus 5.5
parent ed280e2f81
commit 0a797e7e22
4 changed files with 102 additions and 0 deletions
@@ -0,0 +1,79 @@
import { shallowMount } from '@vue/test-utils';
import UpgradeConfig from '@pkg/harvester/components/settings/upgrade-config.vue';
const DEFAULT = JSON.stringify({
imagePreloadOption: { strategy: { type: 'sequential' } },
nodeUpgradeOption: { strategy: { mode: 'auto' } },
restoreVM: false,
});
const mountConfig = (config, featureEnabled) => shallowMount(UpgradeConfig, {
props: {
mode: 'edit',
value: { default: DEFAULT, value: config ? JSON.stringify(config) : '' },
},
global: {
mocks: {
$store: {
dispatch: jest.fn(),
getters: {
currentProduct: { inStore: 'harvester' },
'harvester/all': () => [],
'i18n/t': (key) => key,
'harvester-common/getFeatureEnabled': (name) => name === 'shutdownVMOnMigrationFailure' && featureEnabled,
},
},
},
},
});
const savedValue = (wrapper) => JSON.parse(wrapper.props('value').value);
describe('component: upgrade-config', () => {
it('should default shutdownVMOnMigrationFailure to false when the field is missing', () => {
const wrapper = mountConfig(undefined, true);
expect(savedValue(wrapper).shutdownVMOnMigrationFailure).toBe(false);
expect(wrapper.findComponent('[name="shutdownVMOnMigrationFailure"]').exists()).toBe(true);
});
it('should keep an enabled shutdownVMOnMigrationFailure', () => {
const wrapper = mountConfig({ shutdownVMOnMigrationFailure: true }, true);
expect(savedValue(wrapper).shutdownVMOnMigrationFailure).toBe(true);
});
it('should save the value selected in its radio group', async() => {
const wrapper = mountConfig(undefined, true);
await wrapper.findComponent('[name="shutdownVMOnMigrationFailure"]').vm.$emit('update:value', true);
expect(savedValue(wrapper).shutdownVMOnMigrationFailure).toBe(true);
expect(savedValue(wrapper).restoreVM).toBe(false);
await wrapper.findComponent('[name="restoreVM"]').vm.$emit('update:value', true);
expect(savedValue(wrapper).shutdownVMOnMigrationFailure).toBe(true);
expect(savedValue(wrapper).restoreVM).toBe(true);
});
it('should name the radio groups for screen readers', () => {
const wrapper = mountConfig(undefined, true);
expect(wrapper.findComponent('[name="restoreVM"]').attributes('aria-label')).toBe('harvester.setting.upgrade.restoreVM');
expect(wrapper.findComponent('[name="shutdownVMOnMigrationFailure"]').attributes('aria-label')).toBe('harvester.setting.upgrade.shutdownVMOnMigrationFailure');
});
it('should hide the control and not add the field on clusters without the feature', () => {
const wrapper = mountConfig(undefined, false);
expect(savedValue(wrapper)).not.toHaveProperty('shutdownVMOnMigrationFailure');
expect(wrapper.findComponent('[name="shutdownVMOnMigrationFailure"]').exists()).toBe(false);
});
it('should keep a field set outside the UI on clusters without the feature', () => {
const wrapper = mountConfig({ shutdownVMOnMigrationFailure: true }, false);
expect(savedValue(wrapper).shutdownVMOnMigrationFailure).toBe(true);
});
});
@@ -74,6 +74,10 @@ export default {
},
methods: {
// A method, as normalizeValue also runs in data(), before computed properties are available
shutdownVMOnMigrationFailureEnabled() {
return this.$store.getters['harvester-common/getFeatureEnabled']('shutdownVMOnMigrationFailure');
},
normalizeValue(obj) {
// handle nodeUpgradeOption.strategy
if (obj?.nodeUpgradeOption?.strategy?.mode === 'auto') {
@@ -107,6 +111,9 @@ export default {
if (typeof obj.restoreVM !== 'boolean') {
obj.restoreVM = false;
}
if (this.shutdownVMOnMigrationFailureEnabled() && typeof obj.shutdownVMOnMigrationFailure !== 'boolean') {
obj.shutdownVMOnMigrationFailure = false;
}
return obj;
},
@@ -179,10 +186,24 @@ export default {
v-model:value="parseDefaultValue.restoreVM"
class="mb-20"
name="restoreVM"
:aria-label="t('harvester.setting.upgrade.restoreVM')"
:options="[true, false]"
:labels="[t('generic.enabled'), t('generic.disabled')]"
@update:value="update"
/>
<div v-if="shutdownVMOnMigrationFailureEnabled()">
<label class="mb-5"><b>{{ t('harvester.setting.upgrade.shutdownVMOnMigrationFailure') }}</b></label>
<RadioGroup
v-model:value="parseDefaultValue.shutdownVMOnMigrationFailure"
class="mb-20"
name="shutdownVMOnMigrationFailure"
:aria-label="t('harvester.setting.upgrade.shutdownVMOnMigrationFailure')"
:mode="mode"
:options="[true, false]"
:labels="[t('generic.enabled'), t('generic.disabled')]"
@update:value="update"
/>
</div>
<div v-if="resumeUpgradePausedNodeEnabled">
<label class="mb-5"><b>{{ t('harvester.setting.upgrade.nodeUpgradeOption') }}</b></label>
<LabeledSelect
+1
View File
@@ -86,6 +86,7 @@ const FEATURE_FLAGS = {
'maintenanceModeConditions',
'maintenanceModeDrainTimeoutSetting',
'componentHealth',
'shutdownVMOnMigrationFailure',
],
};
+1
View File
@@ -1695,6 +1695,7 @@ harvester:
imagePreloadStrategy: Image Preload Strategy
nodeUpgradeOption: Node Upgrade Option
restoreVM: Restore VM
shutdownVMOnMigrationFailure: Shut Down VM on Migration Failure
strategy: Strategy
pauseNodes: Pause Nodes
strategyType: Strategy Type