Project

General

Profile

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

hammer-cli-csv / test / content_hosts_test.rb @ 5146ac68

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

    
3
describe 'content-hosts' do
4

    
5
  extend CommandTestHelper
6

    
7
  context "import" do
8
    it "update content host facts" do
9
      set_user 'admin'
10

    
11
      hostname = "host#{rand(10000)}"
12

    
13
      # Create content host
14
      file = Tempfile.new('content_hosts_test')
15
      file.write("Name,Count,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions\n")
16
      file.write("#{hostname},1,Mega Corporation,Library,Default Organization View,Mega Corp HQ,No,,RHEL 6.4,x86_64,1,4,1,,,\n")
17
      file.rewind
18

    
19
      stdout,stderr = capture {
20
        hammer.run(%W{csv content-hosts --verbose --file #{file.path}})
21
      }
22
      stderr.must_equal ''
23
      stdout[0..-2].must_equal "Creating content host '#{hostname}'...done\nUpdating hypervisor and guest associations...done"
24
      file.unlink
25

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

    
32
      stdout,stderr = capture {
33
        hammer.run(%W{csv content-hosts --verbose --csv-file #{file.path}})
34
      }
35
      stderr.must_equal ''
36
      stdout[0..-2].must_equal "Updating content host '#{hostname}'...done\nUpdating hypervisor and guest associations...done"
37
      file.unlink
38

    
39
      stdout,stderr = capture {
40
        hammer.run(%W{organization list --search megacorp})
41
      }
42
      stdout.split("\n").length.must_equal 5
43
      organization_id = stdout.split("\n")[3].split('|')[0].to_i
44

    
45
      # Verify system
46
      system = api.resource(:systems).call(:index, {
47
                                              'organization_id' => organization_id,
48
                                              'search' => hostname
49
                                            })['results']
50
      system.wont_be_nil
51
      system.wont_be_empty
52
      system[0]['name'].must_equal hostname
53

    
54
      # Clean up
55
      api.resource(:systems).call(:destroy, {
56
                                             'id' => system[0]['id']
57
                                            })
58
    end
59

    
60
  end
61
end