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

Download certificates when goal state source is Fast Track #2761

Merged
merged 22 commits into from
Mar 7, 2023

Conversation

maddieford
Copy link
Contributor

@maddieford maddieford commented Feb 14, 2023

This PR includes a change to download certificates when goal state source is FastTrack

Fixes #2750

@codecov
Copy link

codecov bot commented Feb 14, 2023

Codecov Report

Merging #2761 (3f39db4) into develop (66a6258) will increase coverage by 0.00%.
The diff coverage is 81.81%.

@@           Coverage Diff            @@
##           develop    #2761   +/-   ##
========================================
  Coverage    71.99%   71.99%           
========================================
  Files          104      104           
  Lines        15831    15839    +8     
  Branches      2264     2265    +1     
========================================
+ Hits         11397    11404    +7     
  Misses        3913     3913           
- Partials       521      522    +1     
Impacted Files Coverage Δ
azurelinuxagent/common/protocol/goal_state.py 95.45% <81.81%> (-0.15%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -412,7 +412,7 @@ def http_get_handler(url, *_, **__):
goal_state = GoalState(protocol.client)

self.assertEqual(2, protocol.mock_wire_data.call_counts['goalstate'], "There should have been exactly 2 requests for the goal state (original + refresh)")
self.assertEqual(2, http_get_handler.certificate_requests, "There should have been exactly 2 requests for the goal state certificates (original + refresh)")
self.assertEqual(4, http_get_handler.certificate_requests, "There should have been exactly 4 requests for the goal state certificates (2x original + 2x refresh)")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous 2 requests became 4 requests for this case because we're downloading certificates in _fetch_full_wire_server_goal_state and _update directly.

Should I add logic to only download certificates once per goals state?

@@ -156,7 +156,7 @@ def http_get_handler(url, *_, **__):
protocol.set_http_handlers(http_get_handler=None)
goal_state.update()
self._assert_directory_contents(
self._find_history_subdirectory("234-987"), ["VmSettings.json"])
self._find_history_subdirectory("234-987"), ["VmSettings.json", "Certificates.json"])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test shows that we create history subdirectory with Certificates.json when we have a fast track goal state. Should I add an additional test to verify the certificates are downloaded?

@@ -1101,7 +1101,7 @@ def test_forced_update_should_update_the_goal_state_and_the_host_plugin_when_the

def test_reset_should_init_provided_goal_state_properties(self):
with mock_wire_protocol(mockwiredata.DATA_FILE) as protocol:
protocol.client.reset_goal_state(goal_state_properties=GoalStateProperties.All & ~GoalStateProperties.ExtensionsGoalState)
protocol.client.reset_goal_state(goal_state_properties=GoalStateProperties.All & ~GoalStateProperties.Certificates)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated this test after separating ExtensionsGoalState and Certificates in GoalStateProperties.

narrieta
narrieta previously approved these changes Mar 1, 2023
@@ -289,6 +290,9 @@ def _update(self, force_update):
# case, to ensure it fetches the new certificate.
#
if self._extensions_goal_state.source == GoalStateSource.FastTrack:
certs_uri = findtext(xml_doc, "Certificates")
if certs_uri is not None:
self._download_certificates(certs_uri)
Copy link
Contributor

@nagworld9 nagworld9 Mar 2, 2023

Choose a reason for hiding this comment

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

In case if we downloaded new certs then we are not updating the state of goal_state certs in self._certs. Next line check certificates is using self._certs which will have old certs. Or am I missing something?

@@ -289,9 +290,14 @@ def _update(self, force_update):
# case, to ensure it fetches the new certificate.
#
if self._extensions_goal_state.source == GoalStateSource.FastTrack:
self._check_certificates()
certs_uri = findtext(xml_doc, "Certificates")
Copy link
Member

Choose a reason for hiding this comment

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

Minor: let's add certs_uri as a data member of self and use that instead of picking it up from the xml_doc we just fetched. With the current code, this makes no difference functionally, but let's do that in case the code changes. That would also emphasize that we are redownloading the same certs as we did before.

Also, we should re-download only if self._goal_state_properties & GoalStateProperties.Certificates != 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants