From f0a785cdfbcacdd976775ef6ed71c9401f3fe1d7 Mon Sep 17 00:00:00 2001 From: Moath Qasim Date: Thu, 22 Apr 2021 17:26:57 +0200 Subject: [PATCH 1/2] fix getWorkerID when mac addresses have captalized letters Signed-off-by: Moath Qasim --- db/workflow.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/workflow.go b/db/workflow.go index 6474d3a20..fa470cd5a 100644 --- a/db/workflow.go +++ b/db/workflow.go @@ -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 { @@ -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") } From d502edecbbad8a9144aa587b9967bc1bd454e5a2 Mon Sep 17 00:00:00 2001 From: Moath Qasim Date: Wed, 30 Jun 2021 16:08:14 +0300 Subject: [PATCH 2/2] add test case for lowered case mac addresses for hardwares Signed-off-by: Moath Qasim --- db/testdata/hardware_2.json | 69 +++++++++++++++++++++++++++++++++++++ db/workflow_test.go | 27 +++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 db/testdata/hardware_2.json diff --git a/db/testdata/hardware_2.json b/db/testdata/hardware_2.json new file mode 100644 index 000000000..13dd973c5 --- /dev/null +++ b/db/testdata/hardware_2.json @@ -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" +} diff --git a/db/workflow_test.go b/db/workflow_test.go index 259e5499c..ca042a164 100644 --- a/db/workflow_test.go +++ b/db/workflow_test.go @@ -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{