Fix vfd mount for capitalized device name

This patch enables virtual media deploy even if the expected virtual
floppy device name "/dev/disk/by-label/ir-vfd-dev" is capitalized to
"/dev/disk/by-label/IR-VFD-DEV".
This change is necessary because some bare metal hardware such as
FUJITSU RX1330 series create the capitalized virtual floppy device
name.

Change-Id: I436b3f9524a83814e082f8dd421df3e53b33f792
Closes-Bug: #1541167
This commit is contained in:
Naohiro Tamura 2016-02-03 11:23:49 +09:00
parent 33b482aa4d
commit 73f81f2982
3 changed files with 49 additions and 7 deletions

View File

@ -223,15 +223,15 @@ class GetAgentParamsTestCase(test_base.BaseTestCase):
@mock.patch.object(os.path, 'exists')
@mock.patch.object(os, 'mkdir')
@mock.patch.object(utils, 'execute')
def test__get_vmedia_params_by_label(self, execute_mock, mkdir_mock,
exists_mock, read_params_mock,
def test__get_vmedia_params_by_label_lower_case(
self, execute_mock, mkdir_mock, exists_mock, read_params_mock,
mkdtemp_mock, rmtree_mock):
mkdtemp_mock.return_value = "/tempdir"
null_output = ["", ""]
expected_params = {'a': 'b'}
read_params_mock.return_value = expected_params
exists_mock.return_value = True
exists_mock.side_effect = [True, False]
execute_mock.side_effect = [null_output, null_output]
returned_params = utils._get_vmedia_params()
@ -245,6 +245,36 @@ class GetAgentParamsTestCase(test_base.BaseTestCase):
mkdtemp_mock.assert_called_once_with()
rmtree_mock.assert_called_once_with("/tempdir")
@mock.patch.object(shutil, 'rmtree', autospec=True)
@mock.patch.object(tempfile, 'mkdtemp', autospec=True)
@mock.patch.object(utils, '_read_params_from_file')
@mock.patch.object(os.path, 'exists')
@mock.patch.object(os, 'mkdir')
@mock.patch.object(utils, 'execute')
def test__get_vmedia_params_by_label_upper_case(
self, execute_mock, mkdir_mock, exists_mock, read_params_mock,
mkdtemp_mock, rmtree_mock):
mkdtemp_mock.return_value = "/tempdir"
null_output = ["", ""]
expected_params = {'a': 'b'}
read_params_mock.return_value = expected_params
exists_mock.side_effect = [False, True]
execute_mock.side_effect = [null_output, null_output]
returned_params = utils._get_vmedia_params()
execute_mock.assert_any_call('mount', "/dev/disk/by-label/IR-VFD-DEV",
"/tempdir")
read_params_mock.assert_called_once_with("/tempdir/parameters.txt")
exists_mock.assert_has_calls(
[mock.call("/dev/disk/by-label/ir-vfd-dev"),
mock.call("/dev/disk/by-label/IR-VFD-DEV")])
execute_mock.assert_any_call('umount', "/tempdir")
self.assertEqual(expected_params, returned_params)
mkdtemp_mock.assert_called_once_with()
rmtree_mock.assert_called_once_with("/tempdir")
@mock.patch.object(shutil, 'rmtree', autospec=True)
@mock.patch.object(tempfile, 'mkdtemp', autospec=True)
@mock.patch.object(utils, '_get_vmedia_device')
@ -261,12 +291,15 @@ class GetAgentParamsTestCase(test_base.BaseTestCase):
null_output = ["", ""]
expected_params = {'a': 'b'}
read_params_mock.return_value = expected_params
exists_mock.return_value = False
exists_mock.side_effect = [False, False]
execute_mock.side_effect = [null_output, null_output]
get_device_mock.return_value = "sda"
returned_params = utils._get_vmedia_params()
exists_mock.assert_has_calls(
[mock.call("/dev/disk/by-label/ir-vfd-dev"),
mock.call("/dev/disk/by-label/IR-VFD-DEV")])
execute_mock.assert_any_call('mount', "/dev/sda",
"/tempdir")
read_params_mock.assert_called_once_with("/tempdir/parameters.txt")

View File

@ -132,8 +132,13 @@ def _get_vmedia_params():
"""
parameters_file = "parameters.txt"
vmedia_device_file = "/dev/disk/by-label/ir-vfd-dev"
if not os.path.exists(vmedia_device_file):
vmedia_device_file_lower_case = "/dev/disk/by-label/ir-vfd-dev"
vmedia_device_file_upper_case = "/dev/disk/by-label/IR-VFD-DEV"
if os.path.exists(vmedia_device_file_lower_case):
vmedia_device_file = vmedia_device_file_lower_case
elif os.path.exists(vmedia_device_file_upper_case):
vmedia_device_file = vmedia_device_file_upper_case
else:
# TODO(rameshg87): This block of code is there only for compatibility
# reasons (so that newer agent can work with older Ironic). Remove

View File

@ -0,0 +1,4 @@
fixes:
- This enables virtual media deploy even if virtual floppy device
name is capitalized to "/dev/disk/by-label/IR-VFD-DEV". see
https://bugs.launchpad.net/ironic/+bug/1541167 for details.