From a76d3744b0be119bca2c94205c6556e245e4fd56 Mon Sep 17 00:00:00 2001 From: Neill Cox Date: Tue, 29 Mar 2016 21:45:48 +1100 Subject: [PATCH] Add tests for the ironic REST API Test ironic using the REST API. Tests currently implemented: - list chassis - list nodes - list drivers - create node - create port - validate node - update node - delete node Change-Id: I0a8ede31d8d3baa3f120ecb3e85bb8ff16e011d4 --- tests/create_node.json | 11 +++ tests/test-rest-api.yml | 145 ++++++++++++++++++++++++++++++++++++++++ tests/test.yml | 5 ++ 3 files changed, 161 insertions(+) create mode 100644 tests/create_node.json create mode 100644 tests/test-rest-api.yml diff --git a/tests/create_node.json b/tests/create_node.json new file mode 100644 index 00000000..6690c370 --- /dev/null +++ b/tests/create_node.json @@ -0,0 +1,11 @@ +{ + "driver": "agent_ipmitool", + "name": "happynode", + "driver_info": { + "deploy_kernel": "http://example.com/kernel.tgz", + "ipmi_address": "1.2.3.4", + "ipmi_username": "admin", + "ipmi_password": "TrickyPa55", + "deploy_ramdisk": "http://example.com/ramdisk.qcow" + } +} diff --git a/tests/test-rest-api.yml b/tests/test-rest-api.yml new file mode 100644 index 00000000..84271799 --- /dev/null +++ b/tests/test-rest-api.yml @@ -0,0 +1,145 @@ +--- +- name: Playbook for functional testing ironic via its REST API + hosts: localhost + user: root + gather_facts: false + tasks: + # needed by the functional test playbook below + - name: Install httplib2 so we can use the uri module + pip: + name: httplib2 + - name: Check the ironic-api + uri: + url: "{{ ironic_service_publicuri }}" + status_code: 200 + - name: list chassis + uri: + url: "{{ ironic_service_publicuri }}/v1/chassis" + status_code: 200 + return_content: yes + register: chassis_list + - name: test chassis list + assert: that="chassis_list.json.chassis == []" + - name: list drivers + uri: + url: "{{ ironic_service_publicuri }}/v1/drivers" + status_code: 200 + return_content: yes + register: driver_list + - name: test drivers + assert: that="driver_list.json.drivers[0].name == 'agent_ipmitool'" + - name: list nodes + uri: + url: "{{ ironic_service_publicuri }}/v1/nodes" + status_code: 200 + return_content: yes + register: node_list + - name: test nodes list is empty + assert: that="node_list.json.nodes == []" + - name: create a node + uri: + url: "{{ ironic_service_publicuri }}/v1/nodes" + method: POST + HEADER_Content-Type: "application/json" + HEADER_X-OpenStack-Ironic-API-Version: "1.9" + body_format: json + body: "{\"name\": \"restnode\", \"driver\": \"agent_ipmitool\", \"driver_info\": {\"ipmi_address\": \"1.2.3.4\"}}" + status_code: 201 + return_content: yes + register: node_response + - name: test node created + assert: + that: + - "node_response.json.target_power_state is none" + - "node_response.json.name == 'restnode'" + - name: create a port + uri: + url: "{{ ironic_service_publicuri }}/v1/ports" + method: POST + HEADER_Content-Type: "application/json" + HEADER_X-OpenStack-Ironic-API-Version: "1.9" + body_format: json + body: " {\"node_uuid\": \"{{ node_response.json.uuid }}\", \"address\": \"00:00:00:00:00:01\"}" + status_code: 201 + return_content: yes + - name: list ports + uri: + HEADER_Content-Type: "application/json" + HEADER_X-OpenStack-Ironic-API-Version: "1.9" + url: "{{ ironic_service_publicuri }}/v1/ports" + body: " {\"node\": \"{{ node_response.json.uuid }}\"}" + body_format: json + return_content: yes + register: port_list + - name: test port list + assert: + that: + - "port_list.json.ports|length == 1" + - "port_list.json.ports[0].address == \"00:00:00:00:00:01\"" + - name: add a second port + uri: + url: "{{ ironic_service_publicuri }}/v1/ports" + method: POST + HEADER_Content-Type: "application/json" + HEADER_X-OpenStack-Ironic-API-Version: "1.9" + body_format: json + body: " {\"node_uuid\": \"{{ node_response.json.uuid }}\", \"address\": \"00:00:00:00:00:02\"}" + status_code: 201 + return_content: yes + - name: list ports again + uri: + HEADER_Content-Type: "application/json" + HEADER_X-OpenStack-Ironic-API-Version: "1.9" + url: "{{ ironic_service_publicuri }}/v1/ports" + body: " {\"node\": \"{{ node_response.json.uuid }}\"}" + body_format: json + return_content: yes + register: port_list2 + - name: test second port exists + assert: + that: + - "port_list2.json.ports|length == 2" + - name: validate a node + uri: + url: "{{ ironic_service_publicuri }}/v1/nodes/restnode/validate" + method: GET + HEADER_X-OpenStack-Ironic-API-Version: "1.9" + status_code: 200 + return_content: yes + register: validate_node + - name: check results of validation + assert: + that: + - "validate_node.json.boot.result == false" + - "validate_node.json.boot.reason == \"Cannot validate PXE bootloader. Some parameters were missing in node's driver_info. Missing are: ['deploy_ramdisk', 'deploy_kernel']\"" + - "validate_node.json.console.result == false" + - "validate_node.json.console.reason == \"Missing 'ipmi_terminal_port' parameter in node's driver_info.\"" + - "validate_node.json.deploy.result == false" + - "validate_node.json.deploy.reason == \"Cannot validate PXE bootloader. Some parameters were missing in node's driver_info. Missing are: ['deploy_ramdisk', 'deploy_kernel']\"" + - "validate_node.json.inspect.result is none" + - "validate_node.json.inspect.reason == \"not supported\"" + - "validate_node.json.management.result == true" + - "validate_node.json.power.result == true" + - "validate_node.json.raid.result == true" + - name: update a node + uri: + url: "{{ ironic_service_publicuri }}/v1/nodes/restnode" + body: " [{\"path\": \"/name\", \"value\": \"renamednode\", \"op\": \"replace\"}]" + method: PATCH + HEADER_Content-Type: "application/json" + HEADER_X-OpenStack-Ironic-API-Version: "1.9" + status_code: 200 + return_content: yes + register: patch_node + - name: check results of update + assert: that="patch_node.json.name == 'renamednode'" + - name: delete a node + uri: + url: "{{ ironic_service_publicuri }}/v1/nodes/renamednode" + method: DELETE + HEADER_Content-Type: "application/json" + HEADER_X-OpenStack-Ironic-API-Version: "1.9" + status_code: 204 + return_content: yes + vars_files: + - test-vars.yml diff --git a/tests/test.yml b/tests/test.yml index ba2c3cd8..48e84c56 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -30,3 +30,8 @@ # Install Ironic - include: test-install-ironic.yml + +# Test REST API +- include: test-rest-api.yml + +