diff options
author | Yujun Zhang <zhang.yujunz@zte.com.cn> | 2017-04-20 03:41:18 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-04-20 03:41:18 +0000 |
commit | 7bc49cecd73a3a88f63828a9219b4aec4d53f70d (patch) | |
tree | a27dee3ea5a4b955a7e4297bb2db809d1947dd9a | |
parent | 59e48a5df9eb9c10708cd1873f8b5c623bdeb5f2 (diff) | |
parent | e37805bda96bd54a6c0108e6fb2e67298bbda280 (diff) |
Merge "fix apex integration"
-rw-r--r-- | qtip/ansible_library/modules/apex_generate_inventory.py (renamed from qtip/ansible_library/modules/apex.py) | 44 | ||||
-rw-r--r-- | tests/integration/setup.yaml | 21 | ||||
-rw-r--r-- | tests/unit/ansible_library/modules/apex_generate_inventory_test.py (renamed from tests/unit/ansible_library/modules/apex_test.py) | 4 |
3 files changed, 33 insertions, 36 deletions
diff --git a/qtip/ansible_library/modules/apex.py b/qtip/ansible_library/modules/apex_generate_inventory.py index 218440b2..9621ba6e 100644 --- a/qtip/ansible_library/modules/apex.py +++ b/qtip/ansible_library/modules/apex_generate_inventory.py @@ -10,7 +10,6 @@ ############################################################################## from collections import defaultdict -import json import re from ansible.module_utils.basic import AnsibleModule @@ -70,10 +69,7 @@ EXAMPLES = ''' def generate_inventory(baremetal_info, server_info): - """Generate ansible inventory from node list in json format - - Modified from https://github.com/martineg/ansible-apex-inventory/blob/master/apex.py - """ + """Generate ansible inventory in json format""" hosts = defaultdict(list) hosts_meta = {} @@ -95,37 +91,17 @@ def generate_inventory(baremetal_info, server_info): def main(): - module = AnsibleModule(argument_spec=dict()) - - (rc, out, err) = module.run_command(['source ~/stackrc']) - - if rc is not None and rc != 0: - return module.fail_json(msg=err) - - cmd = [module.get_bin_path('openstack', True), - 'baremetal', - 'list', - '--fields instance_uuid properties provision_state', - '--format json'] - (rc, out, err) = module.run_command(cmd) - - if rc is not None and rc != 0: - return module.fail_json(msg=err) - - baremetal_info = json.loads(out) - - cmd = [module.get_bin_path('openstack', True), - 'server', - 'list', - '--format json'] - (rc, out, err) = module.run_command(cmd) - - if rc is not None and rc != 0: - return module.fail_json(msg=err) + module = AnsibleModule( + argument_spec=dict( + baremetal_info=dict(type='list'), + server_info=dict(type='list') + ) + ) - server_info = json.loads(out) + baremetal_info = module.params['baremetal_info'] + server_info = module.params['server_info'] - module.exit_json(changed=False, + module.exit_json(changed=True, ansible_facts=generate_inventory(baremetal_info, server_info)) diff --git a/tests/integration/setup.yaml b/tests/integration/setup.yaml index 8d055c23..fed5e9d9 100644 --- a/tests/integration/setup.yaml +++ b/tests/integration/setup.yaml @@ -20,6 +20,27 @@ template: src={{ qtip_resources }}/template/ssh.cfg.j2 dest=./ssh.cfg delegate_to: localhost +- hosts: apex-undercloud + gather_facts: no + + tasks: + - name: collect overcloud baremetal info + shell: . /root/stackrc && openstack baremetal list --fields instance_uuid properties provision_state --format json + register: baremetal_info + - name: collect overcloud server info + shell: . /root/stackrc && openstack server list --format json + register: server_info + - name: generate inventory + apex_generate_inventory: + baremetal_info: "{{ baremetal_info.stdout | from_json }}" + server_info: "{{ server_info.stdout | from_json }}" + - name: update inventory file + template: src={{ qtip_resources }}/template/hosts.j2 dest=./hosts + delegate_to: localhost + - name: update ssh.cfg file + template: src={{ qtip_resources }}/template/ssh.cfg.j2 dest=./ssh.cfg + delegate_to: localhost + # Initialize testapi database - hosts: localhost tasks: diff --git a/tests/unit/ansible_library/modules/apex_test.py b/tests/unit/ansible_library/modules/apex_generate_inventory_test.py index 8a1d0673..7df9d35c 100644 --- a/tests/unit/ansible_library/modules/apex_test.py +++ b/tests/unit/ansible_library/modules/apex_generate_inventory_test.py @@ -10,7 +10,7 @@ import json import os -from qtip.ansible_library.modules import apex +from qtip.ansible_library.modules import apex_generate_inventory def test_generate_inventory(data_root): @@ -18,7 +18,7 @@ def test_generate_inventory(data_root): 'apex', 'baremetal_info.json'))) server_info = json.load(open(os.path.join(data_root, 'external', 'apex', 'server_info.json'))) - inventory = apex.generate_inventory(baremetal_info, server_info) + inventory = apex_generate_inventory.generate_inventory(baremetal_info, server_info) assert dict(inventory['hosts']) == { u'compute': [u'192.0.2.5', u'192.0.2.6'], u'control': [u'192.0.2.7', u'192.0.2.8', u'192.0.2.9']} |