Skip to content

Commit

Permalink
backport-pr-12611 (#12619)
Browse files Browse the repository at this point in the history
  • Loading branch information
aalves08 authored Nov 15, 2024
1 parent 89605e9 commit 6a92a26
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 50 deletions.
8 changes: 8 additions & 0 deletions shell/assets/translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,14 @@ cluster:
placeholder: A unique name for the cluster
directoryConfig:
title: Data directory configuration
banner: Data directory configuration can not be changed once the cluster has been created
radioInput:
defaultLabel: Use default data directory configuration
commonLabel: Use a common base directory for data directory configuration (sub-directories will be used for the system-agent, provisioning and distro paths)
customLabel: Use custom data directories
common:
label: Data directory base path
tooltip: Data directory base path. We will append the sub-directories appropriate for each directory (/agent, /provisioning and either /rke2 or /k3s)
systemAgent:
label: System-agent directory path
tooltip: Data directory for the system-agent connection info and plans
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { nextTick } from 'vue';
/* eslint-disable jest/no-hooks */
import { mount, Wrapper } from '@vue/test-utils';
import DirectoryConfig from '@shell/edit/provisioning.cattle.io.cluster/tabs/DirectoryConfig.vue';
import DirectoryConfig, { DATA_DIR_RADIO_OPTIONS, DEFAULT_SUBDIRS } from '@shell/edit/provisioning.cattle.io.cluster/tabs/DirectoryConfig.vue';
import { _EDIT, _CREATE } from '@shell/config/query-params';
import { clone } from '@shell/utils/object';

Expand All @@ -14,7 +15,8 @@ describe('component: DirectoryConfig', () => {
provisioning: '',
k8sDistro: '',
},
mode: _CREATE,
k8sVersion: 'k3s',
mode: _CREATE,
},
mocks: {
$store: {
Expand All @@ -33,65 +35,148 @@ describe('component: DirectoryConfig', () => {
);

const title = wrapper.find('h3');
const radioInput = wrapper.find('[data-testid="rke2-directory-config-radio-input"]');
const commonInput = wrapper.find('[data-testid="rke2-directory-config-common-data-dir"]');
const systemAgentInput = wrapper.find('[data-testid="rke2-directory-config-systemAgent-data-dir"]');
const provisioningInput = wrapper.find('[data-testid="rke2-directory-config-provisioning-data-dir"]');
const k8sDistroInput = wrapper.find('[data-testid="rke2-directory-config-k8sDistro-data-dir"]');

expect(title.exists()).toBe(true);
expect(radioInput.exists()).toBe(true);

expect(systemAgentInput.exists()).toBe(true);
expect(provisioningInput.exists()).toBe(true);
expect(k8sDistroInput.exists()).toBe(true);
// for the default config, the default radio input should be "default"
expect(wrapper.vm.dataConfigRadioValue).toBe(DATA_DIR_RADIO_OPTIONS.DEFAULT);

// since we have all of the vars empty, then the inputs should not be there
expect(commonInput.exists()).toBe(false);
expect(systemAgentInput.exists()).toBe(false);
expect(provisioningInput.exists()).toBe(false);
expect(k8sDistroInput.exists()).toBe(false);
});

it('updating each individual data dir should set the correct values on each data dir variable', async() => {
it('updating common base directory should set the correct values on each data dir variable', async() => {
const newMountOptions = clone(mountOptions);

wrapper = mount(
DirectoryConfig,
mountOptions
{
...newMountOptions,
// couldn't use setData, so this is the next best solution
data() {
return { dataConfigRadioValue: DATA_DIR_RADIO_OPTIONS.COMMON };
}
}
);

const inputPath = 'some-data-dir';
const commonInput = wrapper.find('[data-testid="rke2-directory-config-common-data-dir"]');

// update base dir value
expect(commonInput.exists()).toBe(true);
commonInput.setValue(inputPath);
await nextTick();

expect(wrapper.vm.value.systemAgent).toStrictEqual(`${ inputPath }/${ DEFAULT_SUBDIRS.AGENT }`);
expect(wrapper.vm.value.provisioning).toStrictEqual(`${ inputPath }/${ DEFAULT_SUBDIRS.PROVISIONING }`);
expect(wrapper.vm.value.k8sDistro).toStrictEqual(`${ inputPath }/${ DEFAULT_SUBDIRS.K8S_DISTRO_K3S }`);
});

it('updating each individual data dir should set the correct values on each data dir variable', async() => {
const newMountOptions = clone(mountOptions);

wrapper = mount(
DirectoryConfig,
{
...newMountOptions,
// couldn't use setData, so this is the next best solution
data() {
return { dataConfigRadioValue: DATA_DIR_RADIO_OPTIONS.CUSTOM };
}
}
);
const inputPath = 'some-data-dir';
const agentValue = `${ inputPath }/${ DEFAULT_SUBDIRS.AGENT }`;
const provisioningValue = `${ inputPath }/${ DEFAULT_SUBDIRS.PROVISIONING }`;
const k8sDistroValue = `${ inputPath }/${ DEFAULT_SUBDIRS.K8S_DISTRO_RKE2 }`;

const systemAgentInput = wrapper.find('[data-testid="rke2-directory-config-systemAgent-data-dir"]');
const provisioningInput = wrapper.find('[data-testid="rke2-directory-config-provisioning-data-dir"]');
const k8sDistroInput = wrapper.find('[data-testid="rke2-directory-config-k8sDistro-data-dir"]');

systemAgentInput.setValue(inputPath);
provisioningInput.setValue(inputPath);
k8sDistroInput.setValue(inputPath);
await wrapper.vm.$nextTick();
systemAgentInput.setValue(agentValue);
provisioningInput.setValue(provisioningValue);
k8sDistroInput.setValue(k8sDistroValue);
await nextTick();

expect(wrapper.vm.value.systemAgent).toStrictEqual(inputPath);
expect(wrapper.vm.value.provisioning).toStrictEqual(inputPath);
expect(wrapper.vm.value.k8sDistro).toStrictEqual(inputPath);
expect(wrapper.vm.value.systemAgent).toStrictEqual(agentValue);
expect(wrapper.vm.value.provisioning).toStrictEqual(provisioningValue);
expect(wrapper.vm.value.k8sDistro).toStrictEqual(k8sDistroValue);
});

it('on a mode different than _CREATE all visible inputs should be disabled (with different values)', () => {
it('should render the component with configuration being an empty object, without errors and radio be of value DATA_DIR_RADIO_OPTIONS.CUSTOM (edit scenario)', () => {
const newMountOptions = clone(mountOptions);
const inputPath1 = 'some-data-dir1';
const inputPath2 = 'some-data-dir2';
const inputPath3 = 'some-data-dir3';

newMountOptions.propsData.value.systemAgent = inputPath1;
newMountOptions.propsData.value.provisioning = inputPath2;
newMountOptions.propsData.value.k8sDistro = inputPath3;
newMountOptions.propsData.value = {};
newMountOptions.propsData.mode = _EDIT;

wrapper = mount(
DirectoryConfig,
newMountOptions
);

const title = wrapper.find('h3');
const radioInput = wrapper.find('[data-testid="rke2-directory-config-radio-input"]');
const systemAgentInput = wrapper.find('[data-testid="rke2-directory-config-systemAgent-data-dir"]');
const provisioningInput = wrapper.find('[data-testid="rke2-directory-config-provisioning-data-dir"]');
const k8sDistroInput = wrapper.find('[data-testid="rke2-directory-config-k8sDistro-data-dir"]');

expect(title.exists()).toBe(true);
expect(radioInput.isVisible()).toBe(false);

expect(wrapper.vm.dataConfigRadioValue).toBe(DATA_DIR_RADIO_OPTIONS.CUSTOM);

// since we have all of the vars empty, then the inputs should not be there
expect(systemAgentInput.exists()).toBe(true);
expect(provisioningInput.exists()).toBe(true);
expect(k8sDistroInput.exists()).toBe(true);

expect(systemAgentInput.attributes('disabled')).toBe('disabled');
expect(provisioningInput.attributes('disabled')).toBe('disabled');
expect(k8sDistroInput.attributes('disabled')).toBe('disabled');
expect(systemAgentInput.attributes().disabled).toBeDefined();
expect(provisioningInput.attributes().disabled).toBeDefined();
expect(k8sDistroInput.attributes().disabled).toBeDefined();
});

it('radio input should be set to DATA_DIR_RADIO_OPTIONS.CUSTOM with all data dir values existing and different (edit scenario)', () => {
const newMountOptions = clone(mountOptions);
const inputPath = 'some-data-dir';

newMountOptions.propsData.value.systemAgent = `${ inputPath }/${ DEFAULT_SUBDIRS.AGENT }`;
newMountOptions.propsData.value.provisioning = `${ inputPath }/${ DEFAULT_SUBDIRS.PROVISIONING }`;
newMountOptions.propsData.value.k8sDistro = `${ inputPath }/${ DEFAULT_SUBDIRS.K8S_DISTRO_K3S }`;
newMountOptions.propsData.mode = _EDIT;

wrapper = mount(
DirectoryConfig,
newMountOptions
);

expect(wrapper.vm.dataConfigRadioValue).toBe(DATA_DIR_RADIO_OPTIONS.CUSTOM);

const radioInput = wrapper.find('[data-testid="rke2-directory-config-radio-input"]');
const systemAgentInput = wrapper.find('[data-testid="rke2-directory-config-systemAgent-data-dir"]');
const provisioningInput = wrapper.find('[data-testid="rke2-directory-config-provisioning-data-dir"]');
const k8sDistroInput = wrapper.find('[data-testid="rke2-directory-config-k8sDistro-data-dir"]');

expect(radioInput.isVisible()).toBe(false);
expect(systemAgentInput.isVisible()).toBe(true);
expect(provisioningInput.isVisible()).toBe(true);
expect(k8sDistroInput.isVisible()).toBe(true);

expect(systemAgentInput.attributes().disabled).toBeDefined();
expect(provisioningInput.attributes().disabled).toBeDefined();
expect(k8sDistroInput.attributes().disabled).toBeDefined();

expect(wrapper.vm.value.systemAgent).toStrictEqual(`${ inputPath }/${ DEFAULT_SUBDIRS.AGENT }`);
expect(wrapper.vm.value.provisioning).toStrictEqual(`${ inputPath }/${ DEFAULT_SUBDIRS.PROVISIONING }`);
expect(wrapper.vm.value.k8sDistro).toStrictEqual(`${ inputPath }/${ DEFAULT_SUBDIRS.K8S_DISTRO_K3S }`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default {
<template v-if="haveArgInfo">
<DirectoryConfig
v-model="value.spec.rkeConfig.dataDirectories"
:k8s-version="value.spec.kubernetesVersion"
:mode="mode"
/>
<h3>{{ t('cluster.advanced.argInfo.title') }}</h3>
Expand Down
Loading

0 comments on commit 6a92a26

Please sign in to comment.