Commit 176d351e authored by Rémi Duraffort's avatar Rémi Duraffort
Browse files

lab: print file diff as unified diffs


Signed-off-by: Rémi Duraffort's avatarRémi Duraffort <remi.duraffort@linaro.org>
parent 1ce47182
Pipeline #12892 passed with stages
in 2 minutes and 41 seconds
......@@ -19,9 +19,8 @@
import contextlib
from dataclasses import asdict, dataclass, field, fields, MISSING
import os
import difflib
from pathlib import Path
import subprocess
from typing import Any, Dict, List, Set
import xmlrpc
......@@ -30,6 +29,16 @@ import ruamel.yaml
from lavacli import colors
def print_file_diff(src, dst):
if src is None:
print(" | + None")
elif dst is None:
print(" | - None")
else:
diffs = difflib.unified_diff(src.split("\n"), dst.split("\n"), lineterm="")
print(" | " + "\n | ".join(list(diffs)[2:]))
class Base:
@classmethod
def new(cls, **kwargs):
......@@ -338,6 +347,7 @@ def handle_apply(proxy, options, config):
hc = None
if dt.get_health_check(base) != hc:
print(f" {colors.yellow}-> health-check{colors.reset}")
print_file_diff(hc, dt.get_health_check(base))
if not options.dry_run:
proxy.scheduler.device_types.set_health_check(
dt.name, dt.get_health_check(base)
......@@ -352,6 +362,7 @@ def handle_apply(proxy, options, config):
template = None
if dt.get_template(base) != template:
print(f" {colors.yellow}-> template{colors.reset}")
print_file_diff(template, dt.get_template(base))
if not options.dry_run:
proxy.scheduler.device_types.set_template(
dt.name, dt.template(base)
......@@ -394,6 +405,7 @@ def handle_apply(proxy, options, config):
wconfig = None
if worker.get_config(base) != wconfig:
print(f" {colors.yellow}-> config{colors.reset}")
print_file_diff(wconfig, worker.get_config(base))
if not options.dry_run:
proxy.scheduler.workers.set_config(
dt.name, worker.get_config(base)
......@@ -408,6 +420,7 @@ def handle_apply(proxy, options, config):
wenv = None
if worker.get_env(base) != wenv:
print(f" {colors.yellow}-> env{colors.reset}")
print_file_diff(wenv, worker.get_env(base))
if not options.dry_run:
proxy.scheduler.workers.set_env(dt.name, worker.get_env(base))
......@@ -420,6 +433,7 @@ def handle_apply(proxy, options, config):
wenv_dut = None
if worker.get_env_dut(base) != wenv_dut:
print(f" {colors.yellow}-> env-dut{colors.reset}")
print_file_diff(wenv_dut, worker.get_env_dut(base))
if not options.dry_run:
proxy.scheduler.workers.set_env_dut(
dt.name, worker.get_env_dut(base)
......@@ -486,6 +500,7 @@ def handle_apply(proxy, options, config):
if device.get_dict(base) != ddict:
print(f" {colors.yellow}-> dictionary{colors.reset}")
print_file_diff(ddict, device.get_dict(base))
if not options.dry_run:
proxy.scheduler.devices.set_dictionary(
device.hostname, device.get_dict(base)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment