Skip to content

Commit

Permalink
lint(scap_open): lint scap_open role
Browse files Browse the repository at this point in the history
Signed-off-by: Aldo Lacuku <aldo@lacuku.eu>
  • Loading branch information
alacuku committed Jul 19, 2023
1 parent 6195172 commit 45ffcfe
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 85 deletions.
3 changes: 1 addition & 2 deletions master-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
# Master playbook to run once the whole configuration.
# Check the specific playbooks and roles to have more information.
- import_playbook: bootstrap.yml
#- import_playbook: modern-bpf-test.yml
- import_playbook: git_repos.yml
- import_playbook: scap-open-test.yml
- import_playbook: scap_open.yml
173 changes: 94 additions & 79 deletions roles/scap-open-test/tasks/main.yml → roles/scap_open/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,195 +1,210 @@
---
# tasks file for scap-open-test
# tasks file for scap_open
- name: Setting output directory for results
set_fact: output_dest_dir="{{ output_dir }}/scap-open-test/{{ inventory_hostname }}"
ansible.builtin.set_fact:
output_dest_dir: "{{ output_dir }}/scap-open-test/{{ inventory_hostname }}"

- name: Create output directory on localhost
become: false
delegate_to: localhost
block:
- name: Create output directory ({{ output_dir }}) if it does not exist
file:
- name: Create output directory if it does not exist ({{ output_dir }})
ansible.builtin.file:
path: "{{ output_dest_dir }}"
state: directory
mode: '0755'

become: false
delegate_to: localhost

- name: Prepare the build directory
block:
# TODO: move this elsewhere.
- name: Fix the dns issues
shell: |
ansible.builtin.shell: |
unlink /etc/resolv.conf && echo 'nameserver 1.1.1.1' > /etc/resolv.conf
changed_when: false

- name: Create cmake output dir
file:
ansible.builtin.file:
path: "{{ remote_repos_folder }}/repos/{{ repos['libs'].name }}/build"
state: directory
mode: "0755"
register: cmake_result

- name: Check btf support
stat:
ansible.builtin.stat:
path: /sys/kernel/btf/vmlinux
register: btf_support

- name: Prepare cmake for repository
shell: |
cmake -DUSE_BUNDLED_DEPS=ON -DBUILD_LIBSCAP_MODERN_BPF={{ btf_support.stat.exists }} -DBUILD_LIBSCAP_GVISOR=OFF -DBUILD_BPF=true -DCREATE_TEST_TARGETS=OFF ..
args:
ansible.builtin.command:
cmd: >
cmake
-DUSE_BUNDLED_DEPS=ON
-DBUILD_LIBSCAP_MODERN_BPF={{ btf_support.stat.exists }}
-DBUILD_LIBSCAP_GVISOR=OFF
-DBUILD_BPF=true
-DCREATE_TEST_TARGETS=OFF
..
chdir: "{{ remote_repos_folder }}/repos/{{ repos['libs'].name }}/build"
changed_when: false
register: cmake_result

rescue:
- name: Print error message to stdout --- build directory
ansible.builtin.debug:
var: cmake_result
always:
- name: Dump error message to file
copy:
ansible.builtin.copy:
content: "{{ cmake_result | to_nice_json }}"
dest: "{{ output_dest_dir }}/cmake-build-directory.json"
mode: '0755'
delegate_to: localhost
become: false
rescue:
- name: Print error message to stdout
debug:
var: cmake_result

- name: Build scap-open binary
block:
- name: Build scap-open
shell: |
make scap-open -j {{ cpus }}
args:
ansible.builtin.command:
cmd: make scap-open -j {{ cpus }}
chdir: "{{ remote_repos_folder }}/repos/{{ repos['libs'].name }}/build"
register: scap_open_result
changed_when: false
rescue:
- name: Print error message to stdout --- build scap-open binary
ansible.builtin.debug:
var: scap_open_result
always:
- name: Dump error message to file
copy:
ansible.builtin.copy:
content: "{{ scap_open_result | to_nice_json }}"
dest: "{{ output_dest_dir }}/build-scap-open-binary.json"
mode: '0755'
delegate_to: localhost
become: false
rescue:
- name: Print error message to stdout
debug:
var: scap_open_result

- name: Build and load the kernel module
block:
- name: Unload the kernel module
shell: |
rmmod driver/scap.ko
ignore_errors: True
args:
ansible.builtin.command:
cmd: rmmod driver/scap.ko
chdir: "{{ remote_repos_folder }}/repos/{{ repos['libs'].name }}/build"
failed_when: false
changed_when: false

- name: Build kmod
shell: |
make driver -j {{ cpus }}
args:
ansible.builtin.command:
cmd: make driver -j {{ cpus }}
chdir: "{{ remote_repos_folder }}/repos/{{ repos['libs'].name }}/build"
register: km_result
changed_when: false

- name: Load the kernel module
shell: |
insmod driver/scap.ko
args:
ansible.builtin.command:
cmd: insmod driver/scap.ko
chdir: "{{ remote_repos_folder }}/repos/{{ repos['libs'].name }}/build"
register: km_result
changed_when: false
rescue:
- name: Print error message to stdout --- kernel module
ansible.builtin.debug:
var: km_result
always:
- name: Dump error message to file
copy:
ansible.builtin.copy:
content: "{{ km_result | to_nice_json }}"
dest: "{{ output_dest_dir }}/build-kernel-module.json"
mode: '0755'
delegate_to: localhost
become: false
rescue:
- name: Print error message to stdout
debug:
var: km_result

- name: Scap open + kernel module
- name: Scap-open + kernel module
block:
- name: Run scap-open with kernel module
shell: |
./libscap/examples/01-open/scap-open --num_events 50 --kmod
args:
ansible.builtin.command:
cmd: ./libscap/examples/01-open/scap-open --num_events 50 --kmod
chdir: "{{ remote_repos_folder }}/repos/{{ repos['libs'].name }}/build"
register: result
changed_when: false

- name: Unload the kernel module
shell: |
rmmod driver/scap.ko
args:
ansible.builtin.command:
cmd: rmmod driver/scap.ko
chdir: "{{ remote_repos_folder }}/repos/{{ repos['libs'].name }}/build"
register: result
changed_when: false
rescue:
- name: Print error message to stdout -- scap-open + kernel module
ansible.builtin.debug:
var: result
always:
- name: Dump error message to file
copy:
ansible.builtin.copy:
content: "{{ result | to_nice_json }}"
dest: "{{ output_dest_dir }}/scap-open-and-kernel-module.json"
mode: '0755'
delegate_to: localhost
become: false
rescue:
- name: Print error message to stdout
debug:
var: result

- name: Build bpf probe
block:
- name: Build bpf probe
shell: |
make bpf -j {{ cpus }}
args:
ansible.builtin.command:
cmd: make bpf -j {{ cpus }}
chdir: "{{ remote_repos_folder }}/repos/{{ repos['libs'].name }}/build"
register: bpf_probe_result
changed_when: false
rescue:
- name: Print error message to stdout --- build bpf probe
ansible.builtin.debug:
var: result
always:
- name: Dump error message to file
copy:
ansible.builtin.copy:
content: "{{ bpf_probe_result | to_nice_json }}"
dest: "{{ output_dest_dir }}/build-bpf-probe.json"
mode: '0755'
delegate_to: localhost
become: false
rescue:
- name: Print error message to stdout
debug:
var: result

- name: Scap open + bpf probe
- name: Scap-open + bpf probe
block:
- name: Run scap-open with bpf probe
shell: |
./libscap/examples/01-open/scap-open --num_events 50 --bpf driver/bpf/probe.o
args:
ansible.builtin.command:
cmd: ./libscap/examples/01-open/scap-open --num_events 50 --bpf driver/bpf/probe.o
chdir: "{{ remote_repos_folder }}/repos/{{ repos['libs'].name }}/build"
register: result
changed_when: false
rescue:
- name: Print error message to stdout --- scap-open + bpf probe
ansible.builtin.debug:
var: result
always:
- name: Dump error message to file
copy:
ansible.builtin.copy:
content: "{{ result | to_nice_json }}"
dest: "{{ output_dest_dir }}/scap-open-and-bpf-probe.json"
mode: '0755'
delegate_to: localhost
become: false
rescue:
- name: Print error message to stdout
debug:
var: result

- name: Scap-open + modern probe
block:
- name: Run scap-open with modern-probe
shell: |
./libscap/examples/01-open/scap-open --num_events 50 --modern_bpf
args:
ansible.builtin.command:
cmd: ./libscap/examples/01-open/scap-open --num_events 50 --modern_bpf
chdir: "{{ remote_repos_folder }}/repos/{{ repos['libs'].name }}/build"
register: result
when: btf_support.stat.exists
changed_when: false
rescue:
- name: Print error message to stdout --- scap-open + modern probe
ansible.builtin.debug:
var: result
always:
- name: Dump error message to file
copy:
ansible.builtin.copy:
content: "{{ result | to_nice_json }}"
dest: "{{ output_dest_dir }}/scap-open-and-modern-probe.json"
mode: '0755'
delegate_to: localhost
become: false
rescue:
- name: Print error message to stdout
debug:
var: result
9 changes: 5 additions & 4 deletions scap-open-test.yml → scap_open.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Playbook used to run scap-open-test role.
# Check the role for more information
- hosts: all
gather_facts: no
- name: Play that runs probes tests using scap-open binary
hosts: all
gather_facts: false
remote_user: "{{ remote_user }}"
become: yes
become: true
serial: 30
roles:
- scap-open-test
- scap_open

0 comments on commit 45ffcfe

Please sign in to comment.