Skip to content

Commit 5caad32

Browse files
davidjahnbot
authored andcommitted
remove patch number in stemcell.MF [#150189735]
Signed-off-by: Natalie Arellano <[email protected]>
1 parent 8e95fa4 commit 5caad32

File tree

8 files changed

+31
-15
lines changed

8 files changed

+31
-15
lines changed

lib/stemcell/builder/vsphere.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'tmpdir'
33
require 'zlib'
44
require 'nokogiri'
5+
require 'fileutils'
56

67
module Stemcell
78
class Builder
@@ -101,9 +102,12 @@ def find_file_by_extn(dir, extn)
101102

102103
def run_stembuild
103104
vmdk_file = find_file_by_extn(@output_directory, "vmdk")
104-
cmd = "stembuild -vmdk \"#{vmdk_file}\" -v \"#{@version}\" -output \"#{@output_directory}\""
105+
cmd = "stembuild -vmdk \"#{vmdk_file}\" -v \"#{Stemcell::Manifest::Base.strip_version_build_number(@version)}\" -output \"#{@output_directory}\""
105106
puts "running stembuild command: [[ #{cmd} ]]"
106107
`#{cmd}`
108+
new_filename = "bosh-stemcell-#{@version}-vsphere-esxi-windows2012R2-go_agent.tgz"
109+
puts "renaming stemcell to #{new_filename}"
110+
FileUtils.mv Dir[File.join(@output_directory, "*.tgz")].first, File.join(@output_directory, new_filename)
107111
end
108112

109113
def find_vmx_file(dir)

lib/stemcell/manifest.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@ module Manifest
55
EMPTY_FILE_SHA = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'.freeze
66

77
class Base
8+
def self.strip_version_build_number(version)
9+
md = version.match(/(\d+\.\d+)\.(\d+)-build\.(\d+)/)
10+
if md
11+
return md[1]
12+
else
13+
return version
14+
end
15+
end
16+
817
def initialize(name, version, sha, os)
918
@contents = {
1019
'name' => name,
11-
'version' => version,
20+
'version' => self.class.strip_version_build_number(version),
1221
'sha1' => sha,
1322
'operating_system' => os,
1423
'cloud_properties' => {}

spec/fixtures/vsphere/stembuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ require 'fileutils'
33

44
OUTPUT_DIR = ARGV[5]
55
FileUtils.cp(File.join(__dir__, "bosh-stemcell-5555.5-vsphere-esxi-windows2012R2-go_agent.tgz"), OUTPUT_DIR)
6+
File.write(File.join(OUTPUT_DIR, "myargs"), ARGV.inspect)

spec/integration/build/aws_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
it 'should build an aws stemcell' do
3333
Dir.mktmpdir('aws-stemcell-test') do |tmpdir|
3434
os_version = 'windows2012R2'
35-
version = 'some-version'
35+
version = '1200.3.1-build.2'
3636
agent_commit = 'some-agent-commit'
3737

3838
ENV['AWS_ACCESS_KEY'] = aws_access_key = 'some-aws_access_key'
@@ -47,7 +47,7 @@
4747

4848
File.write(
4949
File.join(@version_dir, 'number'),
50-
'some-version'
50+
version
5151
)
5252

5353
FileUtils.mkdir_p(File.join(@build_dir, 'compiled-agent'))
@@ -84,7 +84,7 @@
8484
stemcell_sha = File.join(@output_directory, "light-bosh-stemcell-#{version}-aws-xen-hvm-#{os_version}-go_agent-#{region}.tgz.sha")
8585

8686
stemcell_manifest = YAML.load(read_from_tgz(stemcell, 'stemcell.MF'))
87-
expect(stemcell_manifest['version']).to eq(version)
87+
expect(stemcell_manifest['version']).to eq('1200.3')
8888
expect(stemcell_manifest['sha1']).to eq(EMPTY_FILE_SHA)
8989
expect(stemcell_manifest['operating_system']).to eq(os_version)
9090
expect(stemcell_manifest['cloud_properties']['infrastructure']).to eq('aws')

spec/integration/build/azure_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
stemcell_sha = File.join(@output_directory, "light-bosh-stemcell-#{version}-azure-hyperv-#{os_version}-go_agent.tgz.sha")
6868

6969
stemcell_manifest = YAML.load(read_from_tgz(stemcell, 'stemcell.MF'))
70-
expect(stemcell_manifest['version']).to eq(version)
70+
expect(stemcell_manifest['version']).to eq('1200.0')
7171
expect(stemcell_manifest['sha1']).to eq(EMPTY_FILE_SHA)
7272
expect(stemcell_manifest['operating_system']).to eq(os_version)
7373
expect(stemcell_manifest['cloud_properties']['infrastructure']).to eq('azure')

spec/integration/build/gcp_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
it 'should build a gcp stemcell' do
3131
Dir.mktmpdir('gcp-stemcell-test') do |tmpdir|
3232
os_version = 'windows2012R2'
33-
version = 'some-version'
33+
version = '1200.3.1-build.2'
3434
agent_commit = 'some-agent-commit'
3535

3636
ENV['ACCOUNT_JSON'] = {'project_id' => 'some-project-id'}.to_json
@@ -41,7 +41,7 @@
4141

4242
File.write(
4343
File.join(@version_dir, 'number'),
44-
'some-version'
44+
version
4545
)
4646

4747
FileUtils.mkdir_p(File.join(@build_dir, 'compiled-agent'))
@@ -59,7 +59,7 @@
5959
stemcell = File.join(@output_directory, "light-bosh-stemcell-#{version}-google-kvm-#{os_version}-go_agent.tgz")
6060

6161
stemcell_manifest = YAML.load(read_from_tgz(stemcell, 'stemcell.MF'))
62-
expect(stemcell_manifest['version']).to eq(version)
62+
expect(stemcell_manifest['version']).to eq('1200.3')
6363
expect(stemcell_manifest['sha1']).to eq(EMPTY_FILE_SHA)
6464
expect(stemcell_manifest['operating_system']).to eq(os_version)
6565
expect(stemcell_manifest['cloud_properties']['infrastructure']).to eq('google')

spec/integration/build/vsphere_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
File.write(
4949
File.join(@version_dir, 'number'),
50-
'some-vmx-version'
50+
'some-version'
5151
)
5252

5353
s3_vmx= double(:s3_vmx)
@@ -72,7 +72,7 @@
7272

7373
it 'should build a vsphere stemcell' do
7474
os_version = 'windows2012R2'
75-
version = 'some-version'
75+
version = '1200.3.1-build.2'
7676
agent_commit = 'some-agent-commit'
7777

7878
ENV['AWS_ACCESS_KEY_ID']= 'some-key'
@@ -135,7 +135,9 @@
135135
Rake::Task['build:vsphere'].invoke
136136
packer_output_vmdk = File.join(@output_directory, 'fake.vmdk')
137137
expect(packer_output_vmdk).not_to be_nil
138-
stemcell = File.join(@output_directory, "bosh-stemcell-#{version}-vsphere-esxi-#{os_version}-go_agent.tgz")
139-
expect(stemcell).not_to be_nil
138+
stembuild_version_arg = JSON.parse(File.read("#{@output_directory}/myargs"))[3]
139+
expect(stembuild_version_arg).to eq('1200.3')
140+
stemcell_filename = File.basename(Dir["#{@output_directory}/*.tgz"].first)
141+
expect(stemcell_filename).to eq "bosh-stemcell-1200.3.1-build.2-vsphere-esxi-windows2012R2-go_agent.tgz"
140142
end
141143
end

spec/stemcell/manifest_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@
8787

8888
describe 'Azure' do
8989
describe 'dump' do
90-
it 'returns a valid stemcell manifest yaml string' do
90+
it 'returns a valid stemcell manifest yaml string with build of version removed' do
9191
manifest = Stemcell::Manifest::Azure.new('1.0.0-build.1', 'some-os', 'some-publisher',
9292
'some-offer', 'some-sku').dump
9393
expect(YAML.load(manifest)).to eq(
9494
'name' => 'bosh-azure-hyperv-some-os-go_agent',
95-
'version' => '1.0.0-build.1',
95+
'version' => '1.0',
9696
'sha1' => 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
9797
'operating_system' => 'some-os',
9898
'cloud_properties' => {

0 commit comments

Comments
 (0)