hammer_cli_foreman 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of hammer_cli_foreman might be problematic. Click here for more details.

Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +27 -0
  3. data/doc/host_create.md +190 -0
  4. data/lib/hammer_cli_foreman.rb +1 -0
  5. data/lib/hammer_cli_foreman/commands.rb +21 -7
  6. data/lib/hammer_cli_foreman/common_parameter.rb +12 -18
  7. data/lib/hammer_cli_foreman/domain.rb +8 -6
  8. data/lib/hammer_cli_foreman/environment.rb +10 -0
  9. data/lib/hammer_cli_foreman/exception_handler.rb +11 -1
  10. data/lib/hammer_cli_foreman/exceptions.rb +9 -0
  11. data/lib/hammer_cli_foreman/host.rb +107 -16
  12. data/lib/hammer_cli_foreman/hostgroup.rb +10 -0
  13. data/lib/hammer_cli_foreman/puppet_class.rb +10 -1
  14. data/lib/hammer_cli_foreman/resource_supported_test.rb +3 -3
  15. data/lib/hammer_cli_foreman/smart_class_parameter.rb +110 -0
  16. data/lib/hammer_cli_foreman/version.rb +1 -1
  17. data/test/unit/apipie_resource_mock.rb +88 -0
  18. data/test/unit/architecture_test.rb +91 -0
  19. data/test/unit/common_parameter_test.rb +77 -0
  20. data/test/unit/compute_resource_test.rb +94 -0
  21. data/test/unit/domain_test.rb +130 -0
  22. data/test/unit/environment_test.rb +110 -0
  23. data/test/unit/exception_handler_test.rb +48 -0
  24. data/test/unit/fact_test.rb +31 -0
  25. data/test/unit/helpers/command.rb +69 -0
  26. data/test/unit/helpers/resource_disabled.rb +24 -0
  27. data/test/unit/host_test.rb +315 -0
  28. data/test/unit/hostgroup_test.rb +145 -0
  29. data/test/unit/image_test.rb +136 -0
  30. data/test/unit/location_test.rb +109 -0
  31. data/test/unit/media_test.rb +106 -0
  32. data/test/unit/model_test.rb +98 -0
  33. data/test/unit/operating_system_test.rb +151 -0
  34. data/test/unit/organization_test.rb +109 -0
  35. data/test/unit/output/formatters_test.rb +19 -0
  36. data/test/unit/partition_table_test.rb +143 -0
  37. data/test/unit/puppet_class_test.rb +71 -0
  38. data/test/unit/report_test.rb +64 -0
  39. data/test/unit/smart_class_parameter_test.rb +77 -0
  40. data/test/unit/smart_proxy_test.rb +102 -0
  41. data/test/unit/subnet_test.rb +95 -0
  42. data/test/unit/template_test.rb +141 -0
  43. data/test/unit/test_helper.rb +27 -0
  44. data/test/unit/test_output_adapter.rb +19 -0
  45. data/test/unit/user_test.rb +92 -0
  46. metadata +107 -29
@@ -0,0 +1,98 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+
4
+
5
+ describe HammerCLIForeman::Model do
6
+
7
+ extend CommandTestHelper
8
+
9
+ before :each do
10
+ cmd.class.resource ApipieResourceMock.new(cmd.class.resource.resource_class)
11
+ end
12
+
13
+ context "ListCommand" do
14
+
15
+ let(:cmd) { HammerCLIForeman::Model::ListCommand.new("", ctx) }
16
+
17
+ context "parameters" do
18
+ it_should_accept "no arguments"
19
+ it_should_accept_search_params
20
+ end
21
+
22
+ context "output" do
23
+ let(:expected_record_count) { cmd.resource.call(:index)[0].length }
24
+
25
+ it_should_print_n_records
26
+ it_should_print_column "Name"
27
+ it_should_print_column "Id"
28
+ it_should_print_column "Vendor class"
29
+ it_should_print_column "HW model"
30
+ end
31
+
32
+ end
33
+
34
+
35
+ context "InfoCommand" do
36
+
37
+ let(:cmd) { HammerCLIForeman::Model::InfoCommand.new("", ctx) }
38
+
39
+ context "parameters" do
40
+ it_should_accept "id", ["--id=1"]
41
+ it_should_accept "name", ["--name=model"]
42
+ it_should_fail_with "no arguments"
43
+ end
44
+
45
+ context "output" do
46
+ with_params ["--id=1"] do
47
+ it_should_print_n_records 1
48
+ it_should_print_column "Name"
49
+ it_should_print_column "Id"
50
+ it_should_print_column "Vendor class"
51
+ it_should_print_column "HW model"
52
+ it_should_print_column "Info"
53
+ it_should_print_column "Created at"
54
+ it_should_print_column "Updated at"
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+
61
+ context "CreateCommand" do
62
+
63
+ let(:cmd) { HammerCLIForeman::Model::CreateCommand.new("", ctx) }
64
+
65
+ context "parameters" do
66
+ it_should_accept "name", ["--name=model", "--info=description", "--vendor-class=class", "--hardware-model=model"]
67
+ it_should_fail_with "name missing", ["--info=description", "--vendor-class=class", "--hardware-model=model"]
68
+ end
69
+
70
+ end
71
+
72
+
73
+ context "DeleteCommand" do
74
+
75
+ let(:cmd) { HammerCLIForeman::Model::DeleteCommand.new("", ctx) }
76
+
77
+ context "parameters" do
78
+ it_should_accept "name", ["--name=model"]
79
+ it_should_accept "id", ["--id=1"]
80
+ it_should_fail_with "name or id missing", []
81
+ end
82
+
83
+ end
84
+
85
+
86
+ context "UpdateCommand" do
87
+
88
+ let(:cmd) { HammerCLIForeman::Model::UpdateCommand.new("", ctx) }
89
+
90
+ context "parameters" do
91
+ it_should_accept "name", ["--name=model", "--new-name=model2", "--info=description", "--vendor-class=class", "--hardware-model=model"]
92
+ it_should_accept "id", ["--id=1", "--new-name=model2", "--info=description", "--vendor-class=class", "--hardware-model=model"]
93
+ it_should_fail_with "no params", []
94
+ it_should_fail_with "name or id missing", ["--new-name=model2", "--info=description", "--vendor-class=class", "--hardware-model=model"]
95
+ end
96
+
97
+ end
98
+ end
@@ -0,0 +1,151 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+
4
+
5
+ describe HammerCLIForeman::OperatingSystem do
6
+
7
+ let(:ctx) { { :adapter => :silent } }
8
+
9
+ extend CommandTestHelper
10
+
11
+ before :each do
12
+ resource_mock = ApipieResourceMock.new(cmd.class.resource.resource_class)
13
+ resource_mock.stub_method(:index, [])
14
+ resource_mock.stub_method(:show, {"operatingsystem" => {}})
15
+ cmd.class.resource resource_mock
16
+ end
17
+
18
+ context "ListCommand" do
19
+
20
+ let(:cmd) { HammerCLIForeman::OperatingSystem::ListCommand.new("", ctx) }
21
+
22
+ context "parameters" do
23
+ it_should_accept "no arguments"
24
+ it_should_accept_search_params
25
+ end
26
+
27
+ context "output" do
28
+ let(:expected_record_count) { cmd.resource.call(:index)[0].length }
29
+
30
+ it_should_print_n_records
31
+ it_should_print_column "Name"
32
+ it_should_print_column "Id"
33
+ it_should_print_column "Release name"
34
+ it_should_print_column "Family"
35
+ end
36
+
37
+ end
38
+
39
+
40
+ context "InfoCommand" do
41
+
42
+ let(:cmd) { HammerCLIForeman::OperatingSystem::InfoCommand.new("", ctx) }
43
+
44
+ before :each do
45
+ HammerCLIForeman::Parameter.stubs(:get_parameters).returns([])
46
+ end
47
+
48
+ context "parameters" do
49
+ it_should_accept "id", ["--id=1"]
50
+ it_should_accept "label", ["--label=os"]
51
+ it_should_fail_with "no arguments"
52
+ end
53
+
54
+ context "output" do
55
+ with_params ["--id=1"] do
56
+ it_should_print_n_records 1
57
+ it_should_print_column "Name"
58
+ it_should_print_column "Id"
59
+ it_should_print_column "Release name"
60
+ it_should_print_column "Family"
61
+ it_should_print_column "Installation media"
62
+ it_should_print_column "Architectures"
63
+ it_should_print_column "Partition tables"
64
+ it_should_print_column "Config templates"
65
+ it_should_print_column "Parameters"
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+
72
+ context "CreateCommand" do
73
+
74
+ let(:cmd) { HammerCLIForeman::OperatingSystem::CreateCommand.new("", ctx) }
75
+
76
+ context "parameters" do
77
+ it_should_accept "name, major, minor, family, release name", ["--name=media", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
78
+ it_should_fail_with "name missing", ["--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
79
+ end
80
+
81
+ with_params ["--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"] do
82
+ it_should_call_action :create, {'operatingsystem' => {'name' => 'os', 'major' => '1', 'minor' => '2', 'release_name' => 'awesome', 'family'=>"Red Hat"}}
83
+ end
84
+ end
85
+
86
+
87
+ context "DeleteCommand" do
88
+
89
+ let(:cmd) { HammerCLIForeman::OperatingSystem::DeleteCommand.new("", ctx) }
90
+
91
+ context "parameters" do
92
+ it_should_accept "label", ["--label=os"]
93
+ it_should_accept "id", ["--id=1"]
94
+ it_should_fail_with "name or id missing", []
95
+ end
96
+
97
+ end
98
+
99
+
100
+ context "UpdateCommand" do
101
+
102
+ let(:cmd) { HammerCLIForeman::OperatingSystem::UpdateCommand.new("", ctx) }
103
+
104
+ context "parameters" do
105
+ it_should_accept "label", ["--label=os"]
106
+ it_should_accept "id", ["--id=1"]
107
+ it_should_accept "name, major, minor, family, release name", ["--id=83", "--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
108
+ it_should_fail_with "no params", []
109
+ it_should_fail_with "label or id missing", ["--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
110
+ end
111
+
112
+ with_params ["--id=83", "--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"] do
113
+ it_should_call_action :update, {'id' => '83', 'operatingsystem' => {'name' => 'os', 'major' => '1', 'minor' => '2', 'release_name' => 'awesome', 'family'=>"Red Hat"}}
114
+ end
115
+
116
+ end
117
+
118
+
119
+ context "SetParameterCommand" do
120
+
121
+ before :each do
122
+ resource_mock = ApipieResourceMock.new(cmd.class.resource.resource_class)
123
+ resource_mock.stub_method(:index, [])
124
+ cmd.class.resource resource_mock
125
+ end
126
+
127
+ let(:cmd) { HammerCLIForeman::OperatingSystem::SetParameterCommand.new("", ctx) }
128
+
129
+ context "parameters" do
130
+ it_should_accept "name, value and os id", ["--name=name", "--value=val", "--os-id=id"]
131
+ it_should_fail_with "name missing", ["--value=val", "--os-id=id"]
132
+ it_should_fail_with "value missing", ["--name=name", "--os-id=id"]
133
+ it_should_fail_with "os id missing", ["--name=name", "--value=val"]
134
+ end
135
+
136
+ end
137
+
138
+
139
+ context "DeleteParameterCommand" do
140
+
141
+ let(:cmd) { HammerCLIForeman::OperatingSystem::DeleteParameterCommand.new("", ctx) }
142
+
143
+ context "parameters" do
144
+ it_should_accept "name and os id", ["--name=domain", "--os-id=id"]
145
+ it_should_fail_with "name missing", ["--os-id=id"]
146
+ it_should_fail_with "os id missing", ["--name=name"]
147
+ end
148
+
149
+ end
150
+
151
+ end
@@ -0,0 +1,109 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'helpers/resource_disabled')
3
+
4
+ describe HammerCLIForeman::Organization do
5
+
6
+ extend CommandTestHelper
7
+ extend ResourceDisabled
8
+
9
+ before :each do
10
+ resource_mock = ApipieResourceMock.new(cmd.class.resource.resource_class)
11
+ resource_mock.stub_method(:index, [])
12
+ resource_mock.stub_method(:show, {})
13
+ cmd.class.resource resource_mock
14
+ end
15
+
16
+ context "ListCommand" do
17
+
18
+ let(:cmd) { HammerCLIForeman::Organization::ListCommand.new("", ctx) }
19
+
20
+ context "parameters" do
21
+ it_should_accept "no arguments"
22
+ it_should_accept_search_params
23
+ end
24
+
25
+ context "output" do
26
+ let(:expected_record_count) { cmd.resource.call(:index)[0].length }
27
+
28
+ it_should_print_n_records
29
+ it_should_print_column "Name"
30
+ it_should_print_column "Id"
31
+ end
32
+
33
+ it_should_fail_when_disabled
34
+ end
35
+
36
+
37
+ context "InfoCommand" do
38
+
39
+ let(:cmd) { HammerCLIForeman::Organization::InfoCommand.new("", ctx) }
40
+
41
+ context "parameters" do
42
+ it_should_accept "id", ["--id=1"]
43
+ it_should_accept "name", ["--name=arch"]
44
+ it_should_fail_with "no arguments"
45
+ end
46
+
47
+ context "output" do
48
+ with_params ["--id=1"] do
49
+ it_should_print_n_records 1
50
+ it_should_print_column "Name"
51
+ it_should_print_column "Id"
52
+ it_should_print_column "Created at"
53
+ it_should_print_column "Updated at"
54
+ end
55
+ end
56
+
57
+ with_params ["--id=1"] do
58
+ it_should_fail_when_disabled
59
+ end
60
+ end
61
+
62
+
63
+ context "CreateCommand" do
64
+
65
+ let(:cmd) { HammerCLIForeman::Organization::CreateCommand.new("", ctx) }
66
+
67
+ context "parameters" do
68
+ it_should_accept "name", ["--name=org"]
69
+ it_should_fail_with "name missing", []
70
+ end
71
+
72
+ with_params ["--name=org"] do
73
+ it_should_fail_when_disabled
74
+ end
75
+ end
76
+
77
+
78
+ context "DeleteCommand" do
79
+
80
+ let(:cmd) { HammerCLIForeman::Organization::DeleteCommand.new("", ctx) }
81
+
82
+ context "parameters" do
83
+ it_should_accept "name", ["--name=org"]
84
+ it_should_accept "id", ["--id=1"]
85
+ it_should_fail_with "name or id missing", []
86
+ end
87
+
88
+ with_params ["--id=1"] do
89
+ it_should_fail_when_disabled
90
+ end
91
+ end
92
+
93
+
94
+ context "UpdateCommand" do
95
+
96
+ let(:cmd) { HammerCLIForeman::Organization::UpdateCommand.new("", ctx) }
97
+
98
+ context "parameters" do
99
+ it_should_accept "name", ["--name=org", "--new-name=org2"]
100
+ it_should_accept "id", ["--id=1", "--new-name=org2"]
101
+ it_should_fail_with "no params", []
102
+ it_should_fail_with "name or id missing", ["--new-name=org2"]
103
+ end
104
+
105
+ with_params ["--id=1"] do
106
+ it_should_fail_when_disabled
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper')
2
+
3
+ describe HammerCLIForeman::Output::Formatters::OSNameFormatter do
4
+ it "formats the os name" do
5
+ formatter = HammerCLIForeman::Output::Formatters::OSNameFormatter.new
6
+ formatter.format({ :name => 'OS', :major => '1', :minor => '2' }).must_equal 'OS 1.2'
7
+ end
8
+ it "formats the os name with only major version" do
9
+ formatter = HammerCLIForeman::Output::Formatters::OSNameFormatter.new
10
+ formatter.format({ :name => 'Fedora', :major => '19'}).must_equal 'Fedora 19'
11
+ end
12
+ end
13
+
14
+ describe HammerCLIForeman::Output::Formatters::ServerFormatter do
15
+ it "formats the server" do
16
+ formatter = HammerCLIForeman::Output::Formatters::ServerFormatter.new
17
+ formatter.format({ :name => 'Server', :url => "URL"}).must_equal 'Server (URL)'
18
+ end
19
+ end
@@ -0,0 +1,143 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+
4
+
5
+ describe HammerCLIForeman::PartitionTable do
6
+
7
+ let(:ctx) { { :adapter => :silent } }
8
+
9
+ extend CommandTestHelper
10
+
11
+ before :each do
12
+ cmd.class.resource ApipieResourceMock.new(cmd.class.resource.resource_class)
13
+
14
+ ::File.stubs(:read).returns("FILE_CONTENT")
15
+ end
16
+
17
+ context "ListCommand" do
18
+
19
+ let(:cmd) { HammerCLIForeman::PartitionTable::ListCommand.new("", ctx) }
20
+
21
+ context "parameters" do
22
+ it_should_accept "no arguments"
23
+ it_should_accept_search_params
24
+ end
25
+
26
+ context "output" do
27
+ let(:expected_record_count) { cmd.resource.call(:index)[0].length }
28
+
29
+ it_should_print_n_records
30
+ it_should_print_columns ["Id", "Name", "OS Family"]
31
+ end
32
+
33
+ end
34
+
35
+
36
+ context "InfoCommand" do
37
+
38
+ let(:cmd) { HammerCLIForeman::PartitionTable::InfoCommand.new("", ctx) }
39
+
40
+ context "parameters" do
41
+ it_should_accept "id", ["--id=1"]
42
+ it_should_accept "name", ["--name=ptable"]
43
+ it_should_fail_with "no arguments"
44
+ end
45
+
46
+ context "output" do
47
+ with_params ["--id=1"] do
48
+ it_should_print_n_records 1
49
+ it_should_print_columns ["Id", "Name", "OS Family", "Created at", "Updated at"]
50
+ end
51
+ end
52
+
53
+ with_params ["--id=83"] do
54
+ it_should_call_action :show, {'id' => '83'}
55
+ end
56
+
57
+ with_params ["--name=ptable"] do
58
+ it_should_call_action :show, {'id' => 'ptable'}
59
+ end
60
+
61
+ end
62
+
63
+
64
+ context "DumpCommand" do
65
+
66
+ let(:cmd) { HammerCLIForeman::PartitionTable::DumpCommand.new("", ctx) }
67
+
68
+ context "parameters" do
69
+ it_should_accept "id", ["--id=1"]
70
+ it_should_accept "name", ["--name=ptable"]
71
+ it_should_fail_with "id or name missing", []
72
+ end
73
+
74
+ with_params ["--id=83"] do
75
+ it_should_call_action :show, {'id' => '83'}
76
+ end
77
+
78
+ with_params ["--name=ptable"] do
79
+ it_should_call_action :show, {'id' => 'ptable'}
80
+ end
81
+
82
+ end
83
+
84
+
85
+ context "CreateCommand" do
86
+
87
+ let(:cmd) { HammerCLIForeman::PartitionTable::CreateCommand.new("", ctx) }
88
+
89
+ before :each do
90
+ cmd.stubs(:template_kind_id).returns(1)
91
+ end
92
+
93
+ context "parameters" do
94
+ it_should_accept "name, file, os family", ["--name=tpl", "--file=~/table.sh", "--os-family=RedHat"]
95
+ it_should_fail_with "name missing", ["--file=~/table.sh", "--os-family=RedHat"]
96
+ it_should_fail_with "file missing", ["--name=tpl", "--os-family=RedHat"]
97
+ end
98
+
99
+ with_params ["--name=ptable","--file=~/table.sh", "--os-family=RedHat"] do
100
+ it_should_call_action :create, {'ptable' => {'name' => 'ptable', 'layout' => 'FILE_CONTENT', 'os_family' => 'RedHat'}}
101
+ end
102
+
103
+ end
104
+
105
+
106
+ context "UpdateCommand" do
107
+
108
+ let(:cmd) { HammerCLIForeman::PartitionTable::UpdateCommand.new("", ctx) }
109
+
110
+ context "parameters" do
111
+ it_should_accept "id, new-name, file, type, audit comment, os ids", ["--id=83", "--new-name=ptable","--file=~/table.sh", "--os-family=RedHat"]
112
+ it_should_accept "name, new-name, file, type, audit comment, os ids", ["--name=ptable", "--new-name=ptable2", "--file=~/table.sh", "--os-family=RedHat"]
113
+ it_should_fail_with "id and name missing", ["--new-name=ptable","--file=~/table.sh", "--os-family=RedHat"]
114
+ end
115
+
116
+ with_params ["--id=83", "--new-name=ptable","--file=~/table.sh", "--os-family=RedHat"] do
117
+ it_should_call_action :update, {'id' => '83', 'ptable' => {'name' => 'ptable', 'layout' => 'FILE_CONTENT', 'os_family' => 'RedHat'}}
118
+ end
119
+
120
+ end
121
+
122
+
123
+ context "DeleteCommand" do
124
+
125
+ let(:cmd) { HammerCLIForeman::PartitionTable::DeleteCommand.new("", ctx) }
126
+
127
+ context "parameters" do
128
+ it_should_accept "id", ["--id=1"]
129
+ it_should_accept "name", ["--name=ptable"]
130
+ it_should_fail_with "id or name missing", []
131
+ end
132
+
133
+ with_params ["--id=1"] do
134
+ it_should_call_action :destroy, {'id' => '1'}
135
+ end
136
+
137
+ with_params ["--name=ptable"] do
138
+ it_should_call_action :destroy, {'id' => 'ptable'}
139
+ end
140
+
141
+ end
142
+
143
+ end