bosh-workspace 0.9.3 → 0.9.4

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: 095b4cec01561a415d908bc83c6a86e5a6861bac
4
- data.tar.gz: 3038bc5ecd5756cf3672bbdc15405eee574a39c1
3
+ metadata.gz: 3f29b754b572e4d5ed8dec967631ad55ad4c1aaf
4
+ data.tar.gz: ef6635245f5b889dce32d237cbc729d757b0e488
5
5
  SHA512:
6
- metadata.gz: 835a7af3d529d8264b273157ce4c2f80e5cdbe73ed3c8b817f469edebd874e730ff64110942b2f2aeb962930ac4fb0a3c39ef62445d9e0bb4c5ebbc04f32876c
7
- data.tar.gz: 75e12938c90cea7260a8c2d16a6098d6c189bf9569431bf889e5cce7b23c70b57fafe297aa396b205e70cc54dc40adba7f47ec755007a9408cb60e3cd78bbd7d
6
+ metadata.gz: f6d369889fcadf43fd158cdbeef13bceca9352acd375b6f7471f7530e9febaab0368a1689a6866ec2db504bfde8c922fe7e091503ad473c2c79a9e34293727ae
7
+ data.tar.gz: d76958a05172e80c8ee96ee84010827cfaab34d94f0b8fe36cfb6917f36f98c9cd959a9af21a0508b4a7552b8993d49948534182392bc82bc4b0c8bfc91ffcd2
@@ -3,6 +3,10 @@ cache: bundler
3
3
  sudo: false
4
4
  rvm:
5
5
  - 2.0
6
+ before_script:
7
+ - wget https://github.com/cloudfoundry-incubator/spiff/releases/download/v1.0.7/spiff_linux_amd64.zip -O /tmp/spiff.zip
8
+ - unzip /tmp/spiff.zip && mkdir bin && mv spiff bin && chmod +x bin/spiff
9
+ - export PATH=$PATH:$PWD/bin
6
10
  addons:
7
11
  code_climate:
8
12
  repo_token:
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_runtime_dependency "bosh_cli", ">= 1.2905.0"
24
24
  spec.add_runtime_dependency "bosh_common", ">= 1.2905.0"
25
- spec.add_runtime_dependency "bosh-template", ">= 1.2905.0"
26
25
  spec.add_runtime_dependency "semi_semantic", "~> 1.1.0"
27
26
  spec.add_runtime_dependency "membrane", "~> 1.1.0"
28
27
  spec.add_runtime_dependency "hashdiff", "~> 0.2.1"
@@ -1,9 +1,11 @@
1
1
  module Bosh::Workspace
2
2
  class ProjectDeployment
3
3
  include Bosh::Cli::Validation
4
- attr_writer :director_uuid
4
+ attr_writer :director_uuid, :stub
5
5
  attr_reader :file
6
6
 
7
+ STUB_WHITELIST = %w(name director_uuid meta)
8
+
7
9
  def initialize(file)
8
10
  @file = file
9
11
  err("Deployment file does not exist: #{file}") unless File.exist?(@file)
@@ -33,8 +35,10 @@ module Bosh::Workspace
33
35
 
34
36
  def manifest
35
37
  return @manifest unless @manifest.nil?
36
- renderer = Bosh::Template::Renderer.new(context: stub.to_json)
37
- @manifest = Psych.load(renderer.render(file))
38
+ @manifest = Psych.load(ERB.new(File.read(file)).result)
39
+ validate_stub! unless stub.empty?
40
+ @manifest = recursive_merge(@manifest, stub) unless stub.empty?
41
+ @manifest
38
42
  end
39
43
 
40
44
  def stub
@@ -51,6 +55,12 @@ module Bosh::Workspace
51
55
 
52
56
  private
53
57
 
58
+ def validate_stub!
59
+ return unless stub.keys.any? { |k| !STUB_WHITELIST.include?(k) }
60
+ offending_keys = stub.keys - STUB_WHITELIST
61
+ err "Key: '#{offending_keys.first}' not allowed in stub file"
62
+ end
63
+
54
64
  def file_basename
55
65
  File.basename(@file)
56
66
  end
@@ -58,5 +68,15 @@ module Bosh::Workspace
58
68
  def file_dirname
59
69
  File.dirname(@file)
60
70
  end
71
+
72
+ def recursive_merge(source, target)
73
+ source.merge(target) do |_, old_value, new_value|
74
+ if old_value.class == Hash && new_value.class == Hash
75
+ recursive_merge(old_value, new_value)
76
+ else
77
+ new_value
78
+ end
79
+ end
80
+ end
61
81
  end
62
82
  end
@@ -0,0 +1,2 @@
1
+ require_relative 'rspec/shared_workspace_examples'
2
+ require_relative 'rspec/manifest_matcher'
@@ -0,0 +1,19 @@
1
+ RSpec::Matchers.define :match_manifest do |expected|
2
+ match do |actual|
3
+ @diff = Bosh::Cli::HashChangeset.new
4
+ @diff.add_hash(normalize_and_load_deployment_manifest(actual), :new)
5
+ @diff.add_hash(normalize_and_load_deployment_manifest(expected), :old)
6
+ !@diff.changed?
7
+ end
8
+
9
+ failure_message do |actual|
10
+ @diff.summary.join("\n")
11
+ end
12
+
13
+ private
14
+
15
+ def normalize_and_load_deployment_manifest(manifest_file)
16
+ manifest_hash = YAML.load_file manifest_file
17
+ Bosh::Cli::DeploymentManifest.new(manifest_hash).normalize
18
+ end
19
+ end
@@ -0,0 +1,46 @@
1
+ require "common/exec"
2
+ require "yaml"
3
+ require 'semi_semantic/version'
4
+ require 'bosh/workspace'
5
+ require 'cli'
6
+
7
+ desc = "behaves as bosh-workspace deployment"
8
+ RSpec.shared_examples desc do |deployment_file, result_file, stub_file|
9
+ let(:workdir) { File.expand_path(File.join(deployment_file, '../..')) }
10
+ let(:stub) do
11
+ result = {} unless File.exist?(stub_file)
12
+ result ||= YAML.load_file(stub_file) || {}
13
+ result.merge({'director_uuid' => '00000000-0000-0000-0000-000000000000'})
14
+ end
15
+
16
+ subject do
17
+ Bosh::Workspace::ProjectDeployment.new(deployment_file).tap do |d|
18
+ d.stub = stub
19
+ d.validate
20
+ end
21
+ end
22
+
23
+ it "is a valid deployment manifest" do
24
+ expect(subject.errors).to eq []
25
+ end
26
+
27
+ def merge_templates(deployment, workdir)
28
+ Bosh::Workspace::ManifestBuilder.build(deployment, workdir)
29
+ end
30
+
31
+ def prepare_templates(deployment, workdir)
32
+ releases_dir = File.join(workdir, '.releases')
33
+ callback = Bosh::Workspace::GitCredentialsProvider
34
+ .new(File.join(workdir, '.credentials.yml')).callback
35
+
36
+ deployment.releases.each do |release|
37
+ Bosh::Workspace::Release.new(release, releases_dir, callback).update_repo
38
+ end
39
+ end
40
+
41
+ it "successfully merges deployment templates" do
42
+ expect { prepare_templates(subject, workdir) }.to_not raise_error
43
+ expect { merge_templates(subject, workdir) }.to_not raise_error
44
+ expect(subject.merged_file).to match_manifest result_file
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Manifests
3
- VERSION = "0.9.3"
3
+ VERSION = "0.9.4"
4
4
  end
5
5
  end
@@ -3,4 +3,3 @@ name: foo
3
3
  templates:
4
4
  - foo/bar.yml
5
5
  meta: {}
6
- stub_value: <%= p('stub.value') %>
@@ -1,4 +1,4 @@
1
1
  ---
2
- properties:
2
+ meta:
3
3
  stub:
4
4
  value: value
@@ -0,0 +1,45 @@
1
+ require 'bosh/workspace/rspec'
2
+
3
+ describe "rspec shared bosh-workspace example" do
4
+ deployment = {
5
+ 'name' => 'foo',
6
+ 'releases' => [],
7
+ 'stemcells' => [],
8
+ 'templates' => [
9
+ 'deployment.yml'
10
+ ],
11
+ 'meta' => {
12
+ 'foo' => 'bar'
13
+ }
14
+ }
15
+ deployment_template = {
16
+ 'director_uuid' => '(( merge ))',
17
+ 'name' => '(( merge ))',
18
+ 'releases' => '(( merge ))',
19
+ 'jobs' => []
20
+ }
21
+ stub = { 'name' => 'bar' }
22
+
23
+ result = {
24
+ 'director_uuid' => '00000000-0000-0000-0000-000000000000',
25
+ 'name' => 'bar',
26
+ 'releases' => [],
27
+ 'jobs' => []
28
+ }
29
+
30
+ deployment_file = get_tmp_yml_file_path(deployment).tap do |d|
31
+ templates_path = File.expand_path('../../templates', d)
32
+ FileUtils.mkdir_p templates_path
33
+ IO.write(
34
+ File.join(templates_path, 'deployment.yml'),
35
+ deployment_template.to_yaml
36
+ )
37
+ end
38
+
39
+ include_examples(
40
+ "behaves as bosh-workspace deployment",
41
+ deployment_file,
42
+ get_tmp_yml_file_path(result),
43
+ get_tmp_yml_file_path(stub)
44
+ )
45
+ end
@@ -24,24 +24,31 @@ module Bosh::Workspace
24
24
  end
25
25
 
26
26
  context 'with stub file' do
27
- let(:manifest) { { 'director_uuid' => '<%= p("stub.value") %>' } }
28
- let(:stub_content) { "---\nproperties:\n stub:\n value: litmus\n" }
27
+ let(:manifest) { { 'director_uuid' => 'DIRECTOR_UUID' } }
28
+ let(:stub_content) do
29
+ {
30
+ 'name' => 'bar',
31
+ 'director_uuid' => 'foo-uuid',
32
+ 'meta' => { 'foo' => 'bar' }
33
+ }.to_yaml
34
+ end
35
+
29
36
  before do
30
37
  allow(File).to receive(:exist?).with(stub_file).and_return(true)
31
38
  allow(File).to receive(:read).with(stub_file).and_return(stub_content)
32
39
  end
33
40
 
34
- it 'reads manifest using bosh-template render' do
35
- expect(subject.manifest['director_uuid']).to eq('litmus')
41
+ it 'merges stub with manifest' do
42
+ expect(subject.manifest['director_uuid']).to eq('foo-uuid')
36
43
  end
37
44
 
38
- context 'with missing properties' do
39
- let(:stub_content) { "---\nproperties:\n stub: litmus\n" }
40
- it 'raises error' do
41
- expect { subject.manifest }.to raise_error /Can't find property/
45
+ context 'stub with releases' do
46
+ let(:stub_content) { { 'releases' => [] }.to_yaml }
47
+
48
+ it 'raises an error' do
49
+ expect{ subject.manifest }.to raise_error /releases.+not allowed/
42
50
  end
43
51
  end
44
-
45
52
  end
46
53
 
47
54
  context 'without stub file' do
@@ -65,6 +65,10 @@ def in_home_dir(&block)
65
65
  FileUtils.chdir(home_file, &block)
66
66
  end
67
67
 
68
+ def get_tmp_yml_file_path(content)
69
+ get_tmp_file_path(content.to_yaml)
70
+ end
71
+
68
72
  def get_tmp_file_path(content, file_name="tmp")
69
73
  tmp_file = File.open(File.join(Dir.mktmpdir, file_name), "w")
70
74
  tmp_file.write(content)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh-workspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Koster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-29 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bosh_cli
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.2905.0
41
- - !ruby/object:Gem::Dependency
42
- name: bosh-template
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 1.2905.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 1.2905.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: semi_semantic
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -212,6 +198,9 @@ files:
212
198
  - lib/bosh/workspace/merge_tool.rb
213
199
  - lib/bosh/workspace/project_deployment.rb
214
200
  - lib/bosh/workspace/release.rb
201
+ - lib/bosh/workspace/rspec.rb
202
+ - lib/bosh/workspace/rspec/manifest_matcher.rb
203
+ - lib/bosh/workspace/rspec/shared_workspace_examples.rb
215
204
  - lib/bosh/workspace/schemas/credentials.rb
216
205
  - lib/bosh/workspace/schemas/deployment_patch.rb
217
206
  - lib/bosh/workspace/schemas/project_deployment.rb
@@ -258,6 +247,7 @@ files:
258
247
  - spec/helpers/project_deployment_helper_spec.rb
259
248
  - spec/helpers/release_helper_spec.rb
260
249
  - spec/helpers/stemcell_helper_spec.rb
250
+ - spec/integration/shared_workspace_examples_spec.rb
261
251
  - spec/manifest_builder_spec.rb
262
252
  - spec/merge_tool_spec.rb
263
253
  - spec/project_deployment_spec.rb
@@ -334,6 +324,7 @@ test_files:
334
324
  - spec/helpers/project_deployment_helper_spec.rb
335
325
  - spec/helpers/release_helper_spec.rb
336
326
  - spec/helpers/stemcell_helper_spec.rb
327
+ - spec/integration/shared_workspace_examples_spec.rb
337
328
  - spec/manifest_builder_spec.rb
338
329
  - spec/merge_tool_spec.rb
339
330
  - spec/project_deployment_spec.rb