Merge "Remove mox from nova/tests/unit/test_configdrive2.py"

This commit is contained in:
Jenkins 2017-03-07 18:55:47 +00:00 committed by Gerrit Code Review
commit 3a0baffaf5
1 changed files with 27 additions and 27 deletions

View File

@ -18,7 +18,6 @@ import os
import tempfile
import mock
from mox3 import mox
from oslo_config import cfg
from oslo_utils import fileutils
@ -39,53 +38,54 @@ class FakeInstanceMD(object):
class ConfigDriveTestCase(test.NoDBTestCase):
def test_create_configdrive_iso(self):
@mock.patch.object(utils, 'execute', return_value=None)
def test_create_configdrive_iso(self, mock_execute):
CONF.set_override('config_drive_format', 'iso9660')
imagefile = None
try:
self.mox.StubOutWithMock(utils, 'execute')
utils.execute('genisoimage', '-o', mox.IgnoreArg(), '-ldots',
'-allow-lowercase', '-allow-multidot', '-l',
'-publisher', mox.IgnoreArg(), '-quiet', '-J', '-r',
'-V', 'config-2', mox.IgnoreArg(), attempts=1,
run_as_root=False).AndReturn(None)
self.mox.ReplayAll()
with configdrive.ConfigDriveBuilder(FakeInstanceMD()) as c:
(fd, imagefile) = tempfile.mkstemp(prefix='cd_iso_')
os.close(fd)
c.make_drive(imagefile)
mock_execute.assert_called_once_with('genisoimage', '-o',
mock.ANY,
'-ldots', '-allow-lowercase',
'-allow-multidot', '-l',
'-publisher',
mock.ANY,
'-quiet', '-J', '-r',
'-V', 'config-2',
mock.ANY,
attempts=1,
run_as_root=False)
finally:
if imagefile:
fileutils.delete_if_exists(imagefile)
def test_create_configdrive_vfat(self):
@mock.patch.object(utils, 'mkfs', return_value=None)
@mock.patch.object(utils, 'execute', return_value=None)
@mock.patch.object(utils, 'trycmd', return_value=(None, None))
def test_create_configdrive_vfat(self, mock_trycmd,
mock_execute, mock_mkfs):
CONF.set_override('config_drive_format', 'vfat')
imagefile = None
try:
self.mox.StubOutWithMock(utils, 'mkfs')
self.mox.StubOutWithMock(utils, 'execute')
self.mox.StubOutWithMock(utils, 'trycmd')
utils.mkfs('vfat', mox.IgnoreArg(),
label='config-2').AndReturn(None)
utils.trycmd('mount', '-o', mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg(),
run_as_root=True).AndReturn((None, None))
utils.execute('umount', mox.IgnoreArg(),
run_as_root=True).AndReturn(None)
self.mox.ReplayAll()
with configdrive.ConfigDriveBuilder(FakeInstanceMD()) as c:
(fd, imagefile) = tempfile.mkstemp(prefix='cd_vfat_')
os.close(fd)
c.make_drive(imagefile)
mock_mkfs.assert_called_once_with('vfat', mock.ANY,
label='config-2')
mock_trycmd.assert_called_once_with('mount', '-o',
mock.ANY,
mock.ANY,
mock.ANY,
run_as_root=True)
mock_execute.assert_called_once_with('umount', mock.ANY,
run_as_root=True)
# NOTE(mikal): we can't check for a VFAT output here because the
# filesystem creation stuff has been mocked out because it
# requires root permissions