Skip to content

Commit

Permalink
fix getWorkerID when mac addresses have captalized letters (#486)
Browse files Browse the repository at this point in the history
* fix getWorkerID when mac addresses have captalized letters

Signed-off-by: Moath Qasim <moad.qassem@gmail.com>

* add test case for lowered case mac addresses for hardwares

Signed-off-by: Moath Qasim <moad.qassem@gmail.com>

Co-authored-by: Gaurav Gahlot <ggahlot@infracloud.io>
  • Loading branch information
moadqassem and Gaurav Gahlot authored Jul 5, 2021
1 parent 4bdd9cb commit 8ea8a0e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
69 changes: 69 additions & 0 deletions db/testdata/hardware_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"metadata": {
"state": "provisioning",
"manufacturer": {},
"instance": {
"operating_system_version": {
"distro": "ubuntu",
"version": "18.04",
"os_slug": "ubuntu_18_04"
},
"crypted_root_password": "$6$xyz$/pdZy4hazXmqu1t0TACitLlKZPD4bFyRUw6ycXiOTdf4kcnkmpgmtg9zUpEE8rG9KtOWwX7kp1Gl96NCGbDk60",
"storage": {
"disks": [
{
"device": "/dev/sda",
"wipe_table": true,
"partitions": [
{ "label": "BIOS", "number": 1, "size": 4096 },
{ "label": "SWAP", "number": 2, "size": 3993600 },
{ "label": "ROOT", "number": 3, "size": 15993600 }
]
}
],
"filesystems": [
{
"mount": {
"device": "/dev/sda3",
"format": "ext4",
"create": { "options": ["-L", "ROOT"] },
"point": "/"
}
},
{
"mount": {
"device": "/dev/sda2",
"format": "swap",
"create": { "options": ["-L", "SWAP"] },
"point": "none"
}
}
]
}
},
"facility": { "plan_slug": "c2.medium.x86", "facility_code": "onprem" }
},
"network": {
"interfaces": [
{
"dhcp": {
"mac": "ae:fb:27:a1:c4:02",
"hostname": "server002",
"lease_time": 86400,
"arch": "x86_64",
"ip": {
"address": "192.168.1.6",
"netmask": "255.255.255.248",
"gateway": "192.168.1.1"
}
},
"netboot": {
"allow_pxe": true,
"allow_workflow": true,
"osie": { "kernel": "vmlinuz-x86_64" }
}
}
]
},
"id": "0eba0bf8-3772-4b4a-ab9f-6ebe93b90a96"
}
4 changes: 2 additions & 2 deletions db/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ func getWorkerIDbyIP(ctx context.Context, db *sql.DB, ip string) (string, error)
}

func getWorkerID(ctx context.Context, db *sql.DB, addr string) (string, error) {
_, err := net.ParseMAC(addr)
parsedMAC, err := net.ParseMAC(addr)
if err != nil {
ip := net.ParseIP(addr)
if ip == nil || ip.To4() == nil {
Expand All @@ -772,7 +772,7 @@ func getWorkerID(ctx context.Context, db *sql.DB, addr string) (string, error) {
return id, errors.WithMessage(err, "no worker found")

}
id, err := getWorkerIDbyMac(ctx, db, addr)
id, err := getWorkerIDbyMac(ctx, db, parsedMAC.String())
return id, errors.WithMessage(err, "no worker found")
}

Expand Down
27 changes: 27 additions & 0 deletions db/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ func TestCreateWorkflow(t *testing.T) {
}
},
},
{
Name: "create-single-workflow-with-upper-case-worker-address",
Input: &input{
workflowCount: 1,
devices: "{\"device_1\":\"AE:FB:27:a1:C4:02\"}",
hardware: readHardwareData("./testdata/hardware_2.json"),
template: func() *workflow.Workflow {
tmp := workflow.MustParseFromFile("./testdata/template_happy_path_1.yaml")
tmp.ID = uuid.New().String()
tmp.Name = fmt.Sprintf("id_%d", rand.Int())
return tmp
}(),
},
Expectation: func(t *testing.T, in *input, tinkDB *db.TinkDB) {
count := 0
err := tinkDB.ListWorkflows(func(wf db.Workflow) error {
count = count + 1
return nil
})
if err != nil {
t.Error(err)
}
if count != in.workflowCount {
t.Errorf("expected %d workflows stored in the database but we got %d", in.workflowCount, count)
}
},
},
{
Name: "create-fails-invalid-worker-address",
Input: &input{
Expand Down

0 comments on commit 8ea8a0e

Please sign in to comment.