crowbar-client 3.3.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4f61c21d5e2910d12bcd4830b825094526e1179
4
- data.tar.gz: 663db27063201dc1e14589fc269ce83fa3184c50
3
+ metadata.gz: 83d51fd825a3ef94b457cf16266f10ba16818937
4
+ data.tar.gz: c3e8ac129f825621c7934a91af226338b57cd1e6
5
5
  SHA512:
6
- metadata.gz: 9b81fe452995214b671f567d6a5f1d3d4619161748fe85cf856e13ac68df7e164ae5746de992a5ae4052bdec314906a7ade471f8a6d8e7bf94e24f5724e0a705
7
- data.tar.gz: 1edb89c44aeab996151d306025570883684b95708f7c7df48a43a45a54155e525d425051ccfa9cd325f97a3a9cd31d89a8065549e22105712c1a7f3cdd753254
6
+ metadata.gz: 4f5cbb5e078d5714216ffb28518b54aad3578b22765b68fb12f2770c366ce8a7d4c6ba7c8117f738185873725196f02e4bdeacd778deb4c1c7f4eae43155967b
7
+ data.tar.gz: d1fedb5e476b78620907e30ae047b8222ab7467e2516a56af5835a1076af6db3edca9b0e6b04980b6c2157566e14342afe6bee7f0e8acfa4a1b0c42b1fa887e1
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.4.0](https://github.com/crowbar/crowbar-client/releases/tag/v3.4.0) - 2017-10-08
4
+
5
+ * BUGFIX
6
+ * Fix proposal create from file (bsc#1037374)
7
+ * Fix create proposal from data (bsc#1037374)
8
+
9
+ * ENHANCEMENT
10
+ * Add filtering of proposal deployment lists
11
+
3
12
  ## [3.3.1](https://github.com/crowbar/crowbar-client/releases/tag/v3.3.1) - 2017-04-07
4
13
 
5
14
  * BUGFIX
@@ -141,7 +141,7 @@ module Crowbar
141
141
  catch_errors(e)
142
142
  end
143
143
 
144
- desc "create BARCLAMP PROPOSAL",
144
+ desc "create BARCLAMP [PROPOSAL]",
145
145
  "Create a proposal for specific barclamp"
146
146
 
147
147
  long_desc <<-LONGDESC
@@ -163,6 +163,8 @@ module Crowbar
163
163
 
164
164
  With --merge option you can deep merge the provided data with
165
165
  the preloaded template.
166
+
167
+ Proposal name, if not provided, is 'default'
166
168
  LONGDESC
167
169
 
168
170
  method_option :data,
@@ -189,7 +191,7 @@ module Crowbar
189
191
  aliases: ["-m"],
190
192
  desc: "Merge input loaded from server with proposal data"
191
193
 
192
- def create(barclamp, proposal)
194
+ def create(barclamp, proposal = "default")
193
195
  Command::Proposal::Create.new(
194
196
  *command_params(
195
197
  barclamp: barclamp,
@@ -76,6 +76,11 @@ module Crowbar
76
76
  err "Failed to parse JSON"
77
77
  end
78
78
 
79
+ if json["id"] != args.proposal
80
+ json["id"] = args.proposal
81
+ say "Using id(#{json["id"]}) as proposal name"
82
+ end
83
+
79
84
  if options[:merge]
80
85
  proposal_preload.easy_merge(
81
86
  json
@@ -104,6 +109,11 @@ module Crowbar
104
109
  err "Failed to process file"
105
110
  end
106
111
 
112
+ if json["id"] != args.proposal
113
+ json["id"] = args.proposal
114
+ say "Using id(#{json["id"]}) as proposal name"
115
+ end
116
+
107
117
  if options[:merge]
108
118
  proposal_preload.easy_merge(
109
119
  json
@@ -26,6 +26,7 @@ module Crowbar
26
26
  #
27
27
  class Edit < Base
28
28
  include Mixin::Barclamp
29
+ include Mixin::Proposal
29
30
 
30
31
  def request
31
32
  @request ||= Request::Proposal::Edit.new(
@@ -58,7 +59,7 @@ module Crowbar
58
59
 
59
60
  case result.code
60
61
  when 200
61
- result.parsed_response
62
+ deployment_cleanup result.parsed_response
62
63
  when 404
63
64
  err "Failed to preload proposal"
64
65
  else
@@ -23,6 +23,7 @@ module Crowbar
23
23
  #
24
24
  class Show < Base
25
25
  include Mixin::Barclamp
26
+ include Mixin::Proposal
26
27
 
27
28
  include Mixin::Format
28
29
  include Mixin::Filter
@@ -45,7 +46,7 @@ module Crowbar
45
46
  headings: ["Key", "Value"],
46
47
  values: Filter::Subset.new(
47
48
  filter: provide_filter,
48
- values: content_from(request)
49
+ values: deployment_cleanup(content_from(request))
49
50
  ).result
50
51
  )
51
52
 
@@ -37,6 +37,9 @@ module Crowbar
37
37
 
38
38
  autoload :SimpleError,
39
39
  File.expand_path("../mixin/simple_error", __FILE__)
40
+
41
+ autoload :Proposal,
42
+ File.expand_path("../mixin/proposal", __FILE__)
40
43
  end
41
44
  end
42
45
  end
@@ -0,0 +1,55 @@
1
+ #
2
+ # Copyright 2017, SUSE
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require "active_support/concern"
18
+
19
+ module Crowbar
20
+ module Client
21
+ module Mixin
22
+ #
23
+ # A mixin with proposal related helpers
24
+ #
25
+ module Proposal
26
+ extend ActiveSupport::Concern
27
+
28
+ included do
29
+ protected
30
+
31
+ def valid_elements
32
+ # fetch node list
33
+ response = Request::Node::List.new.process
34
+ raise "error fetching node list" unless response.code == 200
35
+ nodes = response.parsed_response["nodes"].map { |node| node["name"] }
36
+ # fetch clusters list
37
+ response = Request::Cluster::List.new.process
38
+ raise "error fetching cluster list" unless response.code == 200
39
+ clusters = response.parsed_response.keys
40
+ nodes + clusters
41
+ end
42
+
43
+ def deployment_cleanup(proposal)
44
+ filter = valid_elements
45
+ # filter deployment elements
46
+ proposal["deployment"][args.barclamp]["elements"].each do |role, elements|
47
+ elements.select! { |element| filter.include? element }
48
+ end
49
+ proposal
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -32,6 +32,9 @@ module Crowbar
32
32
  autoload :Batch,
33
33
  File.expand_path("../request/batch", __FILE__)
34
34
 
35
+ autoload :Cluster,
36
+ File.expand_path("../request/cluster", __FILE__)
37
+
35
38
  autoload :Database,
36
39
  File.expand_path("../request/database", __FILE__)
37
40
 
@@ -0,0 +1,29 @@
1
+ #
2
+ # Copyright 2017, SUSE
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Crowbar
18
+ module Client
19
+ module Request
20
+ #
21
+ # Module for the cluster request implementations
22
+ #
23
+ module Cluster
24
+ autoload :List,
25
+ File.expand_path("../cluster/list", __FILE__)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Copyright 2017, SUSE
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Crowbar
18
+ module Client
19
+ module Request
20
+ module Cluster
21
+ #
22
+ # Implementation for the cluster list request
23
+ #
24
+ class List < Base
25
+ #
26
+ # HTTP method that gets used by the request
27
+ #
28
+ # @return [Symbol] the method for the request
29
+ #
30
+ def method
31
+ :get
32
+ end
33
+
34
+ #
35
+ # Path to the API endpoint for the request
36
+ #
37
+ # @return [String] path to the API endpoint
38
+ #
39
+ def url
40
+ "clusters"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -28,12 +28,12 @@ module Crowbar
28
28
  #
29
29
  # Minor version
30
30
  #
31
- MINOR = 3
31
+ MINOR = 4
32
32
 
33
33
  #
34
34
  # Patch version
35
35
  #
36
- PATCH = 1
36
+ PATCH = 0
37
37
 
38
38
  #
39
39
  # Optional suffix
@@ -0,0 +1,183 @@
1
+ #
2
+ # Copyright 2017, SUSE
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require_relative "../../../spec_helper"
18
+
19
+ # monkey patch rest-client to make Travis happy
20
+ # see: https://build.suse.de/package/view_file/SUSE:SLE-12-SP2:Update:Products:Cloud7:Update/rubygem-rest-client/add-digest-auth.patch?expand=1
21
+ module RestClient
22
+ module AbstractResponse
23
+ def parsed_response
24
+ JSON.parse(self.body)
25
+ end
26
+ end
27
+ end
28
+
29
+ class ProposalMock
30
+ include ::Crowbar::Client::Mixin::Proposal
31
+ # expose protected methods
32
+ def test_valid_elements
33
+ valid_elements
34
+ end
35
+
36
+ def test_deployment_cleanup(proposal)
37
+ deployment_cleanup proposal
38
+ end
39
+
40
+ def test_nodes
41
+ [
42
+ "node1",
43
+ "node2"
44
+ ]
45
+ end
46
+
47
+ def test_clusters
48
+ [
49
+ "cluster1",
50
+ "cluster2"
51
+ ]
52
+ end
53
+ end
54
+
55
+ describe "Crowbar::Client::Mixin::Proposal" do
56
+ subject { ProposalMock.new }
57
+
58
+ let!(:proposal) do
59
+ {
60
+ "deployment" => {
61
+ "bctest" => {
62
+ "elements" => {
63
+ "role1" => [
64
+ "node1",
65
+ "oldnode1",
66
+ "oldnode2",
67
+ "cluster1",
68
+ "oldcluster1"
69
+ ],
70
+ "role2" => [
71
+ "node2",
72
+ "cluster2"
73
+ ]
74
+ }
75
+ }
76
+ }
77
+ }
78
+ end
79
+
80
+ before(:each) do
81
+ allow(subject).to receive_message_chain("args.barclamp") { "bctest" }
82
+ end
83
+
84
+ context "without clusters" do
85
+ before(:each) do
86
+ stub_request(:get, "http://crowbar/clusters")
87
+ .with(
88
+ headers: {
89
+ "Accept" => "application/json",
90
+ "Content-Type" => "application/json"
91
+ }
92
+ )
93
+ .to_return(
94
+ status: 200,
95
+ body: "{}",
96
+ headers: {
97
+ "Content-Type" => "application/json"
98
+ }
99
+ )
100
+ stub_request(:get, "http://crowbar/crowbar/machines/1.0")
101
+ .with(
102
+ headers: {
103
+ "Accept" => "application/json",
104
+ "Content-Type" => "application/json"
105
+ }
106
+ )
107
+ .to_return(
108
+ status: 200,
109
+ body: '{ "nodes": [{"name":"node1"}, {"name":"node2"}] }',
110
+ headers: {
111
+ "Content-Type" => "application/json"
112
+ }
113
+ )
114
+ end
115
+
116
+ it "valid_elements returns only nodes" do
117
+ expect(
118
+ subject.test_valid_elements
119
+ ).to eq(subject.test_nodes)
120
+ end
121
+
122
+ it "deployment_cleanup removes all clusters and outdated nodes" do
123
+ clean_proposal = subject.test_deployment_cleanup proposal
124
+ elements = clean_proposal["deployment"]["bctest"]["elements"]
125
+ expect(
126
+ elements["role1"]
127
+ ).to eq(["node1"])
128
+ expect(
129
+ elements["role2"]
130
+ ).to eq(["node2"])
131
+ end
132
+ end
133
+
134
+ context "with clusters" do
135
+ before(:each) do
136
+ stub_request(:get, "http://crowbar/clusters")
137
+ .with(
138
+ headers: {
139
+ "Accept" => "application/json",
140
+ "Content-Type" => "application/json"
141
+ }
142
+ )
143
+ .to_return(
144
+ status: 200,
145
+ body: '{"cluster1":{}, "cluster2":{}}',
146
+ headers: {
147
+ "Content-Type" => "application/json"
148
+ }
149
+ )
150
+ stub_request(:get, "http://crowbar/crowbar/machines/1.0")
151
+ .with(
152
+ headers: {
153
+ "Accept" => "application/json",
154
+ "Content-Type" => "application/json"
155
+ }
156
+ )
157
+ .to_return(
158
+ status: 200,
159
+ body: '{"nodes":[{"name":"node1"},{"name":"node2"}]}',
160
+ headers: {
161
+ "Content-Type" => "application/json"
162
+ }
163
+ )
164
+ end
165
+
166
+ it "valid_elements returns nodes and clusters" do
167
+ expect(
168
+ subject.test_valid_elements
169
+ ).to eq(subject.test_nodes + subject.test_clusters)
170
+ end
171
+
172
+ it "deployment_cleanup removes outdated clusters and nodes" do
173
+ clean_proposal = subject.test_deployment_cleanup proposal
174
+ elements = clean_proposal["deployment"]["bctest"]["elements"]
175
+ expect(
176
+ elements["role1"]
177
+ ).to eq(["node1", "cluster1"])
178
+ expect(
179
+ elements["role2"]
180
+ ).to eq(["node2", "cluster2"])
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # Copyright 2017, SUSE
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require_relative "../../../../spec_helper"
18
+
19
+ describe "Crowbar::Client::Request::Cluster::List" do
20
+ it_behaves_like "a request class", true do
21
+ subject do
22
+ ::Crowbar::Client::Request::Cluster::List.new
23
+ end
24
+
25
+ let!(:params) do
26
+ {}
27
+ end
28
+
29
+ let!(:method) do
30
+ :get
31
+ end
32
+
33
+ let!(:url) do
34
+ "clusters"
35
+ end
36
+
37
+ let!(:headers) do
38
+ {
39
+ "Content-Type" => "application/json",
40
+ "Accept" => "application/json"
41
+ }
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crowbar-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Boerger
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-04-07 00:00:00.000000000 Z
13
+ date: 2017-10-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -346,6 +346,7 @@ files:
346
346
  - lib/crowbar/client/mixin/database.rb
347
347
  - lib/crowbar/client/mixin/filter.rb
348
348
  - lib/crowbar/client/mixin/format.rb
349
+ - lib/crowbar/client/mixin/proposal.rb
349
350
  - lib/crowbar/client/mixin/simple_error.rb
350
351
  - lib/crowbar/client/mixin/upgrade_error.rb
351
352
  - lib/crowbar/client/request.rb
@@ -361,6 +362,8 @@ files:
361
362
  - lib/crowbar/client/request/base.rb
362
363
  - lib/crowbar/client/request/batch.rb
363
364
  - lib/crowbar/client/request/batch/export.rb
365
+ - lib/crowbar/client/request/cluster.rb
366
+ - lib/crowbar/client/request/cluster/list.rb
364
367
  - lib/crowbar/client/request/database.rb
365
368
  - lib/crowbar/client/request/database/connect.rb
366
369
  - lib/crowbar/client/request/database/create.rb
@@ -509,6 +512,7 @@ files:
509
512
  - spec/crowbar/client/formatter/array_spec.rb
510
513
  - spec/crowbar/client/formatter/hash_spec.rb
511
514
  - spec/crowbar/client/formatter/nested_spec.rb
515
+ - spec/crowbar/client/mixin/proposal_spec.rb
512
516
  - spec/crowbar/client/request/backup/create_spec.rb
513
517
  - spec/crowbar/client/request/backup/delete_spec.rb
514
518
  - spec/crowbar/client/request/backup/download_spec.rb
@@ -517,6 +521,7 @@ files:
517
521
  - spec/crowbar/client/request/backup/upload_spec.rb
518
522
  - spec/crowbar/client/request/barclamp/list_spec.rb
519
523
  - spec/crowbar/client/request/batch/export_spec.rb
524
+ - spec/crowbar/client/request/cluster/list_spec.rb
520
525
  - spec/crowbar/client/request/database/connect_spec.rb
521
526
  - spec/crowbar/client/request/database/create_spec.rb
522
527
  - spec/crowbar/client/request/database/test_spec.rb
@@ -597,7 +602,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
597
602
  version: '0'
598
603
  requirements: []
599
604
  rubyforge_project:
600
- rubygems_version: 2.4.5
605
+ rubygems_version: 2.6.13
601
606
  signing_key:
602
607
  specification_version: 4
603
608
  summary: Crowbar commandline client
@@ -674,6 +679,7 @@ test_files:
674
679
  - spec/crowbar/client/formatter/array_spec.rb
675
680
  - spec/crowbar/client/formatter/hash_spec.rb
676
681
  - spec/crowbar/client/formatter/nested_spec.rb
682
+ - spec/crowbar/client/mixin/proposal_spec.rb
677
683
  - spec/crowbar/client/request/backup/create_spec.rb
678
684
  - spec/crowbar/client/request/backup/delete_spec.rb
679
685
  - spec/crowbar/client/request/backup/download_spec.rb
@@ -682,6 +688,7 @@ test_files:
682
688
  - spec/crowbar/client/request/backup/upload_spec.rb
683
689
  - spec/crowbar/client/request/barclamp/list_spec.rb
684
690
  - spec/crowbar/client/request/batch/export_spec.rb
691
+ - spec/crowbar/client/request/cluster/list_spec.rb
685
692
  - spec/crowbar/client/request/database/connect_spec.rb
686
693
  - spec/crowbar/client/request/database/create_spec.rb
687
694
  - spec/crowbar/client/request/database/test_spec.rb