Add http-fileserver role

Role will allow to easily serve static content over http.
python simple http server wrapped into systemd unit

Change-Id: I7726b973ad77ab3a58819ff48033a74095ed3ea0
This commit is contained in:
Kostiantyn Kalynovskyi 2020-01-20 16:52:38 +00:00
parent 3f0f471ed3
commit c9e3feceae
10 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,3 @@
http_fileserver_serve_dir: /srv/http-server
http_fileserver_serve_port: 8099
http_server_action: install

View File

@ -0,0 +1,11 @@
- name: reload systemd configuration
become: yes
systemd:
daemon_reload: yes
- name: http file server restarted
service:
name: simple-http-{{ http_fileserver_name | default('default') }}.service
state: restarted
enabled: true
become: true

View File

@ -0,0 +1,33 @@
- name: install simplehttpserver package
apt:
name:
- python3
state: present
become: true
- name: set http server systemd unit content
set_fact:
http_fileserver_unit_content: |
[Unit]
Description=Simple http server
After=syslog.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 -m http.server {{ http_fileserver_serve_port }}
StandardOutput=syslog
StandardError=syslog
WorkingDirectory={{ http_fileserver_serve_dir }}
[Install]
WantedBy=multi-user.target
- name: Create systemd unit
copy:
content: "{{ http_fileserver_unit_content }}"
dest: /etc/systemd/system/simple-http-{{ http_fileserver_name | default('default') }}.service
notify:
- reload systemd configuration
- http file server restarted
become: true

View File

@ -0,0 +1 @@
- include_tasks: "{{ http_server_action }}.yml"

View File

@ -0,0 +1,6 @@
- name: ensure http service is stopped
service:
name: simple-http-{{ http_fileserver_name | default('default') }}.service
state: stopped
enabled: false
become: true

View File

@ -0,0 +1,30 @@
- name: Include test variables.
include_vars:
file: vars.yml
- name: ensure serve directory exists
file:
path: "{{ http_fileserver_serve_dir }}"
state: directory
mode: "0755"
become: true
- name: install http-fileserver
include_role:
name: http-fileserver
- name: trigger all saved handlers
meta: flush_handlers
- name: copy test file to serve directory
become: true
copy:
content: "{{ http_file_server_test_file_content }}"
dest: "{{ http_fileserver_serve_dir }}/{{ http_fileserver_test_file_name }}"
register: file_copy_command
- name: download test file
get_url:
url: "http://localhost:{{ http_fileserver_serve_port }}/{{ http_fileserver_test_file_name }}"
dest: "/tmp/{{ http_fileserver_test_file_name }}"
checksum: "sha1:{{ file_copy_command.checksum }}"

View File

@ -0,0 +1,4 @@
http_fileserver_serve_dir: /srv/test-dir
http_fileserver_serve_port: 8095
http_file_server_test_file_content: "something to test"
http_fileserver_test_file_name: "test-file"

View File

@ -10,6 +10,7 @@
- libvirt-domain
- redfish-emulator
- airship-libvirt-gate
- http-fileserver
- name: run tests against defined roles
include_tasks: "../../roles/{{ role_name }}/tests/main.yml"
with_items: "{{ test_subject_roles | default(test_subject_roles_default) }}"

View File

@ -15,6 +15,14 @@
run: tests/ansible/lint.yml
nodeset: ubuntu-single-airship
- job:
name: zuul-airship-roles-fileserver
run: tests/ansible/role-test-runner.yml
vars:
test_subject_roles:
- http-fileserver
nodeset: ubuntu-single-airship
- job:
name: zuul-airship-roles-test-libvirt
run: tests/ansible/role-test-runner.yml

View File

@ -4,8 +4,10 @@
- ansible-lint-airship
- zuul-airship-roles-test-libvirt
- zuul-airship-roles-test-airship-gate
- zuul-airship-roles-fileserver
gate:
jobs:
- ansible-lint-airship
- zuul-airship-roles-test-libvirt
- zuul-airship-roles-test-airship-gate
- zuul-airship-roles-fileserver