Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/#17379 check config permisions #82

Merged
merged 10 commits into from
Dec 4, 2024
84 changes: 45 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,82 @@
## redborder-serverspec-manager

Infrastructure integration testing for a redborder manager machine. The idea is to run the tests in a machine that is the validator local machine, so the target machine is affected by the tests.

## Installation

First, clone this repository on your workstation. Then install the gemes by executing this:
```ssh

```cmd
bundle install
```

Sometimes you need to make sure that you share your public ssh key to target machine:
```

```cmd
ssh-copy-id root@<target_ip>
```

## Running Tests

To run all tests, use the following command:
```

```cmd
rake spec
```

Optional parameters:
* TARGET_HOST: Machine where the tests will run via SSH.
* LOGIN_USERNAME: Username for SSH connection to the test machine.
* LOGIN_PASSWORD: Password for SSH connection to the test machine.
* IS_CLUSTER: Boolean to indicate if the target machine is a cluster.
* -j 10 -m: To run tests in pararell
Example with optional parameters:
```
TARGET_HOST="10.1.209.50" LOGIN_USERNAME="root" LOGIN_PASSWORD="redborder" rake spec

- **TARGET_HOST**: Machine where the tests will run via SSH.
- **LOGIN_USERNAME**: Username for SSH connection to the test machine.
- **LOGIN_PASSWORD**: Password for SSH connection to the test machine.
- **IS_CLUSTER**: Boolean to indicate if the target machine is a cluster.
- **-j 10 -m**: To run tests in pararell
Example with optional parameters:

```cmd
IS_CLUSTER="false" TARGET_HOST="10.1.209.50" LOGIN_USERNAME="root" LOGIN_PASSWORD="redborder" rake spec
```

To run a specific test type, use the following command:
```

```cmd
rake spec:configuration
```

To run a specific test in a spec file, better use tags:
```

```cmd
rspec --tag tag_name
To run a specific script test, use the following command:
```
rspec spec/services/cgroup_spec.rb

To run a specific script test, use the following command:

```cmd
rspec spec/services/cgroup_spec.rb
```

List of Available Rake Tasks:
To view the list of available Rake tasks, use the following command:
```

```cmd
rake -T
```

## Developing tests

On creating a new test, is important to follow the Rakefile structure as the directory structure.
When creating a new test, it is important to follow the directory structure outlined in the Rakefile. This structure helps maintain organization and clarity within the test suite.

Directory structure:
```
└── spec/
├── spec_helper.rb
├── services/
│ ├── ... > PUT YOUR TESTS HERE
├── configuration/
│ ├── ... > OR HERE
├── modules/
│ ├── monitor
| ├── ... > OR HERE
└── helpers/
├── ...
```

Tag a describe to run by specific command ie:
```
describe ("Any test for this"), :tagname do
```
```conf
spec/
├── spec_helper.rb
├── services/
│ ├── ... # Place your service-related tests here
├── configuration/
│ ├── ... # Place your configuration-related tests here
├── modules/
│ ├── monitor/
│ ├── ... # Place your module-related tests here
└── helpers/
├── ... # Place your helper-related tests here
```
31 changes: 31 additions & 0 deletions spec/configuration/kafka_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'spec_helper'
set :os, family: 'redhat', release: '9', arch: 'x86_64'
pipelines = %w[
rb_event rb_event_post
rb_monitor rb_monitor_post
rb_loc rb_locne rb_loc_post rb_loc_post_discard rb_location
rb_mobile
rb_radius
rb_nmsp
rb_metrics
rb_state rb_state_post
rb_vault rb_vault_post
rb_http2k_sync
sflow
]

describe 'Check logstash config' do
describe file('/etc/kafka/topics_definitions.yml') do
it { should exist }
it { should be_file }
it { should be_readable }
it { should be_writable.by_user('kafka') }
it { should_not be_writable.by('others') }
it { should_not be_executable }
pipelines.each do |pipeline|
it { should contain pipeline }
end
end
end
2 changes: 1 addition & 1 deletion spec/configuration/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
sync = command('ip addr show').stdout
it 'Have a network sync' do
interfaces_with_ip = sync.scan(/inet\s+(\d+\.\d+\.\d+\.\d+)/).flatten
if ENV['IS_CLUSTER']
if ENV['IS_CLUSTER'] == 'true'
expect(interfaces_with_ip.length).to be >= 3
else
skip 'One node does not need sync interface'
Expand Down
Loading