File 6292-snmp-test-Label-analyzis.patch of Package erlang

From 58d524f41c1565e548f8694f080eb8d25f67842a Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Wed, 10 Jul 2024 15:16:46 +0200
Subject: [PATCH 2/6] [snmp|test] Label analyzis

---
 lib/snmp/test/snmp_test_lib.erl | 387 +++++++++++++++++++-------------
 1 file changed, 228 insertions(+), 159 deletions(-)

diff --git a/lib/snmp/test/snmp_test_lib.erl b/lib/snmp/test/snmp_test_lib.erl
index 88be9643c1..acaa383c7a 100644
--- a/lib/snmp/test/snmp_test_lib.erl
+++ b/lib/snmp/test/snmp_test_lib.erl
@@ -1063,17 +1063,20 @@ do_linux_which_distro_os_release(Version, Label) ->
                     Info = linux_process_os_release(),
                     {value, {_, DistroStr}} = lists:keysearch(name, 1, Info),
                     {value, {_, VersionNo}} = lists:keysearch(version, 1, Info),
-                    io:format("Linux: ~s"
-                              "~n   Distro:                  ~s"
-                              "~n   Distro Version:          ~s"
-                              "~n   TS Extra Platform Label: ~s"
-                              "~n   Product Name:            ~s"
-                              "~n",
-                              [Version, DistroStr, VersionNo, Label,
-                               linux_product_name()]),
+                    %% SLabel = simplify_label(Label),
+                    %% io:format("Linux: ~s"
+                    %%           "~n   Distro:                  ~s"
+                    %%           "~n   Distro Version:          ~s"
+                    %%           "~n   TS Extra Platform Label: ~s (~p)"
+                    %%           "~n   Product Name:            ~s"
+                    %%           "~n",
+                    %%           [Version, DistroStr, VersionNo, Label, SLabel,
+                    %%            linux_product_name()]),
+                    SLabel = linux_distro_release(Version,
+                                                  DistroStr, VersionNo, Label),
                     throw({distro,
                            {linux_distro_str_to_distro_id(DistroStr),
-                            simplify_label(Label)}})
+                            SLabel}})
                 end
             catch
                 throw:{distro, _} = DISTRO ->
@@ -1084,7 +1087,29 @@ do_linux_which_distro_os_release(Version, Label) ->
         _ ->
             retry
     end.
-	    
+
+
+linux_distro_release(Version, Distro, Label) ->
+    SLabel = simplify_label(Label),
+    io:format("Linux: ~s"
+              "~n   Distro:                  ~s"
+              "~n   TS Extra Platform Label: ~s (~p)"
+              "~n   Product Name:            ~s"
+              "~n",
+              [Version, Distro, Label, SLabel, linux_product_name()]),
+    SLabel.
+
+linux_distro_release(Version, Distro, DVersion, Label) ->
+    SLabel = simplify_label(Label),
+    io:format("Linux: ~s"
+              "~n   Distro:                  ~s"
+              "~n   Distro Version:          ~s"
+              "~n   TS Extra Platform Label: ~s (~p)"
+              "~n   Product Name:            ~s"
+              "~n",
+              [Version, Distro, DVersion, Label, SLabel, linux_product_name()]),
+    SLabel.
+
 
 linux_process_os_release() ->
     %% Read the "raw" file
@@ -1174,27 +1199,30 @@ do_linux_which_distro_fedora_release(Version, Label) ->
     %% Check if fedora
     case file:read_file_info("/etc/fedora-release") of
         {ok, _} ->
-            case [string:trim(S) ||
-                     S <- string:tokens(os:cmd("cat /etc/fedora-release"),
-                                        [$\n])] of
-                [DistroStr | _] ->
-                    io:format("Linux: ~s"
-                              "~n   Distro:                  ~s"
-                              "~n   TS Extra Platform Label: ~s"
-                              "~n   Product Name:            ~s"
-                              "~n",
-                              [Version, DistroStr, Label,
-                               linux_product_name()]);
-                _ ->
-                    io:format("Linux: ~s"
-                              "~n   Distro: ~s"
-                              "~n   TS Extra Platform Label: ~s"
-                              "~n   Product Name:            ~s"
-                              "~n",
-                              [Version, "Fedora", Label,
-                               linux_product_name()])
+            SLabel =
+                case [string:trim(S) ||
+                         S <- string:tokens(os:cmd("cat /etc/fedora-release"),
+                                            [$\n])] of
+                    [DistroStr | _] ->
+                        %% io:format("Linux: ~s"
+                        %%           "~n   Distro:                  ~s"
+                        %%           "~n   TS Extra Platform Label: ~s (~p)"
+                        %%           "~n   Product Name:            ~s"
+                        %%           "~n",
+                        %%           [Version, DistroStr, Label, SLabel,
+                        %%            linux_product_name()]);
+                        linux_distro_release(Version, DistroStr, Label);
+                    _ ->
+                        %% io:format("Linux: ~s"
+                        %%           "~n   Distro: ~s"
+                        %%           "~n   TS Extra Platform Label: ~s (~p)"
+                        %%           "~n   Product Name:            ~s"
+                        %%           "~n",
+                        %%           [Version, "Fedora", Label, SLabel
+                        %%            linux_product_name()])
+                        linux_distro_release(Version, "Fedora", Label)
             end,
-            throw({distro, {fedora, simplify_label(Label)}});
+            throw({distro, {fedora, SLabel}});
         _ ->
             throw({error, not_found})
     end.
@@ -1209,32 +1237,41 @@ do_linux_which_distro_suse_release(Version, Label) ->
                              S <- string:tokens(os:cmd("cat /etc/SuSE-release"),
                                                 [$\n])] of
                         ["SUSE Linux Enterprise Server" ++ _ = DistroStr | _] ->
-                            io:format("Linux: ~s"
-                                      "~n   Distro:                  ~s"
-                                      "~n   TS Extra Platform Label: ~s"
-                                      "~n   Product Name:            ~s"
-                                      "~n",
-                                      [Version, DistroStr, Label,
-                                       linux_product_name()]),
-                            throw({distro, {sles, simplify_label(Label)}});
+                            %% io:format("Linux: ~s"
+                            %%           "~n   Distro:                  ~s"
+                            %%           "~n   TS Extra Platform Label: ~s (~p)"
+                            %%           "~n   Product Name:            ~s"
+                            %%           "~n",
+                            %%           [Version, DistroStr, Label, SLabel,
+                            %%            linux_product_name()]),
+                            SLabel = linux_distro_release(Version,
+                                                          DistroStr,
+                                                          Label),
+                            throw({distro, {sles, SLabel}});
                         [DistroStr | _] ->
-                            io:format("Linux: ~s"
-                                      "~n   Distro:                  ~s"
-                                      "~n   TS Extra Platform Label: ~s"
-                                      "~n   Product Name:            ~s"
-                                      "~n",
-                                      [Version, DistroStr, Label,
-                                       linux_product_name()]),
-                            throw({distro, {suse, simplify_label(Label)}});
+                            %% io:format("Linux: ~s"
+                            %%           "~n   Distro:                  ~s"
+                            %%           "~n   TS Extra Platform Label: ~s (~p)"
+                            %%           "~n   Product Name:            ~s"
+                            %%           "~n",
+                            %%           [Version, DistroStr, Label, SLabel,
+                            %%            linux_product_name()]),
+                            SLabel = linux_distro_release(Version,
+                                                          DistroStr,
+                                                          Label),
+                            throw({distro, {suse, SLabel}});
                         _ ->
-                            io:format("Linux: ~s"
-                                      "~n   Distro:                  ~s"
-                                      "~n   TS Extra Platform Label: ~s"
-                                      "~n   Product Name:            ~s"
-                                      "~n",
-                                      [Version, "SuSE", Label,
-                                       linux_product_name()]),
-                            throw({distro, {suse, simplify_label(Label)}})
+                            %% io:format("Linux: ~s"
+                            %%           "~n   Distro:                  ~s"
+                            %%           "~n   TS Extra Platform Label: ~s (~p)"
+                            %%           "~n   Product Name:            ~s"
+                            %%           "~n",
+                            %%           [Version, "SuSE", Label, SLabel,
+                            %%            linux_product_name()]),
+                            SLabel = linux_distro_release(Version,
+                                                          "SuSE",
+                                                          Label),
+                            throw({distro, {suse, SLabel}})
                     end;
                 _ ->
                     case string:tokens(os:cmd("cat /etc/SUSE-brand"), [$\n]) of
@@ -1242,71 +1279,91 @@ do_linux_which_distro_suse_release(Version, Label) ->
                             case [string:strip(S) ||
                                      S <- string:tokens(VERSION, [$=])] of
                                 ["VERSION", VersionNo] ->
-                                    io:format("Linux: ~s"
-                                              "~n   Distro:                  ~s"
-                                              "~n   Distro Version:          ~s"
-                                              "~n   TS Extra Platform Label: ~s"
-                                              "~n   Product Name:            ~s"
-                                              "~n",
-                                              [Version,
-                                               DistroStr, VersionNo,
-                                               Label,
-                                               linux_product_name()]),
-                                    throw({distro,
-                                           {sles, simplify_label(Label)}});
+                                    %% io:format(
+                                    %%   "Linux: ~s"
+                                    %%   "~n   Distro:                  ~s"
+                                    %%   "~n   Distro Version:          ~s"
+                                    %%   "~n   TS Extra Platform Label: ~s (~p)"
+                                    %%   "~n   Product Name:            ~s"
+                                    %%   "~n",
+                                    %%   [Version,
+                                    %%    DistroStr, VersionNo,
+                                    %%    Label, SLabel,
+                                    %%    linux_product_name()]),
+                                    SLabel = linux_distro_release(Version,
+                                                                  DistroStr,
+                                                                  VersionNo,
+                                                                  Label),
+                                    throw({distro, {sles, SLabel}});
                                 _ ->
-                                    io:format("Linux: ~s"
-                                              "~n   Distro:                  ~s"
-                                              "~n   TS Extra Platform Label: ~s"
-                                              "~n   Product Name:            ~s"
-                                              "~n",
-                                              [Version, DistroStr, Label,
-                                               linux_product_name()]),
-                                    throw({distro,
-                                           {sles, simplify_label(Label)}})
+                                    %% io:format(
+                                    %%   "Linux: ~s"
+                                    %%   "~n   Distro:                  ~s"
+                                    %%   "~n   TS Extra Platform Label: ~s (~p)"
+                                    %%   "~n   Product Name:            ~s"
+                                    %%   "~n",
+                                    %%   [Version, DistroStr, Label, SLabel,
+                                    %%    linux_product_name()]),
+                                    SLabel = linux_distro_release(Version,
+                                                                  DistroStr,
+                                                                  Label),
+                                    throw({distro, {sles, SLabel}})
                             end;
                         ["openSUSE" = DistroStr, VERSION | _] ->
                             case [string:strip(S) ||
                                      S <- string:tokens(VERSION, [$=])] of
                                 ["VERSION", VersionNo] ->
-                                    io:format("Linux: ~s"
-                                              "~n   Distro:                  ~s"
-                                              "~n   Distro Version:          ~s"
-                                              "~n   TS Extra Platform Label: ~s"
-                                              "~n   Product Name:            ~s"
-                                              "~n",
-                                              [Version,
-                                               DistroStr, VersionNo,
-                                               Label,
-                                               linux_product_name()]),
-                                    throw({distro,
-                                           {suse, simplify_label(Label)}});
+                                    %% io:format(
+                                    %%   "Linux: ~s"
+                                    %%   "~n   Distro:                  ~s"
+                                    %%   "~n   Distro Version:          ~s"
+                                    %%   "~n   TS Extra Platform Label: ~s (~p)"
+                                    %%   "~n   Product Name:            ~s"
+                                    %%   "~n",
+                                    %%   [Version,
+                                    %%    DistroStr, VersionNo,
+                                    %%    Label, SLabel,
+                                    %%    linux_product_name()]),
+                                    SLabel = linux_distro_release(Version,
+                                                                  DistroStr,
+                                                                  VersionNo,
+                                                                  Label),
+                                    throw({distro, {suse, SLabel}});
                                 _ ->
-                                    io:format("Linux: ~s"
-                                              "~n   Distro:                  ~s"
-                                              "~n   TS Extra Platform Label: ~s"
-                                              "~n   Product Name:            ~s"
-                                              "~n",
-                                              [Version, DistroStr, Label,
-                                               linux_product_name()]),
-                                    throw({distro,
-                                           {suse, simplify_label(Label)}})
+                                    %% io:format(
+                                    %%   "Linux: ~s"
+                                    %%   "~n   Distro:                  ~s"
+                                    %%   "~n   TS Extra Platform Label: ~s (~p)"
+                                    %%   "~n   Product Name:            ~s"
+                                    %%   "~n",
+                                    %%   [Version, DistroStr, Label, SLabel,
+                                    %%    linux_product_name()]),
+                                    SLabel = linux_distro_release(Version,
+                                                                  DistroStr,
+                                                                  Label),
+                                    throw({distro, {suse, SLabel}})
                             end;
                         _ ->
-                            io:format("Linux: ~s"
-                                      "~n   Distro:                  ~s"
-                                      "~n   TS Extra Platform Label: ~s"
-                                      "~n   Product Name:            ~s"
-                                      "~n",
-                                      [Version, "Unknown SUSE", Label,
-                                       linux_product_name()]),
-                            throw({distro, {suse, simplify_label(Label)}})
+                            %% io:format(
+                            %%   "Linux: ~s"
+                            %%   "~n   Distro:                  ~s"
+                            %%   "~n   TS Extra Platform Label: ~s (~p)"
+                            %%   "~n   Product Name:            ~s"
+                            %%   "~n",
+                            %%   [Version, "Unknown SUSE",
+                            %%    Label, SLabel,
+                            %%    linux_product_name()]),
+                            SLabel = linux_distro_release(Version,
+                                                          "Unknown SUSE",
+                                                          Label),
+                            throw({distro, {suse, SLabel}})
                     end
             end;
         _ ->
             throw({error, not_found})
     end.
 
+
 do_linux_which_distro_issue(Version, Label) ->
     case file:read_file_info("/etc/issue") of
         {ok, _} ->
@@ -1315,65 +1372,77 @@ do_linux_which_distro_issue(Version, Label) ->
                 [DistroStr | _] ->
                     case DistroStr of
                         "Wind River Linux" ++ _ ->
-                            io:format("Linux: ~s"
-                                      "~n   Distro:                  ~s"
-                                      "~n   TS Extra Platform Label: ~s"
-                                      "~n   Product Name:            ~s"
-                                      "~n",
-                                      [Version, DistroStr, Label,
-                                       linux_product_name()]),
-                            throw({distro,
-                                   {wind_river, simplify_label(Label)}});
+                            %% io:format(
+                            %%   "Linux: ~s"
+                            %%   "~n   Distro:                  ~s"
+                            %%   "~n   TS Extra Platform Label: ~s (~p)"
+                            %%   "~n   Product Name:            ~s"
+                            %%   "~n",
+                            %%   [Version, DistroStr, Label, SLabel,
+                            %%    linux_product_name()]),
+                            SLabel = linux_distro_release(Version,
+                                                          DistroStr, Label),
+                            throw({distro, {wind_river, SLabel}});
                         "MontaVista" ++ _ ->
-                            io:format("Linux: ~s"
-                                      "~n   Distro:                  ~s"
-                                      "~n   TS Extra Platform Label: ~s"
-                                      "~n   Product Name:            ~s"
-                                      "~n",
-                                      [Version, DistroStr, Label,
-                                       linux_product_name()]),
-                            throw({distro, 
-                                   {montavista, simplify_label(Label)}});
+                            %% io:format(
+                            %%   "Linux: ~s"
+                            %%   "~n   Distro:                  ~s"
+                            %%   "~n   TS Extra Platform Label: ~s (~p)"
+                            %%   "~n   Product Name:            ~s"
+                            %%   "~n",
+                            %%   [Version, DistroStr, Label, SLabel,
+                            %%    linux_product_name()]),
+                            SLabel = linux_distro_release(Version,
+                                                          DistroStr, Label),
+                            throw({distro, {montavista, SLabel}});
                         "Yellow Dog" ++ _ ->
-                            io:format("Linux: ~s"
-                                      "~n   Distro:                  ~s"
-                                      "~n   TS Extra Platform Label: ~s"
-                                      "~n   Product Name:            ~s"
-                                      "~n",
-                                      [Version, DistroStr, Label,
-                                       linux_product_name()]),
-                            throw({distro,
-                                   {yellow_dog, simplify_label(Label)}});
+                            %% io:format(
+                            %%   "Linux: ~s"
+                            %%   "~n   Distro:                  ~s"
+                            %%   "~n   TS Extra Platform Label: ~s (~p)"
+                            %%   "~n   Product Name:            ~s"
+                            %%   "~n",
+                            %%   [Version, DistroStr, Label, SLabel,
+                            %%    linux_product_name()]),
+                            SLabel = linux_distro_release(Version,
+                                                          DistroStr, Label),
+                            throw({distro, {yellow_dog, SLabel}});
                         "Debian" ++ _ ->
-                            io:format("Linux: ~s"
-                                      "~n   Distro:                  ~s"
-                                      "~n   TS Extra Platform Label: ~s"
-                                      "~n   Product Name:            ~s"
-                                      "~n",
-                                      [Version, DistroStr, Label,
-                                       linux_product_name()]),
-                            throw({distro,
-                                   {debian, simplify_label(Label)}});
+                            %% io:format(
+                            %%   "Linux: ~s"
+                            %%   "~n   Distro:                  ~s"
+                            %%   "~n   TS Extra Platform Label: ~s (~p)"
+                            %%   "~n   Product Name:            ~s"
+                            %%   "~n",
+                            %%   [Version, DistroStr, Label, SLabel,
+                            %%    linux_product_name()]),
+                            SLabel = linux_distro_release(Version,
+                                                          DistroStr, Label),
+                            throw({distro, {debian, SLabel}});
                         "Ubuntu" ++ _ ->
-                            io:format("Linux: ~s"
-                                      "~n   Distro:                  ~s"
-                                      "~n   TS Extra Platform Label: ~s"
-                                      "~n   Product Name:            ~s"
-                                      "~n",
-                                      [Version, DistroStr, Label,
-                                       linux_product_name()]),
-                            throw({distro,
-                                   {ubuntu, simplify_label(Label)}});
+                            %% io:format(
+                            %%   "Linux: ~s"
+                            %%   "~n   Distro:                  ~s"
+                            %%   "~n   TS Extra Platform Label: ~s (~p)"
+                            %%   "~n   Product Name:            ~s"
+                            %%   "~n",
+                            %%   [Version, DistroStr, Label, SLabel,
+                            %%    linux_product_name()]),
+                            SLabel = linux_distro_release(Version,
+                                                          DistroStr, Label),
+                            throw({distro, {ubuntu, SLabel}});
                         "Linux Mint" ++ _ ->
-                            io:format("Linux: ~s"
-                                      "~n   Distro:                  ~s"
-                                      "~n   TS Extra Platform Label: ~s"
-                                      "~n   Product Name:            ~s"
-                                      "~n",
-                                      [Version, DistroStr, Label,
-                                       linux_product_name()]),
-                            throw({distro,
-                                   {linux_mint, simplify_label(Label)}});
+                            %% io:format(
+                            %%   "Linux: ~s"
+                            %%   "~n   Distro:                  ~s"
+                            %%   "~n   TS Extra Platform Label: ~s (~p)"
+                            %%   "~n   Product Name:            ~s"
+                            %%   "~n",
+                            %%   [Version, DistroStr, Label, SLabel,
+                            %%    linux_product_name()]),
+                            SLabel = linux_distro_release(Version,
+                                                          DistroStr, Label),
+                            throw({distro, {linux_mint, SLabel}});
                         _ ->
                             DistroStr
                     end;
@@ -1468,7 +1537,7 @@ analyze_and_print_linux_host_info(Version) ->
             _ ->
                 5
         end,
-    AddLabelFactor = label2factor(simplify_label(Label)),
+    AddLabelFactor = label2factor(Label),
     %% Check if we need to adjust the factor because of the memory
     AddMemFactor = try linux_which_meminfo()
                    catch _:_:_ -> 0
-- 
2.43.0

openSUSE Build Service is sponsored by