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,71 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+
4
+
5
+ describe HammerCLIForeman::PuppetClass 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::PuppetClass::ListCommand.new("", ctx) }
16
+
17
+ context "parameters" do
18
+ it_should_accept "no arguments"
19
+ # FIXME: the command should accept search parameters in future
20
+ # it_should_accept_search_params
21
+ end
22
+
23
+ context "output" do
24
+ let(:expected_record_count) { cmd.resource.call(:index)[0].length }
25
+
26
+ it_should_print_n_records
27
+ it_should_print_column "Id"
28
+ it_should_print_column "Name"
29
+ end
30
+
31
+ end
32
+
33
+
34
+ context "InfoCommand" do
35
+
36
+ let(:cmd) { HammerCLIForeman::PuppetClass::InfoCommand.new("", ctx) }
37
+
38
+ context "parameters" do
39
+ it_should_accept "id", ["--id=1"]
40
+ it_should_fail_with "no arguments"
41
+ end
42
+
43
+ context "output" do
44
+ with_params ["--id=1"] do
45
+ it_should_print_n_records 1
46
+ it_should_print_column "Id"
47
+ it_should_print_column "Name"
48
+ it_should_print_column "Smart variables"
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ context "SCParamsCommand" do
55
+
56
+ before :each do
57
+ cmd.class.resource ResourceMocks.smart_class_parameter
58
+ end
59
+
60
+ let(:cmd) { HammerCLIForeman::PuppetClass::SCParamsCommand.new("", ctx) }
61
+
62
+ context "parameters" do
63
+ it_should_accept "name", ["--name=env"]
64
+ it_should_accept "id", ["--id=1"]
65
+ it_should_fail_with "name or id missing", []
66
+ end
67
+
68
+ end
69
+
70
+
71
+ end
@@ -0,0 +1,64 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+
4
+
5
+ describe HammerCLIForeman::Report 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::Report::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 "Id"
27
+ it_should_print_column "Host"
28
+ it_should_print_column "Last report"
29
+ it_should_print_column "Applied"
30
+ it_should_print_column "Restarted"
31
+ it_should_print_column "Failed"
32
+ it_should_print_column "Restart Failures"
33
+ it_should_print_column "Skipped"
34
+ it_should_print_column "Pending"
35
+ end
36
+
37
+ end
38
+
39
+
40
+ context "InfoCommand" do
41
+
42
+ let(:cmd) { HammerCLIForeman::Report::InfoCommand.new("", ctx) }
43
+
44
+ context "parameters" do
45
+ it_should_accept "id", ["--id=1"]
46
+ it_should_fail_with "no arguments"
47
+ end
48
+
49
+ end
50
+
51
+
52
+ context "DeleteCommand" do
53
+
54
+ let(:cmd) { HammerCLIForeman::Report::DeleteCommand.new("", ctx) }
55
+
56
+ context "parameters" do
57
+ it_should_accept "id", ["--id=1"]
58
+ it_should_fail_with "id missing", []
59
+ end
60
+
61
+ end
62
+
63
+
64
+ end
@@ -0,0 +1,77 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+
4
+
5
+ describe HammerCLIForeman::SmartClassParameter do
6
+
7
+ extend CommandTestHelper
8
+
9
+ before :each do
10
+ cmd.class.resource ResourceMocks.smart_class_parameter
11
+ end
12
+
13
+ context "ListCommand" do
14
+
15
+ let(:cmd) { HammerCLIForeman::SmartClassParameter::ListCommand.new("", ctx) }
16
+
17
+ context "parameters" do
18
+ it_should_accept "no arguments"
19
+ it_should_accept "hostgroup id", ["--hostgroup-id=1"]
20
+ it_should_accept "host id", ["--host-id=1"]
21
+ it_should_accept "environment id", ["--environment-id=1"]
22
+ it_should_accept "puppet class id", ["--puppetclass-id=1"]
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_column "Id"
31
+ it_should_print_column "Class Id"
32
+ it_should_print_column "Puppet class"
33
+ it_should_print_column "Parameter"
34
+ it_should_print_column "Default Value"
35
+ it_should_print_column "Override"
36
+ end
37
+
38
+ end
39
+
40
+
41
+ context "InfoCommand" do
42
+
43
+ let(:cmd) { HammerCLIForeman::SmartClassParameter::InfoCommand.new("", ctx) }
44
+
45
+
46
+ context "parameters" do
47
+ it_should_accept "id", ["--id=1"]
48
+ it_should_accept "name", ["--name=param"]
49
+ it_should_fail_with "no arguments"
50
+ end
51
+
52
+ end
53
+
54
+
55
+ context "UpdateCommand" do
56
+
57
+ let(:cmd) { HammerCLIForeman::SmartClassParameter::UpdateCommand.new("", ctx) }
58
+
59
+ context "parameters" do
60
+ it_should_accept "id", ["--id=1"]
61
+ it_should_accept "override", ["--id=1","--override=true"]
62
+ it_should_accept "description", ["--id=1","--description=descr"]
63
+ it_should_accept "default-value", ["--id=1","--default-value=1"]
64
+ it_should_accept "path ", ["--id=1","--path=path"]
65
+ it_should_accept "validator-type", ["--id=1","--validator-type=list"]
66
+ it_should_accept "validator-rule ", ["--id=1","--validator-rule=''"]
67
+ it_should_accept "override-value-order", ["--id=1","--override-value-order=fqdn"]
68
+ it_should_accept "parameter-type ", ["--id=1","--parameter-type=string"]
69
+ it_should_accept "required", ["--id=1","--required=true"]
70
+
71
+ it_should_fail_with "id missing", []
72
+ end
73
+
74
+ end
75
+
76
+
77
+ end
@@ -0,0 +1,102 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+
4
+
5
+ describe HammerCLIForeman::SmartProxy 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::SmartProxy::ListCommand.new("", ctx) }
16
+
17
+ context "parameters" do
18
+ it_should_accept "no arguments"
19
+ it_should_accept "type, page, per_page", ["--type=tftp", "--page=1", "--per-page=2"]
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_columns ["Id", "Name", "URL"]
27
+ end
28
+
29
+ end
30
+
31
+
32
+ context "InfoCommand" do
33
+
34
+ let(:cmd) { HammerCLIForeman::SmartProxy::InfoCommand.new("", ctx) }
35
+
36
+ context "parameters" do
37
+ it_should_accept "id", ["--id=1"]
38
+ it_should_accept "name", ["--name=proxy"]
39
+ it_should_fail_with "no arguments"
40
+ end
41
+
42
+ context "output" do
43
+ with_params ["--id=1"] do
44
+ it_should_print_n_records 1
45
+ it_should_print_columns ["Id", "Name", "URL", "Features", "Created at", "Updated at"]
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+
52
+ context "CreateCommand" do
53
+
54
+ let(:cmd) { HammerCLIForeman::SmartProxy::CreateCommand.new("", ctx) }
55
+
56
+ context "parameters" do
57
+ it_should_accept "name and url", ["--name=proxy", "--url=localhost"]
58
+ it_should_fail_with "name missing", ["--url=loaclhost"]
59
+ it_should_fail_with "url missing", ["--name=proxy"]
60
+ end
61
+
62
+ end
63
+
64
+
65
+ context "DeleteCommand" do
66
+
67
+ let(:cmd) { HammerCLIForeman::SmartProxy::DeleteCommand.new("", ctx) }
68
+
69
+ context "parameters" do
70
+ it_should_accept "id", ["--id=1"]
71
+ it_should_accept "name", ["--name=proxy"]
72
+ it_should_fail_with "name or id missing", []
73
+ end
74
+
75
+ end
76
+
77
+
78
+ context "UpdateCommand" do
79
+
80
+ let(:cmd) { HammerCLIForeman::SmartProxy::UpdateCommand.new("", ctx) }
81
+
82
+ context "parameters" do
83
+ it_should_accept "id", ["--id=1", "--new-name=proxy2", "--url=localhost"]
84
+ it_should_accept "name", ["--name=proxy", "--new-name=proxy2", "--url=localhost"]
85
+ it_should_fail_with "no params", []
86
+ it_should_fail_with "name or id missing", ["--new-name=proxy2"]
87
+ end
88
+
89
+ end
90
+
91
+ context "ImportPuppetClassesCommand" do
92
+
93
+ let(:cmd) { HammerCLIForeman::SmartProxy::ImportPuppetClassesCommand.new("", ctx) }
94
+
95
+ context "parameters" do
96
+ it_should_accept "id, environment-id and dryrun", ["--id=1", "--environment-id=1", "--dryrun"]
97
+ it_should_fail_with "id missing", [""]
98
+ end
99
+
100
+ end
101
+
102
+ end
@@ -0,0 +1,95 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+
4
+
5
+ describe HammerCLIForeman::Subnet 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::Subnet::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_columns ["Id", "Name", "Network", "Mask"]
27
+ end
28
+
29
+ end
30
+
31
+
32
+ context "InfoCommand" do
33
+
34
+ let(:cmd) { HammerCLIForeman::Subnet::InfoCommand.new("", ctx) }
35
+
36
+ context "parameters" do
37
+ it_should_accept "id", ["--id=1"]
38
+ it_should_accept "name", ["--name=arch"]
39
+ it_should_fail_with "no arguments"
40
+ end
41
+
42
+ context "output" do
43
+ with_params ["--id=1"] do
44
+ it_should_print_n_records 1
45
+ it_should_print_columns ["Id", "Name", "Network", "Mask"]
46
+ it_should_print_columns ["Priority"]
47
+ it_should_print_columns ["DNS", "Primary DNS", "Secondary DNS"]
48
+ it_should_print_columns ["Domain ids", "TFTP", "TFTP id", "DHCP", "DHCP id"]
49
+ it_should_print_columns ["vlan id", "Gateway", "From", "To"]
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+
56
+ context "CreateCommand" do
57
+
58
+ let(:cmd) { HammerCLIForeman::Subnet::CreateCommand.new("", ctx) }
59
+
60
+ context "parameters" do
61
+ it_should_accept "name", ["--name=arch", "--network=192.168.83.0", "--mask=255.255.255.0"]
62
+ it_should_fail_with "name missing", ["--network=192.168.83.0", "--mask=255.255.255.0"]
63
+ it_should_fail_with "network missing", ["--name=arch", "--mask=255.255.255.0"]
64
+ it_should_fail_with "mask missing", ["--name=arch", "--network=192.168.83.0"]
65
+ end
66
+
67
+ end
68
+
69
+
70
+ context "DeleteCommand" do
71
+
72
+ let(:cmd) { HammerCLIForeman::Subnet::DeleteCommand.new("", ctx) }
73
+
74
+ context "parameters" do
75
+ it_should_accept "name", ["--name=arch"]
76
+ it_should_accept "id", ["--id=1"]
77
+ it_should_fail_with "name or id missing", []
78
+ end
79
+
80
+ end
81
+
82
+
83
+ context "UpdateCommand" do
84
+
85
+ let(:cmd) { HammerCLIForeman::Subnet::UpdateCommand.new("", ctx) }
86
+
87
+ context "parameters" do
88
+ it_should_accept "name", ["--name=arch", "--new-name=arch2"]
89
+ it_should_accept "id", ["--id=1", "--new-name=arch2"]
90
+ it_should_fail_with "no params", []
91
+ it_should_fail_with "name or id missing", ["--new-name=arch2"]
92
+ end
93
+
94
+ end
95
+ end
@@ -0,0 +1,141 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+
4
+
5
+ describe HammerCLIForeman::Template do
6
+
7
+ extend CommandTestHelper
8
+
9
+ let(:template_hash) {
10
+ {
11
+ "config_template" => {
12
+ "template_kind" => {}
13
+ }
14
+ }
15
+ }
16
+
17
+ before :each do
18
+ resource_mock = ApipieResourceMock.new(cmd.class.resource.resource_class)
19
+ resource_mock.stub_method(:index, [])
20
+ resource_mock.stub_method(:show, template_hash)
21
+ cmd.class.resource resource_mock
22
+ File.stubs(:read).returns("")
23
+ end
24
+
25
+ context "ListCommand" do
26
+
27
+ let(:cmd) { HammerCLIForeman::Template::ListCommand.new("", ctx) }
28
+
29
+ context "parameters" do
30
+ it_should_accept "no arguments"
31
+ it_should_accept_search_params
32
+ end
33
+
34
+ context "output" do
35
+ let(:expected_record_count) { cmd.resource.call(:index)[0].length }
36
+
37
+ it_should_print_n_records
38
+ it_should_print_columns ["Id", "Name", "Type"]
39
+
40
+ it "should print template without kind set" do
41
+ template_wo_kind = {
42
+ "config_template" => {
43
+ :id => 1, :name => "PXE"
44
+ }
45
+ }
46
+ mock_resource_method(:index, [[template_wo_kind], nil])
47
+ cmd.run([]).must_equal 0
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+
54
+ context "InfoCommand" do
55
+
56
+ let(:cmd) { HammerCLIForeman::Template::InfoCommand.new("", ctx) }
57
+
58
+ context "parameters" do
59
+ it_should_accept "id", ["--id=1"]
60
+ it_should_fail_with "no arguments"
61
+ end
62
+
63
+ context "output" do
64
+ with_params ["--id=1"] do
65
+ it_should_print_n_records 1
66
+ it_should_print_columns ["Id", "Name", "Type", "OS ids"]
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+
73
+ context "ListKindsCommand" do
74
+
75
+ let(:cmd) { HammerCLIForeman::Template::ListKindsCommand.new("", ctx) }
76
+
77
+ context "parameters" do
78
+ it_should_accept "no arguments"
79
+ end
80
+
81
+ end
82
+
83
+
84
+ context "DumpCommand" do
85
+
86
+ let(:cmd) { HammerCLIForeman::Template::DumpCommand.new("", ctx) }
87
+
88
+ context "parameters" do
89
+ it_should_accept "id", ["--id=1"]
90
+ it_should_fail_with "id missing", []
91
+ end
92
+
93
+ end
94
+
95
+
96
+ context "CreateCommand" do
97
+
98
+ let(:cmd) { HammerCLIForeman::Template::CreateCommand.new("", ctx) }
99
+
100
+ before :each do
101
+ cmd.stubs(:template_kind_id).returns(1)
102
+ end
103
+
104
+ context "parameters" do
105
+ it_should_accept "name, file, type, audit comment, os ids", ["--name=tpl", "--file=~/tpl.sh", "--type=snippet", "--audit-comment=fix", "--operatingsystem-ids=1,2,3"]
106
+ it_should_fail_with "name missing", ["--file=~/tpl.sh", "--type=snippet", "--audit-comment=fix", "--operatingsystem-ids=1,2,3"]
107
+ it_should_fail_with "type missing", ["--name=tpl", "--file=~/tpl.sh", "--audit-comment=fix", "--operatingsystem-ids=1,2,3"]
108
+ it_should_fail_with "file missing", ["--name=tpl", "--type=snippet", "--audit-comment=fix", "--operatingsystem-ids=1,2,3"]
109
+ end
110
+
111
+ end
112
+
113
+
114
+ context "UpdateCommand" do
115
+
116
+ let(:cmd) { HammerCLIForeman::Template::UpdateCommand.new("", ctx) }
117
+
118
+ before :each do
119
+ cmd.stubs(:template_kind_id).returns(1)
120
+ end
121
+
122
+ context "parameters" do
123
+ it_should_accept "id, name, file, type, audit comment, os ids", ["--id=83", "--name=tpl", "--file=~/tpl.sh", "--type=snippet", "--audit-comment=fix", "--operatingsystem-ids=1,2,3"]
124
+ it_should_fail_with "id missing", ["--name=tpl", "--file=~/tpl.sh", "--type=snippet", "--audit-comment=fix", "--operatingsystem-ids=1,2,3"]
125
+ end
126
+
127
+ end
128
+
129
+
130
+ context "DeleteCommand" do
131
+
132
+ let(:cmd) { HammerCLIForeman::Template::DeleteCommand.new("", ctx) }
133
+
134
+ context "parameters" do
135
+ it_should_accept "id", ["--id=1"]
136
+ it_should_fail_with "id missing", []
137
+ end
138
+
139
+ end
140
+
141
+ end