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

Fix mock for cgroup unit test #3079

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/common/osutil/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ def test_remove_firewall_should_not_retry_invalid_rule(self):

self.assertFalse(osutil._enable_firewall)

@skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4 for now. Need to revisit to fix it")
@skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4, they run on containers where the OS commands needed by the test are not present.")
def test_get_nic_state(self):
state = osutil.DefaultOSUtil().get_nic_state()
self.assertNotEqual(state, {})
Expand Down
2 changes: 1 addition & 1 deletion tests/common/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def test_collect_events_should_be_able_to_process_events_with_non_ascii_characte
self.assertEqual(len(event_list), 1)
self.assertEqual(TestEvent._get_event_message(event_list[0]), u'World\u05e2\u05d9\u05d5\u05ea \u05d0\u05d7\u05e8\u05d5\u05ea\u0906\u091c')

@skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4 for now. Need to revisit to fix it")
@skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4, they run on containers where the OS commands needed by the test are not present.")
def test_collect_events_should_ignore_invalid_event_files(self):
self._create_test_event_file("custom_script_1.tld") # a valid event
self._create_test_event_file("custom_script_utf-16.tld")
Expand Down
7 changes: 5 additions & 2 deletions tests/ga/test_cgroupconfigurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def test_start_extension_command_should_disable_cgroups_and_invoke_the_command_d

self.assertEqual(len(CGroupsTelemetry._tracked), 0, "No cgroups should have been created")

@skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4 for now. Need to revisit to fix it")
@skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4, they run on containers where the OS commands needed by the test are not present.")
@attr('requires_sudo')
@patch('time.sleep', side_effect=lambda _: mock_sleep())
def test_start_extension_command_should_not_use_fallback_option_if_extension_fails(self, *args):
Expand Down Expand Up @@ -564,7 +564,7 @@ def test_start_extension_command_should_not_use_fallback_option_if_extension_fai
# wasn't truncated.
self.assertIn("Running scope as unit", ustr(context_manager.exception))

@skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4 for now. Need to revisit to fix it")
@skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4, they run on containers where the OS commands needed by the test are not present.")
@attr('requires_sudo')
@patch('time.sleep', side_effect=lambda _: mock_sleep())
@patch("azurelinuxagent.ga.extensionprocessutil.TELEMETRY_MESSAGE_MAX_LEN", 5)
Expand Down Expand Up @@ -632,6 +632,7 @@ def test_start_extension_command_should_not_use_fallback_option_if_extension_tim
self.assertEqual(context_manager.exception.code, ExtensionErrorCodes.PluginHandlerScriptTimedout)
self.assertIn("Timeout", ustr(context_manager.exception))

@skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4, they run on containers where the OS commands needed by the test are not present.")
@patch('time.sleep', side_effect=lambda _: mock_sleep())
def test_start_extension_command_should_capture_only_the_last_subprocess_output(self, _):
with self._get_cgroup_configurator() as configurator:
Expand All @@ -647,6 +648,8 @@ def mock_popen(command, *args, **kwargs):
command = command.replace('systemd-run', 'systemd-run syntax_error')
elif isinstance(command, list) and command[0] == 'systemd-run':
command = ['systemd-run', 'syntax_error'] + command[1:]
elif command == ['systemctl', 'daemon-reload']:
command = ['echo', 'systemctl', 'daemon-reload']

return original_popen(command, *args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion tests/ga/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ def _mock_popen(cmd, *args, **kwargs):
"Not setting up persistent firewall rules as OS.EnableFirewall=False" == args[0] for (args, _) in
patch_info.call_args_list), "Info not logged properly, got: {0}".format(patch_info.call_args_list))

@skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4 for now. Need to revisit to fix it")
@skip_if_predicate_true(is_python_version_26_or_34, "Disabled on Python 2.6 and 3.4, they run on containers where the OS commands needed by the test are not present.")
def test_it_should_setup_persistent_firewall_rules_on_startup(self):
iterations = 1
executed_commands = []
Expand Down
Loading