-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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/home-assistant: fix bug causing config file not to be written (including http.server_port
)
#82480
nixos/home-assistant: fix bug causing config file not to be written (including http.server_port
)
#82480
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import ./make-test-python.nix ({ pkgs, ... }: | ||
|
||
let | ||
configDir = "/var/lib/hass"; | ||
configFile = "${configDir}/configuration.yaml"; | ||
port = 4000; | ||
|
||
mkHass = { machineAttrs ? {}, hassAttrs ? {} }: | ||
{ pkgs, ... }: | ||
{ | ||
services.home-assistant = { | ||
inherit configDir port; | ||
enable = true; | ||
} // hassAttrs; | ||
} // machineAttrs; | ||
in { | ||
name = "home-assistant-config"; | ||
|
||
nodes = { | ||
hassMinimal = mkHass {}; | ||
|
||
hassTimeZone = mkHass { | ||
machineAttrs = { time.timeZone = "UTC"; }; | ||
}; | ||
|
||
hassNoDefault = mkHass { | ||
hassAttrs = { applyDefaultConfig = false; }; | ||
}; | ||
Comment on lines
+20
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we are going to need all those tests. They don't test much but still needs to be maintained and they are expensive to evaluate. It would be fine if they only would generate the configuration but they spawn actual VMs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @Mic92 thanks for the feedback. This was my feeling as well, but I wasn't sure how to do unit tests in Nix. Perhaps I just missed some examples or documentation. Is there anything you could point me to that might help? |
||
}; | ||
|
||
testScript = let | ||
portStr = toString port; | ||
in '' | ||
start_all() | ||
|
||
|
||
def check_availability(hass): | ||
hass.wait_for_unit("home-assistant.service") | ||
with subtest("Check that Home Assistant can be reached via port ${portStr}"): | ||
hass.wait_for_open_port(${portStr}) | ||
hass.succeed("curl --fail http://localhost:${portStr}") | ||
|
||
|
||
check_availability(hassMinimal) | ||
with subtest("Check that port is set"): | ||
config = hassMinimal.succeed("cat ${configFile}") | ||
assert "server_port: ${portStr}" in config | ||
|
||
check_availability(hassTimeZone) | ||
with subtest("Check that default_config, port and time_zone are set"): | ||
config = hassTimeZone.succeed("cat ${configFile}") | ||
assert "server_port: ${portStr}" in config | ||
assert "time_zone: UTC" in config | ||
|
||
hassNoDefault.wait_for_unit("home-assistant.service") | ||
|
||
with subtest("Check that server port is not set"): | ||
config = hassNoDefault.succeed("cat ${configFile}") | ||
assert "server_port: ${portStr}" not in config | ||
|
||
# It cannot be reached because defaults (i.e. http.server_port, frontend) are not set | ||
with subtest("Check that Home Assistant cannot be reached via port ${portStr}"): | ||
hassNoDefault.wait_for_closed_port(${portStr}) | ||
''; | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the actual bug fix is this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but I believe
frontend
missing was also causing issues. It's been quite a while though and it's not that fresh anymore. I'll have to spend some time going through and running it in various situations.