Project

General

Profile

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

hammer-cli-csv / test / resources / content_hosts_test.rb @ 400832c6

1
require './test/csv_test_helper'
2
require './lib/hammer_cli_csv'
3

    
4
module Resources
5
  class TestContentHosts < MiniTest::Unit::TestCase
6
    def test_usage
7
      start_vcr
8
      set_user 'admin'
9

    
10
      stdout,stderr = capture {
11
        hammer.run(%W{--reload-cache csv content-hosts --help})
12
      }
13
      assert_equal '', stderr
14
      assert_equal stdout, <<-HELP
15
Usage:
16
     csv content-hosts [OPTIONS]
17

18
Options:
19
 --continue-on-error           Continue processing even if individual resource error
20
 --export                      Export current data instead of importing
21
 --file FILE_NAME              CSV file (default to /dev/stdout with --export, otherwise required)
22
 --itemized-subscriptions      Export one subscription per row, only process update subscriptions on import
23
 --organization ORGANIZATION   Only process organization matching this name
24
 -h, --help                    print help
25
 -v, --verbose                 be verbose
26
HELP
27
      stop_vcr
28
    end
29

    
30
    def test_create_and_update
31
      start_vcr
32
      set_user 'admin'
33

    
34
      @hostname = "testhost1"
35

    
36
      file = Tempfile.new('content_hosts_test')
37
      file.write("Name,Count,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions\n")
38
      file.write("#{@hostname},1,Test Corporation,Library,Default Organization View,,No,,RHEL 6.4,x86_64,1,4,1,,,\n")
39
      file.rewind
40

    
41
      stdout,stderr = capture {
42
        hammer.run(%W{--reload-cache csv content-hosts --verbose --file #{file.path}})
43
      }
44
      assert_equal '', stderr
45
      assert_equal stdout[0..-2], "Creating content host '#{@hostname}'...done"
46

    
47
      file.rewind
48

    
49
      stdout,stderr = capture {
50
        hammer.run(%W{--reload-cache csv content-hosts --verbose --file #{file.path}})
51
      }
52
      assert_equal '', stderr
53
      assert_equal stdout[0..-2], "Updating content host '#{@hostname}'...done"
54
      file.unlink
55

    
56
      stdout,stderr = capture {
57
        hammer.run(%W(--reload-cache host list --search name=#{@hostname}))
58
      }
59
      assert_equal '', stderr
60
      assert_equal stdout.split("\n").length, 5
61
      host_delete(@hostname)
62

    
63
      stop_vcr
64
    end
65

    
66
    def test_export
67
      start_vcr
68
      set_user 'admin'
69

    
70
      stdout,stderr = capture {
71
        hammer.run(%W{--reload-cache csv content-hosts --export --organization Test\ Corporation})
72
      }
73
      assert_equal '', stderr
74
      assert_equal stdout.split("\n")[0], "Name,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions"
75
      stop_vcr
76
    end
77

    
78
    def test_export_subscriptions
79
      start_vcr
80
      set_user 'admin'
81

    
82
      stdout,stderr = capture {
83
        hammer.run(%W{--reload-cache csv content-hosts --export --itemized-subscriptions --organization Test\ Corporation})
84
      }
85
      assert_equal '', stderr
86

    
87
      # rubocop:disable LineLength
88
      assert_equal stdout.split("\n")[0], "Name,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscription Name,Subscription Type,Subscription Quantity,Subscription SKU,Subscription Contract,Subscription Account,Subscription Start,Subscription End"
89
      # rubocop:enable LineLength
90
      stop_vcr
91
    end
92

    
93
    # import a single line, testing that subscription is added
94
    def test_import_single_line
95
      start_vcr
96
      set_user 'admin'
97

    
98
      @hostname = 'testhypervisor1'
99

    
100
      file = Tempfile.new('content_hosts_test')
101
      # rubocop:disable LineLength
102
      file.write("Name,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions\n")
103
      file.write("#{@hostname},Test Corporation,Library,Default Organization View,\"\",Yes,,RHEL 7.2,x86_64,2,3882752,1,\"\",\"69|Red Hat Enterprise Linux Server,290|Red Hat OpenShift Enterprise\",\"\"\"1|RH00001|Red Hat Enterprise Linux for Virtual Datacenters, Premium\"\"\"\n")
104
      # rubocop:enable LineLength
105
      file.rewind
106

    
107
      stdout,stderr = capture {
108
        hammer.run(%W{--reload-cache csv content-hosts --verbose --file #{file.path}})
109
      }
110
      assert_equal '', stderr
111
      assert_equal "Creating content host '#{@hostname}'...done\n", stdout
112

    
113
      stdout,stderr = capture {
114
        hammer.run(%W{--reload-cache csv content-hosts --export --organization Test\ Corporation})
115
      }
116
      assert_equal '', stderr
117
      lines = stdout.split("\n")
118
      assert_equal 2, lines.count
119
      assert_match(/.*Test Corporation,Library,Default Organization View,"",Yes,,RHEL 7.2,x86_64,2,3882752,1.*/, lines[1])
120
      assert_match(/.*1|RH00001|Red Hat Enterprise Linux for Virtual Datacenters, Premium.*/, lines[1])
121
      host_delete(@hostname)
122

    
123
      stop_vcr
124
    end
125
  end
126
end