Skip to content

Commit

Permalink
Add support for windows stemcells during ops mgr deploy_appliance
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Franks <[email protected]>
  • Loading branch information
Kieran Robinson authored and geofffranks committed Jan 18, 2018
1 parent 0195083 commit 1b1dcbd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ruby:2.4.1

ENV GEM_NAME ops_manager_cli
ENV GEM_VERSION 0.7.4
ENV GEM_VERSION 0.7.5
ENV OVFTOOL_VERSION 4.1.0-2459827
ENV OVFTOOL_INSTALLER VMware-ovftool-${OVFTOOL_VERSION}-lin.x86_64.bundle
ARG DOWNLOAD_URL
Expand Down
36 changes: 19 additions & 17 deletions lib/ops_manager/appliance_deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,22 @@ def upgrade

def list_current_stemcells
JSON.parse(installation_settings).fetch('products').inject([]) do |a, p|
a << p['stemcell'].fetch('version')
end
product_name = "stemcells"
if p['stemcell'].fetch('os') =~ /windows/i
product_name = "stemcells-windows-server"
end
a << { version: p['stemcell'].fetch('version'), product: product_name }
end.uniq
end

# Finds available stemcell's pivotal network release.
# If it can not find the exact version it will try to find the newest minor version available.
# #
# @param version [String] the version number, eg: '2362.17'
# @return release_id [Integer] the pivotal netowkr release id of the found stemcell.
def find_stemcell_release(version)
def find_stemcell_release(version, product_name)
version = OpsManager::Semver.new(version)
releases = stemcell_releases.collect do |r|
releases = stemcell_releases(product_name).collect do |r|
{
release_id: r['id'],
version: OpsManager::Semver.new(r['version']),
Expand All @@ -109,8 +113,8 @@ def find_stemcell_release(version)
# @param release_id [String] the version number, eg: '2362.17'
# @param filename [Regex] the version number, eg: /vsphere/
# @return id and name [Array] the pivotal network file ID and Filename for the matching stemcell.
def find_stemcell_file(release_id, filename)
files = JSON.parse(get_product_release_files('stemcells', release_id).body).fetch('product_files')
def find_stemcell_file(release_id, filename, product_name)
files = JSON.parse(get_product_release_files(product_name, release_id).body).fetch('product_files')
file = files.select{ |r| r.fetch('aws_object_key') =~ filename }.first
return file['id'], file['aws_object_key'].split('/')[-1]
end
Expand All @@ -121,16 +125,18 @@ def download_current_stemcells
print "====> Downloading existing stemcells ...".green
puts "no stemcells found".green if list_current_stemcells.empty?
FileUtils.mkdir_p current_stemcell_dir
list_current_stemcells.each do |stemcell_version|
release_id = find_stemcell_release(stemcell_version)
accept_product_release_eula('stemcells', release_id )
list_current_stemcells.each do |stemcell_info|
stemcell_version = stemcell_info[:version]
product_name = stemcell_info[:product]
release_id = find_stemcell_release(stemcell_version, product_name)
accept_product_release_eula(product_name, release_id)
stemcell_regex = /vsphere/
if config[:provider] == "AWS"
stemcell_regex = /aws/
end

file_id, file_name = find_stemcell_file(release_id, stemcell_regex)
download_product_release_file('stemcells', release_id, file_id, write_to: "#{current_stemcell_dir}/#{file_name}")
file_id, file_name = find_stemcell_file(release_id, stemcell_regex, product_name)
download_product_release_file(product_name, release_id, file_id, write_to: "#{current_stemcell_dir}/#{file_name}")
end
end

Expand Down Expand Up @@ -212,12 +218,8 @@ def installation_settings
@installation_settings ||= get_installation_settings.body
end

def get_stemcell_releases
get_product_releases('stemcells')
end

def stemcell_releases
@stemcell_releases ||= JSON.parse(get_stemcell_releases.body).fetch('releases')
def stemcell_releases(product_name)
JSON.parse(get_product_releases(product_name).body).fetch('releases')
end

def current_stemcell_dir
Expand Down
2 changes: 1 addition & 1 deletion lib/ops_manager/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class OpsManager
VERSION = "0.7.4"
VERSION = "0.7.5"
end
38 changes: 27 additions & 11 deletions spec/ops_manager/appliance_deployment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,15 @@

let(:version){ "3062" }
let(:other_version){ "3063" }
let(:windows_version){ "1200" }
let(:installation_settings) do
{
"products" => [
{ "stemcell": { "version" => version } },
{ "stemcell": { "version" => other_version } },
{ "stemcell": { "version" => version, "os" => "ubuntu-trusty"} },
{ "stemcell": { "version" => other_version, "os" => "ubuntu-trusty"} },
{ "stemcell": { "version" => version, "os" => "ubuntu-trusty"} },
{ "stemcell": { "version" => version, "os" => "ubuntu-trusty"} },
{ "stemcell": { "version" => windows_version, "os" => "windowsR2012"} },
]
}
end
Expand All @@ -155,14 +159,18 @@
end

describe 'when installation_settings are present' do
it 'should return list of current stemcells' do
expect(list_current_stemcells).to eq( [ version, other_version ])
it 'should return uniqued list of current stemcells, with version and their corresponding product' do
expect(list_current_stemcells).to eq([
{version: version, product: "stemcells"},
{version: other_version, product: "stemcells"},
{version: windows_version, product: "stemcells-windows-server" },
])
end
end
end

describe '#find_stemcell_release' do
subject(:find_stemcell_release){ appliance_deployment.find_stemcell_release(stemcell_version) }
subject(:find_stemcell_release){ appliance_deployment.find_stemcell_release(stemcell_version, "arbitrary-stemcells") }
let(:product_releases_response) do
{
'releases' => [
Expand All @@ -176,7 +184,7 @@

before do
allow(appliance_deployment).to receive(:get_product_releases)
.with('stemcells')
.with('arbitrary-stemcells')
.and_return(double(status_code: 200, body: product_releases_response.to_json))
end

Expand All @@ -198,7 +206,7 @@
end

describe '#find_stemcell_file' do
subject(:find_stemcell_file){ appliance_deployment.find_stemcell_file(1, /vsphere/) }
subject(:find_stemcell_file){ appliance_deployment.find_stemcell_file(1, /vsphere/, "arbitrary-stemcell") }

let(:stemcell_version){ "3062" }
let(:product_file_id){ 1 }
Expand All @@ -220,7 +228,7 @@

before do
allow(appliance_deployment).to receive(:get_product_release_files)
.with('stemcells', 1)
.with('arbitrary-stemcell', 1)
.and_return(double(status_code: 200, body: product_files_response.to_json))
end

Expand All @@ -238,24 +246,32 @@

describe '#download_current_stemcells' do
subject(:download_current_stemcells){ appliance_deployment.download_current_stemcells }
let(:current_stemcells){ ["3062.0" , "3063.0" ] }
let(:current_stemcells){ [
{version: "3062.0", product: "stemcells"},
{version: "3063.0", product: "stemcells"},
{version: "1200.12", product: "stemcells-windows-server"},
]}
let(:release_id){ rand(1000..9999) }
let(:file_id) { rand(1000..9999) }
let(:stemcell_filepath){ "bosh-stemcell-3062.0-vcloud-esxi-ubuntu-trusty-go_agent.tgz" }
let(:windows_filepath){ "light-bosh-stemcell-1200.12-vsphere-xen-hvm-windows2012R2-go_agent.tgz" }

before do
allow(appliance_deployment).tap do |ad|
ad.to receive(:list_current_stemcells).and_return(current_stemcells)
ad.to receive(:find_stemcell_release).and_return(release_id)
ad.to receive(:find_stemcell_file).with(release_id, /vsphere/).and_return([file_id, stemcell_filepath])
ad.to receive(:find_stemcell_file).with(release_id, /vsphere/, "stemcells").and_return([file_id, stemcell_filepath])
ad.to receive(:find_stemcell_file).with(release_id, /vsphere/, "stemcells-windows-server").and_return([file_id, windows_filepath])
ad.to receive(:accept_product_release_eula)
ad.to receive(:download_product_release_file)
end
end

it 'should download all stemcell' do
it 'should download all stemcells from the appropriate products' do
expect(appliance_deployment).to receive(:download_product_release_file)
.with('stemcells', release_id, file_id, write_to: "/tmp/current_stemcells/#{stemcell_filepath}" ).twice
expect(appliance_deployment).to receive(:download_product_release_file)
.with('stemcells-windows-server', release_id, file_id, write_to: "/tmp/current_stemcells/#{windows_filepath}" )
download_current_stemcells
end

Expand Down

0 comments on commit 1b1dcbd

Please sign in to comment.