Merge "Change method signature for mdcreate from md utils"
This commit is contained in:
commit
2a65f11c10
@ -233,7 +233,7 @@ class Manager(object):
|
||||
|
||||
# creating meta disks
|
||||
for md in self.driver.partition_scheme.mds:
|
||||
mu.mdcreate(md.name, md.level, *md.devices)
|
||||
mu.mdcreate(md.name, md.level, md.devices)
|
||||
|
||||
# creating physical volumes
|
||||
for pv in self.driver.partition_scheme.pvs:
|
||||
|
@ -268,6 +268,48 @@ class TestManager(unittest2.TestCase):
|
||||
mock.call('swap', '', '', '/dev/mapper/os-swap')]
|
||||
self.assertEqual(mock_fu_mf_expected_calls, mock_fu_mf.call_args_list)
|
||||
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch.object(os, 'symlink')
|
||||
@mock.patch.object(os, 'remove')
|
||||
@mock.patch.object(os, 'path')
|
||||
@mock.patch.object(os, 'listdir')
|
||||
@mock.patch.object(utils, 'execute')
|
||||
@mock.patch.object(mu, 'mdclean_all')
|
||||
@mock.patch.object(lu, 'lvremove_all')
|
||||
@mock.patch.object(lu, 'vgremove_all')
|
||||
@mock.patch.object(lu, 'pvremove_all')
|
||||
@mock.patch.object(fu, 'make_fs')
|
||||
@mock.patch.object(lu, 'lvcreate')
|
||||
@mock.patch.object(lu, 'vgcreate')
|
||||
@mock.patch.object(lu, 'pvcreate')
|
||||
@mock.patch.object(mu, 'mdcreate')
|
||||
@mock.patch.object(pu, 'set_gpt_type')
|
||||
@mock.patch.object(pu, 'set_partition_flag')
|
||||
@mock.patch.object(pu, 'make_partition')
|
||||
@mock.patch.object(pu, 'make_label')
|
||||
@mock.patch.object(hu, 'list_block_devices')
|
||||
def test_do_partitioning_md(self, mock_hu_lbd, mock_pu_ml, mock_pu_mp,
|
||||
mock_pu_spf, mock_pu_sgt, mock_mu_m, mock_lu_p,
|
||||
mock_lu_v, mock_lu_l, mock_fu_mf, mock_pvr,
|
||||
mock_vgr, mock_lvr, mock_mdr, mock_exec,
|
||||
mock_os_ld, mock_os_p, mock_os_r, mock_os_s,
|
||||
mock_open):
|
||||
mock_os_ld.return_value = ['not_a_rule', 'fake.rules']
|
||||
mock_os_p.exists.return_value = True
|
||||
mock_hu_lbd.return_value = test_nailgun.LIST_BLOCK_DEVICES_SAMPLE
|
||||
self.mgr.driver.partition_scheme.mds = [
|
||||
objects.MD('fake_md1', 'mirror', devices=['/dev/sda1',
|
||||
'/dev/sdb1']),
|
||||
objects.MD('fake_md2', 'mirror', devices=['/dev/sdb3',
|
||||
'/dev/sdc1']),
|
||||
]
|
||||
self.mgr.do_partitioning()
|
||||
self.assertEqual([mock.call('fake_md1', 'mirror',
|
||||
['/dev/sda1', '/dev/sdb1']),
|
||||
mock.call('fake_md2', 'mirror',
|
||||
['/dev/sdb3', '/dev/sdc1'])],
|
||||
mock_mu_m.call_args_list)
|
||||
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch.object(os, 'symlink')
|
||||
@mock.patch.object(os, 'remove')
|
||||
|
@ -153,7 +153,7 @@ localhost.localdomain)
|
||||
mock_bdevs.return_value = [{'device': '/dev/fake1'},
|
||||
{'device': '/dev/fake2'}]
|
||||
|
||||
mu.mdcreate('/dev/md0', 'mirror', '/dev/fake1', '/dev/fake2')
|
||||
mu.mdcreate('/dev/md0', 'mirror', ['/dev/fake1', '/dev/fake2'])
|
||||
mock_mdclean_expected_calls = [mock.call('/dev/fake1'),
|
||||
mock.call('/dev/fake2')]
|
||||
self.assertEqual(mock_mdclean_expected_calls,
|
||||
@ -171,7 +171,7 @@ localhost.localdomain)
|
||||
mock_mddisplay.return_value = [{'name': '/dev/md0'}]
|
||||
self.assertRaises(
|
||||
errors.MDAlreadyExistsError, mu.mdcreate,
|
||||
'/dev/md0', 'mirror', '/dev/fake')
|
||||
'/dev/md0', 'mirror', ['/dev/fake'])
|
||||
|
||||
@mock.patch.object(mu, 'mddisplay')
|
||||
def test_mdcreate_unsupported_level(self, mock_mddisplay):
|
||||
@ -180,7 +180,7 @@ localhost.localdomain)
|
||||
mock_mddisplay.return_value = [{'name': '/dev/md10'}]
|
||||
self.assertRaises(
|
||||
errors.MDWrongSpecError, mu.mdcreate,
|
||||
'/dev/md0', 'badlevel', '/dev/fake')
|
||||
'/dev/md0', 'badlevel', ['/dev/fake'])
|
||||
|
||||
@mock.patch.object(hu, 'list_block_devices')
|
||||
@mock.patch.object(mu, 'mddisplay')
|
||||
@ -192,7 +192,7 @@ localhost.localdomain)
|
||||
{'device': '/dev/fake10'}]
|
||||
self.assertRaises(
|
||||
errors.MDNotFoundError, mu.mdcreate,
|
||||
'/dev/md0', 'mirror', '/dev/fake1', '/dev/fake2')
|
||||
'/dev/md0', 'mirror', ['/dev/fake1', '/dev/fake2'])
|
||||
|
||||
@mock.patch.object(hu, 'list_block_devices')
|
||||
@mock.patch.object(mu, 'mddisplay')
|
||||
@ -205,7 +205,7 @@ localhost.localdomain)
|
||||
{'device': '/dev/fake2'}]
|
||||
self.assertRaises(
|
||||
errors.MDDeviceDuplicationError, mu.mdcreate,
|
||||
'/dev/md0', 'mirror', '/dev/fake1', '/dev/fake2')
|
||||
'/dev/md0', 'mirror', ['/dev/fake1', '/dev/fake2'])
|
||||
|
||||
@mock.patch.object(utils, 'execute')
|
||||
@mock.patch.object(mu, 'mdclean')
|
||||
@ -217,7 +217,7 @@ localhost.localdomain)
|
||||
mock_mddisplay.return_value = []
|
||||
mock_bdevs.return_value = [{'device': '/dev/fake1'},
|
||||
{'device': '/dev/fake2'}]
|
||||
mu.mdcreate('/dev/md0', 'mirror', '/dev/fake1', '/dev/fake2')
|
||||
mu.mdcreate('/dev/md0', 'mirror', ['/dev/fake1', '/dev/fake2'])
|
||||
expected_calls = [mock.call('/dev/fake1'), mock.call('/dev/fake2')]
|
||||
self.assertEqual(mock_mdclean.call_args_list, expected_calls)
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import itertools
|
||||
import re
|
||||
|
||||
from fuel_agent import errors
|
||||
@ -75,7 +76,7 @@ def mddisplay(names=None):
|
||||
return mds
|
||||
|
||||
|
||||
def mdcreate(mdname, level, device, *args):
|
||||
def mdcreate(mdname, level, devices):
|
||||
mds = mddisplay()
|
||||
|
||||
# check if md device already exists
|
||||
@ -90,8 +91,6 @@ def mdcreate(mdname, level, device, *args):
|
||||
'Error while creating md device: '
|
||||
'level must be one of: %s' % ', '.join(supported_levels))
|
||||
|
||||
devices = [device] + list(args)
|
||||
|
||||
# check if all necessary devices exist
|
||||
if not set(devices).issubset(
|
||||
set([bd['device'] for bd in hu.list_block_devices(disks=False)])):
|
||||
@ -100,8 +99,7 @@ def mdcreate(mdname, level, device, *args):
|
||||
|
||||
# check if devices are not parts of some md array
|
||||
if set(devices) & \
|
||||
set(reduce(lambda x, y: x + y,
|
||||
[md.get('devices', []) for md in mds], [])):
|
||||
set(itertools.chain(*[md.get('devices', []) for md in mds])):
|
||||
raise errors.MDDeviceDuplicationError(
|
||||
'Error while creating md: at least one of devices is '
|
||||
'already in belongs to some md')
|
||||
|
Loading…
x
Reference in New Issue
Block a user