From bae9b11da9ed7dd0b16fe5adeaf4774b7cc628cf Mon Sep 17 00:00:00 2001 From: James Falcon Date: Wed, 15 Dec 2021 20:16:38 -0600 Subject: Adopt Black and isort (SC-700) (#1157) Applied Black and isort, fixed any linting issues, updated tox.ini and CI. --- .../modules/test_power_state_change.py | 48 +++++++++++++--------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'tests/integration_tests/modules/test_power_state_change.py') diff --git a/tests/integration_tests/modules/test_power_state_change.py b/tests/integration_tests/modules/test_power_state_change.py index 5f3a32ac..a629029d 100644 --- a/tests/integration_tests/modules/test_power_state_change.py +++ b/tests/integration_tests/modules/test_power_state_change.py @@ -30,7 +30,7 @@ def _detect_reboot(instance: IntegrationInstance): instance.instance.wait() for _ in range(600): try: - log = instance.read_from_file('/var/log/cloud-init.log') + log = instance.read_from_file("/var/log/cloud-init.log") boot_count = log.count("running 'init-local'") if boot_count == 1: instance.instance.wait() @@ -40,11 +40,11 @@ def _detect_reboot(instance: IntegrationInstance): pass time.sleep(1) else: - raise Exception('Could not detect reboot') + raise Exception("Could not detect reboot") def _can_connect(instance): - return instance.execute('true').ok + return instance.execute("true").ok # This test is marked unstable because even though it should be able to @@ -55,36 +55,44 @@ def _can_connect(instance): @pytest.mark.ubuntu @pytest.mark.lxd_container class TestPowerChange: - @pytest.mark.parametrize('mode,delay,timeout,expected', [ - ('poweroff', 'now', '10', 'will execute: shutdown -P now msg'), - ('reboot', 'now', '0', 'will execute: shutdown -r now msg'), - ('halt', '+1', '0', 'will execute: shutdown -H +1 msg'), - ]) - def test_poweroff(self, session_cloud: IntegrationCloud, - mode, delay, timeout, expected): + @pytest.mark.parametrize( + "mode,delay,timeout,expected", + [ + ("poweroff", "now", "10", "will execute: shutdown -P now msg"), + ("reboot", "now", "0", "will execute: shutdown -r now msg"), + ("halt", "+1", "0", "will execute: shutdown -H +1 msg"), + ], + ) + def test_poweroff( + self, session_cloud: IntegrationCloud, mode, delay, timeout, expected + ): with session_cloud.launch( user_data=USER_DATA.format( - delay=delay, mode=mode, timeout=timeout, condition='true'), - launch_kwargs={'wait': False}, + delay=delay, mode=mode, timeout=timeout, condition="true" + ), + launch_kwargs={"wait": False}, ) as instance: - if mode == 'reboot': + if mode == "reboot": _detect_reboot(instance) else: instance.instance.wait_for_stop() instance.instance.start(wait=True) - log = instance.read_from_file('/var/log/cloud-init.log') + log = instance.read_from_file("/var/log/cloud-init.log") assert _can_connect(instance) lines_to_check = [ - 'Running module power-state-change', + "Running module power-state-change", expected, "running 'init-local'", - 'config-power-state-change already ran', + "config-power-state-change already ran", ] verify_ordered_items_in_text(lines_to_check, log) - @pytest.mark.user_data(USER_DATA.format(delay='0', mode='poweroff', - timeout='0', condition='false')) + @pytest.mark.user_data( + USER_DATA.format( + delay="0", mode="poweroff", timeout="0", condition="false" + ) + ) def test_poweroff_false_condition(self, client: IntegrationInstance): - log = client.read_from_file('/var/log/cloud-init.log') + log = client.read_from_file("/var/log/cloud-init.log") assert _can_connect(client) - assert 'Condition was false. Will not perform state change' in log + assert "Condition was false. Will not perform state change" in log -- cgit v1.2.3