Revision c06f1783
Added by Thomas McKay over 6 years ago
test/resources/content_hosts_test.rb | ||
---|---|---|
10 | 10 |
stdout,stderr = capture { |
11 | 11 |
hammer.run(%W{csv content-hosts --help}) |
12 | 12 |
} |
13 |
assert_equal stderr, ''
|
|
13 |
assert_equal '', stderr
|
|
14 | 14 |
assert_equal stdout, <<-HELP |
15 |
**** This command is unsupported and is provided as tech preview. **** |
|
16 | 15 |
Usage: |
17 | 16 |
csv content-hosts [OPTIONS] |
18 | 17 |
|
... | ... | |
20 | 19 |
--export Export current data instead of importing |
21 | 20 |
--file FILE_NAME CSV file (default to /dev/stdout with --export, otherwise required) |
22 | 21 |
--organization ORGANIZATION Only process organization matching this name |
22 |
--subscriptions-only Export only detailed subscription information |
|
23 | 23 |
-h, --help print help |
24 | 24 |
-v, --verbose be verbose |
25 | 25 |
HELP |
... | ... | |
32 | 32 |
start_vcr |
33 | 33 |
set_user 'admin' |
34 | 34 |
|
35 |
hostname = "host00001" |
|
36 |
|
|
37 |
stdout,stderr = capture { |
|
38 |
hammer.run(%W{organization list --search label=examplecorp}) |
|
39 |
} |
|
40 |
stdout.split("\n").length.must_equal 5 |
|
35 |
@hostname = "testhost1" |
|
41 | 36 |
|
42 | 37 |
file = Tempfile.new('content_hosts_test') |
43 | 38 |
file.write("Name,Count,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions\n") |
44 |
file.write("#{hostname},1,Example Corporation,Library,Default Organization View,,No,,RHEL 6.4,x86_64,1,4,1,,,\n")
|
|
39 |
file.write("#{@hostname},1,Test Corporation,Library,Default Organization View,,No,,RHEL 6.4,x86_64,1,4,1,,,\n")
|
|
45 | 40 |
file.rewind |
46 | 41 |
|
47 | 42 |
stdout,stderr = capture { |
48 | 43 |
hammer.run(%W{csv content-hosts --verbose --file #{file.path}}) |
49 | 44 |
} |
50 |
stderr.must_equal ''
|
|
51 |
stdout[0..-2].must_equal "Creating content host '#{hostname}'...done"
|
|
45 |
assert_equal '', stderr
|
|
46 |
assert_equal stdout[0..-2], "Creating content host '#{@hostname}'...done"
|
|
52 | 47 |
|
53 | 48 |
file.rewind |
54 | 49 |
|
55 | 50 |
stdout,stderr = capture { |
56 | 51 |
hammer.run(%W{csv content-hosts --verbose --file #{file.path}}) |
57 | 52 |
} |
58 |
stderr.must_equal ''
|
|
59 |
stdout[0..-2].must_equal "Updating content host '#{hostname}'...done"
|
|
53 |
assert_equal '', stderr
|
|
54 |
assert_equal stdout[0..-2], "Updating content host '#{@hostname}'...done"
|
|
60 | 55 |
file.unlink |
61 | 56 |
|
62 | 57 |
stdout,stderr = capture { |
63 |
hammer.run(%W(host list --search name=#{hostname})) |
|
58 |
hammer.run(%W(host list --search name=#{@hostname}))
|
|
64 | 59 |
} |
65 |
assert_equal stderr, ''
|
|
60 |
assert_equal '', stderr
|
|
66 | 61 |
assert_equal stdout.split("\n").length, 5 |
62 |
host_delete(@hostname) |
|
63 |
|
|
64 |
stop_vcr |
|
65 |
end |
|
66 |
end |
|
67 |
|
|
68 |
class TestContentHostsExport < MiniTest::Unit::TestCase |
|
69 |
def test_export |
|
70 |
start_vcr |
|
71 |
set_user 'admin' |
|
72 |
|
|
73 |
stdout,stderr = capture { |
|
74 |
hammer.run(%W{csv content-hosts --export --organization Test\ Corporation}) |
|
75 |
} |
|
76 |
assert_equal '', stderr |
|
77 |
assert_equal stdout.split("\n")[0], "Name,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions" |
|
78 |
stop_vcr |
|
79 |
end |
|
80 |
|
|
81 |
def test_export_subscriptions |
|
82 |
start_vcr |
|
83 |
set_user 'admin' |
|
84 |
|
|
85 |
stdout,stderr = capture { |
|
86 |
hammer.run(%W{csv content-hosts --export --subscriptions-only --organization Test\ Corporation}) |
|
87 |
} |
|
88 |
assert_equal '', stderr |
|
89 |
|
|
90 |
# rubocop:disable LineLength |
|
91 |
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" |
|
92 |
# rubocop:enable LineLength |
|
93 |
stop_vcr |
|
94 |
end |
|
95 |
end |
|
96 |
|
|
97 |
class TestContentHostsImport < MiniTest::Unit::TestCase |
|
98 |
# import a single line, testing that subscription is added |
|
99 |
def test_import_single_line |
|
100 |
start_vcr |
|
101 |
set_user 'admin' |
|
102 |
|
|
103 |
@hostname = 'testhypervisor1' |
|
104 |
|
|
105 |
file = Tempfile.new('content_hosts_test') |
|
106 |
# rubocop:disable LineLength |
|
107 |
file.write("Name,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions\n") |
|
108 |
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") |
|
109 |
# rubocop:enable LineLength |
|
110 |
file.rewind |
|
67 | 111 |
|
68 | 112 |
stdout,stderr = capture { |
69 |
hammer.run(%W(host delete --name #{hostname}))
|
|
113 |
hammer.run(%W{csv content-hosts --verbose --file #{file.path}})
|
|
70 | 114 |
} |
115 |
assert_equal '', stderr |
|
116 |
assert_equal "Creating content host '#{@hostname}'...done\n", stdout |
|
117 |
|
|
118 |
stdout,stderr = capture { |
|
119 |
hammer.run(%W{csv content-hosts --export --organization Test\ Corporation}) |
|
120 |
} |
|
121 |
assert_equal '', stderr |
|
122 |
lines = stdout.split("\n") |
|
123 |
assert_equal 2, lines.count |
|
124 |
assert_match(/.*Test Corporation,Library,Default Organization View,"",Yes,,RHEL 7.2,x86_64,2,3882752,1.*/, lines[1]) |
|
125 |
assert_match(/.*1|RH00001|Red Hat Enterprise Linux for Virtual Datacenters, Premium.*/, lines[1]) |
|
126 |
host_delete(@hostname) |
|
127 |
|
|
71 | 128 |
stop_vcr |
72 | 129 |
end |
73 | 130 |
end |
Also available in: Unified diff
fixes #15743 - import and export of subscriptions one-per-line