Adopt shaker.lib to recent result model changes
Change-Id: I153e822d6a83a332a248df22a55aed97aa22edf1
This commit is contained in:
parent
92cf085e53
commit
bc59fb2d76
@ -25,8 +25,20 @@ LOG = logging.getLogger(__name__)
|
||||
class Shaker(object):
|
||||
"""How to use Shaker as library
|
||||
|
||||
shaker = Shaker('127.0.0.1:5999', ['the-agent'])
|
||||
res = shaker.run_program('the-agent', 'ls -al')
|
||||
>>> from shaker import lib
|
||||
>>> shaker = lib.Shaker('127.0.0.1:5999', ['the-agent'])
|
||||
>>> shaker.run_program('the-agent', 'date')
|
||||
{
|
||||
'status': 'ok',
|
||||
'stdout': 'Thu Apr 23 13:09:08 EAT 2015\n',
|
||||
'agent': 'the-agent',
|
||||
'command': {'data': 'date', 'type': 'program'},
|
||||
'stderr': u'',
|
||||
'executor': 'shell',
|
||||
'test': 'shell',
|
||||
'type': 'agent',
|
||||
'id': '3a7c3d97-45f1-43ba-8460-2e37e679e3d5'
|
||||
}
|
||||
"""
|
||||
def __init__(self, server_endpoint, agent_ids, polling_interval=1,
|
||||
agent_loss_timeout=60, agent_join_timeout=600):
|
||||
@ -43,9 +55,7 @@ class Shaker(object):
|
||||
execution = {'tests': [test]}
|
||||
execution_result = server.execute(self.quorum, execution, agents)
|
||||
|
||||
results_per_iteration = execution_result[0]['results_per_iteration']
|
||||
results_per_agent = results_per_iteration[0]['results_per_agent']
|
||||
return dict((s['agent']['id'], s) for s in results_per_agent)
|
||||
return list(execution_result.values())[0]
|
||||
|
||||
def run_program(self, agent_id, program):
|
||||
return self._run(agent_id, {'program': program})
|
||||
|
37
tests/test_lib.py
Normal file
37
tests/test_lib.py
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright (c) 2015 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from shaker import lib
|
||||
|
||||
|
||||
class TestLib(testtools.TestCase):
|
||||
|
||||
@mock.patch('shaker.engine.quorum.make_quorum')
|
||||
def test_run_program(self, make_quorum_patch):
|
||||
quorum_mock = mock.MagicMock()
|
||||
make_quorum_patch.return_value = quorum_mock
|
||||
|
||||
quorum_mock.execute = mock.Mock(
|
||||
return_value={'AGENT': {'status': 'ok', 'stdout': 'STDOUT', }})
|
||||
|
||||
shaker = lib.Shaker('127.0.0.1:5999', ['AGENT'])
|
||||
res = shaker.run_program('AGENT', 'ls -al')
|
||||
|
||||
self.assertDictContainsSubset(
|
||||
{'status': 'ok', 'stdout': 'STDOUT', 'agent': 'AGENT',
|
||||
'executor': 'shell', 'type': 'agent'}, res)
|
Loading…
Reference in New Issue
Block a user