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,145 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+
4
+
5
+ describe HammerCLIForeman::Hostgroup 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::Hostgroup::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", "Label", "Operating System Id", "Subnet Id"]
27
+ it_should_print_columns ["Domain Id", "Environment Id", "Puppetclass Ids", "Ancestry"]
28
+ end
29
+
30
+ end
31
+
32
+ context "InfoCommand" do
33
+
34
+ let(:cmd) { HammerCLIForeman::Hostgroup::InfoCommand.new("", ctx) }
35
+
36
+ before :each do
37
+ HammerCLIForeman::Parameter.stubs(:get_parameters).returns([])
38
+ end
39
+
40
+ context "parameters" do
41
+ it_should_accept "id", ["--id=1"]
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_columns ["Id", "Name", "Label", "Operating System Id", "Subnet Id"]
49
+ it_should_print_columns ["Domain Id", "Environment Id", "Puppetclass Ids", "Ancestry"]
50
+ it_should_print_columns ["Parameters"]
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ context "DeleteCommand" do
57
+
58
+ let(:cmd) { HammerCLIForeman::Hostgroup::DeleteCommand.new("", ctx) }
59
+
60
+ context "parameters" do
61
+ it_should_accept "id", ["--id=1"]
62
+ it_should_fail_with "id missing", []
63
+ end
64
+
65
+ end
66
+
67
+ context "CreateCommand" do
68
+
69
+ let(:cmd) { HammerCLIForeman::Hostgroup::CreateCommand.new("", ctx) }
70
+
71
+ context "parameters" do
72
+ it_should_accept "name, parent_id, environment_id, architecture_id, domain_id, puppet_proxy_id, operatingsystem_id and more",
73
+ ["--name=hostgroup", "--parent-id=1", "--environment-id=1", "--architecture-id=1", "--domain-id=1", "--puppet-proxy-id=1",
74
+ "--operatingsystem-id=1", "--medium-id=1", "--ptable-id=1", "--subnet-id=1", '--puppet-ca-proxy-id=1']
75
+ it_should_fail_with "name or id missing",
76
+ ["--environment-id=1", "--architecture-id=1", "--domain-id=1", "--puppet-proxy-id=1", "--operatingsystem-id=1"]
77
+ end
78
+ end
79
+
80
+ context "UpdateCommand" do
81
+
82
+ let(:cmd) { HammerCLIForeman::Hostgroup::UpdateCommand.new("", ctx) }
83
+
84
+ context "parameters" do
85
+ it_should_accept "name, parent_id, environment_id, architecture_id, domain_id, puppet_proxy_id, operatingsystem_id and more",
86
+ ["--id=1 --name=hostgroup2", "--parent-id=1", "--environment-id=1", "--architecture-id=1", "--domain-id=1", "--puppet-proxy-id=1",
87
+ "--operatingsystem-id=1", "--medium-id=1", "--ptable-id=1", "--subnet-id=1", '--puppet-ca-proxy-id=1']
88
+ it_should_fail_with "no params", []
89
+ it_should_fail_with "id missing", ["--name=host2"]
90
+ end
91
+
92
+ end
93
+
94
+
95
+ context "SetParameterCommand" do
96
+
97
+ before :each do
98
+ resource_mock = ApipieResourceMock.new(cmd.class.resource.resource_class)
99
+ resource_mock.stub_method(:index, [])
100
+ cmd.class.resource resource_mock
101
+ end
102
+
103
+ let(:cmd) { HammerCLIForeman::Hostgroup::SetParameterCommand.new("", ctx) }
104
+
105
+ context "parameters" do
106
+ it_should_accept "name, value and hostgroup id", ["--name=name", "--value=val", "--hostgroup-id=id"]
107
+ it_should_fail_with "name missing", ["--value=val", "--hostgroup-id=1"]
108
+ it_should_fail_with "value missing", ["--name=name", "--hostgroup-id=1"]
109
+ it_should_fail_with "hostgroup id missing", ["--name=name", "--value=val"]
110
+ end
111
+
112
+ end
113
+
114
+
115
+ context "DeleteParameterCommand" do
116
+
117
+ let(:cmd) { HammerCLIForeman::Hostgroup::DeleteParameterCommand.new("", ctx) }
118
+
119
+ context "parameters" do
120
+ it_should_accept "name and hostgroup id", ["--name=name", "--hostgroup-id=id"]
121
+ it_should_fail_with "name missing", ["--hostgroup-id=id"]
122
+ it_should_fail_with "hostgroup id missing", ["--name=name"]
123
+ end
124
+
125
+ end
126
+
127
+
128
+ context "SCParamsCommand" do
129
+
130
+ before :each do
131
+ cmd.class.resource ResourceMocks.smart_class_parameter
132
+ end
133
+
134
+ let(:cmd) { HammerCLIForeman::Hostgroup::SCParamsCommand.new("", ctx) }
135
+
136
+ context "parameters" do
137
+ it_should_accept "name", ["--name=env"]
138
+ it_should_accept "id", ["--id=1"]
139
+ it_should_fail_with "name or id missing", []
140
+ end
141
+
142
+ end
143
+
144
+ end
145
+
@@ -0,0 +1,136 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+ require File.join(File.dirname(__FILE__), 'test_output_adapter')
4
+
5
+
6
+
7
+ describe HammerCLIForeman::Image do
8
+
9
+
10
+ extend CommandTestHelper
11
+
12
+ before :each do
13
+ cmd.class.resource ApipieResourceMock.new(cmd.class.resource.resource_class)
14
+ end
15
+
16
+ context "ListCommand" do
17
+
18
+ let(:cmd) { HammerCLIForeman::Image::ListCommand.new("", ctx) }
19
+
20
+ context "parameters" do
21
+ it_should_accept "compute resource name", ["--compute-resource=cr"]
22
+ it_should_accept "compute resource id", ["--compute-resource-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
+ with_params ["--compute-resource-id=1"] do
30
+ it_should_print_n_records
31
+ it_should_print_column "Id"
32
+ it_should_print_column "Name"
33
+ it_should_print_column "Operating System Id"
34
+ it_should_print_column "Username"
35
+ it_should_print_column "UUID"
36
+ end
37
+ end
38
+ end
39
+
40
+
41
+ context "InfoCommand" do
42
+
43
+ let(:cmd) { HammerCLIForeman::Image::InfoCommand.new("", ctx) }
44
+
45
+ context "parameters" do
46
+ it_should_accept "compute resource name and image's uuid", ["--compute-resource=cr", "--id=1"]
47
+ it_should_accept "compute resource id and image's uuid", ["--compute-resource-id=1", "--id=1"]
48
+ end
49
+
50
+ context "output" do
51
+ let(:expected_record_count) { cmd.resource.call(:index)[0].length }
52
+
53
+ with_params ["--compute-resource-id=1", "--id=1"] do
54
+ it_should_print_n_records 1
55
+ it_should_print_column "Id"
56
+ it_should_print_column "Name"
57
+ it_should_print_column "Operating System Id"
58
+ it_should_print_column "Architecture Id"
59
+ it_should_print_column "Username"
60
+ it_should_print_column "UUID"
61
+ it_should_print_column "IAM role"
62
+ end
63
+ end
64
+ end
65
+
66
+ context "AvailableImagesCommand" do
67
+
68
+ let(:cmd) { HammerCLIForeman::Image::AvailableImagesCommand.new("", ctx) }
69
+
70
+ before :each do
71
+ resource_mock = ApipieResourceMock.new(cmd.class.resource.resource_class)
72
+ resource_mock.stub_method(:available_images, [])
73
+ cmd.class.resource resource_mock
74
+ end
75
+
76
+ context "parameters" do
77
+ it_should_accept "compute resource name", ["--compute-resource=cr"]
78
+ it_should_accept "compute resource id", ["--compute-resource-id=1"]
79
+ end
80
+
81
+ context "output" do
82
+ with_params ["--compute-resource-id=1"] do
83
+ it_should_print_column "Name"
84
+ it_should_print_column "UUID"
85
+ end
86
+ end
87
+ end
88
+
89
+ context "CreateCommand" do
90
+
91
+ let(:cmd) { HammerCLIForeman::Image::CreateCommand.new("", ctx) }
92
+
93
+ context "parameters" do
94
+ it_should_accept "all required params", ["--name=img", "--operatingsystem-id=1", "--architecture-id=1", "--username=root", "--uuid=aabbcc123", "--compute-resource-id=1"]
95
+ it_should_accept "all required params and resource's name", ["--name=img", "--operatingsystem-id=1", "--architecture-id=1", "--username=root", "--uuid=aabbcc123", "--compute-resource=ec2"]
96
+ it_should_fail_with "name missing", ["--operatingsystem-id=1", "architecture-id=1", "--username=root", "--uuid=aabbcc123", "--compute-resource-id=1"]
97
+ it_should_fail_with "os id missing", ["--name=img", "--operatingsystem-id=1", "architecture-id=1", "--username=root", "--uuid=aabbcc123", "--compute-resource-id=1"]
98
+ it_should_fail_with "architecture id missing", ["--name=img", "--operatingsystem-id=1", "--username=root", "--uuid=aabbcc123", "--compute-resource-id=1"]
99
+ it_should_fail_with "username id missing", ["--name=img", "--operatingsystem-id=1", "architecture-id=1", "--uuid=aabbcc123", "--compute-resource-id=1"]
100
+ it_should_fail_with "uuid missing", ["--name=img", "--operatingsystem-id=1", "architecture-id=1", "--username=root", "--compute-resource-id=1"]
101
+ end
102
+
103
+ end
104
+
105
+
106
+ context "DeleteCommand" do
107
+
108
+ let(:cmd) { HammerCLIForeman::Image::DeleteCommand.new("", ctx) }
109
+
110
+ context "parameters" do
111
+ it_should_accept "id and resource's id", ["--id=1", "--compute-resource-id=1"]
112
+ it_should_accept "id and resource's name", ["--id=1", "--compute-resource=ec2"]
113
+ it_should_fail_with "id missing", ["--compute-resource-id=1"]
114
+ it_should_fail_with "resource's id or name missing", ["--id=1"]
115
+ end
116
+
117
+ end
118
+
119
+
120
+ context "UpdateCommand" do
121
+
122
+ let(:cmd) { HammerCLIForeman::Image::UpdateCommand.new("", ctx) }
123
+
124
+ context "parameters" do
125
+ it_should_accept "id and resource's id", ["--id=1", "--compute-resource-id=1"]
126
+ it_should_accept "id and resource's name", ["--id=1", "--compute-resource=ec2"]
127
+ it_should_accept "all available params", ["--id=1", "--name=img", "--operatingsystem-id=1", "--architecture-id=1", "--username=root", "--uuid=aabbcc123", "--compute-resource-id=1"]
128
+ it_should_fail_with "id missing", ["--compute-resource-id=1"]
129
+ it_should_fail_with "resource's id or name missing", ["--id=1"]
130
+ end
131
+
132
+ end
133
+
134
+ end
135
+
136
+
@@ -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::Location 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::Location::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::Location::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::Location::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=loc"] do
73
+ it_should_fail_when_disabled
74
+ end
75
+ end
76
+
77
+
78
+ context "DeleteCommand" do
79
+
80
+ let(:cmd) { HammerCLIForeman::Location::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::Location::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,106 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+
4
+
5
+ describe HammerCLIForeman::Medium 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::Medium::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 "Path"
29
+ end
30
+
31
+ end
32
+
33
+
34
+ context "InfoCommand" do
35
+
36
+ let(:cmd) { HammerCLIForeman::Medium::InfoCommand.new("", ctx) }
37
+
38
+ context "parameters" do
39
+ it_should_accept "id", ["--id=1"]
40
+ it_should_accept "name", ["--name=medium_x"]
41
+ it_should_fail_with "no arguments"
42
+ end
43
+
44
+ context "output" do
45
+ with_params ["--id=1"] do
46
+ it_should_print_n_records 1
47
+ it_should_print_column "Name"
48
+ it_should_print_column "Id"
49
+ it_should_print_column "Path"
50
+ it_should_print_column "OS Family"
51
+ it_should_print_column "OS IDs"
52
+ it_should_print_column "Created at"
53
+ it_should_print_column "Updated at"
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+
60
+ context "CreateCommand" do
61
+
62
+ let(:cmd) { HammerCLIForeman::Medium::CreateCommand.new("", ctx) }
63
+
64
+ context "parameters" do
65
+ it_should_accept "name, path, os ids", ["--name=media", "--path=http://some.path/abc/$major/Fedora/$arch/", "--operatingsystem-ids=1,2"]
66
+ it_should_fail_with "name missing", ["--path=http://some.path/abc/$major/Fedora/$arch/"]
67
+ it_should_fail_with "path missing", ["--name=media"]
68
+ end
69
+
70
+ with_params ["--name=medium_x", "--path=http://some.path/", "--operatingsystem-ids=1,2"] do
71
+ it_should_call_action :create, {'medium' => {'name' => 'medium_x', 'path' => 'http://some.path/', 'operatingsystem_ids' => ['1', '2']}}
72
+ end
73
+ end
74
+
75
+
76
+ context "DeleteCommand" do
77
+
78
+ let(:cmd) { HammerCLIForeman::Medium::DeleteCommand.new("", ctx) }
79
+
80
+ context "parameters" do
81
+ it_should_accept "name", ["--name=media"]
82
+ it_should_accept "id", ["--id=1"]
83
+ it_should_fail_with "name or id missing", []
84
+ end
85
+
86
+ end
87
+
88
+
89
+ context "UpdateCommand" do
90
+
91
+ let(:cmd) { HammerCLIForeman::Medium::UpdateCommand.new("", ctx) }
92
+
93
+ context "parameters" do
94
+ it_should_accept "name", ["--name=medium"]
95
+ it_should_accept "id", ["--id=1"]
96
+ it_should_accept "os ids", ["--id=1", "--operatingsystem-ids=1,2"]
97
+ it_should_fail_with "no params", []
98
+ it_should_fail_with "name or id missing", ["--new-name=medium_x", "--path=http://some.path/"]
99
+ end
100
+
101
+ with_params ["--id=1", "--new-name=medium_x", "--path=http://some.path/", "--operatingsystem-ids=1,2"] do
102
+ it_should_call_action :update, {'id' => '1', 'medium' => {'name' => 'medium_x', 'path' => 'http://some.path/', 'operatingsystem_ids' => ['1', '2']}}
103
+ end
104
+
105
+ end
106
+ end