Project

General

Profile

Download (2.71 KB) Statistics
| Branch: | Tag: | Revision:

hammer-cli-csv / test / systems_test.rb @ df47dd3c

1
require File.join(File.dirname(__FILE__), 'csv_test_helper')
2

    
3
describe 'systems' do
4

    
5
  extend CommandTestHelper
6

    
7
  before :each do
8
    HammerCLI::Settings.load_from_file 'test/config.yml'
9

    
10
    @api = ApipieBindings::API.new({
11
                                     :uri => HammerCLI::Settings.get(:csv, :host),
12
                                     :username => HammerCLI::Settings.get(:csv, :username),
13
                                     :password => HammerCLI::Settings.get(:csv, :password),
14
                                     :api_version => 2
15
                                   })
16

    
17
  end
18

    
19
  context "import" do
20

    
21
    # TODO: Bug #4922 - system facts not updating via API
22
    # http://projects.theforeman.org/issues/4922
23
    it "update system facts" do
24

    
25
      hostname = "host#{rand(10000)}"
26

    
27
      # Create system
28
      file = Tempfile.new('systems_test')
29
      file.write("Name,Count,Organization,Environment,Content View,System Groups,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions\n")
30
      file.write("#{hostname},1,Mega Corporation,Library,Default Organization View,Mega Corp HQ,No,,RHEL 6.4,x86_64,1,4,1,Standard,,\n")
31
      file.rewind
32

    
33
      stdout,stderr = capture {
34
        hammer.run(%W{-v csv:systems --csv-file #{file.path}})
35
      }
36
      stderr.must_equal ''
37
      stdout[0..-2].must_equal "Creating system '#{hostname}'...done\nUpdating host and guest associations...done"
38
      file.unlink
39

    
40
      # Update system
41
      file = Tempfile.new('systems_test')
42
      file.write("Name,Count,Organization,Environment,Content View,System Groups,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions\n")
43
      file.write("#{hostname},1,Mega Corporation,Library,Default Organization View,Mega Corp HQ,No,,RHEL 6.4,x86_64,1,8,1,Standard,,\n")
44
      file.rewind
45

    
46
      stdout,stderr = capture {
47
        hammer.run(%W{-v csv:systems --csv-file #{file.path}})
48
      }
49
      stderr.must_equal ''
50
      stdout[0..-2].must_equal "Updating system '#{hostname}'...done\nUpdating host and guest associations...done"
51
      file.unlink
52

    
53
      # Verify system
54
      system = @api.resource(:systems).call(:index, {
55
                                              'organization_id' => 'megacorp',
56
                                              'search' => "name=\"#{hostname}\""
57
                                            })['results']
58
      system.wont_be_nil
59
      system.wont_be_empty
60
      system[0]['name'].must_equal hostname
61

    
62
      # Clean up
63
      # TODO: Bug #4921 - bulk remove systems error "user not set"
64
      # http://projects.theforeman.org/issues/4921
65
      @api.resource(:systems).call(:destroy, {
66
                                              'id' => system[0]['id']
67
                                             })
68
    end
69

    
70
  end
71
end