|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | + |
| 13 | +import mock |
| 14 | + |
| 15 | +from nova.tests.unit.virt.libvirt.volume import test_volume |
| 16 | +from nova.virt.libvirt.volume import lightos |
| 17 | + |
| 18 | +from os_brick import initiator |
| 19 | + |
| 20 | + |
| 21 | +class LibvirtLightVolumeDriverTestCase(test_volume.LibvirtVolumeBaseTestCase): |
| 22 | + |
| 23 | + @mock.patch('queue.Queue', return_value='queue') |
| 24 | + @mock.patch('nova.utils.get_root_helper') |
| 25 | + @mock.patch('os_brick.initiator.connector.InitiatorConnector.factory') |
| 26 | + def test_libvirt_lightos_driver(self, mock_factory, mock_helper, |
| 27 | + queue): |
| 28 | + self.flags(group='libvirt') |
| 29 | + mock_helper.return_value = 'sudo' |
| 30 | + lightos.LibvirtLightOSVolumeDriver(self.fake_host) |
| 31 | + mock_factory.assert_called_once_with( |
| 32 | + initiator.LIGHTOS, root_helper='sudo', |
| 33 | + device_scan_attempts=5) |
| 34 | + |
| 35 | + @mock.patch('os_brick.initiator.connector.InitiatorConnector.factory', |
| 36 | + new=mock.Mock(return_value=mock.Mock())) |
| 37 | + def test_libvirt_lightos_driver_connect(self): |
| 38 | + lightos_driver = lightos.LibvirtLightOSVolumeDriver( |
| 39 | + self.fake_host) |
| 40 | + config = {'server_ip': '127.0.0.1', 'server_port': 9898} |
| 41 | + disk_info = { |
| 42 | + 'id': '1234567', |
| 43 | + 'name': 'aLightVolume', |
| 44 | + 'conf': config} |
| 45 | + connection_info = {'data': disk_info} |
| 46 | + with mock.patch.object(lightos_driver.connector, |
| 47 | + 'connect_volume', |
| 48 | + return_value={'path': '/dev/dms1234567'}): |
| 49 | + lightos_driver.connect_volume(connection_info, None) |
| 50 | + (lightos_driver.connector.connect_volume. |
| 51 | + assert_called_once_with( |
| 52 | + connection_info['data'])) |
| 53 | + self.assertEqual('/dev/dms1234567', |
| 54 | + connection_info['data']['device_path']) |
| 55 | + |
| 56 | + @mock.patch('os_brick.initiator.connector.InitiatorConnector.factory', |
| 57 | + new=mock.Mock(return_value=mock.Mock())) |
| 58 | + def test_libvirt_lightos_driver_disconnect(self): |
| 59 | + lightos_driver = lightos.LibvirtLightOSVolumeDriver(self.connr) |
| 60 | + disk_info = { |
| 61 | + 'path': '/dev/dms1234567', 'name': 'aLightosVolume', |
| 62 | + 'type': 'raw', 'dev': 'vda1', 'bus': 'pci0', |
| 63 | + 'device_path': '/dev/dms123456'} |
| 64 | + connection_info = {'data': disk_info} |
| 65 | + lightos_driver.disconnect_volume(connection_info, None) |
| 66 | + lightos_driver.connector.disconnect_volume.assert_called_once_with( |
| 67 | + disk_info, None) |
| 68 | + |
| 69 | + @mock.patch('os_brick.initiator.connector.InitiatorConnector.factory', |
| 70 | + new=mock.Mock(return_value=mock.Mock())) |
| 71 | + def test_libvirt_lightos_driver_get_config(self): |
| 72 | + lightos_driver = lightos.LibvirtLightOSVolumeDriver(self.fake_host) |
| 73 | + device_path = '/dev/fake-dev' |
| 74 | + connection_info = {'data': {'device_path': device_path}} |
| 75 | + |
| 76 | + conf = lightos_driver.get_config(connection_info, self.disk_info) |
| 77 | + tree = conf.format_dom() |
| 78 | + |
| 79 | + self.assertEqual('block', tree.get('type')) |
| 80 | + self.assertEqual(device_path, tree.find('./source').get('dev')) |
| 81 | + self.assertEqual('raw', tree.find('./driver').get('type')) |
0 commit comments