summaryrefslogtreecommitdiffstats
path: root/nixos/tests/ocsinventory-agent.nix
blob: b2cfba6dcb22d8a8db3e9e2bf3b03d0be6973470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import ./make-test-python.nix (
  { pkgs, ... }:
  {
    name = "ocsinventory-agent";

    nodes.machine =
      { pkgs, ... }:
      {
        services.ocsinventory-agent = {
          enable = true;
          settings = {
            debug = true;
            local = "/var/lib/ocsinventory-agent/reports";
            tag = "MY_INVENTORY_TAG";
          };
        };
      };

    testScript = ''
      path = "/var/lib/ocsinventory-agent/reports"

      # Run the agent to generate the inventory file in offline mode
      start_all()
      machine.succeed("mkdir -p {}".format(path))
      machine.wait_for_unit("ocsinventory-agent.service")
      machine.wait_until_succeeds("journalctl -u ocsinventory-agent.service | grep 'Inventory saved in'")

      # Fetch the path to the generated inventory file
      report_file = machine.succeed("find {}/*.ocs -type f | head -n1".format(path))

      with subtest("Check the tag value"):
        tag = machine.succeed(
          "${pkgs.libxml2}/bin/xmllint --xpath 'string(/REQUEST/CONTENT/ACCOUNTINFO/KEYVALUE)' {}".format(report_file)
        ).rstrip()
        assert tag == "MY_INVENTORY_TAG", f"tag is not valid, was '{tag}'"
    '';
  }
)