Use labels for virtual media dev in agent ramdisk

This commit changes agent deploy ramdisk to find out
the virtual media device by using labels instead of
looking at the model of block device.  This helps in
finding out the device irrespective of the hardware.

Corresponding Ironic change is
If5b78d9af7048f2631d050ee5ce01ab7a67e2354.

Closes-Bug: 1429340
Change-Id: Ib6cc226dc4fb341d913f707737493c31a3f77152
This commit is contained in:
Ramakrishnan G 2015-03-12 04:14:11 +00:00
parent 1fc7136235
commit d0d319d65f
2 changed files with 60 additions and 14 deletions

View File

@ -196,44 +196,78 @@ class GetAgentParamsTestCase(test_base.BaseTestCase):
vmedia_device_returned = utils._get_vmedia_device()
self.assertEqual('sdc', vmedia_device_returned)
@mock.patch.object(utils, '_get_vmedia_device')
@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(self, execute_mock, mkdir_mock,
read_params_mock, get_device_mock):
def test__get_vmedia_params_by_label(self, execute_mock, mkdir_mock,
exists_mock, read_params_mock):
vmedia_mount_point = "/vmedia_mnt"
null_output = ["", ""]
expected_params = {'a': 'b'}
read_params_mock.return_value = expected_params
exists_mock.return_value = True
execute_mock.side_effect = [null_output, null_output]
returned_params = utils._get_vmedia_params()
mkdir_mock.assert_called_once_with(vmedia_mount_point)
execute_mock.assert_any_call('mount', "/dev/disk/by-label/ir-vfd-dev",
vmedia_mount_point)
read_params_mock.assert_called_once_with("/vmedia_mnt/parameters.txt")
exists_mock.assert_called_once_with("/dev/disk/by-label/ir-vfd-dev")
execute_mock.assert_any_call('umount', vmedia_mount_point)
self.assertEqual(expected_params, returned_params)
@mock.patch.object(utils, '_get_vmedia_device')
@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_device(self, execute_mock, mkdir_mock,
exists_mock, read_params_mock,
get_device_mock):
vmedia_mount_point = "/vmedia_mnt"
null_output = ["", ""]
expected_params = {'a': 'b'}
read_params_mock.return_value = expected_params
exists_mock.return_value = False
execute_mock.side_effect = [null_output, null_output]
get_device_mock.return_value = "sda"
returned_params = utils._get_vmedia_params()
mkdir_mock.assert_called_once_with(vmedia_mount_point)
execute_mock.assert_any_call('mount', "/dev/sda", vmedia_mount_point)
execute_mock.assert_any_call('mount', "/dev/sda",
vmedia_mount_point)
read_params_mock.assert_called_once_with("/vmedia_mnt/parameters.txt")
execute_mock.assert_any_call('umount', vmedia_mount_point)
self.assertEqual(expected_params, returned_params)
@mock.patch.object(utils, '_get_vmedia_device')
def test__get_vmedia_params_cannot_find_dev(self, get_device_mock):
@mock.patch.object(os.path, 'exists')
def test__get_vmedia_params_cannot_find_dev(self, exists_mock,
get_device_mock):
get_device_mock.return_value = None
exists_mock.return_value = False
self.assertRaises(errors.VirtualMediaBootError,
utils._get_vmedia_params)
@mock.patch.object(utils, '_get_vmedia_device')
@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_mount_fails(self, execute_mock,
mkdir_mock, read_params_mock,
mkdir_mock, exists_mock,
read_params_mock,
get_device_mock):
vmedia_mount_point = "/vmedia_mnt"
expected_params = {'a': 'b'}
exists_mock.return_value = True
read_params_mock.return_value = expected_params
get_device_mock.return_value = "sda"
@ -243,18 +277,22 @@ class GetAgentParamsTestCase(test_base.BaseTestCase):
utils._get_vmedia_params)
mkdir_mock.assert_called_once_with(vmedia_mount_point)
execute_mock.assert_any_call('mount', "/dev/sda", vmedia_mount_point)
execute_mock.assert_any_call('mount', "/dev/disk/by-label/ir-vfd-dev",
vmedia_mount_point)
@mock.patch.object(utils, '_get_vmedia_device')
@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_umount_fails(self, execute_mock, mkdir_mock,
read_params_mock, get_device_mock):
exists_mock, read_params_mock,
get_device_mock):
vmedia_mount_point = "/vmedia_mnt"
null_output = ["", ""]
expected_params = {'a': 'b'}
exists_mock.return_value = True
read_params_mock.return_value = expected_params
get_device_mock.return_value = "sda"
@ -264,7 +302,8 @@ class GetAgentParamsTestCase(test_base.BaseTestCase):
returned_params = utils._get_vmedia_params()
mkdir_mock.assert_called_once_with(vmedia_mount_point)
execute_mock.assert_any_call('mount', "/dev/sda", vmedia_mount_point)
execute_mock.assert_any_call('mount', "/dev/disk/by-label/ir-vfd-dev",
vmedia_mount_point)
read_params_mock.assert_called_once_with("/vmedia_mnt/parameters.txt")
execute_mock.assert_any_call('umount', vmedia_mount_point)
self.assertEqual(expected_params, returned_params)

View File

@ -92,12 +92,19 @@ def _get_vmedia_params():
vmedia_mount_point = "/vmedia_mnt"
parameters_file = "parameters.txt"
vmedia_device = _get_vmedia_device()
if not vmedia_device:
msg = "Unable to find virtual media device"
raise errors.VirtualMediaBootError(msg)
vmedia_device_file = "/dev/disk/by-label/ir-vfd-dev"
if not os.path.exists(vmedia_device_file):
# TODO(rameshg87): This block of code is there only for compatibility
# reasons (so that newer agent can work with older Ironic). Remove
# this after Liberty release.
vmedia_device = _get_vmedia_device()
if not vmedia_device:
msg = "Unable to find virtual media device"
raise errors.VirtualMediaBootError(msg)
vmedia_device_file = os.path.join("/dev", vmedia_device)
vmedia_device_file = os.path.join("/dev", vmedia_device)
os.mkdir(vmedia_mount_point)
try: