From f70a3f36f10698399d84d775071cce12fe4c2208 Mon Sep 17 00:00:00 2001 From: Przemyslaw Kaminski Date: Tue, 21 Apr 2015 12:02:08 +0200 Subject: [PATCH] Fix resource.py input args so that validation is performed --- haproxy_deployment/haproxy-deployment.yaml | 53 ++++++++++++++++++---- haproxy_deployment/haproxy_deployment.py | 14 +++--- x/resource.py | 4 +- x/resources/docker_container/meta.yaml | 5 ++ x/resources/haproxy/meta.yaml | 1 + x/resources/keystone/meta.yaml | 1 + x/resources/nova/meta.yaml | 1 + 7 files changed, 60 insertions(+), 19 deletions(-) diff --git a/haproxy_deployment/haproxy-deployment.yaml b/haproxy_deployment/haproxy-deployment.yaml index 4fe164dd..bda416b5 100755 --- a/haproxy_deployment/haproxy-deployment.yaml +++ b/haproxy_deployment/haproxy-deployment.yaml @@ -58,12 +58,14 @@ resources: model: x/resources/keystone/ args: ip: + image: TEST ssh_user: ssh_key: - name: keystone2 model: x/resources/keystone/ args: ip: + image: TEST ssh_user: ssh_key: - name: haproxy_keystone_config @@ -95,12 +97,14 @@ resources: model: x/resources/nova/ args: ip: + image: TEST ssh_user: ssh_key: - name: nova2 model: x/resources/nova/ args: ip: + image: TEST ssh_user: ssh_key: - name: haproxy_nova_config @@ -110,13 +114,30 @@ resources: ssh_user: ssh_key: + #- name: haproxy-config-container + # model: x/resources/data_container/ + # args: + # ip: + # image: haproxy-config + # export_volumes: + # - haproxy-config + #- name: haproxy-config + # model: x/resources/haproxy/ + # args: + # ip: + # configs: {} + # ssh_user: + # ssh_key: - name: haproxy - model: x/resources/haproxy/ + model: x/resources/docker_container args: ip: - configs: {} + image: haproxy ssh_user: ssh_key: + host_binds: + - /etc/haproxy: /vagrant/haproxy-etc + volume_binds: connections: @@ -154,13 +175,25 @@ connections: mapping: ip: servers + # HAProxy config container + #- emitter: node5 + # receiver: haproxy-config-container + #- emitter: haproxy-config-container + # receiver: haproxy-config + #- emitter: haproxy_keystone_config + # receiver: haproxy-config + # mapping: + # servers: configs + #- emitter: haproxy_nova_config + # receiver: haproxy-config + # mapping: + # servers: configs + + # HAProxy service - emitter: node5 receiver: haproxy - - emitter: haproxy_keystone_config - receiver: haproxy - mapping: - servers: configs - - emitter: haproxy_nova_config - receiver: haproxy - mapping: - servers: configs + + #- emitter: haproxy-config + # receiver: haproxy + # mapping: + diff --git a/haproxy_deployment/haproxy_deployment.py b/haproxy_deployment/haproxy_deployment.py index 838a056d..606bf1c3 100644 --- a/haproxy_deployment/haproxy_deployment.py +++ b/haproxy_deployment/haproxy_deployment.py @@ -55,13 +55,13 @@ class TestHAProxyDeployment(unittest.TestCase): haproxy = db.get_resource('haproxy') self.assertEqual(node5.args['ip'], haproxy.args['ip']) - self.assertItemsEqual( - haproxy.args['configs'], - { - 'haproxy_keystone_config': haproxy_keystone_config.args['servers'], - 'haproxy_nova_config': haproxy_nova_config.args['servers'], - } - ) + #self.assertItemsEqual( + # haproxy.args['configs'], + # { + # 'haproxy_keystone_config': haproxy_keystone_config.args['servers'], + # 'haproxy_nova_config': haproxy_nova_config.args['servers'], + # } + #) def main(): diff --git a/x/resource.py b/x/resource.py index 8644a61c..4500e4c3 100644 --- a/x/resource.py +++ b/x/resource.py @@ -21,6 +21,7 @@ class Resource(object): self.requires = metadata['input'].keys() self._validate_args(args) self.args = args + self.metadata['input'] = args self.input_types = metadata.get('input-types', {}) self.changed = [] self.tags = tags or [] @@ -92,7 +93,6 @@ def create(name, base_path, dest_path, args, connections={}): meta['id'] = name meta['version'] = '1.0.0' meta['actions'] = {} - meta['input'] = args meta['tags'] = [] if os.path.exists(actions_path): @@ -102,7 +102,7 @@ def create(name, base_path, dest_path, args, connections={}): resource = Resource(name, meta, args, dest_path) signals.assign_connections(resource, connections) - #save + # save shutil.copytree(base_path, dest_path) resource.save() db.resource_add(name, resource) diff --git a/x/resources/docker_container/meta.yaml b/x/resources/docker_container/meta.yaml index 4170f334..ad46d110 100644 --- a/x/resources/docker_container/meta.yaml +++ b/x/resources/docker_container/meta.yaml @@ -2,5 +2,10 @@ id: container handler: ansible version: 1.0.0 input: + ip: image: + host_binds: volume_binds: +input-types: + host_binds: list + volume_binds: list diff --git a/x/resources/haproxy/meta.yaml b/x/resources/haproxy/meta.yaml index 63c64ebf..136a855d 100644 --- a/x/resources/haproxy/meta.yaml +++ b/x/resources/haproxy/meta.yaml @@ -2,6 +2,7 @@ id: haproxy handler: ansible version: 1.0.0 input: + ip: configs: input-types: configs: list diff --git a/x/resources/keystone/meta.yaml b/x/resources/keystone/meta.yaml index 064045fa..80bcb326 100644 --- a/x/resources/keystone/meta.yaml +++ b/x/resources/keystone/meta.yaml @@ -2,4 +2,5 @@ id: keystone handler: ansible version: 1.0.0 input: + ip: image: garland/docker-openstack-keystone diff --git a/x/resources/nova/meta.yaml b/x/resources/nova/meta.yaml index 180686ed..e6a861c0 100644 --- a/x/resources/nova/meta.yaml +++ b/x/resources/nova/meta.yaml @@ -2,4 +2,5 @@ id: nova handler: ansible version: 1.0.0 input: + ip: image: # TODO