Skip to content

go_agent unit test uses hard-coded NIC names #6

@weilanwu

Description

@weilanwu

In bosh/go_agent's ip_resolver_test.go test, it iterates through NIC names and picks up the hard-coded NIC and assume that's the active one:

                    if _, err := gonet.InterfaceByName("en0"); err == nil {
                            return "en0"
                    } else if _, err := gonet.InterfaceByName("eth0"); err == nil {
                            return "eth0"
                    } else if _, err := gonet.InterfaceByName("venet0"); err == nil {
                            // Travis CI uses venet0 as primary network interface
                            return "venet0"
                    }
                    panic("Not sure which interface name to use: en0 and eth0 are not found")

Such an approach is error-prone and in-elegant, e.g. I may have a NIC named 'eth0', but my laptop is disconnected from ethernet cable, and use a wireless NIC named 'wlan0', in this case the test code picks up 'eth0', but the proper one should be used is 'wlan0' (the active one taking traffic), as a result, the test fails.

To address it, proposal is to introduce a environment "PRIMARY_NIC", if it is set, the test uses it, only when this environment is not set, it falls back to the current logic, that is, iterating through the hard-coded NIC's and pick up whatever available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions