Skip to content

Update dscheck_VMware's rpctool check#970

Merged
TheRealFalcon merged 2 commits into
canonical:mainfrom
sshedi:ds-identify-tweaks
Aug 12, 2021
Merged

Update dscheck_VMware's rpctool check#970
TheRealFalcon merged 2 commits into
canonical:mainfrom
sshedi:ds-identify-tweaks

Conversation

@sshedi
Copy link
Copy Markdown
Contributor

@sshedi sshedi commented Aug 11, 2021

Other minor tweaks.

Signed-off-by: Shreenidhi Shedi sshedi@vmware.com

Proposed Commit Message

Update dscheck_VMware's rpctool check

Update dscheck_VMware's rpctool check

This patch updates the dscheck_VMware function's use of "vmware-rpctool".

When checking to see if a "guestinfo" property is set.
Because a successful exit code can occur even if there is an empty
string returned, it is possible that the VMware datasource will be
loaded as a false-positive. This patch ensures that in addition to
validating the exit code, the emitted output is also examined to ensure
a non-empty value is returned by rpctool before returning "${DS_FOUND}"
from "dscheck_VMware()".

Other minor tweaks in ds-identify script.

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

Comment thread tools/ds-identify Outdated
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@TheRealFalcon @blackboxsw
This script is using local keyword in almost all functions & local is not POSIX compliant (shellcheck warns the same).
Can we use bash by default? Ubuntu links sh->dash and I'm unsure about other systems.
I'm assuming that bash is available in all distros by default.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would focus this PR on improving dscheck_VMware and separate general script improvements into a separate change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I got my answer by CI test results. It will be nice to know your clarification.

Comment thread tools/ds-identify Outdated
Comment thread tools/ds-identify Outdated
Comment thread tools/ds-identify
cached "$DI_VIRT" && return 0
detect_virt
DI_VIRT=${_RET}
DI_VIRT="$(echo "${_RET}" | tr '[:upper:]' '[:lower:]')"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just playing safe here, ensuring that DI_VIRT is lower case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the interpreter is BASH then the following should be possible:

DI_VIRT="${_RET,,}"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nope, can't assume that. sh is bash only in some distros. So, we need to use POSIX complaint method.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh sure, I was not assuming it. I was saying if we could switch the interpreter explicitly to BASH as you requested elsewhere.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you happen to know if DASH supports the same pattern?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

DI_VIRT="${_RET,,}" doesn't work on dash. Checked it. It will be nice if we can use bash but it seems like there are distros which doesn't use bash. #!/bin/sh is a symbolic link to a posix complaint shell, it can be bash/ksh/dash or anything. Using bash seems not feasible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And yet local is used elsewhere, huh? Weird. Seems like if /bin/sh is used then the rest of the file should be strictly POSIX compliant...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Exactly, that's what I'm thinking as well. But I read somewhere that even though local is not posix complaint, it's a de facto standard.

@akutz
Copy link
Copy Markdown
Contributor

akutz commented Aug 11, 2021

Thank you for doing this @sshedi. However, can you please provide a more verbose and meaningful commit message?

Comment thread tools/ds-identify Outdated
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would focus this PR on improving dscheck_VMware and separate general script improvements into a separate change.

Comment thread tools/ds-identify
cached "$DI_VIRT" && return 0
detect_virt
DI_VIRT=${_RET}
DI_VIRT="$(echo "${_RET}" | tr '[:upper:]' '[:lower:]')"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the interpreter is BASH then the following should be possible:

DI_VIRT="${_RET,,}"

Comment thread tools/ds-identify Outdated
Comment thread tools/ds-identify Outdated
Comment thread tools/ds-identify Outdated
@sshedi
Copy link
Copy Markdown
Contributor Author

sshedi commented Aug 11, 2021

Thank you for doing this @sshedi. However, can you please provide a more verbose and meaningful commit message?

Okay, I will give a brief info in my commit message. If you have anything in mind, feel free to share :) I struggle a bit while writing commit messages and assigning names to variables.

Comment thread tools/ds-identify Outdated
Comment thread tools/ds-identify Outdated
Comment thread tools/ds-identify Outdated
@akutz
Copy link
Copy Markdown
Contributor

akutz commented Aug 11, 2021

Thank you for doing this @sshedi. However, can you please provide a more verbose and meaningful commit message?

Okay, I will give a brief info in my commit message. If you have anything in mind, feel free to share :) I struggle a bit while writing commit messages and assigning names to variables.

Sure. Well, on the whole of it:

  • The cleanup to be BASH specific shouldn't be part of this PR IMO. That should be an entirely separate PR.
  • The only change I see that should likely occur is with respect to the way the guest info data is checked and return codes. So I'd redact all other changes except that and make the commit message:
Update dscheck_VMware's rpctool check

This patch updates the dscheck_VMware function's use of "vmware-rpctool"
when checking to see if a "guestinfo" property is set. Because a successful
exit code can occur even if there is an empty string returned, it is possible
that the VMware datasource will be loaded as a false-positive. This patch
ensures that in addition to validating the exit code, the emitted output is
also examined to ensure a non-empty value is returned by rpctool before
returning "${DS_FOUND}" from "dscheck_VMware()".

Comment thread tools/ds-identify Outdated
Comment thread tools/ds-identify Outdated
Comment thread tools/ds-identify Outdated
Comment thread tools/ds-identify Outdated
Comment thread tools/ds-identify Outdated
This patch updates the dscheck_VMware function's use of "vmware-rpctool".

When checking to see if a "guestinfo" property is set.
Because a successful exit code can occur even if there is an empty
string returned, it is possible that the VMware datasource will be
loaded as a false-positive. This patch ensures that in addition to
validating the exit code, the emitted output is also examined to ensure
a non-empty value is returned by rpctool before returning "${DS_FOUND}"
from "dscheck_VMware()".

Other minor tweaks in ds-identify script.

Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
@sshedi sshedi changed the title Improve dscheck_VMware Update dscheck_VMware's rpctool check Aug 11, 2021
@akutz
Copy link
Copy Markdown
Contributor

akutz commented Aug 11, 2021

This looks good to me, thank you @sshedi! Consider this approved from my PoV.

@TheRealFalcon TheRealFalcon merged commit 7781dec into canonical:main Aug 12, 2021
Copy link
Copy Markdown
Collaborator

@smoser smoser left a comment

Choose a reason for hiding this comment

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

I do realize that I'm not really active in cloud-init before, but I saw this go by and just want to mention that I really think this kind of software development makes things worse, not better.

Comment thread tools/ds-identify
cached "$DI_VIRT" && return 0
detect_virt
DI_VIRT=${_RET}
DI_VIRT="$(echo "${_RET}" | tr '[:upper:]' '[:lower:]')"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is really bad. We shouldn't do things "just in case". That doesn't actually make things better, but makes them worse for a couple reasons:

  • systemd documents the outputs of 'systemd-detect-virt', and they are all lower case. Accepting upper case is just a waste.
  • it is dramatically slower than it was before (2 additional forks - admittedly forks are fast on linux, but the are much slower than string comparisons).
  • The general policy of "just in case" is silly. Should we also accept misspellings? in case something spells it 'vmwhere' ?

Copy link
Copy Markdown
Contributor

@akutz akutz Aug 13, 2021

Choose a reason for hiding this comment

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

Hi @smoser,

I concur. I thought this was removed prior to merge (see #970 (comment) about reducing this PR to just the bits in dscheck_VMware). To be clear, this is not for misspelling, but your point is well received. Even if not systemd (FreeBSD), the mapping table ensures lower case as well.

I propose we revert this line to the former value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @smoser,

Please see #978.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Point taken. Thanks.

@akutz akutz mentioned this pull request Aug 13, 2021
3 tasks
@sshedi sshedi deleted the ds-identify-tweaks branch August 25, 2021 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants