diff --git a/examples/playbooks/gate/airship.yml b/examples/playbooks/gate/airship.yml new file mode 100644 index 0000000..f377013 --- /dev/null +++ b/examples/playbooks/gate/airship.yml @@ -0,0 +1,9 @@ +--- +- hosts: primary + tasks: + - name: deploy-gate + include_role: + name: airship-libvirt-gate + vars: + gate_flavor: small + gate_action: build-infra diff --git a/roles/airship-libvirt-gate/defaults/main.yml b/roles/airship-libvirt-gate/defaults/main.yml new file mode 100644 index 0000000..e597dc9 --- /dev/null +++ b/roles/airship-libvirt-gate/defaults/main.yml @@ -0,0 +1,86 @@ +airship_gate_names: + provision_network: air_prov + provision_network_bridge: "prov_br" + nat_network: "air_nat" + nat_network_bridge: "nat_br" + ephemeral_vm: air-ephemeral + target_vm_prefix: "air-target" + target_separator: "-" + target_volume_prefix: "vol_target" + ephemeral_volume: "vol_ephemeral" + pool: airship + +airship_gate_ipam: + nat_network: + bridge_ip: "10.23.25.1" + dhcp_start: "10.23.25.100" + dhcp_end: "10.23.25.199" + provision_network: + bridge_ip: "10.23.24.1" + +airship_gate_redfish: + port: 8000 + bind_address: "127.0.0.1" + +airship_gate_flavors: + small: + target_vm_memory_mb: 1024 + target_vm_vcpus: 1 + ephemeral_vm_memory_mb: 1024 + ephemeral_vm_vcpus: 1 + ephemeral_disk_size: 20G + target_disk_size: 10G + disk_format: qcow2 + target_vms_count: 3 + +airship_gate_libvirt_pools: + - path: /var/lib/libvirt/airship + name: "{{ airship_gate_names.pool }}" + +airship_gate_libvirt_domain: + state: running + name: 'vm1' + memory_mb: 2048 + vcpus: 1 + volumes: + - name: 'volume-1' + device: 'disk' + format: 'qcow2' + pool: 'airship' + interfaces: + - network: "{{ airship_gate_names.nat_network }}" + - network: "{{ airship_gate_names.provision_network }}" + +airship_gate_libvirt_networks: + - network_action: create + autostart: false + name: "{{ airship_gate_names.nat_network }}" + spec: + forward: + mode: nat + nat: + port: + - start: 1024 + end: 65535 + bridge: + name: "{{ airship_gate_names.nat_network_bridge }}" + stp: 'on' + delay: '0' + ip: + address: "{{ airship_gate_ipam.nat_network.bridge_ip }}" + netmask: "255.255.255.0" + dhcp: + - range: + start: "{{ airship_gate_ipam.nat_network.dhcp_start }}" + end: "{{ airship_gate_ipam.nat_network.dhcp_end }}" + - network_action: create + autostart: false + name: "{{ airship_gate_names.provision_network }}" + spec: + bridge: + name: "{{ airship_gate_names.provision_network_bridge }}" + stp: 'on' + delay: '0' + ip: + address: "{{ airship_gate_ipam.provision_network.bridge_ip }}" + netmask: "255.255.255.0" \ No newline at end of file diff --git a/roles/airship-libvirt-gate/tasks/build-infra.yml b/roles/airship-libvirt-gate/tasks/build-infra.yml new file mode 100644 index 0000000..90a4392 --- /dev/null +++ b/roles/airship-libvirt-gate/tasks/build-infra.yml @@ -0,0 +1,103 @@ +- name: verify that gate flavor is defined + assert: + that: + - gate_flavor is defined + +- name: set flavor variables. + set_fact: + chosen_flavor: "{{ airship_gate_flavors[gate_flavor] }}" + +- name: install libvirt + include_role: + name: libvirt-install + +- name: create pool + include_role: + name: libvirt-pool + vars: + libvirt_pool: "{{ item }}" + ansible_become: true + with_items: "{{ airship_gate_libvirt_pools }}" + +- name: create networks + include_role: + name: libvirt-network + with_items: "{{ airship_gate_libvirt_networks }}" + vars: + ansible_become: true + libvirt_network: "{{ item }}" + network_action: create + +- name: Create ephemeral volume + include_role: + name: libvirt-volume + vars: + libvirt_volume: + name: "{{ airship_gate_names.ephemeral_volume }}" + size: "{{ chosen_flavor.ephemeral_disk_size }}" + pool: "{{ airship_gate_names.pool }}" + volume_action: create + ansible_become: true +- name: Create target volumes + include_role: + name: libvirt-volume + vars: + ansible_become: true + libvirt_volume: + name: "{{ airship_gate_names.target_volume_prefix }}-{{ vm_index }}" + size: "{{ chosen_flavor.target_disk_size }}" + pool: "{{ airship_gate_names.pool }}" + format: "{{ chosen_flavor.disk_format }}" + volume_action: create + loop_control: + loop_var: vm_index + with_sequence: "start=1 end={{ chosen_flavor.target_vms_count }}" + +- name: Create target domains + include_role: + name: libvirt-domain + vars: + ansible_become: true + libvirt_domain: + state: shutdown + name: "{{ airship_gate_names.target_vm_prefix }}-{{ vm_index }}" + memory_mb: "{{ chosen_flavor.target_vm_memory_mb }}" + vcpus: "{{ chosen_flavor.target_vm_vcpus }}" + volumes: + - name: "{{ airship_gate_names.target_volume_prefix }}-{{ vm_index }}" + device: "disk" + format: "{{ chosen_flavor.disk_format }}" + pool: "{{ airship_gate_names.pool }}" + interfaces: + - network: "{{ airship_gate_names.nat_network }}" + - network: "{{ airship_gate_names.provision_network }}" + loop_control: + loop_var: vm_index + with_sequence: "start=1 end={{ chosen_flavor.target_vms_count }}" + +- name: Create ephemeral domain + include_role: + name: libvirt-domain + vars: + ansible_become: true + libvirt_domain: + state: shutdown + name: "{{ airship_gate_names.ephemeral_vm }}" + memory_mb: "{{ chosen_flavor.ephemeral_vm_memory_mb }}" + vcpus: "{{ chosen_flavor.ephemeral_vm_vcpus }}" + volumes: + - name: "{{ airship_gate_names.ephemeral_volume }}" + device: "disk" + format: "{{ chosen_flavor.disk_format }}" + pool: "{{ airship_gate_names.pool }}" + interfaces: + - network: "{{ airship_gate_names.nat_network }}" + - network: "{{ airship_gate_names.provision_network }}" + +- name: install and start redfish emulator + include_role: + name: redfish-emulator + vars: + redfish_action: "install" + redfish_emulator_bind_ip: "{{ airship_gate_redfish.bind_address }}" + redfish_emulator_bind_port: "{{ airship_gate_redfish.port }}" diff --git a/roles/airship-libvirt-gate/tasks/main.yml b/roles/airship-libvirt-gate/tasks/main.yml new file mode 100644 index 0000000..700beeb --- /dev/null +++ b/roles/airship-libvirt-gate/tasks/main.yml @@ -0,0 +1 @@ +- include_tasks: "{{ gate_action }}.yml" \ No newline at end of file diff --git a/roles/airship-libvirt-gate/tests/main.yml b/roles/airship-libvirt-gate/tests/main.yml new file mode 100644 index 0000000..8bcea38 --- /dev/null +++ b/roles/airship-libvirt-gate/tests/main.yml @@ -0,0 +1,41 @@ +- name: Include test variables. + include_vars: + file: vars.yml + +- name: deploy-gate + include_role: + name: airship-libvirt-gate + vars: + gate_flavor: small + gate_action: build-infra + +- name: query redfish to make sure it has runnig domains + uri: + url: http://{{ airship_gate_redfish.bind_address }}:{{ airship_gate_redfish.port }}/redfish/v1/Systems?format=json + method: GET + return_content: yes + register: redfish_response + +- name: debug redfish machines + debug: + var: redfish_response + +- name: save ids to list + uri: + url: "http://{{ airship_gate_redfish.bind_address }}:{{ airship_gate_redfish.port }}{{ item.value }}?format=json" + method: GET + return_content: yes + with_dict: "{{ redfish_response.json.Members }}" + register: systems_details + +- name: deploy ephemeral host + set_fact: + ephemeral_domain_id: "{{ systems_details | json_query(query_string) | join('') }}" + vars: + query_string: "results[?json.Name=='{{ airship_gate_names.ephemeral_vm }}'].json.Id" + +- name: verify that id is not empty + assert: + that: + - ephemeral_domain_id is defined + - (ephemeral_domain_id | length) > 1 \ No newline at end of file diff --git a/roles/airship-libvirt-gate/tests/vars.yml b/roles/airship-libvirt-gate/tests/vars.yml new file mode 100644 index 0000000..ff1af1c --- /dev/null +++ b/roles/airship-libvirt-gate/tests/vars.yml @@ -0,0 +1,15 @@ +airship_gate_redfish: + port: 8000 + bind_address: "127.0.0.1" + +airship_gate_names: + provision_network: air_prov + provision_network_bridge: "prov_br" + nat_network: "air_nat" + nat_network_bridge: "nat_br" + ephemeral_vm: air-ephemeral + target_vm_prefix: "air-target" + target_separator: "-" + target_volume_prefix: "vol_target" + ephemeral_volume: "vol_ephemeral" + pool: airship \ No newline at end of file diff --git a/tests/ansible/role-test-runner.yml b/tests/ansible/role-test-runner.yml index bb14bf1..d9d6575 100644 --- a/tests/ansible/role-test-runner.yml +++ b/tests/ansible/role-test-runner.yml @@ -9,6 +9,7 @@ - libvirt-volume - libvirt-domain - redfish-emulator + - airship-libvirt-gate - name: run tests against defined roles include_tasks: "../../roles/{{ role_name }}/tests/main.yml" with_items: "{{ test_subject_roles | default(test_subject_roles_default) }}" diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index cae4d1f..c806fa2 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -24,4 +24,14 @@ - libvirt-pool - libvirt-volume - libvirt-domain + - redfish-emulator nodeset: ubuntu-single-airship + +- job: + name: zuul-airship-roles-test-airship-gate + run: tests/ansible/role-test-runner.yml + vars: + test_subject_roles: + - airship-libvirt-gate + nodeset: ubuntu-single-airship + diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml index 67f4915..f2fb241 100644 --- a/zuul.d/project.yaml +++ b/zuul.d/project.yaml @@ -3,7 +3,9 @@ jobs: - ansible-lint-airship - zuul-airship-roles-test-libvirt + - zuul-airship-roles-test-airship-gate gate: jobs: - ansible-lint-airship - zuul-airship-roles-test-libvirt + - zuul-airship-roles-test-airship-gate