Project

General

Profile

Revision 1a2d49fd

Added by Justin Sherrill almost 6 years ago

Fixes #16466 - Add support for applicable rpms

View differences:

lib/runcible/extensions/consumer.rb
141 141
      # Retrieve the set of errata that is applicable to a consumer(s)
142 142
      #
143 143
      # @param  [String, Array]         ids             string containing a single consumer id or an array of ids
144
      # @param  [Array]                 repoids         array of repository ids
145
      # @param  [Boolean]               consumer_report if true, result will list consumers and their
146
      #                                                 applicable errata; otherwise, it will list
147
      #                                                 errata and the consumers they are applicable to
148 144
      # @return [RestClient::Response]  content applicability hash with details of errata available to consumer(s)
149 145
      def applicable_errata(ids)
146
        applicable_for_type(ids, Runcible::Extensions::Errata.content_type)
147
      end
148

  
149
      # Retrieve the set of rpms that are applicable to a consumer(s)
150
      #
151
      # @param  [String, Array]         ids             string containing a single consumer id or an array of ids
152
      # @return [RestClient::Response]  content applicability hash with details of rpms available to consumer(s)
153
      def applicable_rpms(ids)
154
        applicable_for_type(ids, Runcible::Extensions::Rpm.content_type)
155
      end
156

  
157
      private
158

  
159
      def applicable_for_type(ids, type)
150 160
        ids = [ids] if ids.is_a? String
151 161

  
152 162
        criteria = {
153 163
          'criteria' => { 'filters' => { 'id' => { '$in' => ids } } },
154
          'content_types' => [Runcible::Extensions::Errata.content_type]
164
          'content_types' => [type]
155 165
        }
156 166
        applicability(criteria)
157 167
      end
158 168

  
159
      private
160

  
161 169
      def repository_extension
162 170
        Runcible::Extensions::Repository.new(self.config)
163 171
      end
test/extensions/consumer_test.rb
111 111

  
112 112
      assert_equal 200, response.code
113 113
    end
114

  
115
    def test_applicable_rpms
116
      response = @extension.applicable_rpms([@consumer_id])
117

  
118
      assert_equal 200, response.code
119
    end
114 120
  end
115 121

  
116 122
  class TestConsumerApplicabilityScenario < MiniTest::Unit::TestCase
test/fixtures/vcr_cassettes/extensions/consumer/applicable_rpms.yml
1
---
2
http_interactions:
3
- request:
4
    method: delete
5
    uri: https://admin:rGox3G9QhfCRD8fTsNR7FxqdgbvfJfSJ@abed.usersys.redhat.com/pulp/api/v2/consumers/integration_test_consumer_support/
6
    body:
7
      encoding: US-ASCII
8
      string: ''
9
    headers:
10
      Accept:
11
      - application/json
12
      Accept-Encoding:
13
      - gzip, deflate
14
      Content-Type:
15
      - application/json
16
      User-Agent:
17
      - Ruby
18
  response:
19
    status:
20
      code: 404
21
      message: NOT FOUND
22
    headers:
23
      Date:
24
      - Wed, 07 Sep 2016 00:43:18 GMT
25
      Server:
26
      - Apache/2.4.6 (CentOS)
27
      Content-Length:
28
      - '513'
29
      Connection:
30
      - close
31
      Content-Type:
32
      - application/json; charset=utf-8
33
    body:
34
      encoding: UTF-8
35
      string: '{"http_request_method": "DELETE", "exception": null, "error_message":
36
        "Missing resource(s): consumer=integration_test_consumer_support", "_href":
37
        "/pulp/api/v2/consumers/integration_test_consumer_support/", "http_status":
38
        404, "error": {"code": "PLP0009", "data": {"resources": {"consumer": "integration_test_consumer_support"}},
39
        "description": "Missing resource(s): consumer=integration_test_consumer_support",
40
        "sub_errors": []}, "traceback": null, "resources": {"consumer": "integration_test_consumer_support"}}'
41
    http_version: 
42
  recorded_at: Wed, 07 Sep 2016 00:43:18 GMT
43
- request:
44
    method: delete
45
    uri: https://admin:rGox3G9QhfCRD8fTsNR7FxqdgbvfJfSJ@abed.usersys.redhat.com/pulp/api/v2/consumers/integration_test_consumer_support/
46
    body:
47
      encoding: US-ASCII
48
      string: ''
49
    headers:
50
      Accept:
51
      - application/json
52
      Accept-Encoding:
53
      - gzip, deflate
54
      Content-Type:
55
      - application/json
56
      User-Agent:
57
      - Ruby
58
  response:
59
    status:
60
      code: 404
61
      message: NOT FOUND
62
    headers:
63
      Date:
64
      - Wed, 07 Sep 2016 00:43:18 GMT
65
      Server:
66
      - Apache/2.4.6 (CentOS)
67
      Content-Length:
68
      - '513'
69
      Connection:
70
      - close
71
      Content-Type:
72
      - application/json; charset=utf-8
73
    body:
74
      encoding: UTF-8
75
      string: '{"http_request_method": "DELETE", "exception": null, "error_message":
76
        "Missing resource(s): consumer=integration_test_consumer_support", "_href":
77
        "/pulp/api/v2/consumers/integration_test_consumer_support/", "http_status":
78
        404, "error": {"code": "PLP0009", "data": {"resources": {"consumer": "integration_test_consumer_support"}},
79
        "description": "Missing resource(s): consumer=integration_test_consumer_support",
80
        "sub_errors": []}, "traceback": null, "resources": {"consumer": "integration_test_consumer_support"}}'
81
    http_version: 
82
  recorded_at: Wed, 07 Sep 2016 00:43:18 GMT
83
- request:
84
    method: post
85
    uri: https://admin:rGox3G9QhfCRD8fTsNR7FxqdgbvfJfSJ@abed.usersys.redhat.com/pulp/api/v2/consumers/
86
    body:
87
      encoding: UTF-8
88
      string: '{"id":"integration_test_consumer_support"}'
89
    headers:
90
      Accept:
91
      - application/json
92
      Accept-Encoding:
93
      - gzip, deflate
94
      Content-Type:
95
      - application/json
96
      Content-Length:
97
      - '42'
98
      User-Agent:
99
      - Ruby
100
  response:
101
    status:
102
      code: 201
103
      message: CREATED
104
    headers:
105
      Date:
106
      - Wed, 07 Sep 2016 00:43:18 GMT
107
      Server:
108
      - Apache/2.4.6 (CentOS)
109
      Content-Length:
110
      - '2277'
111
      Location:
112
      - https://abed.usersys.redhat.com/pulp/api/v2/consumers/integration_test_consumer_support/
113
      Connection:
114
      - close
115
      Content-Type:
116
      - application/json; charset=utf-8
117
    body:
118
      encoding: UTF-8
119
      string: '{"consumer": {"display_name": "integration_test_consumer_support",
120
        "description": null, "_ns": "consumers", "notes": {}, "rsa_pub": null, "capabilities":
121
        {}, "_id": {"$oid": "57cf62a65ca0131f92a6c584"}, "id": "integration_test_consumer_support",
122
        "_href": "/pulp/api/v2/consumers/integration_test_consumer_support/"}, "certificate":
123
        "-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQCkfOT6Cr+FfPTZiH1wmpAGSEwqI5Pi4dmjKF+QPt5t7OLrbivp\n9b3IQ7Qlv/C+Ab8hGIj77/SbnviWPvtcEgKCC61vn/YNJUp1iiiXFNI7XGf80MQg\nGx19Wjv5tqwL82Xmv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KCZImiZPyLGQBARMYNTdjZjYyYTY1Y2EwMTMxZjkyYTZjNTg0MIGfMA0GCSqG\nSIb3DQEBAQUAA4GNADCBiQKBgQCkfOT6Cr+FfPTZiH1wmpAGSEwqI5Pi4dmjKF+Q\nPt5t7OLrbivp9b3IQ7Qlv/C+Ab8hGIj77/SbnviWPvtcEgKCC61vn/YNJUp1iiiX\nFNI7XGf80MQgGx19Wjv5tqwL82Xmvv4AGPL6Ju9MLqT797/gc8vSj4tFetCpt2jJ\n08l5rwIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQCNXrm73yVMmslxwlZVHFyIg21J\n2I6DcgMSIDJHfv10CCov0Xa/UhBsifL5GNxDaAahogDjpcOrFzk5NqCa7cHJwzRU\nDfJC+5GDRWyM8qb7GWG62FK43sVVfd3Xlz53Ew0BBXD4DUlj1EzJs4hDQO5WwLNz\nDDeaajlDCTX4qxqMrOOtaNVa2ePEd0SZpj3O6XvKHtrgInulQn379DwUD2U6eB36\nukmQS+Ga8YjrvLNKbR3b6eO6v1QXNCf2UxCpH5jOkGaS95vvjPoOmsOMMOR8m5L9\nBE+J8VIqZbXKQj2i7NucrtBh9Wfs68Kuty1uXFUWmWTfRcDKvl6Ombdl8SR3\n-----END
125
        CERTIFICATE-----"}'
126
    http_version: 
127
  recorded_at: Wed, 07 Sep 2016 00:43:18 GMT
128
- request:
129
    method: post
130
    uri: https://admin:rGox3G9QhfCRD8fTsNR7FxqdgbvfJfSJ@abed.usersys.redhat.com/pulp/api/v2/consumers/integration_test_consumer_support/profiles//
131
    body:
132
      encoding: UTF-8
133
      string: '{"content_type":"rpm","profile":[{"name":"elephant","version":"0.2","release":"0.7","epoch":0,"arch":"noarch","vendor":"Fedora"}]}'
134
    headers:
135
      Accept:
136
      - application/json
137
      Accept-Encoding:
138
      - gzip, deflate
139
      Content-Type:
140
      - application/json
141
      Content-Length:
142
      - '130'
143
      User-Agent:
144
      - Ruby
145
  response:
146
    status:
147
      code: 201
148
      message: CREATED
149
    headers:
150
      Date:
151
      - Wed, 07 Sep 2016 00:43:18 GMT
152
      Server:
153
      - Apache/2.4.6 (CentOS)
154
      Content-Length:
155
      - '475'
156
      Location:
157
      - https://abed.usersys.redhat.com/pulp/api/v2/consumers/integration_test_consumer_support/profiles/rpm/
158
      Connection:
159
      - close
160
      Content-Type:
161
      - application/json; charset=utf-8
162
    body:
163
      encoding: UTF-8
164
      string: '{"profile": [{"vendor": "Fedora", "name": "elephant", "epoch": 0, "version":
165
        "0.2", "release": "0.7", "arch": "noarch"}], "_href": "/pulp/api/v2/consumers/integration_test_consumer_support/profiles/rpm/",
166
        "_ns": "consumer_unit_profiles", "profile_hash": "db16b75e977ae3fbbf27beb919693137b26ba59eb7be73f2888197b89521e50d",
167
        "consumer_id": "integration_test_consumer_support", "content_type": "rpm",
168
        "_id": {"$oid": "57cf62a75ca0131f92a6c586"}, "id": "57cf62a75ca0131f92a6c586"}'
169
    http_version: 
170
  recorded_at: Wed, 07 Sep 2016 00:43:19 GMT
171
- request:
172
    method: get
173
    uri: https://admin:rGox3G9QhfCRD8fTsNR7FxqdgbvfJfSJ@abed.usersys.redhat.com/pulp/api/v2/repositories/integration_test_id/?details=true
174
    body:
175
      encoding: US-ASCII
176
      string: ''
177
    headers:
178
      Accept:
179
      - application/json
180
      Accept-Encoding:
181
      - gzip, deflate
182
      Content-Type:
183
      - application/json
184
      User-Agent:
185
      - Ruby
186
  response:
187
    status:
188
      code: 200
189
      message: OK
190
    headers:
191
      Date:
192
      - Wed, 07 Sep 2016 00:43:19 GMT
193
      Server:
194
      - Apache/2.4.6 (CentOS)
195
      Vary:
196
      - Accept-Encoding
197
      Content-Length:
198
      - '1257'
199
      Connection:
200
      - close
201
      Content-Type:
202
      - application/json; charset=utf-8
203
    body:
204
      encoding: ASCII-8BIT
205
      string: '{"scratchpad": {"checksum_type": "sha256"}, "display_name": "integration_test_id",
206
        "description": null, "distributors": [{"repo_id": "integration_test_id", "_href":
207
        "/pulp/api/v2/repositories/integration_test_id/distributors/yum_dist/", "_ns":
208
        "repo_distributors", "last_publish": null, "distributor_type_id": "yum_distributor",
209
        "auto_publish": false, "scratchpad": {}, "_id": {"$oid": "57cf5cc45ca0131f93207bfe"},
210
        "config": {"http": true, "https": true, "relative_url": "path"}, "id": "yum_dist"}],
211
        "last_unit_added": null, "notes": {}, "last_unit_removed": null, "content_unit_counts":
212
        {"package_group": 2, "distribution": 1, "package_category": 1, "rpm": 8, "erratum":
213
        2}, "_ns": "repos", "importers": [{"scratchpad": null, "_href": "/pulp/api/v2/repositories/integration_test_id/importers/yum_importer/",
214
        "_ns": "repo_importers", "importer_type_id": "yum_importer", "last_sync":
215
        "2016-09-07T00:19:27Z", "repo_id": "integration_test_id", "_id": {"$oid":
216
        "57cf5cc45ca0131f93207bfd"}, "config": {"feed": "file:///var/www/repositories/zoo5"},
217
        "id": "yum_importer"}], "locally_stored_units": 14, "_id": {"$oid": "57cf5cc45ca0131f93207bfc"},
218
        "total_repository_units": 14, "id": "integration_test_id", "_href": "/pulp/api/v2/repositories/integration_test_id/"}'
219
    http_version: 
220
  recorded_at: Wed, 07 Sep 2016 00:43:21 GMT
221
- request:
222
    method: post
223
    uri: https://admin:rGox3G9QhfCRD8fTsNR7FxqdgbvfJfSJ@abed.usersys.redhat.com/pulp/api/v2/consumers/integration_test_consumer_support/bindings//
224
    body:
225
      encoding: UTF-8
226
      string: '{"repo_id":"integration_test_id","distributor_id":"yum_dist","notify_agent":false}'
227
    headers:
228
      Accept:
229
      - application/json
230
      Accept-Encoding:
231
      - gzip, deflate
232
      Content-Type:
233
      - application/json
234
      Content-Length:
235
      - '82'
236
      User-Agent:
237
      - Ruby
238
  response:
239
    status:
240
      code: 200
241
      message: OK
242
    headers:
243
      Date:
244
      - Wed, 07 Sep 2016 00:43:21 GMT
245
      Server:
246
      - Apache/2.4.6 (CentOS)
247
      Vary:
248
      - Accept-Encoding
249
      Content-Length:
250
      - '358'
251
      Connection:
252
      - close
253
      Content-Type:
254
      - application/json; charset=utf-8
255
    body:
256
      encoding: ASCII-8BIT
257
      string: '{"spawned_tasks": [], "result": {"notify_agent": false, "repo_id":
258
        "integration_test_id", "deleted": false, "_ns": "consumer_bindings", "distributor_id":
259
        "yum_dist", "consumer_id": "integration_test_consumer_support", "consumer_actions":
260
        [], "binding_config": {}, "_id": {"$oid": "57cf62a95ca0131f9432cf39"}, "id":
261
        "57cf62a95ca0131f9432cf39"}, "error": null}'
262
    http_version: 
263
  recorded_at: Wed, 07 Sep 2016 00:43:21 GMT
264
- request:
265
    method: post
266
    uri: https://admin:rGox3G9QhfCRD8fTsNR7FxqdgbvfJfSJ@abed.usersys.redhat.com/pulp/api/v2/consumers/content/applicability/
267
    body:
268
      encoding: UTF-8
269
      string: '{"criteria":{"filters":{"id":{"$in":["integration_test_consumer_support"]}}},"content_types":["rpm"]}'
270
    headers:
271
      Accept:
272
      - application/json
273
      Accept-Encoding:
274
      - gzip, deflate
275
      Content-Type:
276
      - application/json
277
      Content-Length:
278
      - '101'
279
      User-Agent:
280
      - Ruby
281
  response:
282
    status:
283
      code: 200
284
      message: OK
285
    headers:
286
      Date:
287
      - Wed, 07 Sep 2016 00:43:21 GMT
288
      Server:
289
      - Apache/2.4.6 (CentOS)
290
      Vary:
291
      - Accept-Encoding
292
      Content-Length:
293
      - '122'
294
      Connection:
295
      - close
296
      Content-Type:
297
      - application/json; charset=utf-8
298
    body:
299
      encoding: ASCII-8BIT
300
      string: '[{"applicability": {"rpm": ["904206a3-d520-4f57-b84a-78b3af1597cd"]},
301
        "consumers": ["integration_test_consumer_support"]}]'
302
    http_version: 
303
  recorded_at: Wed, 07 Sep 2016 00:43:21 GMT
304
- request:
305
    method: delete
306
    uri: https://admin:rGox3G9QhfCRD8fTsNR7FxqdgbvfJfSJ@abed.usersys.redhat.com/pulp/api/v2/consumers/integration_test_consumer_support/
307
    body:
308
      encoding: US-ASCII
309
      string: ''
310
    headers:
311
      Accept:
312
      - application/json
313
      Accept-Encoding:
314
      - gzip, deflate
315
      Content-Type:
316
      - application/json
317
      User-Agent:
318
      - Ruby
319
  response:
320
    status:
321
      code: 200
322
      message: OK
323
    headers:
324
      Date:
325
      - Wed, 07 Sep 2016 00:43:21 GMT
326
      Server:
327
      - Apache/2.4.6 (CentOS)
328
      Content-Length:
329
      - '4'
330
      Connection:
331
      - close
332
      Content-Type:
333
      - application/json; charset=utf-8
334
    body:
335
      encoding: UTF-8
336
      string: 'null'
337
    http_version: 
338
  recorded_at: Wed, 07 Sep 2016 00:43:21 GMT
339
recorded_with: VCR 3.0.1

Also available in: Unified diff