Permalink
Browse files

Integration tests

  • Loading branch information...
1 parent 23cb8db commit e5a3c82fe47cde78f718a0caf795ef7e60d5e090 @olegshaldybin olegshaldybin committed Dec 7, 2010
View
@@ -8,3 +8,6 @@ spec_coverage
*.rbc
*.swp
.rvmrc
+spec/assets/*.pid
+spec/assets/bosh_config.yml
+agent/spec/tmp
View
@@ -0,0 +1,7 @@
+task :build do
+ # Build and install bosh-cli gem
+end
+
+task :spec do
+ sh("cd spec && rake spec")
+end
View
@@ -9,14 +9,13 @@ require "highline/import"
$:.unshift(File.expand_path("../../lib", __FILE__))
require "cli"
-$debug = false
+GLOBAL_OPTIONS = {}
def run_cmd(*args)
command = args.shift
output = $stdout
- output.puts("Running #{command} with #{args.inspect}") if $debug
- Bosh::Cli::Runner.run(command, output, *args)
+ Bosh::Cli::Runner.run(command, output, GLOBAL_OPTIONS, *args)
rescue Bosh::Cli::CliError => e
output.puts("ERROR: #{e}")
@@ -28,7 +27,7 @@ end
def display_usage
puts <<-USAGE
-usage: #$0 [--verbose|-v] command [<args>]
+usage: #$0 [--verbose|-v] [--config|-c <FILE>] command [<args>]
Currently available bosh commands are:
@@ -53,23 +52,25 @@ Currently available bosh commands are:
USAGE
end
-global_options = {}
-
opt_parser = OptionParser.new do |opts|
+ opts.on("-c", "--config FILE") do |v|
+ GLOBAL_OPTIONS[:config] = v
+ end
+
opts.on("-v", "--[no-]verbose") do |v|
- global_options[:verbose] = v
+ GLOBAL_OPTIONS[:verbose] = v
end
opts.on("--dry-run") do |v|
- global_options[:dry_run] = v
+ GLOBAL_OPTIONS[:dry_run] = v
end
opts.on("-u", "--username USER", String) do |v|
- global_options[:username] = v
+ GLOBAL_OPTIONS[:username] = v
end
opts.on("-u", "--password PASSWORD", String) do |v|
- global_options[:password] = v
+ GLOBAL_OPTIONS[:password] = v
end
end
View
@@ -95,7 +95,7 @@ def perform_validation
end
if job_manifest_valid && job_manifest["configuration"]
- job_manifest["configuration"].each do |config|
+ job_manifest["configuration"].each_key do |config|
step("Check config '#{config}' for '#{name}'", "No config named '#{config}' for '#{name}'") do
File.exists?(File.expand_path(config, job_tmp_dir + "/config"))
end
View
@@ -5,17 +5,20 @@ module Cli
class Runner
- CONFIG_PATH = File.expand_path("~/.bosh_config")
+ DEFAULT_CONFIG_PATH = File.expand_path("~/.bosh_config")
def self.run(cmd, output, *args)
new(cmd, output, *args).run
end
- def initialize(cmd, output, *args)
- @cmd = cmd
- @args = args
- @out = output
- @work_dir = Dir.pwd
+ def initialize(cmd, output, options, *args)
+ @options = options || {}
+
+ @cmd = cmd
+ @args = args
+ @out = output
+ @work_dir = Dir.pwd
+ @config_path = @options[:config] || DEFAULT_CONFIG_PATH
if logged_in?
@api_client = ApiClient.new(config["target"], credentials["username"], credentials["password"])
@@ -56,7 +59,7 @@ def cmd_set_target(name)
def cmd_show_target
if config['target']
- say("Current target is %s" % [ config['target'] ] )
+ say("Current target is '%s'" % [ config['target'] ] )
else
say("Target not set")
end
@@ -98,7 +101,7 @@ def cmd_list_deployments
def cmd_show_deployment
if config['deployment']
- say("Current deployment is %s" % [ config['deployment'] ] )
+ say("Current deployment is '%s'" % [ config['deployment'] ] )
else
say("Deployment not set")
end
@@ -283,7 +286,7 @@ def config
def save_config
all_configs[@work_dir] = config
- File.open(CONFIG_PATH, "w") do |f|
+ File.open(@config_path, "w") do |f|
YAML.dump(all_configs, f)
end
@@ -294,15 +297,15 @@ def save_config
def all_configs
return @_all_configs unless @_all_configs.nil?
- unless File.exists?(CONFIG_PATH)
- File.open(CONFIG_PATH, "w") { |f| YAML.dump({}, f) }
- File.chmod(0600, CONFIG_PATH)
+ unless File.exists?(@config_path)
+ File.open(@config_path, "w") { |f| YAML.dump({}, f) }
+ File.chmod(0600, @config_path)
end
- configs = YAML.load_file(CONFIG_PATH)
+ configs = YAML.load_file(@config_path)
unless configs.is_a?(Hash)
- raise ConfigError, "Malformed config file: %s" % [ CONFIG_PATH ]
+ raise ConfigError, "Malformed config file: %s" % [ @config_path ]
end
@_all_configs = configs
Binary file not shown.
@@ -2,6 +2,5 @@
packages:
- stuff
configuration:
- - file1.conf
- - file2.conf
-
+ file1.conf: config/file1.conf
+ file2.conf: config/file2.conf
Binary file not shown.
Binary file not shown.
@@ -2,4 +2,4 @@
packages:
- mutator
configuration:
- - test.conf
+ test.conf: config/test
Binary file not shown.
@@ -9,21 +9,21 @@ def cmd_dummy_cmd(arg1, arg2, arg3); end
end
it "dispatches commands to appropriate methods" do
- runner = Bosh::Cli::Runner.new(:dummy_cmd, $stdout, 1, 2, 3)
+ runner = Bosh::Cli::Runner.new(:dummy_cmd, $stdout, {}, 1, 2, 3)
runner.should_receive(:cmd_dummy_cmd).with(1, 2, 3)
runner.run
end
it "whines on invalid arity" do
- runner = Bosh::Cli::Runner.new(:dummy_cmd, $stdout, 1, 2)
+ runner = Bosh::Cli::Runner.new(:dummy_cmd, $stdout, {}, 1, 2)
lambda {
runner.run
}.should raise_error(ArgumentError, "wrong number of arguments for Bosh::Cli::Runner#cmd_dummy_cmd (2 for 3)")
end
it "whines on invalid command" do
- runner = Bosh::Cli::Runner.new(:do_stuff, $stdout, 1, 2)
+ runner = Bosh::Cli::Runner.new(:do_stuff, $stdout, {}, 1, 2)
lambda {
runner.run
View
@@ -38,6 +38,7 @@ module Director
require "director/agent_client"
require "director/cloud"
require "director/cloud/vsphere"
+require "director/cloud/dummy"
require "director/config"
require "director/configuration_hasher"
require "director/deployment_plan"
@@ -184,3 +185,4 @@ def self.consumes(*types)
# TODO: create an endpoint for task output
end
end
+
@@ -0,0 +1,70 @@
+require "digest/sha1"
+require "fileutils"
+
+module Bosh
+
+ module Director
+ class DummyCloud
+
+ class NotImplemented < StandardError; end
+
+ def initialize(options)
+ if options["dir"].nil?
+ raise ArgumentError, "please provide base directory for dummy cloud"
+ end
+
+ @base_dir = options["dir"]
+ @lock = Mutex.new
+ FileUtils.mkdir_p(@base_dir)
+ rescue Errno::EACCES
+ raise ArgumentError, "cannot create dummy cloud base directory #{@base_dir}"
+ end
+
+ def create_stemcell(image, _)
+ stemcell_id = Digest::SHA1.hexdigest(File.read(image))
+ File.open(File.join(@base_dir, "stemcell_#{stemcell_id}"), "w") do |f|
+ f.write(image)
+ end
+
+ stemcell_id
+ end
+
+ def delete_stemcell(stemcell)
+ raise NotImplemented
+ end
+
+ def create_vm(agent_id, stemcell, resource_pool, networks, disk_locality = nil)
+
+ end
+
+ def delete_vm(vm)
+
+ end
+
+ def configure_networks(vm, networks)
+
+ end
+
+ def attach_disk(vm, disk)
+
+ end
+
+ def detach_disk(vm, disk)
+
+ end
+
+ def create_disk(size, vm_locality = nil)
+
+ end
+
+ def delete_disk(disk)
+
+ end
+
+ def validate_deployment(old_manifest, new_manifest)
+
+ end
+
+ end
+ end
+end
@@ -52,10 +52,12 @@ def cloud
@lock.synchronize do
if @cloud.nil?
case @cloud_options["plugin"]
- when "vsphere"
- @cloud = VSphereCloud.new(@cloud_options["properties"])
- else
- raise "Could not find Cloud Provider Plugin: #{@cloud_options["plugin"]}"
+ when "vsphere"
+ @cloud = VSphereCloud.new(@cloud_options["properties"])
+ when "dummy"
+ @cloud = DummyCloud.new(@cloud_options["properties"])
+ else
+ raise "Could not find Cloud Provider Plugin: #{@cloud_options["plugin"]}"
end
end
end
@@ -625,4 +625,4 @@ def delete_instance(instance)
end
end
-end
+end
@@ -36,4 +36,4 @@ server = Thin::Server.new('0.0.0.0', port) do
end
end
server.threaded = true
-server.start!
+server.start!
@@ -57,7 +57,7 @@ def authorized?
end
post "/resources" do
- if params[:content] && params[:content] && params[:content][:tempfile]
+ if params[:content] && params[:content][:tempfile]
object_id = generate_object_id
file_name = get_file_name(object_id)
View
@@ -0,0 +1,12 @@
+require "rubygems"
+require "rake"
+
+require "rspec/core/rake_task"
+
+$:.unshift(File.expand_path("../../bosh/cli/bin"), __FILE__)
+
+RSpec::Core::RakeTask.new(:spec) do |t|
+ t.pattern = "*_spec.rb"
+ t.rspec_opts = %w[--color]
+end
+
@@ -0,0 +1,6 @@
+---
+path: /tmp/bosh_test_blobstore
+port: 9590
+users:
+ bs_admin: bs_pass
+
@@ -0,0 +1,4 @@
+---
+name: appcloud
+version: 0.1
+target: http://localhost:8085
@@ -0,0 +1,4 @@
+---
+name: vmforce
+version: 0.2.1
+target: http://vmforce-target:2560
@@ -0,0 +1,29 @@
+---
+port: 8085
+logging:
+ level: DEBUG
+redis:
+ host: 127.0.0.1
+ port: 63795
+ password:
+dir: /tmp/boshdir
+blobstore:
+ plugin: simple
+ properties:
+ endpoint: http://127.0.0.1:9590
+ user: bs_admin
+ password: bs_pass
+cloud:
+ plugin: dummy
+ properties:
+ dir: /tmp/bosh_test_cloud
+ agent:
+ blobstore:
+ plugin: simple
+ properties:
+ endpoint: http://127.0.0.1:9590
+ user: bs_admin
+ password: bs_pass
+ server:
+ host: 127.0.0.1
+ password:
@@ -0,0 +1,7 @@
+dir ./assets/redis_db
+port 63795
+timeout 300
+loglevel debug
+logfile stdout
+databases 16
+daemonize no
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.

0 comments on commit e5a3c82

Please sign in to comment.