Renames module executil to execcmd

Minor refactoring.

Change-Id: I4b371ca19e588cf2cab4bdb1a0ada43d59c632b6
This commit is contained in:
Alessandro Pilotti 2014-12-24 16:35:34 +01:00
parent e4b01a4992
commit 26c26bde64
6 changed files with 36 additions and 36 deletions

View File

@ -15,16 +15,16 @@
import os
from cloudbaseinit.openstack.common import log as logging
from cloudbaseinit.plugins.common import executil
from cloudbaseinit.plugins.common import execcmd
LOG = logging.getLogger(__name__)
FORMATS = {
"cmd": executil.Shell,
"exe": executil.Shell,
"sh": executil.Bash,
"py": executil.Python,
"ps1": executil.PowershellSysnative,
"cmd": execcmd.Shell,
"exe": execcmd.Shell,
"sh": execcmd.Bash,
"py": execcmd.Python,
"ps1": execcmd.PowershellSysnative,
}

View File

@ -16,7 +16,7 @@ import functools
import re
from cloudbaseinit.openstack.common import log as logging
from cloudbaseinit.plugins.common import executil
from cloudbaseinit.plugins.common import execcmd
LOG = logging.getLogger(__name__)
@ -24,11 +24,11 @@ LOG = logging.getLogger(__name__)
# is deleted afterwards.
_compile = functools.partial(re.compile, flags=re.I)
FORMATS = (
(_compile(br'^rem cmd\s'), executil.Shell),
(_compile(br'^#!/usr/bin/env\spython\s'), executil.Python),
(_compile(br'^#!'), executil.Bash),
(_compile(br'^#(ps1|ps1_sysnative)\s'), executil.PowershellSysnative),
(_compile(br'^#ps1_x86\s'), executil.Powershell),
(_compile(br'^rem cmd\s'), execcmd.Shell),
(_compile(br'^#!/usr/bin/env\spython\s'), execcmd.Python),
(_compile(br'^#!'), execcmd.Bash),
(_compile(br'^#(ps1|ps1_sysnative)\s'), execcmd.PowershellSysnative),
(_compile(br'^#ps1_x86\s'), execcmd.Powershell),
)
del _compile

View File

@ -17,7 +17,7 @@ import unittest
import mock
from cloudbaseinit.plugins.common import executil
from cloudbaseinit.plugins.common import execcmd
from cloudbaseinit.tests import testutils
@ -29,12 +29,12 @@ def _remove_file(filepath):
@mock.patch('cloudbaseinit.osutils.factory.get_os_utils')
class ExecUtilTest(unittest.TestCase):
class execcmdTest(unittest.TestCase):
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.
self.assertTrue(os.path.exists(command._target_path),
@ -50,7 +50,7 @@ class ExecUtilTest(unittest.TestCase):
command._target_path)
def test_args(self, _):
class FakeCommand(executil.BaseCommand):
class FakeCommand(execcmd.BaseCommand):
command = mock.sentinel.command
with testutils.create_tempfile() as tmp:
@ -58,11 +58,11 @@ class ExecUtilTest(unittest.TestCase):
self.assertEqual([mock.sentinel.command, tmp],
fake_command.args)
fake_command = executil.BaseCommand(tmp)
fake_command = execcmd.BaseCommand(tmp)
self.assertEqual([tmp], fake_command.args)
def test_from_data_extension(self, _):
class FakeCommand(executil.BaseCommand):
class FakeCommand(execcmd.BaseCommand):
command = mock.sentinel.command
extension = ".test"
@ -76,7 +76,7 @@ class ExecUtilTest(unittest.TestCase):
mock_osutils = mock_get_os_utils()
with testutils.create_tempfile() as tmp:
command = executil.BaseCommand(tmp)
command = execcmd.BaseCommand(tmp)
command.execute()
mock_osutils.execute_process.assert_called_once_with(
@ -95,7 +95,7 @@ class ExecUtilTest(unittest.TestCase):
mock_osutils = mock_get_os_utils()
with testutils.create_tempfile() as tmp:
command = executil.Powershell(tmp)
command = execcmd.Powershell(tmp)
command.execute()
mock_osutils.execute_powershell_script.assert_called_once_with(
@ -104,7 +104,7 @@ class ExecUtilTest(unittest.TestCase):
def test_execute_cleanup(self, _):
with testutils.create_tempfile() as tmp:
cleanup = mock.Mock()
command = executil.BaseCommand(tmp, cleanup=cleanup)
command = execcmd.BaseCommand(tmp, cleanup=cleanup)
command.execute()
cleanup.assert_called_once_with()

View File

@ -16,7 +16,7 @@ import unittest
import mock
from cloudbaseinit.plugins.common import executil
from cloudbaseinit.plugins.common import execcmd
from cloudbaseinit.plugins.windows import fileexecutils
@ -29,17 +29,17 @@ class TestFileExecutilsPlugin(unittest.TestCase):
def test_executors_mapping(self, _):
self.assertEqual(fileexecutils.FORMATS["cmd"],
executil.Shell)
execcmd.Shell)
self.assertEqual(fileexecutils.FORMATS["exe"],
executil.Shell)
execcmd.Shell)
self.assertEqual(fileexecutils.FORMATS["sh"],
executil.Bash)
execcmd.Bash)
self.assertEqual(fileexecutils.FORMATS["py"],
executil.Python)
execcmd.Python)
self.assertEqual(fileexecutils.FORMATS["ps1"],
executil.PowershellSysnative)
execcmd.PowershellSysnative)
@mock.patch('cloudbaseinit.plugins.common.executil.'
@mock.patch('cloudbaseinit.plugins.common.execcmd.'
'BaseCommand.execute')
def test_exec_file_fails(self, mock_execute, _):
mock_execute.side_effect = ValueError
@ -47,7 +47,7 @@ class TestFileExecutilsPlugin(unittest.TestCase):
mock_execute.assert_called_once_with()
self.assertEqual(0, retval)
@mock.patch('cloudbaseinit.plugins.common.executil.'
@mock.patch('cloudbaseinit.plugins.common.execcmd.'
'BaseCommand.execute')
def test_exec_file_(self, mock_execute, _):
mock_execute.return_value = (

View File

@ -17,7 +17,7 @@ import unittest
import mock
from cloudbaseinit.plugins.common import executil
from cloudbaseinit.plugins.common import execcmd
from cloudbaseinit.plugins.windows import userdatautils
@ -44,19 +44,19 @@ class UserDataUtilsTest(unittest.TestCase):
def test__get_command(self, _):
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')
self.assertIsInstance(command, executil.Python)
self.assertIsInstance(command, execcmd.Python)
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')
self.assertIsInstance(command, executil.PowershellSysnative)
self.assertIsInstance(command, execcmd.PowershellSysnative)
command = self._get_command(b'#ps1_x86\n')
self.assertIsInstance(command, executil.Powershell)
self.assertIsInstance(command, execcmd.Powershell)
command = self._get_command(b'unknown')
self.assertIsNone(command)