features/step_definitions/orbit_steps.rb in uricp-0.0.6 vs features/step_definitions/orbit_steps.rb in uricp-0.0.7
- old
+ new
@@ -1,23 +1,31 @@
require 'inifile'
def obtain_credentials
- config = IniFile.load(ENV['HOME']+ '/.brightbox/config') ||
- raise(RuntimeError, "No brightbox config in home directory. Can't obtain auth token for tests")
- section = config.sections.first
- [config[section]['client_id'], config[section]['secret']]
+ if ENV['ORBIT_USER'] && ENV['ORBIT_KEY']
+ [ENV['ORBIT_USER'], ENV['ORBIT_KEY']]
+ else
+ config = IniFile.load(ENV['HOME']+ '/.brightbox/config')
+ if config.nil? || config.sections.empty?
+ raise(RuntimeError, "No brightbox config in home directory. Can't obtain auth token for tests")
+ end
+ section = config.sections.first
+ [config[section]['client_id'], config[section]['secret']]
+ end
end
def fetch_orbit_token
@clientid, @key = obtain_credentials
- cmd = "curl -I https://orbit.brightbox.com/v1 -H 'X-Auth-User: #{@clientid}' -H 'X-Auth-Key: #{@key}'"
+ @current_url_target = ENV['ORBIT_URL'] || 'https://orbit.brightbox.com/v1'
+ cmd = "curl -I #{@current_url_target} -H 'X-Auth-User: #{@clientid}' -H 'X-Auth-Key: #{@key}'"
run_simple(unescape(cmd))
stdout_from(cmd).each_line do |line|
key, value = line.strip.split(/\s*:\s*/,2)
@current_auth_token = value if key == 'X-Auth-Token'
@current_storage_url = value if key == 'X-Storage-Url'
end
+ raise(RuntimeError, "Credentials not accepted. Can't obtain auth token for tests.") unless @current_auth_token && @current_storage_url
end
def create_download_file(filetype, name, container)
upload_url = File.join(@current_storage_url, container, name)
tempfile = '/tmp/fred55322'
@@ -28,11 +36,11 @@
when 'qcow2'
format = 'qcow2'
when 'zero'
size = '0'
end
- cmd = "qemu-img create -q -f #{format} #{tempfile} #{size}"
+ cmd = "qemu-img create -f #{format} #{tempfile} #{size} >/dev/null 2>&1"
system(unescape(cmd))
cmd = "cat #{tempfile}"
if filetype == 'lz4'
cmd += " | lz4c "
end
@@ -58,13 +66,14 @@
When I successfully run `curl --fail --silent -o #{target} -H 'X-Auth-Token: #{@current_auth_token}' #{url}`
}
end
Given /^a (\d+) byte lz4 file named "([^"]*)"$/ do |file_size, file_name|
+ lz4_target=file_name+'.lz4'
write_fixed_size_file(file_name, file_size.to_i)
- system("lz4c #{file_name}")
- File.rename file_name+'.lz4', file_name
+ system("lz4c #{file_name} #{lz4_target}")
+ File.rename lz4_target, file_name
end
When(/^I store "([^"]*)" into container "([^"]*)" from "([^"]*)"$/) do |name, container, source|
steps %{
When I store "#{name}" with options "" into container "#{container}" from "#{source}"
@@ -177,10 +186,15 @@
assert_exact_output(['QFI',0xfb].pack('a3C'), stdout_from(cmd))
end
Before('@orbit') do
fetch_orbit_token
+ unless $orbit_setup
+ system("swift --quiet --insecure --os-storage-url=#{@current_storage_url} --os-auth-token=#{@current_auth_token} delete test")
+ system("swift --quiet --insecure --os-storage-url=#{@current_storage_url} --os-auth-token=#{@current_auth_token} delete temp_dlo")
+ system("swift --quiet --insecure --os-storage-url=#{@current_storage_url} --os-auth-token=#{@current_auth_token} delete test_upload")
+ end
end
Before('@orbitdownloads') do
$orbit_setup ||= false
unless $orbit_setup
@@ -192,11 +206,9 @@
end
end
After('@orbit') do
if @current_auth_token && @current_container
- steps %{
- When I successfully run `swift --os-storage-url=#{@current_storage_url} --os-auth-token=#{@current_auth_token} delete #{@current_container} #{@current_name}`
- }
+ system("swift --quiet --insecure --os-storage-url=#{@current_storage_url} --os-auth-token=#{@current_auth_token} delete #{@current_container} #{@current_name}")
@current_container = @current_name = nil
end
end