Merge pull request #112 from n-pochet/bug/111
Fix parameters passed to `async_run_on_unit`
This commit is contained in:
@@ -634,24 +634,52 @@ class TestModel(ut_utils.BaseTestCase):
|
||||
'stopped')
|
||||
|
||||
def test_get_unit_time(self):
|
||||
async def _run_on_unit(model_name, unit_name, cmd, timeout=None):
|
||||
async def _run_on_unit(
|
||||
unit_name,
|
||||
command,
|
||||
model_name=None,
|
||||
timeout=None
|
||||
):
|
||||
return {'Stdout': '1524409654'}
|
||||
self.patch_object(model, 'async_run_on_unit')
|
||||
self.async_run_on_unit.side_effect = _run_on_unit
|
||||
self.assertEqual(
|
||||
model.get_unit_time('app/2'),
|
||||
1524409654)
|
||||
self.async_run_on_unit.assert_called_once_with(
|
||||
unit_name='app/2',
|
||||
command="date +'%s'",
|
||||
model_name=None,
|
||||
timeout=None
|
||||
)
|
||||
|
||||
def test_get_unit_service_start_time(self):
|
||||
async def _run_on_unit(model_name, unit_name, cmd, timeout=None):
|
||||
async def _run_on_unit(
|
||||
unit_name,
|
||||
command,
|
||||
model_name=None,
|
||||
timeout=None
|
||||
):
|
||||
return {'Stdout': '1524409654'}
|
||||
self.patch_object(model, 'async_run_on_unit')
|
||||
self.async_run_on_unit.side_effect = _run_on_unit
|
||||
self.assertEqual(
|
||||
model.get_unit_service_start_time('app/2', 'mysvc1'), 1524409654)
|
||||
cmd = "stat -c %Y /proc/$(pidof -x mysvc1 | cut -f1 -d ' ')"
|
||||
self.async_run_on_unit.assert_called_once_with(
|
||||
unit_name='app/2',
|
||||
command=cmd,
|
||||
model_name=None,
|
||||
timeout=None
|
||||
)
|
||||
|
||||
def test_get_unit_service_start_time_not_running(self):
|
||||
async def _run_on_unit(model_name, unit_name, cmd, timeout=None):
|
||||
async def _run_on_unit(
|
||||
unit_name,
|
||||
command,
|
||||
model_name=None,
|
||||
timeout=None
|
||||
):
|
||||
return {'Stdout': ''}
|
||||
self.patch_object(model, 'async_run_on_unit')
|
||||
self.async_run_on_unit.side_effect = _run_on_unit
|
||||
|
||||
@@ -288,9 +288,9 @@ async def async_get_unit_time(unit_name, model_name=None, timeout=None):
|
||||
:rtype: int
|
||||
"""
|
||||
out = await async_run_on_unit(
|
||||
model_name,
|
||||
unit_name,
|
||||
"date +'%s'",
|
||||
unit_name=unit_name,
|
||||
command="date +'%s'",
|
||||
model_name=model_name,
|
||||
timeout=timeout)
|
||||
return int(out['Stdout'])
|
||||
|
||||
@@ -318,7 +318,11 @@ async def async_get_unit_service_start_time(unit_name, service,
|
||||
:raises: ServiceNotRunning
|
||||
"""
|
||||
cmd = "stat -c %Y /proc/$(pidof -x {} | cut -f1 -d ' ')".format(service)
|
||||
out = await async_run_on_unit(model_name, unit_name, cmd, timeout=timeout)
|
||||
out = await async_run_on_unit(
|
||||
unit_name=unit_name,
|
||||
command=cmd,
|
||||
model_name=model_name,
|
||||
timeout=timeout)
|
||||
out = out['Stdout'].strip()
|
||||
if out:
|
||||
return int(out)
|
||||
|
||||
Reference in New Issue
Block a user