mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #24936 from jtand/psutil
Fixed ps module to not use depreciated psutil commands
This commit is contained in:
commit
d26a5447ba
@ -125,7 +125,7 @@ def top(num_processes=5, interval=3):
|
||||
'''
|
||||
result = []
|
||||
start_usage = {}
|
||||
for pid in psutil.get_pid_list():
|
||||
for pid in psutil.pids():
|
||||
try:
|
||||
process = psutil.Process(pid)
|
||||
user, system = process.get_cpu_times()
|
||||
@ -177,7 +177,7 @@ def get_pid_list():
|
||||
|
||||
salt '*' ps.get_pid_list
|
||||
'''
|
||||
return psutil.get_pid_list()
|
||||
return psutil.pids()
|
||||
|
||||
|
||||
def kill_pid(pid, signal=15):
|
||||
@ -535,9 +535,9 @@ def network_io_counters(interface=None):
|
||||
salt '*' ps.network_io_counters interface=eth0
|
||||
'''
|
||||
if not interface:
|
||||
return dict(psutil.network_io_counters()._asdict())
|
||||
return dict(psutil.net_io_counters()._asdict())
|
||||
else:
|
||||
stats = psutil.network_io_counters(pernic=True)
|
||||
stats = psutil.net_io_counters(pernic=True)
|
||||
if interface in stats:
|
||||
return dict(stats[interface]._asdict())
|
||||
else:
|
||||
@ -577,7 +577,7 @@ def get_users():
|
||||
salt '*' ps.get_users
|
||||
'''
|
||||
try:
|
||||
recs = psutil.get_users()
|
||||
recs = psutil.users()
|
||||
return [dict(x._asdict()) for x in recs]
|
||||
except AttributeError:
|
||||
# get_users is only present in psutil > v0.5.0
|
||||
|
@ -79,7 +79,7 @@ class PsTestCase(TestCase):
|
||||
MOCK_PROC.name = 'test_mock_proc'
|
||||
MOCK_PROC.pid = 9999999999
|
||||
|
||||
@patch('psutil.get_pid_list', new=MagicMock(return_value=STUB_PID_LIST))
|
||||
@patch('psutil.pids', new=MagicMock(return_value=STUB_PID_LIST))
|
||||
def test_get_pid_list(self):
|
||||
self.assertListEqual(STUB_PID_LIST, ps.get_pid_list())
|
||||
|
||||
@ -149,7 +149,7 @@ class PsTestCase(TestCase):
|
||||
## Should only be tested in integration
|
||||
# def test_boot_time(self):
|
||||
# pass
|
||||
@patch('psutil.network_io_counters', new=MagicMock(return_value=STUB_NETWORK_IO))
|
||||
@patch('psutil.net_io_counters', new=MagicMock(return_value=STUB_NETWORK_IO))
|
||||
def test_network_io_counters(self):
|
||||
self.assertDictEqual(
|
||||
{'packets_sent': 500, 'packets_recv': 600, 'bytes_recv': 2000, 'dropout': 4, 'bytes_sent': 1000,
|
||||
@ -161,7 +161,7 @@ class PsTestCase(TestCase):
|
||||
{'read_time': 2000, 'write_bytes': 600, 'read_bytes': 500, 'write_time': 3000, 'read_count': 1000,
|
||||
'write_count': 2000}, ps.disk_io_counters())
|
||||
|
||||
@patch('psutil.get_users', new=MagicMock(return_value=[STUB_USER]))
|
||||
@patch('psutil.users', new=MagicMock(return_value=[STUB_USER]))
|
||||
def test_get_users(self):
|
||||
self.assertDictEqual({'terminal': 'ttys000', 'started': 0.0, 'host': 'localhost', 'name': 'bdobbs'},
|
||||
ps.get_users()[0])
|
||||
|
Loading…
Reference in New Issue
Block a user