Project

General

Profile

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

hammer-cli-csv / test / resources / content_hosts_test.rb @ 611959a3

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

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

    
10
      stdout,stderr = capture {
11
        hammer.run(%W{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
  end
30

    
31
  class TestContentHostsImport < MiniTest::Unit::TestCase
32
    def test_create_and_update
33
      start_vcr
34
      set_user 'admin'
35

    
36
      @hostname = "testhost1"
37

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

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

    
49
      file.rewind
50

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

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

    
65
      stop_vcr
66
    end
67
  end
68

    
69
  class TestContentHostsExport < MiniTest::Unit::TestCase
70
    def test_export
71
      start_vcr
72
      set_user 'admin'
73

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

    
82
    def test_export_subscriptions
83
      start_vcr
84
      set_user 'admin'
85

    
86
      stdout,stderr = capture {
87
        hammer.run(%W{csv content-hosts --export --itemized-subscriptions --organization Test\ Corporation})
88
      }
89
      assert_equal '', stderr
90

    
91
      # rubocop:disable LineLength
92
      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"
93
      # rubocop:enable LineLength
94
      stop_vcr
95
    end
96
  end
97

    
98
  class TestContentHostsImport < MiniTest::Unit::TestCase
99
    # import a single line, testing that subscription is added
100
    def test_import_single_line
101
      start_vcr
102
      set_user 'admin'
103

    
104
      @hostname = 'testhypervisor1'
105

    
106
      file = Tempfile.new('content_hosts_test')
107
      # rubocop:disable LineLength
108
      file.write("Name,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions\n")
109
      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")
110
      # rubocop:enable LineLength
111
      file.rewind
112

    
113
      stdout,stderr = capture {
114
        hammer.run(%W{csv content-hosts --verbose --file #{file.path}})
115
      }
116
      assert_equal '', stderr
117
      assert_equal "Creating content host '#{@hostname}'...done\n", stdout
118

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

    
129
      stop_vcr
130
    end
131
  end
132
end