Skip to content

Commit 1eea970

Browse files
committed
make logging more consistent
Use consistent capitalization and naming conventions for the loggers. Use the test logging function for test messages instead of mixing those in with the regular log output. Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
1 parent 8804372 commit 1eea970

8 files changed

+15
-19
lines changed

controllers/metal3.io/baremetalhost_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ func (r *BareMetalHostReconciler) actionMatchProfile(prov provisioner.Provisione
516516
func (r *BareMetalHostReconciler) actionProvisioning(prov provisioner.Provisioner, info *reconcileInfo) actionResult {
517517
hostConf := &hostConfigData{
518518
host: info.host,
519-
log: info.log,
519+
log: info.log.WithName("host_config_data"),
520520
client: r,
521521
}
522522
info.log.Info("provisioning")

controllers/metal3.io/baremetalhost_controller_test.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func newTestReconcilerWithProvisionerFactory(factory provisioner.Factory, initOb
9999
Client: c,
100100
Scheme: scheme.Scheme,
101101
ProvisionerFactory: factory,
102-
Log: ctrl.Log.WithName("controller").WithName("baremetalhost").WithName("test"),
102+
Log: ctrl.Log.WithName("controllers").WithName("BareMetalHost"),
103103
}
104104
}
105105

@@ -122,8 +122,7 @@ func tryReconcile(t *testing.T, r *BareMetalHostReconciler, host *metal3v1alpha1
122122
request := newRequest(host)
123123

124124
for i := 0; ; i++ {
125-
logger := r.Log.WithValues("iteration", i)
126-
logger.Info("tryReconcile: top of loop")
125+
t.Logf("tryReconcile: top of loop %d", i)
127126
if i >= 25 {
128127
t.Fatal(fmt.Errorf("Exceeded 25 iterations"))
129128
}
@@ -143,11 +142,11 @@ func tryReconcile(t *testing.T, r *BareMetalHostReconciler, host *metal3v1alpha1
143142
updatedHost.DeepCopyInto(host)
144143

145144
if isDone(host, result) {
146-
logger.Info("tryReconcile: loop done")
145+
t.Logf("tryReconcile: loop done %d", i)
147146
break
148147
}
149148

150-
logger.Info("tryReconcile: loop bottom", "result", result)
149+
t.Logf("tryReconcile: loop bottom %d result=%v", i, result)
151150
if !result.Requeue && result.RequeueAfter == 0 {
152151
t.Fatal(fmt.Errorf("Ended reconcile at iteration %d without test condition being true", i))
153152
break
@@ -156,11 +155,10 @@ func tryReconcile(t *testing.T, r *BareMetalHostReconciler, host *metal3v1alpha1
156155
}
157156

158157
func waitForStatus(t *testing.T, r *BareMetalHostReconciler, host *metal3v1alpha1.BareMetalHost, desiredStatus metal3v1alpha1.OperationalStatus) {
159-
logger := r.Log.WithValues("desiredStatus", desiredStatus)
160158
tryReconcile(t, r, host,
161159
func(host *metal3v1alpha1.BareMetalHost, result reconcile.Result) bool {
162160
state := host.OperationalStatus()
163-
logger.Info("WAIT FOR STATUS", "State", state)
161+
t.Logf("Waiting for status %s: %s", desiredStatus, state)
164162
return state == desiredStatus
165163
},
166164
)
@@ -169,7 +167,7 @@ func waitForStatus(t *testing.T, r *BareMetalHostReconciler, host *metal3v1alpha
169167
func waitForError(t *testing.T, r *BareMetalHostReconciler, host *metal3v1alpha1.BareMetalHost) {
170168
tryReconcile(t, r, host,
171169
func(host *metal3v1alpha1.BareMetalHost, result reconcile.Result) bool {
172-
r.Log.Info("WAIT FOR ERROR", "ErrorMessage", host.Status.ErrorMessage)
170+
t.Logf("Waiting for error: %q", host.Status.ErrorMessage)
173171
return host.HasError()
174172
},
175173
)
@@ -178,7 +176,7 @@ func waitForError(t *testing.T, r *BareMetalHostReconciler, host *metal3v1alpha1
178176
func waitForNoError(t *testing.T, r *BareMetalHostReconciler, host *metal3v1alpha1.BareMetalHost) {
179177
tryReconcile(t, r, host,
180178
func(host *metal3v1alpha1.BareMetalHost, result reconcile.Result) bool {
181-
r.Log.Info("WAIT FOR NO ERROR", "ErrorMessage", host.Status.ErrorMessage)
179+
t.Logf("Waiting for no error message: %q", host.Status.ErrorMessage)
182180
return !host.HasError()
183181
},
184182
)
@@ -749,8 +747,6 @@ func TestFixSecret(t *testing.T) {
749747
// moves out of the error state.
750748
func TestBreakThenFixSecret(t *testing.T) {
751749

752-
logger := ctrl.Log.WithName("Test").WithName("TestBreakThenFixSecret")
753-
754750
// Create the host without any errors and wait for it to be
755751
// registered and get a provisioning ID.
756752
secret := newBMCCredsSecret("bmc-creds-toggle-user", "User", "Pass")
@@ -765,7 +761,7 @@ func TestBreakThenFixSecret(t *testing.T) {
765761
tryReconcile(t, r, host,
766762
func(host *metal3v1alpha1.BareMetalHost, result reconcile.Result) bool {
767763
id := host.Status.Provisioning.ID
768-
logger.Info("WAIT FOR PROVISIONING ID", "ID", id)
764+
t.Logf("Waiting for provisioning ID to be set: %q", id)
769765
return id != ""
770766
},
771767
)

controllers/metal3.io/demo_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func newDemoReconciler(initObjs ...runtime.Object) *BareMetalHostReconciler {
2828
Client: c,
2929
Scheme: scheme.Scheme,
3030
ProvisionerFactory: demo.New,
31-
Log: ctrl.Log.WithName("controller").WithName("baremetalhost").WithName("demo").WithName("test"),
31+
Log: ctrl.Log.WithName("controller").WithName("BareMetalHost"),
3232
}
3333
}
3434

controllers/metal3.io/host_config_data_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func TestProvisionWithHostConfig(t *testing.T) {
227227
c.Create(goctx.TODO(), tc.NetworkDataSecret)
228228
hcd := &hostConfigData{
229229
host: tc.Host,
230-
log: ctrl.Log.WithName("Test").WithName(tc.Scenario),
230+
log: ctrl.Log.WithName("controllers").WithName("BareMetalHost").WithName("host_config_data"),
231231
client: c,
232232
}
233233

controllers/metal3.io/host_state_machine_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func (hb *hostBuilder) SetImageURL(url string) *hostBuilder {
315315

316316
func makeDefaultReconcileInfo(host *metal3v1alpha1.BareMetalHost) *reconcileInfo {
317317
return &reconcileInfo{
318-
log: logf.Log.WithName("test"),
318+
log: logf.Log.WithName("controllers").WithName("BareMetalHost").WithName("host_state_machine"),
319319
host: host,
320320
request: ctrl.Request{},
321321
bmcCredsSecret: &corev1.Secret{

pkg/provisioner/demo/demo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/metal3-io/baremetal-operator/pkg/provisioner"
1212
)
1313

14-
var log = logf.Log.WithName("demo")
14+
var log = logf.Log.WithName("provisioner").WithName("demo")
1515
var deprovisionRequeueDelay = time.Second * 10
1616
var provisionRequeueDelay = time.Second * 10
1717

pkg/provisioner/fixture/fixture.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/metal3-io/baremetal-operator/pkg/provisioner"
1212
)
1313

14-
var log = logf.Log.WithName("fixture")
14+
var log = logf.Log.WithName("provisioner").WithName("fixture")
1515
var deprovisionRequeueDelay = time.Second * 10
1616
var provisionRequeueDelay = time.Second * 10
1717

pkg/provisioner/ironic/ironic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/hardwaredetails"
2828
)
2929

30-
var log = logf.Log.WithName("baremetalhost_ironic")
30+
var log = logf.Log.WithName("provisioner").WithName("ironic")
3131
var deprovisionRequeueDelay = time.Second * 10
3232
var provisionRequeueDelay = time.Second * 10
3333
var powerRequeueDelay = time.Second * 10

0 commit comments

Comments
 (0)