Repository: metal3-io/baremetal-operator
Pull request #974 (2021-09-09 07:32:37)

Add more context to node lookup logging


Patch:
diff --git a/pkg/provisioner/ironic/ironic.go b/pkg/provisioner/ironic/ironic.go
index 13075b7a..65b3e726 100644
--- a/pkg/provisioner/ironic/ironic.go
+++ b/pkg/provisioner/ironic/ironic.go
@@ -193,11 +193,11 @@ func (p *ironicProvisioner) nodeHasAssignedPort(ironicNode *nodes.Node) (bool, e
 	}
 
 	if empty {
-		p.debugLog.Info("node has no assigned port")
+		p.debugLog.Info("node has no assigned port", "node", ironicNode.UUID)
 		return false, nil
 	}
 
-	p.debugLog.Info("node has assigned port")
+	p.debugLog.Info("node has assigned port", "node", ironicNode.UUID)
 	return true, nil
 }
 
@@ -213,7 +213,7 @@ func (p *ironicProvisioner) isAddressAllocatedToPort(address string) (bool, erro
 		return false, nil
 	}
 
-	p.debugLog.Info("address is allocated to port", "address", address)
+	p.debugLog.Info("address is allocated to port", "address", address, "node", allPorts[0].NodeUUID)
 	return true, nil
 }
 
@@ -236,7 +236,7 @@ func (p *ironicProvisioner) findExistingHost(bootMACAddress string) (ironicNode
 		ironicNode, err = nodes.Get(p.client, nodeName).Extract()
 		switch err.(type) {
 		case nil:
-			p.debugLog.Info("found existing node by name")
+			p.debugLog.Info("found existing node by name", "name", nodeName, "node", ironicNode.UUID)
 			return ironicNode, nil
 		case gophercloud.ErrDefault404:
 			p.log.Info(
@@ -261,7 +261,7 @@ func (p *ironicProvisioner) findExistingHost(bootMACAddress string) (ironicNode
 		ironicNode, err = nodes.Get(p.client, nodeUUID).Extract()
 		switch err.(type) {
 		case nil:
-			p.debugLog.Info("found existing node by ID")
+			p.debugLog.Info("found existing node by MAC", "MAC", bootMACAddress, "node", ironicNode.UUID, "name", ironicNode.Name)
 
 			// If the node has a name, this means we didn't find it above.
 			if ironicNode.Name != "" {
@@ -271,10 +271,10 @@ func (p *ironicProvisioner) findExistingHost(bootMACAddress string) (ironicNode
 			return ironicNode, nil
 		case gophercloud.ErrDefault404:
 			return nil, errors.Wrap(err,
-				fmt.Sprintf("port exists but linked node doesn't %s", nodeUUID))
+				fmt.Sprintf("port %s exists but linked node doesn't %s", bootMACAddress, nodeUUID))
 		default:
 			return nil, errors.Wrap(err,
-				fmt.Sprintf("port exists but failed to find linked node by ID %s", nodeUUID))
+				fmt.Sprintf("port %s exists but failed to find linked node by ID %s", bootMACAddress, nodeUUID))
 		}
 	} else {
 		p.log.Info("port with address doesn't exist", "MAC", bootMACAddress)


Test patch:
diff --git a/pkg/provisioner/ironic/validatemanagementaccess_test.go b/pkg/provisioner/ironic/validatemanagementaccess_test.go
index bfcc5b7e..a5c0a306 100644
--- a/pkg/provisioner/ironic/validatemanagementaccess_test.go
+++ b/pkg/provisioner/ironic/validatemanagementaccess_test.go
@@ -604,7 +604,7 @@ func TestValidateManagementAccessExistingPortWithWrongUUID(t *testing.T) {
 	}
 
 	_, _, err = prov.ValidateManagementAccess(provisioner.ManagementAccessData{}, false, false)
-	assert.EqualError(t, err, "failed to find existing host: port exists but linked node doesn't random-wrong-id: Resource not found")
+	assert.EqualError(t, err, "failed to find existing host: port 11:11:11:11:11:11 exists but linked node doesn't random-wrong-id: Resource not found")
 }
 
 func TestValidateManagementAccessExistingPortButHasName(t *testing.T) {