Project

General

Profile

Revision bf81b9cf

Added by Thomas McKay over 8 years ago

test-fixes - setup_test clean except for manifest upload repeat

View differences:

.gitignore
22 22
config/initializers/secret_token.rb
23 23
test/data/*.zip
24 24
test/config.yml
25
.ruby-version
25
.ruby-version
26
.idea
Gemfile
2 2

  
3 3
gemspec
4 4

  
5
gem 'apipie-bindings', :path => "../apipie-bindings"
5 6
gem 'hammer_cli', :path => "../hammer-cli"
6 7
gem 'hammer_cli_foreman', :path => "../hammer-cli-foreman"
7 8
gem 'hammer_cli_katello', :path => "../hammer-cli-katello"
8 9
gem 'hammer_cli_foreman_tasks', :path => "../hammer-cli-foreman-tasks"
9 10

  
10
gem 'pry'
11
gem 'pry-debugger'
12

  
13 11
group :test do
14 12
  gem 'rake'
15 13
  gem 'thor'
lib/hammer_cli_csv/activation_keys.rb
44 44
        csv << [NAME, COUNT, ORGANIZATION, DESCRIPTION, LIMIT, ENVIRONMENT, CONTENTVIEW,
45 45
                SYSTEMGROUPS, SUBSCRIPTIONS]
46 46
        @api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization|
47
          @api.resource(:activationkeys).call(:index, {'per_page' => 999999,
47
          @api.resource(:activation_keys).call(:index, {'per_page' => 999999,
48 48
                                       'organization_id' => organization['label']
49 49
                                     })['results'].each do |activationkey|
50 50
            puts "Writing activation key '#{activationkey['name']}'" if option_verbose?
......
85 85
    def create_activationkeys_from_csv(line)
86 86
      if !@existing[line[ORGANIZATION]]
87 87
        @existing[line[ORGANIZATION]] = {}
88
        @api.resource(:activationkeys).call(:index, {
88
        @api.resource(:activation_keys).call(:index, {
89 89
                                     'per_page' => 999999,
90 90
                                     'organization_id' => katello_organization(:name => line[ORGANIZATION])
91 91
                                   })['results'].each do |activationkey|
......
98 98

  
99 99
        if !@existing[line[ORGANIZATION]].include? name
100 100
          print "Creating activation key '#{name}'..." if option_verbose?
101
          activationkey = @api.resource(:activationkeys).call(:create, {
101
          activationkey = @api.resource(:activation_keys).call(:create, {
102 102
                                      'name' => name,
103 103
                                      'environment_id' => katello_environment(line[ORGANIZATION],
104 104
                                                                              :name => line[ENVIRONMENT]),
......
109 109
          @existing[line[ORGANIZATION]][activationkey['name']] = activationkey['id']
110 110
        else
111 111
          print "Updating activation key '#{name}'..." if option_verbose?
112
          activationkey = @api.resource(:activationkeys).call(:update, {
112
          activationkey = @api.resource(:activation_keys).call(:update, {
113 113
                                        'id' => @existing[line[ORGANIZATION]][name],
114 114
                                        'name' => name,
115 115
                                        'environment_id' => katello_environment(line[ORGANIZATION],
......
131 131
      if line[SYSTEMGROUPS] && line[SYSTEMGROUPS] != ''
132 132
        # TODO: note that existing system groups are not removed
133 133
        CSV.parse_line(line[SYSTEMGROUPS], {:skip_blanks => true}).each do |name|
134
          @api.resource(:systemgroups).call(:add_activation_keys, {
134
          @api.resource(:system_groups).call(:add_activation_keys, {
135 135
                                                   'id' => katello_systemgroup(line[ORGANIZATION], :name => name),
136 136
                                                   'activation_key_ids' => [activationkey['id']]
137 137
                                                 })
lib/hammer_cli_csv/base.rb
415 415
        return nil if options[:name].nil? || options[:name].empty?
416 416
        options[:id] = @environments[organization][options[:name]]
417 417
        if !options[:id]
418
          @api.resource(:environments).call(:index, {'organization_id' => katello_organization(:name => organization)})['results'].each do |environment|
418
          @api.resource(:lifecycle_environments).call(:index, {
419
                                                        'organization_id' => katello_organization(:name => organization),
420
                                                        'library' => true
421
                                                      })['results'].each do |environment|
419 422
            @environments[organization][environment['name']] = environment['id']
420 423
          end
421 424
          options[:id] = @environments[organization][options[:name]]
......
426 429
        return nil if options[:id].nil?
427 430
        options[:name] = @environments.key(options[:id])
428 431
        if !options[:name]
429
          environment = @api.resource(:environments).call(:show, {'id' => options[:id]})
432
          environment = @api.resource(:lifecycle_environments).call(:show, {'id' => options[:id]})
430 433
          raise "Lifecycle environment '#{options[:name]}' not found" if !environment || environment.empty?
431 434
          options[:name] = environment['name']
432 435
          @environments[options[:name]] = options[:id]
......
445 448
        return nil if options[:name].nil? || options[:name].empty?
446 449
        options[:id] = @contentviews[organization][options[:name]]
447 450
        if !options[:id]
448
          @api.resource(:contentviews).call(:index, {'organization_id' => katello_organization(:name => organization)})['results'].each do |contentview|
451
          @api.resource(:content_views).call(:index, {'organization_id' => katello_organization(:name => organization)})['results'].each do |contentview|
449 452
            @contentviews[organization][contentview['name']] = contentview['id']
450 453
          end
451 454
          options[:id] = @contentviews[organization][options[:name]]
......
456 459
        return nil if options[:id].nil?
457 460
        options[:name] = @contentviews.key(options[:id])
458 461
        if !options[:name]
459
          contentview = @api.resource(:contentviews).call(:show, {'id' => options[:id]})
462
          contentview = @api.resource(:content_views).call(:show, {'id' => options[:id]})
460 463
          raise "Puppet contentview '#{options[:name]}' not found" if !contentview || contentview.empty?
461 464
          options[:name] = contentview['name']
462 465
          @contentviews[options[:name]] = options[:id]
......
510 513
        return nil if options[:name].nil? || options[:name].empty?
511 514
        options[:id] = @systemgroups[organization][options[:name]]
512 515
        if !options[:id]
513
          @api.resource(:systemgroups).call(:index, {
516
          @api.resource(:system_groups).call(:index, {
514 517
                                     'organization_id' => katello_organization(:name => organization),
515 518
                                     'search' => "name:\"#{options[:name]}\""
516 519
                                   })['results'].each do |systemgroup|
......
524 527
        return nil if options[:id].nil?
525 528
        options[:name] = @systemgroups.key(options[:id])
526 529
        if !options[:name]
527
          systemgroup = @api.resource(:systemgroups).call(:show, {'id' => options[:id]})
530
          systemgroup = @api.resource(:system_groups).call(:show, {'id' => options[:id]})
528 531
          raise "System group '#{options[:name]}' not found" if !systemgroup || systemgroup.empty?
529 532
          options[:name] = systemgroup['name']
530 533
          @systemgroups[options[:name]] = options[:id]
lib/hammer_cli_csv/domains.rb
62 62
          print "Creating domain '#{name}'..." if option_verbose?
63 63
          domain_id = @api.resource(:domains).call(:create, {
64 64
                                             'name' => name,
65
                                             'organization_ids' => organization_ids
66 65
                                           })['domain']['id']
67 66
        else
68 67
          print "Updating domain '#{name}'..." if option_verbose?
69 68
          domain_id = @api.resource(:domains).call(:update, {
70 69
                                             'id' => @existing[name],
71
                                             'domain' => {
72
                                               'name' => name
73
                                             }
70
                                             'name' => name
74 71
                                           })['domain']['id']
75 72
        end
76 73

  
lib/hammer_cli_csv/hosts.rb
88 88
                               'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
89 89
                               'environment_id' => foreman_environment(:name => line[ENVIRONMENT]),
90 90
                               'operatingsystem_id' => foreman_operatingsystem(:name => line[OPERATINGSYSTEM]),
91
                               'environment_id' => foreman_environment(:name => line[ENVIRONMENT]),
92 91
                               'architecture_id' => foreman_architecture(:name => line[ARCHITECTURE]),
93 92
                               'domain_id' => foreman_domain(:name => line[DOMAIN]),
94 93
                               'ptable_id' => foreman_partitiontable(:name => line[PARTITIONTABLE])
......
104 103
                                 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
105 104
                                 'environment_id' => foreman_environment(:name => line[ENVIRONMENT]),
106 105
                                 'operatingsystem_id' => foreman_operatingsystem(:name => line[OPERATINGSYSTEM]),
107
                                 'environment_id' => foreman_environment(:name => line[ENVIRONMENT]),
108 106
                                 'architecture_id' => foreman_architecture(:name => line[ARCHITECTURE]),
109 107
                                 'domain_id' => foreman_domain(:name => line[DOMAIN]),
110 108
                                 'ptable_id' => foreman_partitiontable(:name => line[PARTITIONTABLE])
lib/hammer_cli_csv/lifecycle_environments.rb
59 59
      @api.resource(:organizations).call(:index, {'per_page' => 999999})['results'].each do |organization|
60 60
        @api.resource(:environments).call(:index, {
61 61
                                   'per_page' => 999999,
62
                                   'organization_id' => katello_organization(:name => organization['name'])
62
                                   'organization_id' => katello_organization(:name => organization['name']),
63
                                   'library' => true
63 64
                                 })['results'].each do |environment|
64 65
          @existing[organization['name']] ||= {}
65 66
          @existing[organization['name']][environment['name']] = environment['id'] if environment
......
89 90
        else
90 91
          print "Updating environment '#{name}'..." if option_verbose?
91 92
          @api.resource(:environments).call(:update, {
92
                                      'id' => katello_environment(line[ORGANIZATION], :name => label),
93
                                      'id' => @existing[line[ORGANIZATION]][name],
93 94
                                      'name' => name,
94 95
                                      'new_name' => name,
95 96
                                      'organization_id' => katello_organization(:name => line[ORGANIZATION]),
lib/hammer_cli_csv/products.rb
58 58
          @existing_products[line[ORGANIZATION]][product['name']] = product['id'] if product
59 59

  
60 60
          if product
61
            @api.resource(:repositorys).call(:index, {
61
            @api.resource(:repositories).call(:index, {
62 62
                                      'organization_id' => katello_organization(:name => line[ORGANIZATION]),
63 63
                                      'product_id' => product['id'],
64 64
                                      'enabled' => true,
......
83 83
                                               'name' => name
84 84
                                             })['id']
85 85
          @existing_products[line[ORGANIZATION]][name] = product_id
86
          print "done\n" if option_verbose?
86
        else
87
          # Nothing to update for products
88
          print "Updating product '#{name}'..." if option_verbose?
87 89
        end
90
        print "done\n" if option_verbose?
88 91
        @existing_repositories[line[ORGANIZATION] + name] ||= {}
89 92

  
90 93
        # Only creating repositories, not updating
91 94
        repository_name = namify(line[REPOSITORY], number)
92 95
        if !@existing_repositories[line[ORGANIZATION] + name][labelize(repository_name)]
93 96
          print "Creating repository '#{repository_name}' in product '#{name}'..." if option_verbose?
94
          @api.resource(:repositorys).call(:create, {
97
          @api.resource(:repositories).call(:create, {
95 98
                                     'organization_id' => katello_organization(:name => line[ORGANIZATION]),
96 99
                                     'name' => repository_name,
97 100
                                     'label' => labelize(repository_name),
lib/hammer_cli_csv/puppet_environments.rb
74 74
        end
75 75

  
76 76
        # Update associated resources
77
        # TODO: Bug #4738: organization json does not include puppet environments
78
        #       http://projects.theforeman.org/issues/4738#change-15319
79
        #       Update below to match style of domains
77 80
        organization_ids = CSV.parse_line(line[ORGANIZATIONS]).collect do |organization|
78 81
          foreman_organization(:name => organization)
79 82
        end
lib/hammer_cli_csv/systems.rb
140 140
        if !@existing[line[ORGANIZATION]].include? name
141 141
          print "Creating system '#{name}'..." if option_verbose?
142 142
          system_id = @api.resource(:systems).call(:create, {
143
                                 'name' => name,
144
                                 'organization_id' => katello_organization(:name => line[ORGANIZATION]),
145
                                 'environment_id' => katello_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
146
                                 'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
147
                                 'facts' => facts(line),
148
                                 'installed_products' => products(line),
149
                                 'type' => 'system'
150
                               })['uuid']
143
                                                     'name' => name,
144
                                                     'organization_id' => katello_organization(:name => line[ORGANIZATION]),
145
                                                     'environment_id' => katello_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
146
                                                     'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
147
                                                     'facts' => facts(line),
148
                                                     'installed_products' => products(line),
149
                                                     'type' => 'system'
150
                                                   })['uuid']
151 151
          @existing[line[ORGANIZATION]][name] = system_id
152 152
        else
153 153
          print "Updating system '#{name}'..." if option_verbose?
154 154
          system_id = @api.resource(:systems).call(:update, {
155
                                 'id' => @existing[line[ORGANIZATION]][name],
156
                                 'name' => name,
157
                                 'environment_id' => katello_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
158
                                 'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
159
                                 'facts' => facts(line),
160
                                 'installed_products' => products(line)
161
                               })['uuid']
155
                                                     'id' => @existing[line[ORGANIZATION]][name],
156
                                                     'system' => {
157
                                                       'name' => name,
158
                                                       'environment_id' => katello_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
159
                                                       'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
160
                                                       'facts' => facts(line),
161
                                                       'installed_products' => products(line)
162
                                                     }
163
                                                   })['uuid']
162 164
        end
163 165

  
164 166
        if line[VIRTUAL] == 'Yes' && line[HOST]
......
194 196

  
195 197
    def set_system_groups(system_id, line)
196 198
      CSV.parse_line(line[SYSTEMGROUPS]).each do |systemgroup_name|
197
        @api.resource(:systemgroups).call(:add_systems, {
199
        @api.resource(:system_groups).call(:add_systems, {
198 200
                                         'id' => katello_systemgroup(line[ORGANIZATION], :name => systemgroup_name),
199 201
                                         'system_ids' => [system_id]
200 202
                                       })
test/csv_test_helper.rb
14 14
require "minitest-spec-context"
15 15
require "mocha/setup"
16 16

  
17
require 'hammer_cli'
18
require 'hammer_cli_foreman/commands'
19

  
20
HammerCLI::Settings.load_from_file 'test/config.yml'
21

  
17 22
require 'hammer_cli_csv'
18
require 'hammer_cli_katello'
19 23
require 'hammer_cli_foreman'
24
require 'hammer_cli_katello'
20 25

  
21 26
def ctx
22 27
  {
23
    :interactive => false
28
    :interactive => false,
29
    :username => 'admin',
30
    :password => 'changeme'
24 31
  }
25 32
end
26 33

  
test/data/systems.csv
1 1
Name,Count,Organization,Environment,Content View,System Groups,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions
2
host%d,1,Mega Corporation,Library,,"Mega Corp HQ",No,,RHEL 6.4,x86_64,1,4,1,Standard,"69|Red Hat Enterprise Linux Server,79|Red Hat Enterprise Linux Server",RH0103708|Red Hat Enterprise Linux Server Premium (8 sockets) (Up to 4 guests)
3
guest%d,1,Mega Corporation,Library,,"Mega Corp HQ,Accounting",Yes,host0,RHEL 6.4,x86_64,1,4,1,Standard,"69|Red Hat Enterprise Linux Server,79|Red Hat Enterprise Linux Server",RH0103708|Red Hat Enterprise Linux Server Premium (8 sockets) (Up to 4 guests)
2
host%d,1,Mega Corporation,Library,Default Organization View,"Mega Corp HQ",No,,RHEL 6.4,x86_64,1,4,1,Standard,"69|Red Hat Enterprise Linux Server,79|Red Hat Enterprise Linux Server",RH0103708|Red Hat Enterprise Linux Server Premium (8 sockets) (Up to 4 guests)
3
guest%d,1,Mega Corporation,Library,Default Organization View,"Mega Corp HQ,Accounting",Yes,host0,RHEL 6.4,x86_64,1,4,1,Standard,"69|Red Hat Enterprise Linux Server,79|Red Hat Enterprise Linux Server",RH0103708|Red Hat Enterprise Linux Server Premium (8 sockets) (Up to 4 guests)
4 4

  
test/setup_test.rb
101 101

  
102 102
  context 'subscription setup' do
103 103
    it "hammer -v subscription upload --organization-id megacorp --file test/data/megacorp.zip" do
104
      # TODO: http://projects.theforeman.org/issues/4748
105
      "".must_equal "TODO: Bug #4748 - errors on import manifest should complete dynflow task and display information to user"
104 106
      stdout,stderr = capture {
105 107
        hammer.run(%W{-v subscription upload --organization-id megacorp --file test/data/megacorp.zip})
106 108
      }
......
125 127
        hammer.run(%W{-v csv:lifecycleenv --csv-file test/data/lifecycleenvironments.csv})
126 128
      }
127 129
      stderr.must_equal ''
128
      stdout.must_match /.*xxx.*/
130
      stdout.must_match /.*environment 'Development'.*/
129 131
    end
130 132
  end
131 133

  

Also available in: Unified diff