2014-07-14 12:51:34 +04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
#
|
|
|
|
|
require "erb"
|
|
|
|
|
require "yaml"
|
|
|
|
|
require "ostruct"
|
2014-07-14 13:05:14 +04:00
|
|
|
require "fileutils"
|
2014-11-27 18:45:35 +03:00
|
|
|
require "./templates/fixtures/fixture_formatter"
|
2014-07-14 12:51:34 +04:00
|
|
|
|
2014-07-14 13:05:14 +04:00
|
|
|
class Generator < OpenStruct
|
2014-07-14 12:51:34 +04:00
|
|
|
|
2014-07-14 13:25:10 +04:00
|
|
|
CONFIG = "params.yml"
|
|
|
|
|
TESTS_CONFIG = "features/support/config.yml"
|
2014-07-14 12:51:34 +04:00
|
|
|
|
|
|
|
|
def initialize
|
2014-07-14 13:25:10 +04:00
|
|
|
@config = YAML.load_file(File.new(ENV["CONFIG"] || CONFIG))
|
2014-11-27 18:45:35 +03:00
|
|
|
load_fixtures()
|
2014-07-14 13:25:10 +04:00
|
|
|
super(:config => @config)
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-21 14:22:46 +03:00
|
|
|
def configure!
|
2014-07-14 13:25:10 +04:00
|
|
|
c = {}
|
2015-02-19 13:26:14 +03:00
|
|
|
%w{host port username password path_prefix username_without_privileges password_without_privileges openstack ec2}.each do |key|
|
2014-07-14 13:25:10 +04:00
|
|
|
c[key] = @config[key]
|
|
|
|
|
end
|
|
|
|
|
File.open(TESTS_CONFIG, "w") {|f| f.write(c.to_yaml) }
|
2014-11-21 14:22:46 +03:00
|
|
|
self
|
2014-07-14 12:51:34 +04:00
|
|
|
end
|
|
|
|
|
|
2014-11-21 14:22:46 +03:00
|
|
|
def generate!(templates)
|
|
|
|
|
templates.each do |input, output|
|
2015-02-19 13:26:14 +03:00
|
|
|
puts "Input: #{input}"
|
2014-11-21 14:22:46 +03:00
|
|
|
if File.exists?(input)
|
2015-02-19 13:26:14 +03:00
|
|
|
file_data = File.read(input)
|
|
|
|
|
if file_data.nil?
|
|
|
|
|
puts "Data of file '#{input}' is nil"
|
|
|
|
|
else
|
|
|
|
|
data = render(file_data)
|
|
|
|
|
dir = File.dirname(output)
|
|
|
|
|
FileUtils.mkdir_p(dir) unless File.exists?(dir)
|
|
|
|
|
File.open(output, "w") {|f| f.write(data)}
|
|
|
|
|
end
|
2014-11-21 14:22:46 +03:00
|
|
|
else
|
|
|
|
|
puts "WARN: file '#{input}' does not exist"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def clean!(feature_files)
|
|
|
|
|
feature_files.each do |feature_file|
|
|
|
|
|
if File.exists?(feature_file)
|
|
|
|
|
FileUtils.rm(feature_file)
|
|
|
|
|
else
|
|
|
|
|
puts "WARN: file '#{feature_file}' does not exist"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
2014-07-14 12:51:34 +04:00
|
|
|
def render(template)
|
2015-02-25 13:57:50 +03:00
|
|
|
ERB.new(template).result(binding)
|
2014-07-14 12:51:34 +04:00
|
|
|
end
|
2014-11-27 18:45:35 +03:00
|
|
|
|
|
|
|
|
def load_fixtures
|
|
|
|
|
@fixtures = {}
|
|
|
|
|
@fixtures['deploy_env'] = YAML.load_file('templates/fixtures/deploy_env.yml')
|
|
|
|
|
@formatter = FixtureFormatter.new(@fixtures)
|
|
|
|
|
end
|
2014-07-14 12:51:34 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
templates = {
|
2014-07-15 11:34:42 +04:00
|
|
|
|
|
|
|
|
#list
|
2014-07-15 01:36:31 +04:00
|
|
|
"templates/api_v2/00_list/flavor.feature.erb" => "features/api_v2/00_list/flavor.feature",
|
2014-07-15 13:08:00 +04:00
|
|
|
"templates/api_v2/00_list/10_user.feature.erb" => "features/api_v2/00_list/10_user.feature",
|
2014-07-15 11:34:42 +04:00
|
|
|
|
|
|
|
|
#create
|
2014-07-15 01:36:31 +04:00
|
|
|
"templates/api_v2/10_create/00_filter.feature.erb" => "features/api_v2/10_create/00_filter.feature",
|
|
|
|
|
"templates/api_v2/10_create/10_image.feature.erb" => "features/api_v2/10_create/10_image.feature",
|
|
|
|
|
"templates/api_v2/10_create/20_project.feature.erb" => "features/api_v2/10_create/20_project.feature",
|
2014-07-15 12:15:42 +04:00
|
|
|
"templates/api_v2/10_create/30_script.feature.erb" => "features/api_v2/10_create/30_script.feature",
|
2014-11-26 15:45:33 +03:00
|
|
|
"templates/api_v2/10_create/40_deploy_env.feature.erb" => "features/api_v2/10_create/40_deploy_env.feature",
|
2014-07-15 12:57:21 +04:00
|
|
|
"templates/api_v2/10_create/00_user.feature.erb" => "features/api_v2/10_create/00_user.feature",
|
2014-07-15 12:15:42 +04:00
|
|
|
|
|
|
|
|
#update
|
2014-07-15 12:22:51 +04:00
|
|
|
"templates/api_v2/20_update/10_image.feature.erb" => "features/api_v2/20_update/10_image.feature",
|
2014-07-16 13:32:59 +04:00
|
|
|
"templates/api_v2/20_update/00_user.feature.erb" => "features/api_v2/20_update/00_user.feature",
|
2014-07-15 12:22:51 +04:00
|
|
|
|
|
|
|
|
#delete
|
2014-07-15 12:49:41 +04:00
|
|
|
"templates/api_v2/90_delete/10_script.feature.erb" => "features/api_v2/90_delete/10_script.feature",
|
2014-11-26 15:45:33 +03:00
|
|
|
"templates/api_v2/90_delete/20_deploy_env.feature.erb" => "features/api_v2/90_delete/20_deploy_env.feature",
|
2014-07-15 12:49:41 +04:00
|
|
|
"templates/api_v2/90_delete/80_project.feature.erb" => "features/api_v2/90_delete/80_project.feature",
|
|
|
|
|
"templates/api_v2/90_delete/90_image.feature.erb" => "features/api_v2/90_delete/90_image.feature",
|
2014-07-15 13:26:24 +04:00
|
|
|
"templates/api_v2/90_delete/99_filter.feature.erb" => "features/api_v2/90_delete/99_filter.feature",
|
2014-07-15 12:57:21 +04:00
|
|
|
"templates/api_v2/90_delete/90_user.feature.erb" => "features/api_v2/90_delete/90_user.feature"
|
2014-07-15 12:15:42 +04:00
|
|
|
|
2014-07-14 12:51:34 +04:00
|
|
|
}
|
2014-11-21 14:22:46 +03:00
|
|
|
|
|
|
|
|
generator = Generator.new.configure!
|
|
|
|
|
if ARGV.first != 'clean'
|
|
|
|
|
generator.generate!(templates)
|
|
|
|
|
else
|
|
|
|
|
generator.clean!(templates.values)
|
2014-07-14 12:51:34 +04:00
|
|
|
end
|
2014-11-21 14:22:46 +03:00
|
|
|
|
|
|
|
|
|