From aa9716f3e0a52089b171dad343a88b1238a0d377 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat <ishakhat@mirantis.com> Date: Mon, 6 Apr 2015 13:10:41 +0300 Subject: [PATCH] Fix agent extending Change-Id: I29c92a6d99b5aa01a7431e55997996700bf904ee --- shaker/engine/server.py | 14 +++++++++----- tests/test_server.py | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/shaker/engine/server.py b/shaker/engine/server.py index a2319bd..77a7b9f 100644 --- a/shaker/engine/server.py +++ b/shaker/engine/server.py @@ -112,12 +112,16 @@ def read_scenario(): return scenario -def _extend_agents(agents): - for agent in agents.values(): +def _extend_agents(agents_map): + extended_agents = {} + for agent in agents_map.values(): + extended = copy.deepcopy(agent) if agent.get('slave_id'): - agent['slave'] = copy.deepcopy(agents[agent['slave_id']]) + extended['slave'] = copy.deepcopy(agents_map[agent['slave_id']]) if agent.get('master_id'): - agent['master'] = copy.deepcopy(agents[agent['master_id']]) + extended['master'] = copy.deepcopy(agents_map[agent['master_id']]) + extended_agents[agent['id']] = extended + return extended_agents def _pick_agents(agents, size): @@ -141,7 +145,7 @@ def _pick_agents(agents, size): def execute(quorum, execution, agents): - _extend_agents(agents) + agents = _extend_agents(agents) result = [] diff --git a/tests/test_server.py b/tests/test_server.py index bd28467..a87d245 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -21,7 +21,7 @@ from shaker.engine import server class TestServer(testtools.TestCase): def test_extend_agents(self): - agents = { + agents_map = { 'UU1D_master_0': { 'id': 'UU1D_master_0', 'mode': 'master', @@ -33,7 +33,7 @@ class TestServer(testtools.TestCase): 'mode': 'slave', 'node': 'dos'}, } - server._extend_agents(agents) + agents = server._extend_agents(agents_map) self.assertDictContainsSubset(agents['UU1D_master_0']['slave'], agents['UU1D_slave_0']) self.assertDictContainsSubset(agents['UU1D_slave_0']['master'],