commit a2c9720932b256a762ffb1a1c5d6c393ae0aacbc
Author: Tom McKay <thomasmckay@redhat.com>
Date:   Tue Mar 21 15:36:11 2017 -0400

    fixes #18616 -   for import

diff --git a/lib/hammer_cli_csv/products.rb b/lib/hammer_cli_csv/products.rb
index 999f8d1..9c575b9 100644
--- a/lib/hammer_cli_csv/products.rb
+++ b/lib/hammer_cli_csv/products.rb
@@ -10,7 +10,8 @@ module HammerCLICsv
       REPOSITORY = 'Repository'
       REPOSITORY_TYPE = 'Repository Type'
       CONTENT_SET = 'Content Set'
-      RELEASE = 'Release'
+      RELEASEVER = '$releasever'
+      BASEARCH = '$basearch'
       REPOSITORY_URL = 'Repository Url'
       DESCRIPTION = 'Description'
       VERIFY_SSL = 'Verify SSL'
@@ -22,7 +23,7 @@ module HammerCLICsv
 
       def export(csv)
         csv << [NAME, LABEL, ORGANIZATION, DESCRIPTION, REPOSITORY, REPOSITORY_TYPE,
-                CONTENT_SET, RELEASE, REPOSITORY_URL, VERIFY_SSL, UNPROTECTED, MIRROR_ON_SYNC, DOWNLOAD_POLICY,
+                CONTENT_SET, BASEARCH, RELEASEVER, REPOSITORY_URL, VERIFY_SSL, UNPROTECTED, MIRROR_ON_SYNC, DOWNLOAD_POLICY,
                 UPSTREAM_USERNAME, UPSTREAM_PASSWORD]
         @api.resource(:organizations).call(:index, {
             :per_page => 999999,
@@ -50,10 +51,11 @@ module HammerCLICsv
                 repository_type = "Red Hat #{repository['content_type'].capitalize}"
                 content_set = get_content_set(organization, product, repository)
               end
-              release = repository['minor'] #=~ /Server/ ? repository['minor'] : "#{repository['major']}.#{repository['minor']}"
+              releasever = repository['minor']
+              basearch = nil
               csv << [product['name'], product['label'], organization['name'],
                       product['description'], repository['name'], repository_type,
-                      content_set, release, repository['url'],
+                      content_set, basearch, releasever, repository['url'],
                       repository['verify_ssl_on_sync'] ? 'Yes' : 'No',
                       repository['unprotected'] ? 'Yes' : 'No',
                       repository['mirror_on_sync'] ? 'Yes' : 'No', repository['download_policy'],
@@ -228,13 +230,13 @@ module HammerCLICsv
           end
           raise "No match for content set '#{line[CONTENT_SET]}'" if !product_content
 
-          basearch,releasever = parse_basearch_releasever(line[REPOSITORY])
+          basearch,releasever = parse_basearch_releasever(line)
           params = {
               'id' => product_content['content']['id'],
-              'product_id' => product['id'],
-              'basearch' => basearch,
-              'releasever' => releasever
+              'product_id' => product['id']
           }
+          params['basearch'] = basearch if !basearch.nil? && repository_set['contentUrl'] =~ /\$basearch/
+          params['releasever'] = releasever if !releasever.nil? && repository_set['contentUrl'] =~ /\$releasever/
           @api.resource(:repository_sets).call(:enable, params)
           puts _('done') if option_verbose?
         else
@@ -245,13 +247,19 @@ module HammerCLICsv
 
       # basearch and releasever are required for repo set enable. The repository ends with, for example,
       # "x86_64 6.1" or "ia64 6 Server"
-      def parse_basearch_releasever(content_set)
+      def parse_basearch_releasever(line)
+        basearch = line[BASEARCH] if !line[BASEARCH].nil? && !line[BASEARCH].empty?
+        releasever = line[RELEASEVER] if !line[RELEASEVER].nil? && !line[RELEASEVER].empty?
+        content_set = line[REPOSITORY]
         pieces = content_set.split
         if pieces[-1] == 'Server'
-          return pieces[-3], "#{pieces[-2]}#{pieces[-1]}"
+          basearch = pieces[-3] unless basearch
+          releasever = "#{pieces[-2]}#{pieces[-1]}" unless releasever
         else
-          return pieces[-2], pieces[-1]
+          basearch = pieces[-2] unless basearch
+          releasever = pieces[-1] unless releasever
         end
+        return basearch,releasever
       end
 
       def content_type(repository_type)
diff --git a/test/config.template.yml b/test/config.template.yml
index d6ab3ff..6b4a92f 100644
--- a/test/config.template.yml
+++ b/test/config.template.yml
@@ -12,6 +12,9 @@
 :log_api_calls: false
 :log_size: 5 # MB
 
+:ssl:
+  :verify_ssl: false
+
 :foreman:
   :enable_module: true
   :host:          'https://localhost'
diff --git a/test/resources/products_test.rb b/test/resources/products_test.rb
index 31c96a7..40c6f8a 100644
--- a/test/resources/products_test.rb
+++ b/test/resources/products_test.rb
@@ -41,6 +41,7 @@ HELP
 Name,Label,Organization,Description,Repository,Repository Type,Content Set,Release,Repository Url
 #{name},#{name},Test Corporation,,Zoo,Custom Yum,,,https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/
 FILE
+      # rubocop:enable LineLength
       file.rewind
 
       stdout,stderr = capture {
@@ -66,6 +67,7 @@ FILE
 Name,Label,Organization,Description,Repository,Repository Type,Content Set,Release,Repository Url
 #{name},#{name},Test Corporation,,Zoo,Custom Yum,,,https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/
 FILE
+      # rubocop:enable LineLength
       file.rewind
 
       stdout,stderr = capture {
@@ -101,6 +103,7 @@ Name,Label,Organization,Description,Repository,Repository Type,Content Set,Relea
 #{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,,
 #{name},#{name}label,Test Corporation,Docker Product,thomasmckay/hammer,Custom Docker,thomasmckay/hammer,,https://registry-1.docker.io/,Yes,Yes,Yes,"",,
 FILE
+      # rubocop:enable LineLength
       file.rewind
 
       stdout,stderr = capture {
@@ -126,6 +129,45 @@ FILE
       stop_vcr
     end
 
+    def test_create_rhel_release
+      start_vcr
+      set_user 'admin'
+
+      name = 'Red Hat Satellite Capsule 6.2 for RHEL 7 Server RPMs x86_64'
+
+      file = Tempfile.new('products_test')
+      # rubocop:disable LineLength
+      file.write <<-FILE
+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
+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,,
+FILE
+      # rubocop:enable LineLength
+      file.rewind
+
+      stdout,stderr = capture {
+        hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
+      }
+      stderr.must_equal ''
+      lines = stdout.split("\n")
+      assert_equal "Enabling repository Red Hat Satellite Capsule 6.2 for RHEL 7 Server RPMs x86_64...done", lines[0]
+      assert_equal "Updating repository '#{name}'...done", lines[1]
+
+      file.rewind
+      stdout,stderr = capture {
+        hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
+      }
+      stderr.must_equal ''
+      lines = stdout.split("\n")
+      assert_equal "Repository Red Hat Satellite Capsule 6.2 for RHEL 7 Server RPMs x86_64 already enabled", lines[0]
+      assert_equal "Updating repository '#{name}'...done", lines[1]
+
+      file.unlink
+
+      # TODO: need to 'repository-set disable' but command is not working (test again against Sat-6.3)
+      #       disable manually for now after the test to re-record
+      stop_vcr
+    end
+
     def product_delete(name)
       stdout,stderr = capture {
         hammer.run(%W(product list --organization Test\ Corporation --search #{name}))
