foreman_rh_cloud 13.2.11 → 13.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2139dff816242e974e133f964b393409a65962f4dc5a5de0651b85d1d3c4bcb7
4
- data.tar.gz: f362df63107b1a8834c6984654bedef584875e6d1d226dcab130c1d8fa11d181
3
+ metadata.gz: '02381fe754515035b984e0c7a5a8b8c3b84f6a9ec086bae66ca4c5edf6109c53'
4
+ data.tar.gz: 239b22edd6071beadb3a32377f8560ea3a0f3079b00a486b2bc12733d77f3d3d
5
5
  SHA512:
6
- metadata.gz: 1a06fbaad9e79093b83f8ac8454ffcbf0ffa875f1978ef04697b8cfcf58c0a35812a7eee649f08b45df4c938a20e6784bffcba5bbc702c73a5bf224fe8958b47
7
- data.tar.gz: d5c4b920bc78b449ddca4b080be077a24c3766950de46f30f9611745a85927e37e44c18d7aea6223b91e2faa4e3a6eb39fe9fab139207d9c73a1917c6910b0cd
6
+ metadata.gz: 0eb11bb0ff17fc1ae0a6e7ac2c43a2f91adf6b6f0299f5570ba6d58fa2a8dd7045f35a7dbe380e98f5debda30d41e3aff5898125f0498672117914fcffbbb9c1
7
+ data.tar.gz: b0341e69c8718e61f1695a5c9ecca09064cab6927f163249bf774e3dc770bac599e15fce4798b1c56ea4d13671961089774d25756dfb00e5ac3bfa0fd6bbf5ce
@@ -5,6 +5,7 @@ module ForemanRhCloud
5
5
  TAG_NAMESPACE = 'sat_iam'.freeze
6
6
  TAG_SHORT_NAME = 'scope'.freeze
7
7
  TAG_NAME = "#{TAG_NAMESPACE}/#{TAG_SHORT_NAME}".freeze
8
+ SYNC_CACHE_TTL = 10.seconds
8
9
 
9
10
  def self.auth_tag_for(user, org, loc)
10
11
  new(user, org, loc, nil).auth_tag
@@ -20,20 +21,28 @@ module ForemanRhCloud
20
21
  end
21
22
 
22
23
  def update_tag
23
- loc_name = location_name_for_tag
24
- logger.debug("Updating tags for user: #{@user}, org: #{@org.name}, loc: #{loc_name}")
24
+ cached = Rails.cache.read(sync_identity)
25
+ return cached if cached
25
26
 
26
- payload = tags_query_payload
27
- params = {
28
- organization: @org,
29
- method: :post,
30
- url: "#{InsightsCloud.gateway_url}/tags",
31
- headers: {
32
- content_type: :json,
33
- },
34
- payload: payload.to_json,
35
- }
36
- execute_cloud_request(params) unless payload[:host_id_list].empty?
27
+ Foreman::AdvisoryLockManager.with_session_lock(sync_identity) do
28
+ Rails.cache.fetch(sync_identity, expires_in: SYNC_CACHE_TTL) do
29
+ loc_name = location_name_for_tag
30
+ logger.debug("Updating tags for user: #{@user}, org: #{@org.name}, loc: #{loc_name}")
31
+
32
+ payload = tags_query_payload
33
+ params = {
34
+ organization: @org,
35
+ method: :post,
36
+ url: "#{InsightsCloud.gateway_url}/tags",
37
+ headers: {
38
+ content_type: :json,
39
+ },
40
+ payload: payload.to_json,
41
+ }
42
+ execute_cloud_request(params) unless payload[:host_id_list].empty?
43
+ true
44
+ end
45
+ end
37
46
  end
38
47
 
39
48
  def allowed_hosts
@@ -63,5 +72,11 @@ module ForemanRhCloud
63
72
  def location_name_for_tag
64
73
  @loc ? @loc.name : '*'
65
74
  end
75
+
76
+ # Single identity string reused as BOTH the advisory-lock name and the
77
+ # Rails.cache key, so the lock and the cached entry always correspond 1:1.
78
+ def sync_identity
79
+ "rh_cloud_tags_auth_sync_#{tag_value}"
80
+ end
66
81
  end
67
82
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '13.2.11'.freeze
2
+ VERSION = '13.2.12'.freeze
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "13.2.11",
3
+ "version": "13.2.12",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -3,6 +3,7 @@ require 'json'
3
3
 
4
4
  class TagsAuthTest < ActiveSupport::TestCase
5
5
  setup do
6
+ Rails.cache.clear
6
7
  @user = FactoryBot.build(:user)
7
8
  @logger = Logger.new(IO::NULL)
8
9
  @org = FactoryBot.build(:organization)
@@ -41,6 +42,31 @@ class TagsAuthTest < ActiveSupport::TestCase
41
42
  @auth.update_tag
42
43
  end
43
44
 
45
+ test 'Does not repeat cloud request for the same user/org/location within the sync TTL' do
46
+ @auth.stubs(:allowed_hosts).returns(['test_uuid1'])
47
+ @auth.expects(:execute_cloud_request).once
48
+
49
+ @auth.update_tag
50
+ @auth.update_tag
51
+ end
52
+
53
+ test 'Serializes sync through an advisory lock on a cold cache miss' do
54
+ @auth.stubs(:allowed_hosts).returns(['test_uuid1'])
55
+ @auth.stubs(:execute_cloud_request)
56
+ Foreman::AdvisoryLockManager.expects(:with_session_lock).yields
57
+
58
+ @auth.update_tag
59
+ end
60
+
61
+ test 'Skips the advisory lock entirely on a warm cache hit' do
62
+ @auth.stubs(:allowed_hosts).returns(['test_uuid1'])
63
+ @auth.stubs(:execute_cloud_request)
64
+ @auth.update_tag
65
+
66
+ Foreman::AdvisoryLockManager.expects(:with_session_lock).never
67
+ @auth.update_tag
68
+ end
69
+
44
70
  test 'Generates tags with wildcard location when location is nil' do
45
71
  auth_with_nil_loc = ::ForemanRhCloud::TagsAuth.new(@user, @org, nil, @logger)
46
72
  uuid1 = 'test_uuid1'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rh_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.2.11
4
+ version: 13.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team
@@ -639,7 +639,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
639
639
  - !ruby/object:Gem::Version
640
640
  version: '0'
641
641
  requirements: []
642
- rubygems_version: 4.0.16
642
+ rubygems_version: 4.0.20
643
643
  specification_version: 4
644
644
  summary: Summary of ForemanRhCloud.
645
645
  test_files: