Renames module executil to execcmd
Minor refactoring. Change-Id: I4b371ca19e588cf2cab4bdb1a0ada43d59c632b6
This commit is contained in:
parent
e4b01a4992
commit
26c26bde64
@ -15,16 +15,16 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from cloudbaseinit.openstack.common import log as logging
|
from cloudbaseinit.openstack.common import log as logging
|
||||||
from cloudbaseinit.plugins.common import executil
|
from cloudbaseinit.plugins.common import execcmd
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
FORMATS = {
|
FORMATS = {
|
||||||
"cmd": executil.Shell,
|
"cmd": execcmd.Shell,
|
||||||
"exe": executil.Shell,
|
"exe": execcmd.Shell,
|
||||||
"sh": executil.Bash,
|
"sh": execcmd.Bash,
|
||||||
"py": executil.Python,
|
"py": execcmd.Python,
|
||||||
"ps1": executil.PowershellSysnative,
|
"ps1": execcmd.PowershellSysnative,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import functools
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from cloudbaseinit.openstack.common import log as logging
|
from cloudbaseinit.openstack.common import log as logging
|
||||||
from cloudbaseinit.plugins.common import executil
|
from cloudbaseinit.plugins.common import execcmd
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -24,11 +24,11 @@ LOG = logging.getLogger(__name__)
|
|||||||
# is deleted afterwards.
|
# is deleted afterwards.
|
||||||
_compile = functools.partial(re.compile, flags=re.I)
|
_compile = functools.partial(re.compile, flags=re.I)
|
||||||
FORMATS = (
|
FORMATS = (
|
||||||
(_compile(br'^rem cmd\s'), executil.Shell),
|
(_compile(br'^rem cmd\s'), execcmd.Shell),
|
||||||
(_compile(br'^#!/usr/bin/env\spython\s'), executil.Python),
|
(_compile(br'^#!/usr/bin/env\spython\s'), execcmd.Python),
|
||||||
(_compile(br'^#!'), executil.Bash),
|
(_compile(br'^#!'), execcmd.Bash),
|
||||||
(_compile(br'^#(ps1|ps1_sysnative)\s'), executil.PowershellSysnative),
|
(_compile(br'^#(ps1|ps1_sysnative)\s'), execcmd.PowershellSysnative),
|
||||||
(_compile(br'^#ps1_x86\s'), executil.Powershell),
|
(_compile(br'^#ps1_x86\s'), execcmd.Powershell),
|
||||||
)
|
)
|
||||||
del _compile
|
del _compile
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import unittest
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from cloudbaseinit.plugins.common import executil
|
from cloudbaseinit.plugins.common import execcmd
|
||||||
from cloudbaseinit.tests import testutils
|
from cloudbaseinit.tests import testutils
|
||||||
|
|
||||||
|
|
||||||
@ -29,12 +29,12 @@ def _remove_file(filepath):
|
|||||||
|
|
||||||
|
|
||||||
@mock.patch('cloudbaseinit.osutils.factory.get_os_utils')
|
@mock.patch('cloudbaseinit.osutils.factory.get_os_utils')
|
||||||
class ExecUtilTest(unittest.TestCase):
|
class execcmdTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_from_data(self, _):
|
def test_from_data(self, _):
|
||||||
command = executil.BaseCommand.from_data(b"test")
|
command = execcmd.BaseCommand.from_data(b"test")
|
||||||
|
|
||||||
self.assertIsInstance(command, executil.BaseCommand)
|
self.assertIsInstance(command, execcmd.BaseCommand)
|
||||||
|
|
||||||
# Not public API, though.
|
# Not public API, though.
|
||||||
self.assertTrue(os.path.exists(command._target_path),
|
self.assertTrue(os.path.exists(command._target_path),
|
||||||
@ -50,7 +50,7 @@ class ExecUtilTest(unittest.TestCase):
|
|||||||
command._target_path)
|
command._target_path)
|
||||||
|
|
||||||
def test_args(self, _):
|
def test_args(self, _):
|
||||||
class FakeCommand(executil.BaseCommand):
|
class FakeCommand(execcmd.BaseCommand):
|
||||||
command = mock.sentinel.command
|
command = mock.sentinel.command
|
||||||
|
|
||||||
with testutils.create_tempfile() as tmp:
|
with testutils.create_tempfile() as tmp:
|
||||||
@ -58,11 +58,11 @@ class ExecUtilTest(unittest.TestCase):
|
|||||||
self.assertEqual([mock.sentinel.command, tmp],
|
self.assertEqual([mock.sentinel.command, tmp],
|
||||||
fake_command.args)
|
fake_command.args)
|
||||||
|
|
||||||
fake_command = executil.BaseCommand(tmp)
|
fake_command = execcmd.BaseCommand(tmp)
|
||||||
self.assertEqual([tmp], fake_command.args)
|
self.assertEqual([tmp], fake_command.args)
|
||||||
|
|
||||||
def test_from_data_extension(self, _):
|
def test_from_data_extension(self, _):
|
||||||
class FakeCommand(executil.BaseCommand):
|
class FakeCommand(execcmd.BaseCommand):
|
||||||
command = mock.sentinel.command
|
command = mock.sentinel.command
|
||||||
extension = ".test"
|
extension = ".test"
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ class ExecUtilTest(unittest.TestCase):
|
|||||||
mock_osutils = mock_get_os_utils()
|
mock_osutils = mock_get_os_utils()
|
||||||
|
|
||||||
with testutils.create_tempfile() as tmp:
|
with testutils.create_tempfile() as tmp:
|
||||||
command = executil.BaseCommand(tmp)
|
command = execcmd.BaseCommand(tmp)
|
||||||
command.execute()
|
command.execute()
|
||||||
|
|
||||||
mock_osutils.execute_process.assert_called_once_with(
|
mock_osutils.execute_process.assert_called_once_with(
|
||||||
@ -95,7 +95,7 @@ class ExecUtilTest(unittest.TestCase):
|
|||||||
mock_osutils = mock_get_os_utils()
|
mock_osutils = mock_get_os_utils()
|
||||||
|
|
||||||
with testutils.create_tempfile() as tmp:
|
with testutils.create_tempfile() as tmp:
|
||||||
command = executil.Powershell(tmp)
|
command = execcmd.Powershell(tmp)
|
||||||
command.execute()
|
command.execute()
|
||||||
|
|
||||||
mock_osutils.execute_powershell_script.assert_called_once_with(
|
mock_osutils.execute_powershell_script.assert_called_once_with(
|
||||||
@ -104,7 +104,7 @@ class ExecUtilTest(unittest.TestCase):
|
|||||||
def test_execute_cleanup(self, _):
|
def test_execute_cleanup(self, _):
|
||||||
with testutils.create_tempfile() as tmp:
|
with testutils.create_tempfile() as tmp:
|
||||||
cleanup = mock.Mock()
|
cleanup = mock.Mock()
|
||||||
command = executil.BaseCommand(tmp, cleanup=cleanup)
|
command = execcmd.BaseCommand(tmp, cleanup=cleanup)
|
||||||
command.execute()
|
command.execute()
|
||||||
|
|
||||||
cleanup.assert_called_once_with()
|
cleanup.assert_called_once_with()
|
@ -16,7 +16,7 @@ import unittest
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from cloudbaseinit.plugins.common import executil
|
from cloudbaseinit.plugins.common import execcmd
|
||||||
from cloudbaseinit.plugins.windows import fileexecutils
|
from cloudbaseinit.plugins.windows import fileexecutils
|
||||||
|
|
||||||
|
|
||||||
@ -29,17 +29,17 @@ class TestFileExecutilsPlugin(unittest.TestCase):
|
|||||||
|
|
||||||
def test_executors_mapping(self, _):
|
def test_executors_mapping(self, _):
|
||||||
self.assertEqual(fileexecutils.FORMATS["cmd"],
|
self.assertEqual(fileexecutils.FORMATS["cmd"],
|
||||||
executil.Shell)
|
execcmd.Shell)
|
||||||
self.assertEqual(fileexecutils.FORMATS["exe"],
|
self.assertEqual(fileexecutils.FORMATS["exe"],
|
||||||
executil.Shell)
|
execcmd.Shell)
|
||||||
self.assertEqual(fileexecutils.FORMATS["sh"],
|
self.assertEqual(fileexecutils.FORMATS["sh"],
|
||||||
executil.Bash)
|
execcmd.Bash)
|
||||||
self.assertEqual(fileexecutils.FORMATS["py"],
|
self.assertEqual(fileexecutils.FORMATS["py"],
|
||||||
executil.Python)
|
execcmd.Python)
|
||||||
self.assertEqual(fileexecutils.FORMATS["ps1"],
|
self.assertEqual(fileexecutils.FORMATS["ps1"],
|
||||||
executil.PowershellSysnative)
|
execcmd.PowershellSysnative)
|
||||||
|
|
||||||
@mock.patch('cloudbaseinit.plugins.common.executil.'
|
@mock.patch('cloudbaseinit.plugins.common.execcmd.'
|
||||||
'BaseCommand.execute')
|
'BaseCommand.execute')
|
||||||
def test_exec_file_fails(self, mock_execute, _):
|
def test_exec_file_fails(self, mock_execute, _):
|
||||||
mock_execute.side_effect = ValueError
|
mock_execute.side_effect = ValueError
|
||||||
@ -47,7 +47,7 @@ class TestFileExecutilsPlugin(unittest.TestCase):
|
|||||||
mock_execute.assert_called_once_with()
|
mock_execute.assert_called_once_with()
|
||||||
self.assertEqual(0, retval)
|
self.assertEqual(0, retval)
|
||||||
|
|
||||||
@mock.patch('cloudbaseinit.plugins.common.executil.'
|
@mock.patch('cloudbaseinit.plugins.common.execcmd.'
|
||||||
'BaseCommand.execute')
|
'BaseCommand.execute')
|
||||||
def test_exec_file_(self, mock_execute, _):
|
def test_exec_file_(self, mock_execute, _):
|
||||||
mock_execute.return_value = (
|
mock_execute.return_value = (
|
||||||
|
@ -17,7 +17,7 @@ import unittest
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from cloudbaseinit.plugins.common import executil
|
from cloudbaseinit.plugins.common import execcmd
|
||||||
from cloudbaseinit.plugins.windows import userdatautils
|
from cloudbaseinit.plugins.windows import userdatautils
|
||||||
|
|
||||||
|
|
||||||
@ -44,19 +44,19 @@ class UserDataUtilsTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test__get_command(self, _):
|
def test__get_command(self, _):
|
||||||
command = self._get_command(b'rem cmd test')
|
command = self._get_command(b'rem cmd test')
|
||||||
self.assertIsInstance(command, executil.Shell)
|
self.assertIsInstance(command, execcmd.Shell)
|
||||||
|
|
||||||
command = self._get_command(b'#!/usr/bin/env python\ntest')
|
command = self._get_command(b'#!/usr/bin/env python\ntest')
|
||||||
self.assertIsInstance(command, executil.Python)
|
self.assertIsInstance(command, execcmd.Python)
|
||||||
|
|
||||||
command = self._get_command(b'#!/bin/bash')
|
command = self._get_command(b'#!/bin/bash')
|
||||||
self.assertIsInstance(command, executil.Bash)
|
self.assertIsInstance(command, execcmd.Bash)
|
||||||
|
|
||||||
command = self._get_command(b'#ps1_sysnative\n')
|
command = self._get_command(b'#ps1_sysnative\n')
|
||||||
self.assertIsInstance(command, executil.PowershellSysnative)
|
self.assertIsInstance(command, execcmd.PowershellSysnative)
|
||||||
|
|
||||||
command = self._get_command(b'#ps1_x86\n')
|
command = self._get_command(b'#ps1_x86\n')
|
||||||
self.assertIsInstance(command, executil.Powershell)
|
self.assertIsInstance(command, execcmd.Powershell)
|
||||||
|
|
||||||
command = self._get_command(b'unknown')
|
command = self._get_command(b'unknown')
|
||||||
self.assertIsNone(command)
|
self.assertIsNone(command)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user