Skip to content

Commit 6a995e4

Browse files
authored
Merge pull request #181 from angelabriel/master
fix bare-metal handling for tag 'virt'
2 parents 9381dd8 + 5cc9f1a commit 6a995e4

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

system/daemon.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func SystemdDetectVirt(opt string) (bool, string, error) {
6666
return virt, vtype, ErrorLog("%v - Failed to call systemd-detect-virt %s - %s", err, opt, strings.TrimSpace(string(out)))
6767
}
6868
vtype = strings.TrimSpace(string(out))
69+
if vtype == "none" {
70+
vtype = "bare-metal"
71+
err = nil
72+
}
6973
return virt, vtype, err
7074
}
7175

system/daemon_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ func TestSystemdDetectVirt(t *testing.T) {
496496
t.Errorf("Test failed, returned error should be 'nil', but got: '%v'", err)
497497
}
498498

499-
exp = "none"
499+
exp = "bare-metal"
500500
virt, vtype, err = SystemdDetectVirt(opt)
501501
if !virt {
502502
t.Error("virtualization should be true, but is false")
@@ -510,16 +510,16 @@ func TestSystemdDetectVirt(t *testing.T) {
510510

511511
// test: virtualization NOT available
512512
systemddvCmd = path.Join(os.Getenv("GOPATH"), "/src/github.com/SUSE/saptune/testdata/systemdDVNOK")
513-
exp = "none"
513+
exp = "bare-metal"
514514
virt, vtype, err = SystemdDetectVirt("-v")
515515
if virt {
516516
t.Error("virtualization should be false, but is true")
517517
}
518518
if vtype != exp {
519519
t.Errorf("Test failed, expected: '%s', got: '%s'", exp, vtype)
520520
}
521-
if err == nil {
522-
t.Errorf("Test failed, returned error should be NOT 'nil', but got: '%v'", err)
521+
if err != nil {
522+
t.Errorf("Test failed, returned error should be 'nil', but got: '%v'", err)
523523
}
524524
virt, vtype, err = SystemdDetectVirt("-c")
525525
if virt {
@@ -528,8 +528,8 @@ func TestSystemdDetectVirt(t *testing.T) {
528528
if vtype != exp {
529529
t.Errorf("Test failed, expected: '%s', got: '%s'", exp, vtype)
530530
}
531-
if err == nil {
532-
t.Errorf("Test failed, returned error should be NOT 'nil', but got: '%v'", err)
531+
if err != nil {
532+
t.Errorf("Test failed, returned error should be 'nil', but got: '%v'", err)
533533
}
534534
virt, vtype, err = SystemdDetectVirt(opt)
535535
if virt {
@@ -538,8 +538,8 @@ func TestSystemdDetectVirt(t *testing.T) {
538538
if vtype != exp {
539539
t.Errorf("Test failed, expected: '%s', got: '%s'", exp, vtype)
540540
}
541-
if err == nil {
542-
t.Errorf("Test failed, returned error should be NOT 'nil', but got: '%v'", err)
541+
if err != nil {
542+
t.Errorf("Test failed, returned error should be 'nil', but got: '%v'", err)
543543
}
544544
exp = ""
545545
virt, vtype, err = SystemdDetectVirt("-r")

txtparser/tags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func chkVirtTags(tagField string, secFields []string) bool {
234234
}
235235
// order of vopt and err check is by intention
236236
if err != nil {
237-
system.InfoLog("No virtualization detected - bare metal system or error with systemd-detect-virt. Skipping whole section '%v' with all lines till next valid section definition", secFields)
237+
system.InfoLog("No virtualization detected - error with systemd-detect-virt. Skipping whole section '%v' with all lines till next valid section definition", secFields)
238238
return false
239239
}
240240
if tagField != chkVirt {

0 commit comments

Comments
 (0)