Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support specifying mac address without quotation mark #364

Closed
wants to merge 1 commit into from

Conversation

liangwen12year
Copy link
Collaborator

Signed-off-by: Wen Liang [email protected]

@liangwen12year liangwen12year force-pushed the mac branch 2 times, most recently from a5dfe08 to 11e8424 Compare March 18, 2021 02:16
@thom311
Copy link
Contributor

thom311 commented Mar 18, 2021

can you show an example how this is used?

What prompted this merge-request, is there an issue that you can link to?

   validator._validate_impl(41135085296, "mac"), "52:54:00:12:34:56"

Why does 41135085296 correspond to "52:54:00:12:34:56", or better, where did you get this (to me unknown) algorithm with divmod(num, 60)? That doesn't make sense to me.

@liangwen12year
Copy link
Collaborator Author

can you show an example how this is used?

What prompted this merge-request, is there an issue that you can link to?

   validator._validate_impl(41135085296, "mac"), "52:54:00:12:34:56"

Why does 41135085296 correspond to "52:54:00:12:34:56", or better, where did you get this (to me unknown) algorithm with divmod(num, 60)? That doesn't make sense to me.

The issue:
#365

@liangwen12year liangwen12year requested a review from tyll March 18, 2021 13:15
@thom311
Copy link
Contributor

thom311 commented Mar 18, 2021

The issue:
#365

Btw, would have been good to link the background information upfront.

That doesn't seem a good idea. It allows nonsense like:

   mac: 1

which IMO should be rejected as error.

Also, if you read https://stackoverflow.com/a/52732369/354393 you'll see that number larger or equal than 60 are treated as carrier to the next digit. So, I would guess that "00:00:00:00:60" is the same as "00:00:00:01:00", which seems very wrong.

@thom311
Copy link
Contributor

thom311 commented Mar 18, 2021

Also, if you read https://stackoverflow.com/a/52732369/354393 you'll see that number larger or equal than 60 are treated as carrier to the next digit. So, I would guess that "00:00:00:00:60" is the same as "00:00:00:01:00", which seems very wrong.

Ah wrong, it doesn't carry over. The link says "Since your other MAC-address, 84:19:14:15:86:58, has a number after the first number that is over 59 (86 that is), it is not considered as a sexagesimal number and is therefore treated literally as a string.".

But that seems not something that the role should try to work around. The user has to set the MAC address as string and not the role interpreting integers as hours:minutes:seconds...

@liangwen12year
Copy link
Collaborator Author

The issue:
#365

Btw, would have been good to link the background information upfront.

That doesn't seem a good idea. It allows nonsense like:

   mac: 1

which IMO should be rejected as error.

Also, if you read https://stackoverflow.com/a/52732369/354393 you'll see that number larger or equal than 60 are treated as carrier to the next digit. So, I would guess that "00:00:00:00:60" is the same as "00:00:00:01:00", which seems very wrong.

mac: 1 was indeed rejected as error by the function num_to_mac()

@richm
Copy link
Contributor

richm commented Mar 18, 2021

Are you absolutely guaranteed that you can always convert a mac address specified like mac: 52:54:00:12:34:56 into a unique number, and that number can always be converted back into the same exact mac address specified in the original YAML?
If you are not absolutely guaranteed, then you will just have to require users to specify the mac address as a string in any of the various ways to specify a string in YAML.

@liangwen12year
Copy link
Collaborator Author

liangwen12year commented Mar 18, 2021

Also, if you read https://stackoverflow.com/a/52732369/354393 you'll see that number larger or equal than 60 are treated as carrier to the next digit. So, I would guess that "00:00:00:00:60" is the same as "00:00:00:01:00", which seems very wrong.

Ah wrong, it doesn't carry over. The link says "Since your other MAC-address, 84:19:14:15:86:58, has a number after the first number that is over 59 (86 that is), it is not considered as a sexagesimal number and is therefore treated literally as a string.".

But that seems not something that the role should try to work around. The user has to set the MAC address as string and not the role interpreting integers as hours:minutes:seconds...

Are you absolutely guaranteed that you can always convert a mac address specified like mac: 52:54:00:12:34:56 into a unique number, and that number can always be converted back into the same exact mac address specified in the original YAML?
If you are not absolutely guaranteed, then you will just have to require users to specify the mac address as a string in any of the various ways to specify a string in YAML.

the function num_to_mac() literally is to remediate yaml's peculiarity that "string literal consists of a series of one or two-digit numbers delimited by colons and all numbers but the first are between 0 and 59, it would be interpreted as a sexagesimal number, and would be converted automatically to the equivalent number of seconds". I am guaranteed that the function num_to_mac() will always convert it back into mac address specified in the original YAML. Also, I understand the concern from @thom311, like specifying arbitrary integer( e.g. mac: 1), but we also have force_len to raise error for invalid interger value

@liangwen12year
Copy link
Collaborator Author

Are you absolutely guaranteed that you can always convert a mac address specified like mac: 52:54:00:12:34:56 into a unique number, and that number can always be converted back into the same exact mac address specified in the original YAML?
If you are not absolutely guaranteed, then you will just have to require users to specify the mac address as a string in any of the various ways to specify a string in YAML.

And it is very good suggestion that always remind users to specify the mac address as a string in any of the various ways to specify a string in YAML.

@liangwen12year liangwen12year force-pushed the mac branch 2 times, most recently from f06095e to 1f423c0 Compare March 18, 2021 20:59
README.md Outdated Show resolved Hide resolved
@liangwen12year liangwen12year force-pushed the mac branch 5 times, most recently from 1fca175 to 8859ad1 Compare March 24, 2021 01:09
@liangwen12year liangwen12year changed the title [WIP]Support specifying mac address without quotation mark Support specifying mac address without quotation mark Apr 1, 2021
Copy link
Collaborator

@cathay4t cathay4t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the magic number, this PR is breaking the API!

Previously, the unquoted mac address works well when mac address contains [a-f], but your patch change it to raise exception.

Your title says you are supporting unquoted mac address, but the code looks like you are raise exception for it.

module_utils/network_lsr/argument_validator.py Outdated Show resolved Hide resolved
@cathay4t cathay4t added Wait_Submitter The submitter needs to do something before this can move on and removed Wait_Review labels Apr 2, 2021
@liangwen12year
Copy link
Collaborator Author

liangwen12year commented Apr 2, 2021

Besides the magic number, this PR is breaking the API!

Previously, the unquoted mac address works well when mac address contains [a-f], but your patch change it to raise exception.

Your title says you are supporting unquoted mac address, but the code looks like you are raise exception for it.

For the unquoted mac address containing [a-f], it will not raise an exception, it will work as before. And the code will only support valid unquoted mac address, will raise an exception for invalid unquoted mac address.

@cathay4t cathay4t added Wait_Submitter The submitter needs to do something before this can move on and removed Wait_Review labels Apr 30, 2021
@@ -11,6 +11,9 @@
from ansible.module_utils.network_lsr.utils import Util # noqa:E501

UINT32_MAX = 0xFFFFFFFF
# a MAC address for type ethernet requires 6 octets
# a MAC address for type infiniband requires 20 octets
MAC_ADDR_OCTETS = [6, 20]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong.

The kernel has no limitation minimum MAC address length.
And the maximum is not 20, but in /usr/include/linux/netdevice.h:

#define MAX_ADDR_LEN 32 /* Largest hardware address length */

That is 32 octets and 64 hex string characters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason that I define MAC_ADDR_OCTETS = [6, 20] is because I saw the validation check here,
https://github.com/linux-system-roles/network/blob/main/module_utils/network_lsr/argument_validator.py#L1483

And in NM,it was also clear indicated,

     * ---ifcfg-rh---
     * property: mac-address
     * variable: HWADDR
     * description: IBoIP 20-byte hardware address of the device (in traditional
     *    hex-digits-and-colons notation).
     *    Note that for initscripts this is the current MAC address of the device as found
     *    during ifup. For NetworkManager this is the permanent MAC address. Or in case no
     *    permanent MAC address exists, the MAC address initially configured on the device.
     * example: HWADDR=01:02:03:04:05:06:07:08:09:0A:01:02:03:04:05:06:07:08:09:11
     * ---end---
     
     /* ---keyfile---
     * property: mac-address
     * format: usual hex-digits-and-colons notation
     * description: MAC address in traditional hex-digits-and-colons notation
     *   (e.g. 00:22:68:12:79:A2), or semicolon separated list of 6 bytes (obsolete)
     *   (e.g. 0;34;104;18;121;162)
     * ---end---

@liangwen12year liangwen12year force-pushed the mac branch 2 times, most recently from 223ca16 to 48706ab Compare May 2, 2021 01:17
@liangwen12year
Copy link
Collaborator Author

@liangwen12year This PR is still in DRAFT state. And the git commit has no commit comment explaining why patch is required and how this patch is fixing the issue.

Added commit message to explain why patch is required and how this patch is fixing the issue.

@liangwen12year liangwen12year removed the Wait_Submitter The submitter needs to do something before this can move on label May 2, 2021
@jharuda
Copy link
Contributor

jharuda commented May 3, 2021

[citest pending]

- In yaml, all the string value consists of a series of one-digit or
two-digit numbers delimited by colons and all numbers but the first are
between 0 and 59, it would be interpreted as a sexagesimal number, and
would be converted automatically to the equivalent number of seconds.

- The committed patch will guarantee to remediate the yaml's peculiarity
and convert back into the mac address specified in the original yaml
file. And in case that user specifies arbitrary integer(e.g. `mac:1234`),
we introduce `force_len`(e.g. `MAC_ADDR_OCTETS = [6, 20]`) to raise
error for invalid integer value.

Signed-off-by: Wen Liang <[email protected]>
@coveralls
Copy link

coveralls commented May 4, 2021

Pull Request Test Coverage Report for Build 809885115

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 103 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.7%) to 40.22%

Files with Coverage Reduction New Missed Lines %
/home/runner/work/network/network/module_utils/network_lsr/utils.py 14 54.48%
/home/runner/work/network/network/module_utils/network_lsr/argument_validator.py 89 83.71%
Totals Coverage Status
Change from base Build 809105682: 0.7%
Covered Lines: 1024
Relevant Lines: 2546

💛 - Coveralls

@richm
Copy link
Contributor

richm commented May 4, 2021

[citest pending]

@richm
Copy link
Contributor

richm commented May 4, 2021

[citest bad]

@richm
Copy link
Contributor

richm commented May 4, 2021

[citest pending]

@cathay4t
Copy link
Collaborator

cathay4t commented May 7, 2021

@liangwen12year This PR is still in DRAFT mode. Is it ready for review?

@liangwen12year
Copy link
Collaborator Author

liangwen12year commented May 7, 2021

@liangwen12year This PR is still in DRAFT mode. Is it ready for review?

It is still in DRAFT mode, because we need to discuss first if this patch is actually needed.

@stale
Copy link

stale bot commented Jun 6, 2021

Thank you for your contribution! There was no activity in this pull request recently. To avoid pull requests to pile up, an automated process marked this pull request as stale. It will close this pull request if no further activity occurs. The current policy is available at: https://github.com//linux-system-roles/network/blob/main/.github/stale.yml

@stale stale bot added the stale label Jun 6, 2021
@richm
Copy link
Contributor

richm commented Jun 14, 2021

[citest pending]

@stale stale bot removed the stale label Jun 14, 2021
@richm
Copy link
Contributor

richm commented Jul 6, 2021

any update on this?

@tyll
Copy link
Member

tyll commented Jul 6, 2021

This is currently not a priority, therefore it is just a draft PR. We can revisit this after #363 are handled and the current CI problems are handled. Would you prefer to have the PR closed for now?

@richm
Copy link
Contributor

richm commented Jul 6, 2021

This is currently not a priority, therefore it is just a draft PR. We can revisit this after #363 are handled and the current CI problems are handled. Would you prefer to have the PR closed for now?

No, this is fine - it is marked as WIP/Draft

@stale
Copy link

stale bot commented Aug 5, 2021

Thank you for your contribution! There was no activity in this pull request recently. To avoid pull requests to pile up, an automated process marked this pull request as stale. It will close this pull request if no further activity occurs. The current policy is available at: https://github.com//linux-system-roles/network/blob/main/.github/stale.yml

@stale stale bot added the stale label Aug 5, 2021
@cathay4t cathay4t removed the stale label Aug 5, 2021
@stale
Copy link

stale bot commented Sep 4, 2021

Thank you for your contribution! There was no activity in this pull request recently. To avoid pull requests to pile up, an automated process marked this pull request as stale. It will close this pull request if no further activity occurs. The current policy is available at: https://github.com//linux-system-roles/network/blob/main/.github/stale.yml

@stale stale bot added the stale label Sep 4, 2021
@stale stale bot closed this Sep 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need to convert number back into mac address because of yaml's peculiarity
8 participants