Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] fixes to iLo module #55083

Merged
merged 3 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions salt/modules/ilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __execute_cmd(name, xml):
with tempfile.NamedTemporaryFile(dir=tmp_dir,
prefix=name + six.text_type(os.getpid()),
suffix='.xml',
mode='w',
delete=False) as fh:
tmpfilename = fh.name
fh.write(xml)
Expand Down
23 changes: 22 additions & 1 deletion tests/unit/modules/test_ilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals

import logging
import tempfile

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
Expand All @@ -18,6 +21,9 @@

# Import Salt Libs
import salt.modules.ilo as ilo
import salt.modules.file

log = logging.getLogger(__name__)


@skipIf(NO_MOCK, NO_MOCK_REASON)
Expand All @@ -26,7 +32,22 @@ class IloTestCase(TestCase, LoaderModuleMockMixin):
Test cases for salt.modules.ilo
'''
def setup_loader_modules(self):
return {ilo: {}}
return {ilo:
{'__opts__': {'cachedir': tempfile.gettempdir()},
'__salt__': {'file.remove': salt.modules.file.remove}}
}

# '__execute_cmd' function tests: 1

def test_execute_cmd(self):
'''
Test if __execute_command opens the temporary file
properly when calling global_settings.
'''
mock_cmd_run = MagicMock(return_value={'retcode': 0, 'stdout': ''})
with patch.dict(ilo.__salt__, {'cmd.run_all': mock_cmd_run}):
ret = ilo.global_settings()
self.assertEqual(ret, True)

# 'global_settings' function tests: 1

Expand Down