From 4d48188e96cb6d86a3d83027af53173a6c7f8feb Mon Sep 17 00:00:00 2001 From: Przemyslaw Kaminski Date: Wed, 16 Sep 2015 11:41:56 +0200 Subject: [PATCH] Signals: fix hash update for multiple connections syntax with list --- solar/solar/core/signals.py | 7 +++-- solar/solar/test/test_signals.py | 46 +++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/solar/solar/core/signals.py b/solar/solar/core/signals.py index 2f45e18d..6e6345e4 100644 --- a/solar/solar/core/signals.py +++ b/solar/solar/core/signals.py @@ -53,10 +53,6 @@ def connect(emitter, receiver, mapping={}, events=None): return for src, dst in mapping.items(): - if ':' in dst: - connect_multi(emitter, src, receiver, dst) - continue - if not isinstance(dst, list): dst = [dst] @@ -77,6 +73,9 @@ def connect(emitter, receiver, mapping={}, events=None): def connect_single(emitter, src, receiver, dst): + if ':' in dst: + return connect_multi(emitter, src, receiver, dst) + # Disconnect all receiver inputs # Check if receiver input is of list type first emitter_input = emitter.resource_inputs()[src] diff --git a/solar/solar/test/test_signals.py b/solar/solar/test/test_signals.py index edd826b4..27a27fb0 100644 --- a/solar/solar/test/test_signals.py +++ b/solar/solar/test/test_signals.py @@ -457,10 +457,10 @@ input: 'sample2', sample_meta_dir, {'ip': '10.0.0.2', 'port': 1001} ) list_input = self.create_resource( - 'list-input', list_input_meta_dir, {} + 'list-input', list_input_meta_dir, ) list_input_nested = self.create_resource( - 'list-input-nested', list_input_nested_meta_dir, {} + 'list-input-nested', list_input_nested_meta_dir, ) xs.connect(sample1, list_input, mapping={'ip': 'ips', 'port': 'ports'}) @@ -517,7 +517,7 @@ input: 'sample', sample_meta_dir, args={'ip': '10.0.0.1', 'port': 5000} ) receiver = self.create_resource( - 'receiver', receiver_meta_dir, args={'server': None} + 'receiver', receiver_meta_dir ) xs.connect(sample, receiver, mapping={'ip': 'server:ip', 'port': 'server:port'}) self.assertDictEqual( @@ -595,7 +595,7 @@ input: 'sample1', sample_meta_dir, args={'ip': '10.0.0.1', 'port': 5000} ) receiver = self.create_resource( - 'receiver', receiver_meta_dir, args={'server': None} + 'receiver', receiver_meta_dir ) xs.connect(sample1, receiver, mapping={'ip': 'server:ip', 'port': 'server:port'}) self.assertItemsEqual( @@ -616,3 +616,41 @@ input: [{'ip': sample2.args['ip'], 'port': sample2.args['port']}], receiver.args['server'], ) + + def test_hash_input_with_multiple_connections(self): + sample_meta_dir = self.make_resource_meta(""" +id: sample +handler: ansible +version: 1.0.0 +input: + ip: + schema: str! + value: + """) + receiver_meta_dir = self.make_resource_meta(""" +id: receiver +handler: ansible +version: 1.0.0 +input: + ip: + schema: str! + value: + server: + schema: {ip: str!} + """) + + sample = self.create_resource( + 'sample', sample_meta_dir, args={'ip': '10.0.0.1'} + ) + receiver = self.create_resource( + 'receiver', receiver_meta_dir + ) + xs.connect(sample, receiver, mapping={'ip': ['ip', 'server:ip']}) + self.assertEqual( + sample.args['ip'], + receiver.args['ip'] + ) + self.assertDictEqual( + {'ip': sample.args['ip']}, + receiver.args['server'], + )