Project

General

Profile

Revision a2c97209

Added by Thomas McKay over 4 years ago

fixes #18616 - for import

View differences:

lib/hammer_cli_csv/products.rb
10 10
      REPOSITORY = 'Repository'
11 11
      REPOSITORY_TYPE = 'Repository Type'
12 12
      CONTENT_SET = 'Content Set'
13
      RELEASE = 'Release'
13
      RELEASEVER = '$releasever'
14
      BASEARCH = '$basearch'
14 15
      REPOSITORY_URL = 'Repository Url'
15 16
      DESCRIPTION = 'Description'
16 17
      VERIFY_SSL = 'Verify SSL'
......
22 23

  
23 24
      def export(csv)
24 25
        csv << [NAME, LABEL, ORGANIZATION, DESCRIPTION, REPOSITORY, REPOSITORY_TYPE,
25
                CONTENT_SET, RELEASE, REPOSITORY_URL, VERIFY_SSL, UNPROTECTED, MIRROR_ON_SYNC, DOWNLOAD_POLICY,
26
                CONTENT_SET, BASEARCH, RELEASEVER, REPOSITORY_URL, VERIFY_SSL, UNPROTECTED, MIRROR_ON_SYNC, DOWNLOAD_POLICY,
26 27
                UPSTREAM_USERNAME, UPSTREAM_PASSWORD]
27 28
        @api.resource(:organizations).call(:index, {
28 29
            :per_page => 999999,
......
50 51
                repository_type = "Red Hat #{repository['content_type'].capitalize}"
51 52
                content_set = get_content_set(organization, product, repository)
52 53
              end
53
              release = repository['minor'] #=~ /Server/ ? repository['minor'] : "#{repository['major']}.#{repository['minor']}"
54
              releasever = repository['minor']
55
              basearch = nil
54 56
              csv << [product['name'], product['label'], organization['name'],
55 57
                      product['description'], repository['name'], repository_type,
56
                      content_set, release, repository['url'],
58
                      content_set, basearch, releasever, repository['url'],
57 59
                      repository['verify_ssl_on_sync'] ? 'Yes' : 'No',
58 60
                      repository['unprotected'] ? 'Yes' : 'No',
59 61
                      repository['mirror_on_sync'] ? 'Yes' : 'No', repository['download_policy'],
......
228 230
          end
229 231
          raise "No match for content set '#{line[CONTENT_SET]}'" if !product_content
230 232

  
231
          basearch,releasever = parse_basearch_releasever(line[REPOSITORY])
233
          basearch,releasever = parse_basearch_releasever(line)
232 234
          params = {
233 235
              'id' => product_content['content']['id'],
234
              'product_id' => product['id'],
235
              'basearch' => basearch,
236
              'releasever' => releasever
236
              'product_id' => product['id']
237 237
          }
238
          params['basearch'] = basearch if !basearch.nil? && repository_set['contentUrl'] =~ /\$basearch/
239
          params['releasever'] = releasever if !releasever.nil? && repository_set['contentUrl'] =~ /\$releasever/
238 240
          @api.resource(:repository_sets).call(:enable, params)
239 241
          puts _('done') if option_verbose?
240 242
        else
......
245 247

  
246 248
      # basearch and releasever are required for repo set enable. The repository ends with, for example,
247 249
      # "x86_64 6.1" or "ia64 6 Server"
248
      def parse_basearch_releasever(content_set)
250
      def parse_basearch_releasever(line)
251
        basearch = line[BASEARCH] if !line[BASEARCH].nil? && !line[BASEARCH].empty?
252
        releasever = line[RELEASEVER] if !line[RELEASEVER].nil? && !line[RELEASEVER].empty?
253
        content_set = line[REPOSITORY]
249 254
        pieces = content_set.split
250 255
        if pieces[-1] == 'Server'
251
          return pieces[-3], "#{pieces[-2]}#{pieces[-1]}"
256
          basearch = pieces[-3] unless basearch
257
          releasever = "#{pieces[-2]}#{pieces[-1]}" unless releasever
252 258
        else
253
          return pieces[-2], pieces[-1]
259
          basearch = pieces[-2] unless basearch
260
          releasever = pieces[-1] unless releasever
254 261
        end
262
        return basearch,releasever
255 263
      end
256 264

  
257 265
      def content_type(repository_type)
test/config.template.yml
12 12
:log_api_calls: false
13 13
:log_size: 5 # MB
14 14

  
15
:ssl:
16
  :verify_ssl: false
17

  
15 18
:foreman:
16 19
  :enable_module: true
17 20
  :host:          'https://localhost'
test/resources/products_test.rb
41 41
Name,Label,Organization,Description,Repository,Repository Type,Content Set,Release,Repository Url
42 42
#{name},#{name},Test Corporation,,Zoo,Custom Yum,,,https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/
43 43
FILE
44
      # rubocop:enable LineLength
44 45
      file.rewind
45 46

  
46 47
      stdout,stderr = capture {
......
66 67
Name,Label,Organization,Description,Repository,Repository Type,Content Set,Release,Repository Url
67 68
#{name},#{name},Test Corporation,,Zoo,Custom Yum,,,https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/
68 69
FILE
70
      # rubocop:enable LineLength
69 71
      file.rewind
70 72

  
71 73
      stdout,stderr = capture {
......
101 103
#{name},#{name}label,Test Corporation,Yum Product,Zoo,Custom Yum,,,https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/,No,No,No,on_demand,,
102 104
#{name},#{name}label,Test Corporation,Docker Product,thomasmckay/hammer,Custom Docker,thomasmckay/hammer,,https://registry-1.docker.io/,Yes,Yes,Yes,"",,
103 105
FILE
106
      # rubocop:enable LineLength
104 107
      file.rewind
105 108

  
106 109
      stdout,stderr = capture {
......
126 129
      stop_vcr
127 130
    end
128 131

  
132
    def test_create_rhel_release
133
      start_vcr
134
      set_user 'admin'
135

  
136
      name = 'Red Hat Satellite Capsule 6.2 for RHEL 7 Server RPMs x86_64'
137

  
138
      file = Tempfile.new('products_test')
139
      # rubocop:disable LineLength
140
      file.write <<-FILE
141
Name,Label,Organization,Description,Repository,Repository Type,Content Set,$basearch,$releasever,Repository Url,Verify SSL,Publish via HTTP,Mirror on Sync,Download Policy,Username,Password
142
Red Hat Satellite Capsule,Red_Hat_Satellite_Capsule,Test Corporation,,Red Hat Satellite Capsule 6.2 for RHEL 7 Server RPMs x86_64,Red Hat Yum,Red Hat Satellite Capsule 6.2 (for RHEL 7 Server) (RPMs),x86_64,,https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/sat-capsule/6.2/os,No,No,No,on_demand,,
143
FILE
144
      # rubocop:enable LineLength
145
      file.rewind
146

  
147
      stdout,stderr = capture {
148
        hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
149
      }
150
      stderr.must_equal ''
151
      lines = stdout.split("\n")
152
      assert_equal "Enabling repository Red Hat Satellite Capsule 6.2 for RHEL 7 Server RPMs x86_64...done", lines[0]
153
      assert_equal "Updating repository '#{name}'...done", lines[1]
154

  
155
      file.rewind
156
      stdout,stderr = capture {
157
        hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
158
      }
159
      stderr.must_equal ''
160
      lines = stdout.split("\n")
161
      assert_equal "Repository Red Hat Satellite Capsule 6.2 for RHEL 7 Server RPMs x86_64 already enabled", lines[0]
162
      assert_equal "Updating repository '#{name}'...done", lines[1]
163

  
164
      file.unlink
165

  
166
      # TODO: need to 'repository-set disable' but command is not working (test again against Sat-6.3)
167
      #       disable manually for now after the test to re-record
168
      stop_vcr
169
    end
170

  
129 171
    def product_delete(name)
130 172
      stdout,stderr = capture {
131 173
        hammer.run(%W(product list --organization Test\ Corporation --search #{name}))

Also available in: Unified diff