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

workaround for python3.5 UTs build setup and replace assert_called_once mock method #3191

Merged
merged 5 commits into from
Aug 26, 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
5 changes: 5 additions & 0 deletions .github/workflows/ci_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ jobs:
matrix:
include:
- python-version: "3.5"
# workaround found in https://github.com/actions/setup-python/issues/866
# for issue "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:728)" on Python 3.5
pip_trusted_host: "pypi.python.org pypi.org files.pythonhosted.org"
Copy link
Member

Choose a reason for hiding this comment

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

good find; could you add actions/setup-python#866 to the comment?

- python-version: "3.6"
- python-version: "3.7"
- python-version: "3.8"
Expand All @@ -111,6 +114,8 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
env:
PIP_TRUSTED_HOST: ${{ matrix.pip_trusted_host }}

- name: Install dependencies
id: install-dependencies
Expand Down
8 changes: 4 additions & 4 deletions tests/common/protocol/test_protocol_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ def test_get_protocol_wireserver_to_wireserver_update_removes_metadataserver_art
self.assertFalse(os.path.exists(mds_cert_path))

# Check firewall rules was reset
protocol_util.osutil.remove_firewall.assert_called_once()
protocol_util.osutil.enable_firewall.assert_called_once()
self.assertEqual(1, protocol_util.osutil.remove_firewall.call_count, "remove_firewall should be called once")
self.assertEqual(1, protocol_util.osutil.enable_firewall.call_count, "enable_firewall should be called once")

@patch('azurelinuxagent.common.conf.get_lib_dir')
@patch('azurelinuxagent.common.conf.enable_firewall')
Expand Down Expand Up @@ -234,8 +234,8 @@ def test_get_protocol_metadataserver_to_wireserver_update_removes_metadataserver
self.assertTrue(os.path.isfile(ws_cert_path))

# Check firewall rules was reset
protocol_util.osutil.remove_firewall.assert_called_once()
protocol_util.osutil.enable_firewall.assert_called_once()
self.assertEqual(1, protocol_util.osutil.remove_firewall.call_count, "remove_firewall should be called once")
self.assertEqual(1, protocol_util.osutil.enable_firewall.call_count, "enable_firewall should be called once")

# Check Protocol File is updated to WireProtocol
with open(os.path.join(dir, PROTOCOL_FILE_NAME), "r") as f:
Expand Down
2 changes: 1 addition & 1 deletion tests/ga/test_exthandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ def test_it_should_read_only_the_head_of_large_outputs(self):
self.assertGreaterEqual(len(output), 1024)
self.assertLessEqual(len(output), TELEMETRY_MESSAGE_MAX_LEN)

mock_format.assert_called_once()
self.assertEqual(1, mock_format.call_count, "format_stdout_stderr should be called once")

args, kwargs = mock_format.call_args # pylint: disable=unused-variable
stdout, stderr = args
Expand Down
9 changes: 5 additions & 4 deletions tests/ga/test_exthandlers_download_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def stream(_, destination, **__):
self.ext_handler_instance.download()

# first download attempt should succeed
mock_stream.assert_called_once()
mock_report_event.assert_called_once()
self.assertEqual(1, mock_stream.call_count, "wireserver stream should be called once")
self.assertEqual(1, mock_report_event.call_count, "report_event should be called once")

self._assert_download_and_expand_succeeded()

Expand All @@ -154,7 +154,7 @@ def stream(_, destination, **__):
with DownloadExtensionTestCase.create_mock_stream(stream) as mock_stream:
self.ext_handler_instance.download()

mock_stream.assert_called_once()
self.assertEqual(1, mock_stream.call_count, "wireserver stream should be called once")

self._assert_download_and_expand_succeeded()

Expand All @@ -179,7 +179,8 @@ def stream(_, destination, **__):
with DownloadExtensionTestCase.create_mock_stream(stream) as mock_stream:
self.ext_handler_instance.download()

mock_stream.assert_called_once()
self.assertEqual(1, mock_stream.call_count, "wireserver stream should be called once")

self._assert_download_and_expand_succeeded()
self.assertEqual(self.ext_handler_instance.get_handler_state(), ExtHandlerState.NotInstalled,
"Ensure that the state is maintained for extension HandlerState")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def mock_cgroup(*args, **kwargs): # pylint: disable=W0613
agent = Agent(False, conf_file_path=os.path.join(data_dir, "test_waagent.conf"))
agent.collect_logs(is_full_mode=True)

mock_log_collector.assert_called_once()
self.assertEqual(1, mock_log_collector.call_count, "LogCollector should be called once")

finally:
CollectLogsHandler.disable_monitor_cgroups_check()
Expand Down
Loading