Skip to content

Commit

Permalink
Add the redis server as a multihost sync example
Browse files Browse the repository at this point in the history
Co-authored-by: Petr Šplíchal <psplicha@redhat.com>
  • Loading branch information
jscotka and psss committed Dec 1, 2023
1 parent c59c98c commit afae40b
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -815,11 +815,17 @@ libraries, e.g. one of the following:
* `a native beakerlib library`__ by Dalibor Pospisil, a
distributed version of Ondrej Moris's library, supporting any
number of hosts.
* `redis server`__ by Jan Scotka, a simple key-value exchange
solution between machines. The primary purpose is data
transfer. It is not a library prepared for synchronization,
but it's possible to use it as well. See the example to learn
how to set up a redis server and use it.

__ https://github.com/beaker-project/rhts
__ https://github.com/beakerlib/sync/tree/master/sync
__ https://github.com/RedHat-SP-Security/keylime-tests/tree/main/Library/sync
__ https://github.com/beakerlib/ControlFlow/tree/master/sync
__ https://github.com/teemtee/tmt/tree/main/examples/redis


Current Limits
Expand Down
1 change: 1 addition & 0 deletions examples/redis/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
8 changes: 8 additions & 0 deletions examples/redis/ansible/setup_server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- hosts: all
vars:
- version: "{{ ansible_distribution_version }}"
tasks:
- import_tasks: tasks/redis.yml
- import_tasks: tasks/redis_variables.yml
...
63 changes: 63 additions & 0 deletions examples/redis/ansible/tasks/redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
- name: setup syncing redis server
package: name={{ item }} state=present
with_items:
- redis
- firewalld
become: true

- name: bind to all interfaces
ansible.builtin.lineinfile:
path: /etc/redis/redis.conf
regexp: '^bind '
line: "bind 0.0.0.0 -::0"
become: true

- name: remove protected mode
ansible.builtin.lineinfile:
path: /etc/redis/redis.conf
regexp: '^protected-mode'
line: "protected-mode no"
become: true


- name: Start redis service, if not started
ansible.builtin.service:
name: redis
state: restarted
enabled: yes
become: true


- name: Start firewalld service, if not started
ansible.builtin.service:
name: firewalld
state: started
enabled: yes
become: true

- name: add sshd to firewalld
ansible.posix.firewalld:
service: ssh
permanent: yes
state: enabled
immediate: true
become: true

- name: add redis to firewalld
ansible.posix.firewalld:
service: redis
permanent: yes
state: enabled
immediate: true
become: true

- name: add redis-sentinel to firewall
ansible.posix.firewalld:
service: redis-sentinel
permanent: yes
state: enabled
immediate: true
become: true

# redis-cli -h $GUEST set variable value
# redis-cli -h $GUEST get variable
5 changes: 5 additions & 0 deletions examples/redis/ansible/tasks/redis_variables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: Set variables into redis database
ansible.builtin.shell: |
redis-cli set key value1
args:
executable: /bin/bash
43 changes: 43 additions & 0 deletions examples/redis/plan.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
description: |
This is an example how to use redis for data synchronization
between guests

how to send data to server:
redis-cli -h $GUEST set variable value

how to get data from server:
redis-cli -h $GUEST get variable

If you need more features like waiting for events or atomic
commands or deleting keys see doc for redis commands
https://redis.io/commands/

discover:
- how: fmf
where:
- guest

provision:
- how: virtual
role: server
image: fedora
connection: system
- how: virtual
role: guest
image: fedora
connection: system

prepare:
- how: ansible
playbook:
- ansible/setup_server.yml
extra-args: '-vvv'
where:
- server
- how: install
package: redis
where:
- guest

execute:
how: tmt
3 changes: 3 additions & 0 deletions examples/redis/test.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
summary: This is an example of the redis sync
test: ./test.sh
framework: shell
10 changes: 10 additions & 0 deletions examples/redis/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -eux

. "$TMT_TOPOLOGY_BASH"
# verify that TOPLOGY to be defined to be able to run the tests.
test -z "${TMT_ROLES[server]}" && exit 125

SERVER=${TMT_GUESTS[${TMT_ROLES[server]}.hostname]}
redis-cli -h $SERVER get key | grep value1

0 comments on commit afae40b

Please sign in to comment.