From 32df37daad883ae4aefe3dc5cc476c3d61c78aad Mon Sep 17 00:00:00 2001 From: Jan Kubalek Date: Mon, 13 Jan 2025 18:37:40 +0100 Subject: [PATCH 1/3] Fix lsb_release instability --- tools/lsb_release/main.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tools/lsb_release/main.go b/tools/lsb_release/main.go index b6099ec..c1932a7 100644 --- a/tools/lsb_release/main.go +++ b/tools/lsb_release/main.go @@ -8,7 +8,6 @@ import ( "os" "path" "path/filepath" - "reflect" "regexp" ) @@ -77,28 +76,30 @@ func (data *DataStruct) ReadFromFile(filePath string, validate bool) { } defer file.Close() - parseStruct := map[string]func(string){ - "^Distributor ID:\t([^\t]+)$": func(s string) { data.DistributorID = s }, - "^Release:\t([^\t]+)$": func(s string) { data.ReleaseNumber = s }, + type KeyValue struct { + Key string + Callback func(string) + } + parseStruct := []KeyValue{ + {"^Distributor ID:\t([^\t]+)$", func(s string) { data.DistributorID = s }}, + {"^Release:\t([^\t]+)$", func(s string) { data.ReleaseNumber = s }}, } scanner := bufio.NewScanner(file) - keys := reflect.ValueOf(parseStruct).MapKeys() handled := 0 for scanner.Scan() { line := scanner.Text() - for _, key := range keys { - keyString := key.String() - data := parseLine(line, keyString) + for _, keyValue := range parseStruct { + data := parseLine(line, keyValue.Key) if data != "" { - parseStruct[keyString](data) + keyValue.Callback(data) handled++ break } } } - if validate && len(keys) != handled { + if validate && len(parseStruct) != handled { log.Panicf("Not all needed values were extracted!") } } From 58d45f49395921eb304a287d9f62bf94563312ef Mon Sep 17 00:00:00 2001 From: Jan Kubalek Date: Mon, 13 Jan 2025 18:39:14 +0100 Subject: [PATCH 2/3] No need to retry, lsb_release fixed --- modules/bringauto_package/PlatformString.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/modules/bringauto_package/PlatformString.go b/modules/bringauto_package/PlatformString.go index d26f8f0..a9b7376 100644 --- a/modules/bringauto_package/PlatformString.go +++ b/modules/bringauto_package/PlatformString.go @@ -3,8 +3,8 @@ package bringauto_package import ( "bringauto/modules/bringauto_docker" "bringauto/modules/bringauto_prerequisites" - "bringauto/modules/bringauto_ssh" "bringauto/modules/bringauto_process" + "bringauto/modules/bringauto_ssh" "fmt" "regexp" "strings" @@ -165,18 +165,7 @@ func runShellCommandOverSSH(credentials bringauto_ssh.SSHCredentials, command st Command: command, } - // If the fake lsb_release run in the Docker container - // it fails in 2/3. So we try to run fake lsb_release and fake uname multiple times. - i := 0 - var commandStdOut string - for { - commandStdOut, err = commandSsh.RunCommandOverSSH(credentials) - if err != nil && i < NumberOfTriesForFakeCommands { - i++ - continue - } - break - } + commandStdOut, err := commandSsh.RunCommandOverSSH(credentials) if err != nil { panic(fmt.Errorf("cannot run command '%s', error: %s", command, err)) } From ce969e84540dfecf249f276119ceb1d062a68b3e Mon Sep 17 00:00:00 2001 From: Jan Kubalek Date: Mon, 13 Jan 2025 19:01:09 +0100 Subject: [PATCH 3/3] Remove unused constants --- modules/bringauto_package/PlatformString.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/bringauto_package/PlatformString.go b/modules/bringauto_package/PlatformString.go index a9b7376..c132b20 100644 --- a/modules/bringauto_package/PlatformString.go +++ b/modules/bringauto_package/PlatformString.go @@ -25,10 +25,6 @@ const ( ModeAnyMachine = "any_machine" // ModeAuto compute platform string automatically by lsb_release and uname ModeAuto = "auto" - // NumberOfTriesForFakeCommands try to call fake lsb_release multiple times if fails. - // For same reason the fake lsb_release fail 1 of 3 (max). It's not clear why. - // We choose 5 as a good compromise: 3 + 1 + 1 - NumberOfTriesForFakeCommands = 5 ) // PlatformString represents standard platform string