Skip to content

Commit c5a33bc

Browse files
committed
fix tests with plugins as dependencies
1 parent d89caaf commit c5a33bc

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

.github/scripts/list-plugins-to-build-and-test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,22 @@ def add_package_info(packaging_file, build=True, test=True):
4343
if line.startswith("package "):
4444
plugin_package_name = line.split()[1].replace(";", "")
4545
break
46+
packaging_dir = Path(packaging_file).parent
47+
test_dependencies = []
48+
rpm_file = f'{packaging_dir}/rpm.json'
49+
if rpm_file.exists():
50+
with open(rpm_file) as rf:
51+
rpm_data = json.load(rf)
52+
test_dependencies = [dependency for dependency in rpm_data.get('dependencies', []) if dependency.lower().startswith('centreon-plugin-')]
4653
if packaging['pkg_name'] not in list_plugins:
4754
list_plugins[packaging['pkg_name']] = {
4855
"perl_package": plugin_package_name,
4956
"command": packaging['plugin_name'],
5057
"paths": plugin_paths,
5158
"build": build,
5259
"test": test,
53-
"runner_id": runner_id
60+
"runner_id": runner_id,
61+
"test_dependencies": test_dependencies
5462
}
5563
if runner_id == max_runners:
5664
runner_id = 1

.github/scripts/test-plugins.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,18 @@ def refresh_packet_manager(archi, logs_dir):
4747

4848

4949
# Install plugin, from local file if build is true, from repository if false.
50-
def install_plugin(plugin, archi, build, logs_dir):
50+
def install_plugin(plugin, archi, build, logs_dir, dependencies=None):
51+
if dependencies:
52+
for dep in dependencies:
53+
if archi == "deb":
54+
local_exists = len(glob.glob(f"./{dep.lower()}*.deb")) > 0
55+
else:
56+
local_exists = len(glob.glob(f"./{dep}*.rpm")) > 0
57+
if local_exists:
58+
print(f"Installing test dependency {dep} for {plugin}")
59+
dep_status = install_plugin(dep, archi, True, logs_dir)
60+
if dep_status != 0:
61+
print(f"Warning: failed to install test dependency {dep} for {plugin}")
5162
with open(f'{logs_dir}/test-plugins-installation.log', "a") as outfile:
5263
if archi == "deb":
5364
if build:
@@ -177,13 +188,13 @@ def remove_plugin(plugin, archi, logs_dir):
177188
parser.add_argument('--runner-id', type=int, help='ID du runner pour le test des plugins')
178189
parser.add_argument('--logs-dir', type=str, help='Répertoire des logs', default='/var/log')
179190
parser.add_argument('--reports-dir', type=str, help='Répertoire des rapports', default='reports')
180-
parser.add_argument('--skip-robot-tests', type=bool, help='True to skip robot tests, default value: False', default=False)
191+
parser.add_argument('--skip-robot-tests', type=str, help='True to skip robot tests, default value: False', default='false')
181192
args = parser.parse_args()
182193

183194
launch_snmp_sim()
184195
archi = args.extension # expected either deb or rpm.
185196
logs_dir = args.logs_dir
186-
skip_robot_tests = args.skip_robot_tests
197+
skip_robot_tests = args.skip_robot_tests.lower() == 'true'
187198
if args.runner_id:
188199
logs_dir = os.path.join(logs_dir, f"runner-{args.runner_id}")
189200
os.makedirs(logs_dir, exist_ok=True)
@@ -213,7 +224,9 @@ def remove_plugin(plugin, archi, logs_dir):
213224
print("Testing plugin : ", plugin)
214225

215226
nb_plugins += 1
216-
tmp = install_plugin(plugin, archi, plugins[plugin]["build"], logs_dir)
227+
228+
test_deps = plugins[plugin].get("test_dependencies", [])
229+
tmp = install_plugin(plugin, archi, plugins[plugin]["build"], logs_dir, test_deps)
217230
if tmp > 0:
218231
error_install += 1
219232
list_plugin_error.add(plugin)

.github/workflows/plugins.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ jobs:
364364
strategy:
365365
fail-fast: false
366366
matrix:
367-
#image: [testing-plugins-alma8, testing-plugins-alma9, testing-plugins-alma10, testing-plugins-jammy, testing-plugins-bullseye, testing-plugins-bookworm, testing-plugins-trixie, testing-plugins-noble, testing-plugins-bullseye-arm64]
368-
image: [testing-plugins-alma8, testing-plugins-alma9, testing-plugins-jammy, testing-plugins-bullseye, testing-plugins-bookworm, testing-plugins-noble, testing-plugins-bullseye-arm64]
367+
image: [testing-plugins-alma8, testing-plugins-alma9, testing-plugins-alma10, testing-plugins-jammy, testing-plugins-bullseye, testing-plugins-bookworm, testing-plugins-trixie, testing-plugins-noble, testing-plugins-bullseye-arm64]
369368
include:
370369
- skip_robot_tests: false
371370
- package_extension: rpm
@@ -419,6 +418,7 @@ jobs:
419418
package-extension: ${{ matrix.package_extension }}
420419
packages-cache-key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}
421420
plugins-json-cache-key: plugins-${{ github.sha }}-${{ github.run_id }}
421+
skip-robot-tests: ${{ matrix.skip_robot_tests }}
422422
secrets:
423423
registry_username: ${{ secrets.HARBOR_CENTREON_PULL_USERNAME }}
424424
registry_password: ${{ secrets.HARBOR_CENTREON_PULL_TOKEN }}

0 commit comments

Comments
 (0)