From a866f2c29b011afb8db3a1eed7583c7e05625986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Ole=C5=9B?= Date: Fri, 25 Sep 2015 09:20:12 +0200 Subject: [PATCH] Allow VirtualResource only with `updates` section --- solar/solar/core/resource/virtual_resource.py | 4 ++-- solar/solar/test/resource_fixtures/update.yaml.tmpl | 6 ------ solar/solar/test/test_virtual_resource.py | 12 ++++++++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/solar/solar/core/resource/virtual_resource.py b/solar/solar/core/resource/virtual_resource.py index 72f1fe21..0de2986d 100644 --- a/solar/solar/core/resource/virtual_resource.py +++ b/solar/solar/core/resource/virtual_resource.py @@ -65,9 +65,9 @@ def create_resource(name, base_path, args=None, virtual_resource=None): def create_virtual_resource(vr_name, template): - template_resources = template['resources'] + template_resources = template.get('resources', []) template_events = template.get('events', []) - resources_to_update = template.get('updates', {}) + resources_to_update = template.get('updates', []) created_resources = create_resources(template_resources) events = parse_events(template_events) diff --git a/solar/solar/test/resource_fixtures/update.yaml.tmpl b/solar/solar/test/resource_fixtures/update.yaml.tmpl index a2ca3fc7..14aaf12f 100644 --- a/solar/solar/test/resource_fixtures/update.yaml.tmpl +++ b/solar/solar/test/resource_fixtures/update.yaml.tmpl @@ -1,10 +1,4 @@ id: simple_multinode -resources: - - id: node1 - from: {resource_path} - values: - ip: '10.0.0.3' - updates: - id: node1 values: diff --git a/solar/solar/test/test_virtual_resource.py b/solar/solar/test/test_virtual_resource.py index 6eb05285..e9d47cd1 100644 --- a/solar/solar/test/test_virtual_resource.py +++ b/solar/solar/test/test_virtual_resource.py @@ -74,16 +74,24 @@ def test_create_virtual_resource(tmpdir): assert len(resources) == 2 def test_update(tmpdir): + # XXX: make helper for it base_path = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'resource_fixtures') - vr_tmpl_path = os.path.join(base_path, 'update.yaml.tmpl') + vr_node_tmpl_path = os.path.join(base_path, 'nodes.yaml.tmpl') + vr_update_tmpl_path = os.path.join(base_path, 'update.yaml.tmpl') + update_path = os.path.join(base_path, 'update') node_resource_path = os.path.join(base_path, 'node') - with open(vr_tmpl_path) as f: + with open(vr_node_tmpl_path) as f: vr_data = f.read().format(resource_path=node_resource_path) + with open(vr_update_tmpl_path) as f: + update_data = f.read().format(resource_path=update_path) vr_file = tmpdir.join('nodes.yaml') vr_file.write(vr_data) + update_file = tmpdir.join('update.yaml') + update_file.write(update_data) resources = vr.create('nodes', str(vr_file)) + vr.create('updates', str(update_file)) assert resources[0].args['ip'] == '10.0.0.4' def test_parse_events(good_events):