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
This commit is contained in:
Neill Cox 2016-03-29 21:45:48 +11:00
parent b5d7b7986c
commit a76d3744b0
3 changed files with 161 additions and 0 deletions

11
tests/create_node.json Normal file
View File

@ -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"
}
}

145
tests/test-rest-api.yml Normal file
View File

@ -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

View File

@ -30,3 +30,8 @@
# Install Ironic
- include: test-install-ironic.yml
# Test REST API
- include: test-rest-api.yml