2015-04-23 12:43:27 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Rupesh Tare <rupesht@saltstack.com>`
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python Libs
|
2018-01-26 14:23:44 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2017-03-22 16:42:17 +00:00
|
|
|
import os
|
2015-04-23 12:43:27 +00:00
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-03-22 16:42:17 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import TestCase, skipIf
|
|
|
|
from tests.support.mock import (
|
2015-04-23 12:43:27 +00:00
|
|
|
MagicMock,
|
|
|
|
patch,
|
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.qemu_img as qemu_img
|
2015-04-23 12:43:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-03-22 16:42:17 +00:00
|
|
|
class QemuimgTestCase(TestCase, LoaderModuleMockMixin):
|
2015-04-23 12:43:27 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.modules.qemu_img
|
|
|
|
'''
|
2017-03-22 16:42:17 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {qemu_img: {}}
|
|
|
|
|
2015-04-23 12:43:27 +00:00
|
|
|
def test_make_image(self):
|
|
|
|
'''
|
|
|
|
Test for create a blank virtual machine image file
|
|
|
|
of the specified size in megabytes
|
|
|
|
'''
|
|
|
|
with patch.object(os.path, 'isabs',
|
|
|
|
MagicMock(side_effect=[False, True, True, True])):
|
|
|
|
self.assertEqual(qemu_img.make_image('location', 'size', 'fmt'), '')
|
|
|
|
|
|
|
|
with patch.object(os.path, 'isdir',
|
|
|
|
MagicMock(side_effect=[False, True, True])):
|
2018-01-26 14:25:49 +00:00
|
|
|
self.assertEqual(qemu_img.make_image('location', 'size', 'fmt'), '')
|
2015-04-23 12:43:27 +00:00
|
|
|
|
|
|
|
with patch.dict(qemu_img.__salt__,
|
2018-01-26 14:25:49 +00:00
|
|
|
{'cmd.retcode': MagicMock(side_effect=[False, True])}):
|
|
|
|
self.assertEqual(qemu_img.make_image('location', 'size', 'fmt'), 'location')
|
|
|
|
self.assertEqual(qemu_img.make_image('location', 'size', 'fmt'), '')
|