Use pypowervm fixture for local disk UT
Change localdisk.py to use pypowervm UT fixture. Change-Id: I2b1b9f34a013f93b2c0808c1713d34552943b163
This commit is contained in:
parent
6137c1f574
commit
3b33c52d50
|
@ -25,6 +25,7 @@ from pypowervm.tests.wrappers.util import pvmhttp
|
|||
from pypowervm.wrappers import virtual_io_server as vios_w
|
||||
|
||||
from nova_powervm.tests.virt import powervm
|
||||
from nova_powervm.tests.virt.powervm import fixtures as fx
|
||||
from nova_powervm.virt.powervm import localdisk as ld
|
||||
|
||||
|
||||
|
@ -48,6 +49,8 @@ class TestLocalDisk(test.TestCase):
|
|||
|
||||
self.vg_to_vio = resp(VOL_GRP_WITH_VIOS)
|
||||
self.vio_to_vg = resp(VIOS_WITH_VOL_GRP)
|
||||
self.pypvm = self.useFixture(fx.PyPowerVM())
|
||||
self.apt = self.pypvm.apt
|
||||
|
||||
def get_ls(self, adpt):
|
||||
local = ld.LocalStorage({'adapter': adpt,
|
||||
|
@ -56,7 +59,6 @@ class TestLocalDisk(test.TestCase):
|
|||
'vios_uuid': 'vios_uuid'})
|
||||
return local
|
||||
|
||||
@mock.patch('pypowervm.adapter.Adapter')
|
||||
@mock.patch('pypowervm.jobs.upload_lv.upload_new_vdisk')
|
||||
@mock.patch('nova_powervm.virt.powervm.localdisk.LocalStorage.'
|
||||
'_get_vg_uuid')
|
||||
|
@ -66,13 +68,12 @@ class TestLocalDisk(test.TestCase):
|
|||
@mock.patch('nova.image.API')
|
||||
def test_create_volume_from_image(self, mock_img_api, mock_file_adpt,
|
||||
mock_get_dname, mock_vg_uuid,
|
||||
mock_upload_lv, mock_adpt):
|
||||
mock_upload_lv):
|
||||
mock_img = {'id': 'fake_id', 'size': 50}
|
||||
mock_get_dname.return_value = 'fake_vol'
|
||||
|
||||
vol_name = self.get_ls(mock_adpt).create_volume_from_image(None, None,
|
||||
mock_img,
|
||||
20)
|
||||
vol_name = self.get_ls(self.apt).create_volume_from_image(
|
||||
None, None, mock_img, 20)
|
||||
mock_upload_lv.assert_called_with(mock.ANY, mock.ANY, mock.ANY,
|
||||
mock.ANY, 'fake_vol', 50,
|
||||
d_size=21474836480L)
|
||||
|
@ -83,8 +84,7 @@ class TestLocalDisk(test.TestCase):
|
|||
'_get_vg_uuid')
|
||||
@mock.patch('nova_powervm.virt.powervm.localdisk.LocalStorage.'
|
||||
'_get_vg')
|
||||
@mock.patch('pypowervm.adapter.Adapter')
|
||||
def test_capacity(self, mock_adpt, mock_get_vg, mock_vg_uuid, mock_vg):
|
||||
def test_capacity(self, mock_get_vg, mock_vg_uuid, mock_vg):
|
||||
"""Tests the capacity methods."""
|
||||
|
||||
# Set up the mock data. This will simulate our vg wrapper
|
||||
|
@ -93,15 +93,14 @@ class TestLocalDisk(test.TestCase):
|
|||
type(wrap).available_size = mock.PropertyMock(return_value='2048')
|
||||
|
||||
mock_vg.load_from_response.return_value = wrap
|
||||
local = self.get_ls(mock_adpt)
|
||||
local = self.get_ls(self.apt)
|
||||
|
||||
self.assertEqual(5120.0, local.capacity)
|
||||
self.assertEqual(3072.0, local.capacity_used)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.localdisk.LocalStorage.'
|
||||
'_get_vg_uuid')
|
||||
@mock.patch('pypowervm.adapter.Adapter')
|
||||
def test_disconnect_image_volume(self, mock_adpt, mock_vg_uuid):
|
||||
def test_disconnect_image_volume(self, mock_vg_uuid):
|
||||
"""Tests the disconnect_image_volume method."""
|
||||
|
||||
# Set up the mock data.
|
||||
|
@ -109,47 +108,44 @@ class TestLocalDisk(test.TestCase):
|
|||
type(resp).body = mock.PropertyMock(return_value='2')
|
||||
mock_vg_uuid.return_value = 'd5065c2c-ac43-3fa6-af32-ea84a3960291'
|
||||
|
||||
mock_adpt.read.side_effect = [self.vio_to_vg, resp]
|
||||
self.apt.read.side_effect = [self.vio_to_vg, resp]
|
||||
|
||||
def validate_update(*kargs, **kwargs):
|
||||
# Make sure that the mappings are only 1 (the remaining vopt)
|
||||
self.assertEqual([vios_w.XAG_VIOS_SCSI_MAPPING], kwargs['xag'])
|
||||
vio = vios_w.VirtualIOServer(adpt.Entry({}, kargs[0]))
|
||||
self.assertEqual(1, len(vio.scsi_mappings))
|
||||
mock_adpt.update.side_effect = validate_update
|
||||
self.apt.update.side_effect = validate_update
|
||||
|
||||
local = self.get_ls(mock_adpt)
|
||||
local = self.get_ls(self.apt)
|
||||
local.disconnect_image_volume(mock.MagicMock(), mock.MagicMock(), '2')
|
||||
self.assertEqual(1, mock_adpt.update.call_count)
|
||||
self.assertEqual(1, self.apt.update.call_count)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.localdisk.LocalStorage.'
|
||||
'_get_vg_uuid')
|
||||
@mock.patch('pypowervm.adapter.Adapter')
|
||||
def test_delete_volumes(self, mock_adpt, mock_vg_uuid):
|
||||
def test_delete_volumes(self, mock_vg_uuid):
|
||||
# Mocks
|
||||
mock_adpt.side_effect = [self.vg_to_vio]
|
||||
self.apt.side_effect = [self.vg_to_vio]
|
||||
|
||||
# Find from the data the vDisk scsi mapping
|
||||
scsi_mapping = mock.MagicMock()
|
||||
scsi_mapping.udid = '0300025d4a00007a000000014b36d9deaf.1'
|
||||
|
||||
# Invoke the call
|
||||
local = self.get_ls(mock_adpt)
|
||||
local = self.get_ls(self.apt)
|
||||
local.delete_volumes(mock.MagicMock(), mock.MagicMock(),
|
||||
[scsi_mapping])
|
||||
|
||||
# Validate the call
|
||||
self.assertEqual(1, mock_adpt.update.call_count)
|
||||
self.assertEqual(1, self.apt.update.call_count)
|
||||
|
||||
@mock.patch('pypowervm.wrappers.storage.VolumeGroup')
|
||||
@mock.patch('nova_powervm.virt.powervm.localdisk.LocalStorage.'
|
||||
'_get_vg_uuid')
|
||||
@mock.patch('nova_powervm.virt.powervm.localdisk.LocalStorage.'
|
||||
'_get_disk_name')
|
||||
@mock.patch('pypowervm.adapter.Adapter')
|
||||
def test_extend_volume(self, mock_adpt, mock_dsk_name,
|
||||
mock_vg_uuid, mock_vg):
|
||||
local = self.get_ls(mock_adpt)
|
||||
def test_extend_volume(self, mock_dsk_name, mock_vg_uuid, mock_vg):
|
||||
local = self.get_ls(self.apt)
|
||||
|
||||
inst = objects.Instance(**powervm.TEST_INSTANCE)
|
||||
|
||||
|
@ -168,5 +164,5 @@ class TestLocalDisk(test.TestCase):
|
|||
local.extend_volume('context', inst, dict(type='boot'), 1000)
|
||||
|
||||
# Validate the call
|
||||
self.assertEqual(1, mock_adpt.update.call_count)
|
||||
self.assertEqual(1, self.apt.update.call_count)
|
||||
self.assertEqual(vdisk.capacity, 1000)
|
||||
|
|
Loading…
Reference in New Issue