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

nixos/tests: improve get_unit_info expressiveness on failure #73032

Merged
merged 1 commit into from Nov 8, 2019

Conversation

marijanp
Copy link
Contributor

@marijanp marijanp commented Nov 8, 2019

Motivation for this change

The returning of None results in an unexpressive "'NoneType' object is not subscriptable" exception in wait_for_unit and require_unit_state when accessing the info dictionary.

Things done

Code conforms the Black coding style.
Changed the simple.nix test and ran it to provocate a failure and check if the Exception is thrown.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @tfc @worldofpeace

@ofborg ofborg bot added the 6.topic: nixos label Nov 8, 2019
@@ -319,7 +319,11 @@ def wait_for_unit(self, unit, user=None):
def get_unit_info(self, unit, user=None):
status, lines = self.systemctl('--no-pager show "{}"'.format(unit), user)
if status != 0:
return None
raise Exception(
'retrieving the info for unit "{}" {} failed with exit code {}'.format(
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe write "retrieving systemctl info for unit ..." would be more expressive for users who see this for the first time without consulting the source code of the driver.

@@ -319,7 +319,11 @@ def wait_for_unit(self, unit, user=None):
def get_unit_info(self, unit, user=None):
status, lines = self.systemctl('--no-pager show "{}"'.format(unit), user)
if status != 0:
return None
raise Exception(
Copy link
Member

@Mic92 Mic92 Nov 8, 2019

Choose a reason for hiding this comment

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

I agree with this. The current usage of this function in the code of this is buggy in the presents of returning None.

@Mic92 Mic92 merged commit 438a0cd into NixOS:master Nov 8, 2019
@marijanp marijanp deleted the improvement-test-driver-py branch November 8, 2019 10:28
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.

None yet

3 participants