Open parmstro opened 1 year ago
What is the cache refresh API?! :)
- name: "Get the compute resource id"
redhat.satellite.compute_resource:
username: "{{ satellite_admin_username }}"
password: "{{ satellite_admin_password }}"
server_url: "{{ satellite_url }}"
validate_certs: "{{ satellite_validate_certs }}"
name: "{{ cpr.compute_attributes[0].compute_resource }}"
state: "present"
register: result
- ansible.builtin.set_fact:
cr_id: "{{ result.entity.compute_resources[0].id }}"
# you can change the name of the compute profile by simply passing name and updated_name
- name: "Force refresh of Compute Resource API cache"
ansible.builtin.uri:
url: "{{ satellite_url }}/api/compute_resources/{{ cr_id }}-{{ cpr.compute_attributes[0].compute_resource }}/refresh_cache"
method: "PUT"
body_format: "json"
user: "{{ satellite_admin_username }}"
password: "{{ satellite_admin_password }}"
force_basic_auth: true
validate_certs: "{{ satellite_validate_certs }}"
register: refresh_result
- debug:
var: refresh_result.json.message
Wait, you create a fresh CR and after that the cache is invalid? That sounds like a Foreman bug, not something we should (have to) workaround in FAM.
Interestingly, https://github.com/theforeman/foreman/blob/develop/app/models/concerns/compute_resource_caching.rb only calls a refresh automatically after_update
, but not after_create
(or after_save
which would contain both).
The original refresh was added in https://projects.theforeman.org/issues/19506 / https://github.com/theforeman/foreman/pull/4524
Wonder what @ares thinks about this.
That patch was create to only solve the issue of updating the CR. I'm not sure how the cache could be invalid right after the CR creation, but if it helps, I think replacing after_update
with after_save
is a good move. There was no higher logic in why we don't do that after the CR creation, it just felt unnecessary.
Yeah, I am too curious how this ended up with a "bad" cache, but here we are.
@parmstro if the issue is sufficiently reproducible in your env, could you try patching it to use after_save
instead of after_update
and see if it makes anything better?
Yes. I will patch to use after_save and set caching_enabled to true for my next test run. Please Note: with only caching_enabled, and no code to call cache_refresh, the builder creates the CR and gets through a couple of CPs then emits the error. This is very reproducible. with caching_enabled, and the code to call cache_refresh (code queries the API to get the ID of the compute resources so that we can use it in the call), this errors right after the call that creates the CR.
Could you by any chance provide access to a reproducer system?
The systems are built and torn down constantly. I would have to spin you up one, but that can be done. Let me see if I can work on it. I am in the middle of a test right now with caching_enabled: false .. The environment build is past the compute_resource creation and is actively using it to build systems. I am switching it back for the next run and creating the edit that you requested in comment 5. Currently building tang hosts, so environment should be finished in about 90 minutes or so.
SUMMARY
FAILED! => {"changed": false, "error": {"message": "undefined method `resource_pools' for nil:NilClass"}, "msg": "Failed to show resource: HTTPError: 500 Server Error: Internal Server Error for url: https://sat.example.ca/api/compute_resources/1"}
ISSUE TYPE
ANSIBLE VERSION
COLLECTION VERSION
KATELLO/FOREMAN VERSION
STEPS TO REPRODUCE
EXPECTED RESULTS
No errors, all profiles created successfully.
ACTUAL RESULTS
NOTE: If I call the cache_refresh api before creating the profiles, all is good. However, I have run into the problem that trying to query the Satellite to get the info so I can call a cache refresh can also run into the error. This is a real bummer when you are an hour and a half in on a build and things bomb out. I am currently testing with the compute resource created with the cache off.
It would be nice to have a cache refresh embedded in the background as this is an automation task and not a UI thing. No one is waiting and watching.