Skip to content

Commit

Permalink
ui/volumes: Fix the defaults path start from the input path
Browse files Browse the repository at this point in the history
The recommend default device path should start from the global one

Refs: #2964
  • Loading branch information
ChengYanJin committed Dec 20, 2020
1 parent 2083cee commit 5cd9a87
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 1 addition & 4 deletions ui/src/containers/CreateVolume.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,7 @@ const CreateVolume = (props) => {
}
} else if (fieldname === 'path') {
if (values.path.trim() !== '' && touched.path) {
setFieldValue(
name,
linuxDrivesNamingIncrement(values.path, index + 1),
);
setFieldValue(name, linuxDrivesNamingIncrement(values.path, index));
}
}
}, [
Expand Down
2 changes: 2 additions & 0 deletions ui/src/services/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ export const linuxDrivesNamingIncrement = (devicePath, increment) => {
}
}
return devicePath;
} else if (devicePath.match(/^\/dev\/vd[a-z]/) && increment === 0) {
return devicePath;
} else {
return '';
}
Expand Down
9 changes: 7 additions & 2 deletions ui/src/services/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ it('should return /dev/vdaa after /dev/vdz', () => {
expect(result).toEqual('/dev/vdaa');
});

it('should return the original path if the increment is 0', () => {
const result = linuxDrivesNamingIncrement('/dev/vdc', 0);
expect(result).toEqual('/dev/vdc');
});

it('should return an empty string if the driver is not virtualization-aware disk driver', () => {
const result = linuxDrivesNamingIncrement('/dev/sda', 2);
expect(result).toEqual('');
Expand All @@ -295,7 +300,7 @@ it('should return an empty string if the device path is empty', () => {
expect(result).toEqual('');
});

it('should return an empty string if the increment is smaller than 1', () => {
const result = linuxDrivesNamingIncrement('/dev/vda', 0);
it('should return an empty string if the increment is smaller than 0', () => {
const result = linuxDrivesNamingIncrement('/dev/vda', -1);
expect(result).toEqual('');
});

0 comments on commit 5cd9a87

Please sign in to comment.