From 88980766cde3758a3a8352c39a6b376fece9e83e Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Wed, 5 Mar 2014 16:29:58 -0800 Subject: [PATCH] remove(dep): Remove dep on plumbum - Plumbum is not on the openstack global requirements list, and removing it as a requirement is a prerequisite to being accepted as an Openstack project --- requirements.txt | 1 - teeth_agent/hardware.py | 12 ++++++------ teeth_agent/tests/hardware.py | 8 +++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/requirements.txt b/requirements.txt index e43dbace9..b0528704f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ Werkzeug==0.9.4 requests==2.0.0 cherrypy==3.2.4 -plumbum==1.4.0 stevedore==0.13 -e git+https://github.com/racker/teeth-rest.git@e876c0fddd5ce2f5223ab16936f711b0d57e19c4#egg=teeth_rest diff --git a/teeth_agent/hardware.py b/teeth_agent/hardware.py index e37cea7cd..bc79db391 100644 --- a/teeth_agent/hardware.py +++ b/teeth_agent/hardware.py @@ -17,8 +17,8 @@ limitations under the License. import abc import collections import os +import subprocess -import plumbum import stevedore import structlog @@ -121,14 +121,14 @@ class GenericHardwareManager(HardwareManager): for name in iface_names if self._is_device(name)] - def _cmd(self, command_name): - """Mocking plumbum is frustratingly difficult. Instead, mock this.""" - return plumbum.local[command_name] + def _cmd(self, command): + process = subprocess.Popen(command, stdout=subprocess.PIPE) + return process.communicate() def _list_block_devices(self): - report = self._cmd('blockdev')('--report').strip() + report = self._cmd(['blockdev', '--report'])[0] lines = report.split('\n') - lines = [line.split() for line in lines] + lines = [line.split() for line in lines if line is not ''] startsec_idx = lines[0].index('StartSec') device_idx = lines[0].index('Device') size_idx = lines[0].index('Size') diff --git a/teeth_agent/tests/hardware.py b/teeth_agent/tests/hardware.py index 6435b683d..8e4a75d68 100644 --- a/teeth_agent/tests/hardware.py +++ b/teeth_agent/tests/hardware.py @@ -41,18 +41,16 @@ class TestGenericHardwareManager(unittest.TestCase): def test_get_os_install_device(self): self.hardware._cmd = mock.Mock() - self.hardware._cmd.return_value = blockdev = mock.Mock() - blockdev.return_value = ( + self.hardware._cmd.return_value = ( 'RO RA SSZ BSZ StartSec Size Device\n' 'rw 256 512 4096 0 249578283616 /dev/sda\n' 'rw 256 512 4096 2048 8587837440 /dev/sda1\n' 'rw 256 512 4096 124967424 15728640 /dev/sda2\n' 'rw 256 512 4096 0 31016853504 /dev/sdb\n' - 'rw 256 512 4096 0 249578283616 /dev/sdc\n') + 'rw 256 512 4096 0 249578283616 /dev/sdc\n', '') self.assertEqual(self.hardware.get_os_install_device(), '/dev/sdb') - self.hardware._cmd.assert_called_once_with('blockdev') - blockdev.assert_called_once_with('--report') + self.hardware._cmd.assert_called_once_with(['blockdev', '--report']) def test_list_hardwre_info(self): self.hardware.list_network_interfaces = mock.Mock()