From 0ddda8f5915436764439656d4690f41a47375c4d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 24 Aug 2010 09:19:16 -0700 Subject: [PATCH] Remove all old commands. They're all being rewritten --- lib/vagrant.rb | 4 +- lib/vagrant/command.rb | 27 --- lib/vagrant/commands/base.rb | 181 -------------------- lib/vagrant/commands/box.rb | 16 -- lib/vagrant/commands/box/add.rb | 24 --- lib/vagrant/commands/box/list.rb | 30 ---- lib/vagrant/commands/box/remove.rb | 31 ---- lib/vagrant/commands/box/repackage.rb | 35 ---- lib/vagrant/commands/destroy.rb | 37 ---- lib/vagrant/commands/halt.rb | 43 ----- lib/vagrant/commands/init.rb | 36 ---- lib/vagrant/commands/package.rb | 81 --------- lib/vagrant/commands/provision.rb | 31 ---- lib/vagrant/commands/reload.rb | 36 ---- lib/vagrant/commands/resume.rb | 35 ---- lib/vagrant/commands/ssh.rb | 78 --------- lib/vagrant/commands/ssh_config.rb | 45 ----- lib/vagrant/commands/status.rb | 125 -------------- lib/vagrant/commands/suspend.rb | 36 ---- lib/vagrant/commands/up.rb | 44 ----- lib/vagrant/environment.rb | 9 - test/vagrant/command_test.rb | 53 ------ test/vagrant/commands/base_test.rb | 139 --------------- test/vagrant/commands/box/add_test.rb | 34 ---- test/vagrant/commands/box/list_test.rb | 32 ---- test/vagrant/commands/box/remove_test.rb | 41 ----- test/vagrant/commands/box/repackage_test.rb | 52 ------ test/vagrant/commands/destroy_test.rb | 44 ----- test/vagrant/commands/halt_test.rb | 50 ------ test/vagrant/commands/init_test.rb | 71 -------- test/vagrant/commands/package_test.rb | 97 ----------- test/vagrant/commands/provision_test.rb | 60 ------- test/vagrant/commands/reload_test.rb | 47 ----- test/vagrant/commands/resume_test.rb | 44 ----- test/vagrant/commands/ssh_config_test.rb | 77 --------- test/vagrant/commands/ssh_test.rb | 129 -------------- test/vagrant/commands/status_test.rb | 40 ----- test/vagrant/commands/suspend_test.rb | 44 ----- test/vagrant/commands/up_test.rb | 49 ------ test/vagrant/environment_test.rb | 14 -- 40 files changed, 2 insertions(+), 2099 deletions(-) delete mode 100644 lib/vagrant/command.rb delete mode 100644 lib/vagrant/commands/base.rb delete mode 100644 lib/vagrant/commands/box.rb delete mode 100644 lib/vagrant/commands/box/add.rb delete mode 100644 lib/vagrant/commands/box/list.rb delete mode 100644 lib/vagrant/commands/box/remove.rb delete mode 100644 lib/vagrant/commands/box/repackage.rb delete mode 100644 lib/vagrant/commands/destroy.rb delete mode 100644 lib/vagrant/commands/halt.rb delete mode 100644 lib/vagrant/commands/init.rb delete mode 100644 lib/vagrant/commands/package.rb delete mode 100644 lib/vagrant/commands/provision.rb delete mode 100644 lib/vagrant/commands/reload.rb delete mode 100644 lib/vagrant/commands/resume.rb delete mode 100644 lib/vagrant/commands/ssh.rb delete mode 100644 lib/vagrant/commands/ssh_config.rb delete mode 100644 lib/vagrant/commands/status.rb delete mode 100644 lib/vagrant/commands/suspend.rb delete mode 100644 lib/vagrant/commands/up.rb delete mode 100644 test/vagrant/command_test.rb delete mode 100644 test/vagrant/commands/base_test.rb delete mode 100644 test/vagrant/commands/box/add_test.rb delete mode 100644 test/vagrant/commands/box/list_test.rb delete mode 100644 test/vagrant/commands/box/remove_test.rb delete mode 100644 test/vagrant/commands/box/repackage_test.rb delete mode 100644 test/vagrant/commands/destroy_test.rb delete mode 100644 test/vagrant/commands/halt_test.rb delete mode 100644 test/vagrant/commands/init_test.rb delete mode 100644 test/vagrant/commands/package_test.rb delete mode 100644 test/vagrant/commands/provision_test.rb delete mode 100644 test/vagrant/commands/reload_test.rb delete mode 100644 test/vagrant/commands/resume_test.rb delete mode 100644 test/vagrant/commands/ssh_config_test.rb delete mode 100644 test/vagrant/commands/ssh_test.rb delete mode 100644 test/vagrant/commands/status_test.rb delete mode 100644 test/vagrant/commands/suspend_test.rb delete mode 100644 test/vagrant/commands/up_test.rb diff --git a/lib/vagrant.rb b/lib/vagrant.rb index a1948ce4e..c10d6410f 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -31,9 +31,9 @@ end # Load them up. One day we'll convert this to autoloads. Today # is not that day. Low hanging fruit for anyone wishing to do it. libdir = File.expand_path("lib/vagrant", Vagrant.source_root) -Vagrant::GlobLoader.glob_require(libdir, %w{util util/stacked_proc_runner +Vagrant::GlobLoader.glob_require(libdir, %w{util util/stacked_proc_runner cli downloaders/base config provisioners/base provisioners/chef systems/base - commands/base commands/box action/exception_catcher hosts/base}) + action/exception_catcher hosts/base}) # Initialize the built-in actions Vagrant::Action.builtin! diff --git a/lib/vagrant/command.rb b/lib/vagrant/command.rb deleted file mode 100644 index 686c2d6e2..000000000 --- a/lib/vagrant/command.rb +++ /dev/null @@ -1,27 +0,0 @@ -module Vagrant - # This class handles commands from the command line program `vagrant` - # and redirects them to the proper sub-command, setting up the environment - # and executing. - class Command - attr_reader :env - - class << self - # Executes a given subcommand within the current environment (from the - # current working directory). - def execute(*args) - env = Environment.load! - env.commands.subcommand(*args) - end - end - - def initialize(env) - @env = env - end - - # Execute a subcommand with the given name and args. This method properly - # finds the subcommand, instantiates it, and executes. - def subcommand(*args) - Commands::Base.dispatch(env, *args) - end - end -end diff --git a/lib/vagrant/commands/base.rb b/lib/vagrant/commands/base.rb deleted file mode 100644 index 4cbc0082c..000000000 --- a/lib/vagrant/commands/base.rb +++ /dev/null @@ -1,181 +0,0 @@ -require 'optparse' - -module Vagrant - class Commands - # This is the base command class which all sub-commands must - # inherit from. Subclasses of bases are expected to implement two - # methods: {#execute} and {#options_spec} (optional). The former - # defines the actual behavior of the command while the latter is a spec - # outlining the options that the command may take. - class Base - include Util - - attr_reader :env - - class << self - # Contains the list of registered subcommands. The registered commands are - # stored in a hash table and are therefore unordered. - # - # @return [Hash] - def subcommands - @subcommands ||= {} - end - - # Registers a command with `vagrant`. This method allows 3rd parties to - # dynamically add new commands to the `vagrant` command, allowing plugins - # to act as 1st class citizens within vagrant. - # - # @param [String] key The subcommand which will invoke the registered command. - # @param [Class] klass. The subcommand class (a subclass of {Base}) - def subcommand(key, klass) - subcommands[key] = klass - end - - # Dispatches a subcommand to the proper registered command. Otherwise, it - # prints a help message. - def dispatch(env, *args) - klass = subcommands[args[0]] unless args.empty? - if klass.nil? - # Run _this_ command! - command = self.new(env) - command.execute(args) - return - end - - # Shift off the front arg, since we just consumed it in finding the - # subcommand. - args.shift - - # Dispatch to the next class - klass.dispatch(env, *args) - end - - # Sets or reads the description, depending on if the value is set in the - # parameter. - def description(value=nil) - @description ||= '' - - return @description if value.nil? - @description = value - end - end - - def initialize(env) - @env = env - end - - # This method should be overriden by subclasses. This is the method - # which is called by {Vagrant::Command} when a command is being - # executed. The `args` parameter is an array of parameters to the - # command (similar to ARGV) - def execute(args) - parse_options(args) - - if options[:version] - puts_version - else - # Just print out the help, since this top-level command does nothing - # on its own - show_help - end - end - - # This method is called by the base class to get the `optparse` configuration - # for the command. - def options_spec(opts) - opts.banner = "Usage: vagrant SUBCOMMAND" - - opts.on("--version", "Output running Vagrant version.") do |v| - options[:version] = v - end - end - - #------------------------------------------------------------------- - # Methods below are not meant to be overriden/implemented by subclasses - #------------------------------------------------------------------- - - # Parses the options for a given command and if a name was - # given, it calls the single method, otherwise it calls the all - # method. This helper is an abstraction which allows commands to - # easily be used in both regular and multi-VM environments. - def all_or_single(args, method_prefix) - args = parse_options(args) - - single_method = "#{method_prefix}_single".to_sym - if args[0] - send(single_method, args[0]) - else - env.vms.keys.each do |name| - send(single_method, name) - end - end - end - - # Shows the version - def puts_version - puts VERSION - end - - # Returns the `OptionParser` instance to be used with this subcommand, - # based on the specs defined in {#options_spec}. - def option_parser(reload=false) - @option_parser = nil if reload - @option_parser ||= OptionParser.new do |opts| - # The --help flag is available on all children commands, and will - # immediately show help. - opts.on("--help", "Show help for the current subcommand.") do - show_help - end - - options_spec(opts) - end - end - - # The options for the given command. This will just be an empty hash - # until {#parse_options} is called. - def options - @options ||= {} - end - - # Parse options out of the command-line. This method uses `optparse` - # to parse command line options. - def parse_options(args) - option_parser.parse!(args) - rescue OptionParser::InvalidOption - show_help - end - - # Gets the description of the command. This is similar grabbed from the - # class level. - def description - self.class.description - end - - # Prints the help for the given command. Prior to calling this method, - # {#parse_options} must be called or a nilerror will be raised. This - # is by design. - def show_help - if !description.empty? - puts "Description: #{description}" - end - - puts option_parser.help - - my_klass = self.class - if !my_klass.subcommands.empty? - puts "\nSupported subcommands:" - my_klass.subcommands.keys.sort.each do |key| - klass = my_klass.subcommands[key] - next if klass.description.empty? - - puts "#{' ' * 8}#{key.ljust(20)}#{klass.description}" - end - - puts "\nFor help on a specific subcommand, run `vagrant SUBCOMMAND --help`" - end - - exit - end - end - end -end diff --git a/lib/vagrant/commands/box.rb b/lib/vagrant/commands/box.rb deleted file mode 100644 index fbfcaea95..000000000 --- a/lib/vagrant/commands/box.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Vagrant - class Commands - # Manages the `vagrant box` command, allowing the user to add - # and remove boxes. This single command, given an array, determines - # which action to take and calls the respective action method - # (see {box_add} and {box_remove}) - class BoxCommand < Base - Base.subcommand "box", self - description "Box commands" - - def options_spec(opts) - opts.banner = "Usage: vagrant box SUBCOMMAND" - end - end - end -end \ No newline at end of file diff --git a/lib/vagrant/commands/box/add.rb b/lib/vagrant/commands/box/add.rb deleted file mode 100644 index 67b0f7f02..000000000 --- a/lib/vagrant/commands/box/add.rb +++ /dev/null @@ -1,24 +0,0 @@ -module Vagrant - class Commands - # Adds a box to the local filesystem, given a URI. - module Box - class Add < BoxCommand - BoxCommand.subcommand "add", self - description "Add a box" - - def execute(args) - if args.length != 2 - show_help - return - end - - Vagrant::Box.add(env, args[0], args[1]) - end - - def options_spec(opts) - opts.banner = "Usage: vagrant box add NAME URI" - end - end - end - end -end \ No newline at end of file diff --git a/lib/vagrant/commands/box/list.rb b/lib/vagrant/commands/box/list.rb deleted file mode 100644 index 23e1175e9..000000000 --- a/lib/vagrant/commands/box/list.rb +++ /dev/null @@ -1,30 +0,0 @@ -module Vagrant - class Commands - # Lists all added boxes - module Box - class List < BoxCommand - BoxCommand.subcommand "list", self - description "List all installed boxes" - - def execute(args=[]) - boxes = Vagrant::Box.all(env).sort - - wrap_output do - if !boxes.empty? - puts "Installed Vagrant Boxes:\n\n" - boxes.each do |box| - puts box - end - else - puts "No Vagrant Boxes Added!" - end - end - end - - def options_spec(opts) - opts.banner = "Usage: vagrant box list" - end - end - end - end -end diff --git a/lib/vagrant/commands/box/remove.rb b/lib/vagrant/commands/box/remove.rb deleted file mode 100644 index 88670b798..000000000 --- a/lib/vagrant/commands/box/remove.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Vagrant - class Commands - # Removes a box permanently from the hard drive. - module Box - class Remove < BoxCommand - BoxCommand.subcommand "remove", self - description "Remove an installed box permanently." - - def execute(args=[]) - if args.length != 1 - show_help - return - end - - - box = Vagrant::Box.find(env, args[0]) - if box.nil? - error_and_exit(:box_remove_doesnt_exist) - return # for tests - end - - box.destroy - end - - def options_spec(opts) - opts.banner = "Usage: vagrant box remove NAME" - end - end - end - end -end \ No newline at end of file diff --git a/lib/vagrant/commands/box/repackage.rb b/lib/vagrant/commands/box/repackage.rb deleted file mode 100644 index eda1ae1b6..000000000 --- a/lib/vagrant/commands/box/repackage.rb +++ /dev/null @@ -1,35 +0,0 @@ -module Vagrant - class Commands - module Box - # Repackage a box which has been added. - class Repackage < BoxCommand - BoxCommand.subcommand "repackage", self - description "Repackages a box which has already been added." - - def execute(args=[]) - args = parse_options(args) - return show_help if args.length != 1 - - box = Vagrant::Box.find(env, args.first) - return error_and_exit(:box_repackage_doesnt_exist) if box.nil? - box.repackage(options) - end - - def options_spec(opts) - opts.banner = "Usage: vagrant box repackage NAME [--output FILENAME] [--include FILES]" - - options["package.output"] = nil - options["package.include"] = [] - - opts.on("--include x,y,z", Array, "List of files to include in the package") do |v| - options["package.include"] = v - end - - opts.on("-o", "--output FILE", "File to save the package as.") do |v| - options["package.output"] = v - end - end - end - end - end -end diff --git a/lib/vagrant/commands/destroy.rb b/lib/vagrant/commands/destroy.rb deleted file mode 100644 index ffad6232a..000000000 --- a/lib/vagrant/commands/destroy.rb +++ /dev/null @@ -1,37 +0,0 @@ -module Vagrant - class Commands - # Destroys a vagrant instance. This not only shuts down the instance - # (if its running), but also deletes it from the system, including the - # hard disks associated with it. - # - # This command requires that an instance already be brought up with - # `vagrant up`. - class Destroy < Base - Base.subcommand "destroy", self - description "Destroys the vagrant environment" - - def execute(args=[]) - all_or_single(args, :destroy) - end - - # Destroys a single VM by name. - def destroy_single(name) - vm = env.vms[name.to_sym] - if vm.nil? - error_and_exit(:unknown_vm, :vm => name) - return # for tests - end - - if vm.created? - vm.destroy - else - vm.env.logger.info "VM '#{name}' not created. Ignoring." - end - end - - def options_spec(opts) - opts.banner = "Usage: vagrant destroy" - end - end - end -end diff --git a/lib/vagrant/commands/halt.rb b/lib/vagrant/commands/halt.rb deleted file mode 100644 index a61545e21..000000000 --- a/lib/vagrant/commands/halt.rb +++ /dev/null @@ -1,43 +0,0 @@ -module Vagrant - class Commands - # Halts a running vagrant instance. This forcibly halts the instance; - # it is the equivalent of pulling the power on a machine. The instance - # can be restarted again with {up}. - # - # This command requires than an instance already be brought up with - # `vagrant up`. - class Halt < Base - Base.subcommand "halt", self - description "Halts the currently running vagrant environment" - - def execute(args=[]) - all_or_single(args, :halt) - end - - def halt_single(name) - vm = env.vms[name.to_sym] - if vm.nil? - error_and_exit(:unknown_vm, :vm => name) - return # for tests - end - - if vm.created? - vm.halt(options) - else - vm.env.logger.info "VM '#{name}' not created. Ignoring." - end - end - - def options_spec(opts) - opts.banner = "Usage: vagrant halt" - - # Defaults - options[:force] = false - - opts.on("-f", "--force", "Forceful shutdown of virtual machine.") do |v| - options[:force] = true - end - end - end - end -end diff --git a/lib/vagrant/commands/init.rb b/lib/vagrant/commands/init.rb deleted file mode 100644 index 7303e0805..000000000 --- a/lib/vagrant/commands/init.rb +++ /dev/null @@ -1,36 +0,0 @@ -module Vagrant - class Commands - class Init < Base - Base.subcommand "init", self - description "Initializes current folder for Vagrant usage" - - def execute(args) - create_vagrantfile(:default_box => args[0] , :default_box_url => args[1]) - end - - def options_spec(opts) - opts.banner = "Usage: vagrant init [name] [box_url]" - end - - # Actually writes the initial Vagrantfile to the current working directory. - # The Vagrantfile will contain the base box configuration specified, or - # will just use "base" if none is specified. - # - # @param [String] :default_box The default base box for this - # Vagrantfile - # @param [String] :default_box_url The default url for fetching - # the given box for the Vagrantfile - def create_vagrantfile(opts={}) - rootfile_path = File.join(Dir.pwd, Environment::ROOTFILE_NAME) - error_and_exit(:rootfile_already_exists) if File.exist?(rootfile_path) - - # Set the defaults of the Vagrantfile - opts[:default_box] ||= "base" - - File.open(rootfile_path, 'w+') do |f| - f.write(TemplateRenderer.render(Environment::ROOTFILE_NAME, opts)) - end - end - end - end -end diff --git a/lib/vagrant/commands/package.rb b/lib/vagrant/commands/package.rb deleted file mode 100644 index 05d373a98..000000000 --- a/lib/vagrant/commands/package.rb +++ /dev/null @@ -1,81 +0,0 @@ -module Vagrant - class Commands - # Export and package the current vm - # - # This command requires that an instance be powered off - class Package < Base - Base.subcommand "package", self - description "Packages a vagrant environment for distribution" - - def execute(args=[]) - args = parse_options(args) - - if options[:base] - package_base - else - package_single(args[0]) - end - end - - def package_base - # Packaging a base box; that is a VM not tied to a specific - # vagrant environment - vm = VM.find(options[:base], env) - if !vm - error_and_exit(:vm_base_not_found, :name => options[:base]) - return # for tests - end - - package_vm(vm) - end - - def package_single(name) - if name.nil? && env.multivm? - error_and_exit(:package_multivm) - return - end - - vm = if name.nil? - env.vms.values.first - else - env.vms[name.to_sym] - end - - if vm.nil? - error_and_exit(:unknown_vm, :vm => name) - return - elsif !vm.created? - error_and_exit(:environment_not_created) - return - end - - package_vm(vm) - end - - def package_vm(vm) - vm.package(options) - end - - def options_spec(opts) - opts.banner = "Usage: vagrant package [--base BASE] [--output FILENAME] [--include FILES]" - - # Defaults - options[:base] = nil - options["package.output"] = nil - options["package.include"] = [] - - opts.on("--base BASE", "Name or UUID of VM to create a base box from") do |v| - options[:base] = v - end - - opts.on("--include x,y,z", Array, "List of files to include in the package") do |v| - options["package.include"] = v - end - - opts.on("-o", "--output FILE", "File to save the package as.") do |v| - options["package.output"] = v - end - end - end - end -end diff --git a/lib/vagrant/commands/provision.rb b/lib/vagrant/commands/provision.rb deleted file mode 100644 index 88830e2a5..000000000 --- a/lib/vagrant/commands/provision.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Vagrant - class Commands - #run the provisioner on a running vm - class Provision < Base - Base.subcommand "provision", self - description "Run the provisioner" - - def execute(args=[]) - all_or_single(args, :provision) - end - - def provision_single(name) - vm = env.vms[name.to_sym] - if vm.nil? - error_and_exit(:unknown_vm, :vm => name) - return # for tests - end - - if vm.created? && vm.vm.running? - vm.provision - else - vm.env.logger.info "VM '#{name}' not running. Ignoring provision request." - end - end - - def options_spec(opts) - opts.banner = "Usage: vagrant provision" - end - end - end -end diff --git a/lib/vagrant/commands/reload.rb b/lib/vagrant/commands/reload.rb deleted file mode 100644 index 20f4b1784..000000000 --- a/lib/vagrant/commands/reload.rb +++ /dev/null @@ -1,36 +0,0 @@ -module Vagrant - class Commands - # Reload the environment. This is almost equivalent to the {up} command - # except that it doesn't import the VM and do the initialize bootstrapping - # of the instance. Instead, it forces a shutdown (if its running) of the - # VM, updates the metadata (shared folders, forwarded ports), restarts - # the VM, and then reruns the provisioning if enabled. - class Reload < Base - Base.subcommand "reload", self - description "Reload the vagrant environment" - - def execute(args=[]) - env.require_root_path - all_or_single(args, :reload) - end - - def reload_single(name) - vm = env.vms[name.to_sym] - if vm.nil? - error_and_exit(:unknown_vm, :vm => name) - return # for tests - end - - if vm.created? - vm.reload - else - vm.env.logger.info "VM '#{name}' not created. Ignoring." - end - end - - def options_spec(opts) - opts.banner = "Usage: vagrant reload" - end - end - end -end diff --git a/lib/vagrant/commands/resume.rb b/lib/vagrant/commands/resume.rb deleted file mode 100644 index f970de3e4..000000000 --- a/lib/vagrant/commands/resume.rb +++ /dev/null @@ -1,35 +0,0 @@ -module Vagrant - class Commands - # Resume a running vagrant instance. This resumes an already suspended - # instance (from {suspend}). - # - # This command requires that an instance already be brought up with - # `vagrant up`. - class Resume < Base - Base.subcommand "resume", self - description "Resumes a suspend vagrant environment" - - def execute(args=[]) - all_or_single(args, :resume) - end - - def resume_single(name) - vm = env.vms[name.to_sym] - if vm.nil? - error_and_exit(:unknown_vm, :vm => name) - return # for tests - end - - if vm.created? - vm.resume - else - vm.env.logger.info "VM '#{name}' not created. Ignoring." - end - end - - def options_spec(opts) - opts.banner = "Usage: vagrant resume" - end - end - end -end diff --git a/lib/vagrant/commands/ssh.rb b/lib/vagrant/commands/ssh.rb deleted file mode 100644 index 2522ba2be..000000000 --- a/lib/vagrant/commands/ssh.rb +++ /dev/null @@ -1,78 +0,0 @@ -module Vagrant - class Commands - # Reload the environment. This is almost equivalent to the {up} command - # except that it doesn't import the VM and do the initialize bootstrapping - # of the instance. Instead, it forces a shutdown (if its running) of the - # VM, updates the metadata (shared folders, forwarded ports), restarts - # the VM, and then reruns the provisioning if enabled. - class SSH < Base - Base.subcommand "ssh", self - description "SSH into the currently running environment" - - def execute(args=[]) - args = parse_options(args) - if !options[:execute].empty? - vms = args[0] ? {args[0] => env.vms[args[0].to_sym]} : env.vms - vms.each do |name, vm| - ssh_execute(name, vm) - end - else - ssh_connect(args[0]) - end - end - - def ssh_execute(name, vm) - if vm.nil? - error_and_exit(:unknown_vm, :vm => name) - return # for tests - elsif !vm.created? - error_and_exit(:environment_not_created) - return - end - - vm.ssh.execute do |ssh| - options[:execute].each do |command| - vm.env.logger.info("Execute: #{command}") - ssh.exec!(command) do |channel, type, data| - # TODO: Exit status checking? - vm.env.logger.info("#{type}: #{data}") - end - end - end - end - - def ssh_connect(name) - if name.nil? && env.multivm? - if env.primary_vm.nil? - error_and_exit(:ssh_multivm) - return # for tests - end - end - - vm = name.nil? ? env.primary_vm : env.vms[name.to_sym] - if vm.nil? - error_and_exit(:unknown_vm, :vm => name) - return # for tests - end - - if !vm.created? - error_and_exit(:environment_not_created) - return - else - vm.ssh.connect - end - end - - def options_spec(opts) - opts.banner = "Usage: vagrant ssh [--execute COMMAND]" - - # Defaults - options[:execute] = [] - - opts.on("-e", "--execute COMMAND", "A command to execute. Multiple -e's may be specified.") do |value| - options[:execute] << value - end - end - end - end -end diff --git a/lib/vagrant/commands/ssh_config.rb b/lib/vagrant/commands/ssh_config.rb deleted file mode 100644 index 4b76a13bd..000000000 --- a/lib/vagrant/commands/ssh_config.rb +++ /dev/null @@ -1,45 +0,0 @@ -module Vagrant - class Commands - # Outputs a valid entry for .ssh/config which can be used to connect - # to this environment. - class SSHConfig < Base - Base.subcommand "ssh-config", self - description "outputs .ssh/config valid syntax for connecting to this environment via ssh" - - def execute(args=[]) - env.require_root_path - - args = parse_options(args) - show_single(args[0]) - end - - def show_single(name) - if name.nil? && env.multivm? - error_and_exit(:ssh_config_multivm) - return # for tests - end - - vm = name.nil? ? env.vms.values.first : env.vms[name.to_sym] - if vm.nil? - error_and_exit(:unknown_vm, :vm => name) - return # for tests - end - - puts TemplateRenderer.render("ssh_config", { - :host_key => options[:host] || "vagrant", - :ssh_user => vm.env.config.ssh.username, - :ssh_port => vm.ssh.port, - :private_key_path => vm.env.config.ssh.private_key_path - }) - end - - def options_spec(opts) - opts.banner = "Usage: vagrant ssh-config [--host NAME]" - - opts.on("-h", "--host [HOST]", "Host name for the SSH config") do |h| - options[:host] = h - end - end - end - end -end diff --git a/lib/vagrant/commands/status.rb b/lib/vagrant/commands/status.rb deleted file mode 100644 index 795779042..000000000 --- a/lib/vagrant/commands/status.rb +++ /dev/null @@ -1,125 +0,0 @@ -module Vagrant - class Commands - # Outputs the status of the current environment. This command outputs - # useful information such as whether or not the environment is created - # and if its running, suspended, etc. - class Status < Base - Base.subcommand "status", self - description "Shows the status of the Vagrant environment." - - def execute(args=[]) - args = parse_options(args) - if args.length > 1 - # There should never be more than 1 arg - show_help - return - end - - if !options[:global] - show_local_status(*args) - else - show_global_status - end - end - - # Shows the status of the CURRENT environment (the current working - # directory). If a specific VM was given, it will print out - # detailed information regarding that VM. If no single VM was - # specified and it is a multi-VM environment, it will simply - # show a listing of all the VMs and their short one word - # statuses. - def show_local_status(vm=nil) - if !env.root_path - wrap_output { puts Translator.t(:status_no_environment) } - return - end - - if vm.nil? - if env.multivm? - # No specific VM was specified in a multi-vm environment, - # so show short info for each VM - show_list - return - else - # Set the VM to just be the root VM - vm = env.vms.values.first - end - else - # Try to get the vm based on the name. If the specified VM - # doesn't exist, then error saying so - vm = env.vms[vm.to_sym] || error_and_exit(:unknown_vm, :vm => vm) - end - - show_single(vm) - end - - # Lists the available VMs and brief statuses about each. - def show_list - wrap_output do - puts Translator.t(:status_listing) - puts "" - - env.vms.each do |name, vm| - state = vm.created? ? vm.vm.state : "not created" - puts "#{name.to_s.ljust(30)}#{state}" - end - end - end - - # Shows a paragraph of information based on the current state of - # a single, specified VM. - def show_single(vm) - string_key = nil - - if !vm.created? - string_key = :status_not_created - else - additional_key = nil - if vm.vm.running? - additional_key = :status_created_running - elsif vm.vm.saved? - additional_key = :status_created_saved - elsif vm.vm.powered_off? - additional_key = :status_created_powered_off - end - - string_key = [:status_created, { - :vm_state => vm.vm.state, - :additional_message => additional_key ? Translator.t(additional_key) : "" - }] - end - - wrap_output { puts Translator.t(*string_key) } - end - - # Shows the status of the GLOBAL Vagrant environment. This prints out - # a listing of the virtual machines which Vagrant manages (running or - # not). - def show_global_status - entries = [] - - env.active_list.list.each do |uuid, data| - vm = Vagrant::VM.find(uuid, env) - entries << Translator.t(:status_global_entry, { - :vm => vm, - :data => data - }) - end - - wrap_output { puts Translator.t(:status_global, :entries => entries) } - end - - def options_spec(opts) - opts.banner = "Usage: vagrant status [--global]" - - # Defaults - options[:global] = false - options[:vm] = nil - - opts.on("-g", "--global", "Show global status of Vagrant (running VMs managed by Vagrant)") do |v| - options[:global] = true - end - end - end - end -end diff --git a/lib/vagrant/commands/suspend.rb b/lib/vagrant/commands/suspend.rb deleted file mode 100644 index 6c0d7fad3..000000000 --- a/lib/vagrant/commands/suspend.rb +++ /dev/null @@ -1,36 +0,0 @@ -module Vagrant - class Commands - # Suspend a running vagrant instance. This suspends the instance, saving - # the state of the VM and "pausing" it. The instance can be resumed - # again with {resume}. - # - # This command requires that an instance already be brought up with - # `vagrant up`. - class Suspend < Base - Base.subcommand "suspend", self - description "Suspends the currently running vagrant environment" - - def execute(args=[]) - all_or_single(args, :suspend) - end - - def suspend_single(name) - vm = env.vms[name.to_sym] - if vm.nil? - error_and_exit(:unknown_vm, :vm => name) - return # for tests - end - - if vm.created? - vm.suspend - else - vm.env.logger.info "VM '#{name}' not created. Ignoring." - end - end - - def options_spec(opts) - opts.banner = "Usage: vagrant suspend" - end - end - end -end diff --git a/lib/vagrant/commands/up.rb b/lib/vagrant/commands/up.rb deleted file mode 100644 index 6cd62204e..000000000 --- a/lib/vagrant/commands/up.rb +++ /dev/null @@ -1,44 +0,0 @@ -module Vagrant - class Commands - # Bring up a vagrant instance. This handles everything from importing - # the base VM, setting up shared folders, forwarded ports, etc to - # provisioning the instance with chef. {up} also starts the instance, - # running it in the background. - class Up < Base - Base.subcommand "up", self - description "Creates the vagrant environment" - - def execute(args=[]) - env.require_root_path - all_or_single(args, :up) - end - - def up_single(name) - vm = env.vms[name.to_sym] - if vm.nil? - error_and_exit(:unknown_vm, :vm => name) - return # for tests - end - - if vm.created? - vm.env.logger.info "VM '#{name}' already created. Booting if its not already running..." - vm.start - else - vm.env.logger.info "Creating VM '#{name}'" - vm.up - end - end - - def options_spec(opts) - opts.banner = "Usage: vagrant up [--no-provision]" - - # Defaults - options[:provision] = true - - opts.on("--no-provision", "Do not provision during this up.") do |v| - options[:provision] = false - end - end - end - end -end diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index bfd8ab76b..ca896cdff 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -23,7 +23,6 @@ module Vagrant attr_accessor :vm attr_reader :vms attr_reader :active_list - attr_reader :commands attr_reader :logger attr_reader :actions @@ -153,7 +152,6 @@ module Vagrant self.class.check_virtualbox! load_vm! load_active_list! - load_commands! load_actions! self end @@ -312,13 +310,6 @@ module Vagrant @active_list = ActiveList.new(self) end - # Loads the instance of {Command} for this environment. This allows - # users of the instance to run commands such as "up" "down" etc. in - # the context of this environment. - def load_commands! - @commands = Command.new(self) - end - # Loads the instance of {Action} for this environment. This allows # users of the instance to run action sequences in the context of # this environment. diff --git a/test/vagrant/command_test.rb b/test/vagrant/command_test.rb deleted file mode 100644 index cd8e294ca..000000000 --- a/test/vagrant/command_test.rb +++ /dev/null @@ -1,53 +0,0 @@ -require "test_helper" - -class CommandTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Command - end - - context "initializing" do - setup do - @env = mock("environment") - end - - should "set the env attribute" do - @instance = @klass.new(@env) - assert_equal @env, @instance.env - end - end - - context "class methods" do - context "executing" do - should "load the environment then send the command on commands" do - env = mock("env") - commands = mock("commands") - env.stubs(:commands).returns(commands) - Vagrant::Environment.expects(:load!).returns(env) - commands.expects(:subcommand).with(1,2,3).once - - @klass.execute(1,2,3) - end - end - end - - context "with an instance" do - setup do - @env = mock_environment - @instance = @klass.new(@env) - end - - context "subcommands" do - setup do - @raw_name = :bar - @name = :foo - @instance.stubs(:camelize).with(@raw_name).returns(@name) - end - - should "send the env, name, and args to the base class" do - args = [1,2,3] - Vagrant::Commands::Base.expects(:dispatch).with(@env, @name, *args) - @instance.subcommand(@name, *args) - end - end - end -end diff --git a/test/vagrant/commands/base_test.rb b/test/vagrant/commands/base_test.rb deleted file mode 100644 index ae7d3a8af..000000000 --- a/test/vagrant/commands/base_test.rb +++ /dev/null @@ -1,139 +0,0 @@ -require "test_helper" - -class CommandsBaseTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Base - end - - context "initializing" do - should "setup the env attribute" do - env = mock("env") - instance = @klass.new(env) - assert_equal env, instance.env - end - end - - context "class methods" do - setup do - @env = mock_environment - @klass.subcommands.clear - end - - context "registering commands" do - should "register commands" do - klass = mock("klass") - @klass.subcommand("init", klass) - assert_equal klass, @klass.subcommands["init"] - end - end - - context "dispatching to subcommands" do - setup do - @command_klass = mock("klass") - @name = "init" - @klass.subcommand(@name, @command_klass) - - @args = [1,2,3] - end - - should "call dispatch on child if subcommand is found" do - @command_klass.expects(:dispatch).with(@env, *@args) - @klass.dispatch(@env, @name, *@args) - end - - should "instantiate and execute when no subcommand is found" do - instance = mock("instance") - @klass.expects(:new).with(@env).returns(instance) - instance.expects(:execute).with(@args) - @klass.dispatch(@env, *@args) - end - end - - context "descriptions" do - should "be able to set description" do - description = "The lazy fox yada yada" - @klass.description(description) - assert_equal description, @klass.description - end - end - end - - context "instance methods" do - setup do - @env = mock_environment - @instance = @klass.new(@env) - end - - context "executing" do - should "show version if flag is set" do - @instance.expects(:puts_version).once - @instance.expects(:show_help).never - @instance.execute(["--version"]) - end - - should "just print the help by default" do - @instance.expects(:puts_version).never - @instance.expects(:show_help).once - @instance.execute([]) - end - end - - context "all or single methods" do - should "call the single method if a name is given" do - name = "bar" - @instance.expects(:foo_single).with(name).once - @instance.all_or_single(["bar"], :foo) - end - - should "call the single method for each VM if no name is given" do - vms = { :foo => nil, :bar => nil } - vms.keys.each do |name| - @instance.expects(:foo_single).with(name).once - end - - @env.stubs(:vms).returns(vms) - @instance.all_or_single([], :foo) - end - end - - context "getting the option parser" do - should "create it with the options spec if it hasn't been created yet" do - opts = mock("opts") - opts.stubs(:on) - - result = mock("result") - OptionParser.expects(:new).yields(opts).returns(result) - @instance.expects(:options_spec).with(opts) - - assert_equal result, @instance.option_parser(true) - end - - should "not create it once its been created" do - result = mock("result") - OptionParser.expects(:new).once.returns(result) - - assert_equal result, @instance.option_parser(true) - assert_equal result, @instance.option_parser - assert_equal result, @instance.option_parser - end - end - - context "parsing options" do - setup do - @args = [] - - @options = mock("options") - @option_parser = mock("option_parser") - - @instance.stubs(:option_parser).returns(@option_parser) - @instance.stubs(:options).returns(@options) - end - - should "parse the options with the args" do - result = mock("result") - @option_parser.expects(:parse!).with(@args).once.returns(result) - assert_equal result, @instance.parse_options(@args) - end - end - end -end diff --git a/test/vagrant/commands/box/add_test.rb b/test/vagrant/commands/box/add_test.rb deleted file mode 100644 index 592e84bb8..000000000 --- a/test/vagrant/commands/box/add_test.rb +++ /dev/null @@ -1,34 +0,0 @@ -require "test_helper" - -class CommandsBoxAddTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Box::Add - - @persisted_vm = mock("persisted_vm") - @persisted_vm.stubs(:execute!) - - @env = mock_environment - @env.stubs(:require_persisted_vm) - @env.stubs(:vm).returns(@persisted_vm) - - @instance = @klass.new(@env) - end - - context "executing" do - setup do - @name = "foo" - @path = "bar" - end - - should "execute the add action with the name and path" do - Vagrant::Box.expects(:add).with(@env, @name, @path).once - @instance.execute([@name, @path]) - end - - should "show help if not enough arguments" do - Vagrant::Box.expects(:add).never - @instance.expects(:show_help).once - @instance.execute([]) - end - end -end diff --git a/test/vagrant/commands/box/list_test.rb b/test/vagrant/commands/box/list_test.rb deleted file mode 100644 index 4b90d5833..000000000 --- a/test/vagrant/commands/box/list_test.rb +++ /dev/null @@ -1,32 +0,0 @@ -require "test_helper" - -class CommandsBoxListTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Box::List - - @persisted_vm = mock("persisted_vm") - @persisted_vm.stubs(:execute!) - - @env = mock_environment - @env.stubs(:require_persisted_vm) - @env.stubs(:vm).returns(@persisted_vm) - - @instance = @klass.new(@env) - end - - context "executing" do - setup do - @boxes = ["foo", "bar"] - - Vagrant::Box.stubs(:all).returns(@boxes) - @instance.stubs(:wrap_output) - end - - should "call all on box and sort the results" do - @all = mock("all") - @all.expects(:sort).returns(@boxes) - Vagrant::Box.expects(:all).with(@env).returns(@all) - @instance.execute - end - end -end diff --git a/test/vagrant/commands/box/remove_test.rb b/test/vagrant/commands/box/remove_test.rb deleted file mode 100644 index 5a66e7b15..000000000 --- a/test/vagrant/commands/box/remove_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -require "test_helper" - -class CommandsBoxRemoveTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Box::Remove - - @persisted_vm = mock("persisted_vm") - @persisted_vm.stubs(:execute!) - - @env = mock_environment - @env.stubs(:require_persisted_vm) - @env.stubs(:vm).returns(@persisted_vm) - - @instance = @klass.new(@env) - end - - context "executing" do - setup do - @name = "foo" - end - - should "show help if not enough arguments" do - Vagrant::Box.expects(:find).never - @instance.expects(:show_help).once - @instance.execute([]) - end - - should "error and exit if the box doesn't exist" do - Vagrant::Box.expects(:find).returns(nil) - @instance.expects(:error_and_exit).with(:box_remove_doesnt_exist).once - @instance.execute([@name]) - end - - should "call destroy on the box if it exists" do - @box = mock("box") - Vagrant::Box.expects(:find).with(@env, @name).returns(@box) - @box.expects(:destroy).once - @instance.execute([@name]) - end - end -end diff --git a/test/vagrant/commands/box/repackage_test.rb b/test/vagrant/commands/box/repackage_test.rb deleted file mode 100644 index 2af394ac1..000000000 --- a/test/vagrant/commands/box/repackage_test.rb +++ /dev/null @@ -1,52 +0,0 @@ -require "test_helper" - -class CommandsBoxRepackageTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Box::Repackage - - @persisted_vm = mock("persisted_vm") - @persisted_vm.stubs(:execute!) - - @env = mock_environment - @env.stubs(:require_persisted_vm) - @env.stubs(:vm).returns(@persisted_vm) - - @instance = @klass.new(@env) - end - - context "executing" do - setup do - @name = "foo" - end - - should "show help if not enough arguments" do - Vagrant::Box.expects(:find).never - @instance.expects(:show_help).once - @instance.execute(["--include", "x,y,z"]) - end - - should "error and exit if the box doesn't exist" do - Vagrant::Box.expects(:find).returns(nil) - @instance.expects(:error_and_exit).with(:box_repackage_doesnt_exist).once - @instance.execute([@name]) - end - - should "call repackage on the box if it exists" do - @box = mock("box") - Vagrant::Box.expects(:find).with(@env, @name).returns(@box) - @box.expects(:repackage).once - @instance.execute([@name]) - end - - should "pass given options into repackage" do - @box = mock("box") - Vagrant::Box.expects(:find).with(@env, @name).returns(@box) - @box.expects(:repackage).once.with() do |opts| - assert opts.is_a?(Hash) - assert_equal "filename.box", opts["package.output"] - true - end - @instance.execute([@name, "--output", "filename.box"]) - end - end -end diff --git a/test/vagrant/commands/destroy_test.rb b/test/vagrant/commands/destroy_test.rb deleted file mode 100644 index c3b9b8f18..000000000 --- a/test/vagrant/commands/destroy_test.rb +++ /dev/null @@ -1,44 +0,0 @@ -require "test_helper" - -class CommandsDestroyTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Destroy - - @env = mock_environment - - @instance = @klass.new(@env) - end - - context "executing" do - should "call all or single for the method" do - @instance.expects(:all_or_single).with([], :destroy) - @instance.execute - end - end - - context "destroying a single VM" do - setup do - @foo_vm = mock("vm") - @foo_vm.stubs(:env).returns(@env) - vms = { :foo => @foo_vm } - @env.stubs(:vms).returns(vms) - end - should "error and exit if the VM doesn't exist" do - @env.stubs(:vms).returns({}) - @instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once - @instance.destroy_single(:foo) - end - - should "destroy if its created" do - @foo_vm.stubs(:created?).returns(true) - @foo_vm.expects(:destroy).once - @instance.destroy_single(:foo) - end - - should "do nothing if its not created" do - @foo_vm.stubs(:created?).returns(false) - @foo_vm.expects(:destroy).never - @instance.destroy_single(:foo) - end - end -end diff --git a/test/vagrant/commands/halt_test.rb b/test/vagrant/commands/halt_test.rb deleted file mode 100644 index 35d87a7aa..000000000 --- a/test/vagrant/commands/halt_test.rb +++ /dev/null @@ -1,50 +0,0 @@ -require "test_helper" - -class CommandsHaltTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Halt - - @env = mock_environment - @instance = @klass.new(@env) - end - - context "executing" do - should "call all or single for the method" do - @instance.expects(:all_or_single).with([], :halt) - @instance.execute - end - end - - context "halting a single VM" do - setup do - @foo_vm = mock("vm") - @foo_vm.stubs(:env).returns(@env) - vms = { :foo => @foo_vm } - @env.stubs(:vms).returns(vms) - end - - should "error and exit if the VM doesn't exist" do - @env.stubs(:vms).returns({}) - @instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once - @instance.halt_single(:foo) - end - - should "halt if its created" do - @foo_vm.stubs(:created?).returns(true) - @foo_vm.expects(:halt).with(:force => false).once - @instance.execute(["foo"]) - end - - should "halt and force if specified" do - @foo_vm.stubs(:created?).returns(true) - @foo_vm.expects(:halt).with(:force => true).once - @instance.execute(["foo", "--force"]) - end - - should "do nothing if its not created" do - @foo_vm.stubs(:created?).returns(false) - @foo_vm.expects(:halt).never - @instance.halt_single(:foo) - end - end -end diff --git a/test/vagrant/commands/init_test.rb b/test/vagrant/commands/init_test.rb deleted file mode 100644 index 8655b4a09..000000000 --- a/test/vagrant/commands/init_test.rb +++ /dev/null @@ -1,71 +0,0 @@ -require "test_helper" - -class CommandsInitTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Init - - @env = mock_environment - @instance = @klass.new(@env) - end - - context "execute" do - should "create a vagrant file without any args" do - args = [] - @instance.expects(:create_vagrantfile).with(:default_box => nil, :default_box_url => nil) - @instance.execute(args) - end - context "when any arg is provided" do - should "create the vagrant file using the first arg as default_box and the second as default_box_url" do - args = [] - args[0] = "foo" - args[1] = "foo.box" - - @instance.expects(:create_vagrantfile).with(:default_box => "foo", :default_box_url => "foo.box") - @instance.execute(args) - end - end - end - - context "creating the vagrantfile" do - setup do - @file = mock("file") - @file.stubs(:write) - File.stubs(:open).yields(@file) - @rootfile_path = File.join(Dir.pwd, Vagrant::Environment::ROOTFILE_NAME) - - Vagrant::Util::TemplateRenderer.stubs(:render) - end - - should "error and exit if a rootfile already exists" do - File.expects(:exist?).with(@rootfile_path).returns(true) - @instance.expects(:error_and_exit).with(:rootfile_already_exists).once - @instance.create_vagrantfile - end - - should "write to the rootfile path using the template renderer" do - result = "foo" - Vagrant::Util::TemplateRenderer.expects(:render).returns(result).once - @file.expects(:write).with(result).once - File.expects(:open).with(@rootfile_path, 'w+').yields(@file) - - @instance.create_vagrantfile - end - - should "use the given base box if given" do - box = "zooo" - Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => box) - @instance.create_vagrantfile :default_box => box - end - - should "use the box_url if given" do - box_url = "fubar.box" - Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => "base", :default_box_url => "fubar.box") - @instance.create_vagrantfile :default_box_url => box_url - end - - should "use the default `base` if no box is given" do - Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => "base") - @instance.create_vagrantfile - end - end -end diff --git a/test/vagrant/commands/package_test.rb b/test/vagrant/commands/package_test.rb deleted file mode 100644 index a7586e248..000000000 --- a/test/vagrant/commands/package_test.rb +++ /dev/null @@ -1,97 +0,0 @@ -require "test_helper" - -class CommandsPackageTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Package - - @env = mock_environment - @instance = @klass.new(@env) - end - - context "executing" do - should "package base if a base is given" do - @instance.expects(:package_base).once - @instance.execute(["--base","foo"]) - end - - should "package single if no name is given" do - @instance.expects(:package_single).with(nil).once - @instance.execute - end - - should "package single if a name is given" do - @instance.expects(:package_single).with("foo").once - @instance.execute(["foo"]) - end - end - - context "packaging base" do - should "error and exit if no VM is found" do - Vagrant::VM.expects(:find).with("foo", @instance.env).returns(nil) - @instance.expects(:error_and_exit).with(:vm_base_not_found, :name => "foo").once - @instance.execute(["--base", "foo"]) - end - - should "package the VM like any other VM" do - vm = mock("vm") - Vagrant::VM.expects(:find).with("foo", @instance.env).returns(vm) - @instance.expects(:package_vm).with(vm).once - @instance.execute(["--base", "foo"]) - end - end - - context "packaging a single VM" do - setup do - @vm = mock("vm") - @vm.stubs(:created?).returns(true) - - @vms = {:bar => @vm} - @env.stubs(:vms).returns(@vms) - @env.stubs(:multivm?).returns(false) - end - - should "error and exit if no name is given in a multi-vm env" do - @env.stubs(:multivm?).returns(true) - @instance.expects(:error_and_exit).with(:package_multivm).once - @instance.package_single(nil) - end - - should "error and exit if the VM doesn't exist" do - @instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once - @instance.package_single(:foo) - end - - should "error and exit if the VM is not created" do - @vm.stubs(:created?).returns(false) - @instance.expects(:error_and_exit).with(:environment_not_created).once - @instance.package_single(:bar) - end - - should "use the first VM is no name is given in a single VM environment" do - @instance.expects(:package_vm).with(@vm).once - @instance.package_single(nil) - end - - should "package the VM" do - @instance.expects(:package_vm).with(@vm).once - @instance.package_single(:bar) - end - end - - context "packaging a VM" do - setup do - @vm = mock("vm") - - @options = {} - @instance.stubs(:options).returns(@options) - end - - should "package the VM with the proper arguments" do - @options[:output] = "foo.box" - @options[:include] = :bar - - @vm.expects(:package).with(@options).once - @instance.package_vm(@vm) - end - end -end diff --git a/test/vagrant/commands/provision_test.rb b/test/vagrant/commands/provision_test.rb deleted file mode 100644 index 74c6ad61d..000000000 --- a/test/vagrant/commands/provision_test.rb +++ /dev/null @@ -1,60 +0,0 @@ -require "test_helper" - -class CommandsProvisionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Provision - @env = mock_environment - @instance = @klass.new(@env) - end - - context "executing" do - should "provision all if no name is given" do - @instance.expects(:all_or_single).with([], :provision).once - @instance.execute - end - end - - context "provisioning a single VM" do - setup do - @foo_vm = mock("vm") - @foo_vm.stubs(:env).returns(@env) - @foo_vm.stubs(:created?).returns(true) - - @vm_for_real = mock("vm for real") - @foo_vm.stubs(:vm).returns(@vm_for_real) - vms = { :foo => @foo_vm } - @env.stubs(:vms).returns(vms) - end - - should "error and exit if the VM doesn't exist" do - @env.stubs(:vms).returns({}) - @instance.expects(:error_and_exit).with(:unknown_vm, :vm => 'foo').once - @instance.execute(["foo"]) - end - - should "reload if it's running" do - @vm_for_real.stubs(:running?).returns(true) - @foo_vm.expects(:provision).once - @instance.execute(["foo"]) - end - - should "do log to info if it's not running" do - logger = mock("logger") - logger.expects(:info) - @env.stubs(:logger).returns(logger) - @vm_for_real.stubs(:running?).returns(false) - @foo_vm.expects(:provision).never - @instance.execute(["foo"]) - end - - should "do log to info if it's not created" do - logger = mock("logger") - logger.expects(:info) - @env.stubs(:logger).returns(logger) - @foo_vm.stubs(:created?).returns(false) - @foo_vm.expects(:provision).never - @instance.execute(["foo"]) - end - end - -end diff --git a/test/vagrant/commands/reload_test.rb b/test/vagrant/commands/reload_test.rb deleted file mode 100644 index 56e656ecd..000000000 --- a/test/vagrant/commands/reload_test.rb +++ /dev/null @@ -1,47 +0,0 @@ -require "test_helper" - -class CommandsReloadTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Reload - - @env = mock_environment - @env.stubs(:require_root_path) - @instance = @klass.new(@env) - end - - context "executing" do - should "call all or single for the method" do - seq = sequence("seq") - @env.expects(:require_root_path).in_sequence(seq) - @instance.expects(:all_or_single).with([], :reload).in_sequence(seq) - @instance.execute - end - end - - context "reloading a single VM" do - setup do - @foo_vm = mock("vm") - @foo_vm.stubs(:env).returns(@env) - vms = { :foo => @foo_vm } - @env.stubs(:vms).returns(vms) - end - - should "error and exit if the VM doesn't exist" do - @env.stubs(:vms).returns({}) - @instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once - @instance.reload_single(:foo) - end - - should "reload if its created" do - @foo_vm.stubs(:created?).returns(true) - @foo_vm.expects(:reload).once - @instance.execute(["foo"]) - end - - should "do nothing if its not created" do - @foo_vm.stubs(:created?).returns(false) - @foo_vm.expects(:reload).never - @instance.reload_single(:foo) - end - end -end diff --git a/test/vagrant/commands/resume_test.rb b/test/vagrant/commands/resume_test.rb deleted file mode 100644 index cb47502f0..000000000 --- a/test/vagrant/commands/resume_test.rb +++ /dev/null @@ -1,44 +0,0 @@ -require "test_helper" - -class CommandsResumeTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Resume - - @env = mock_environment - @instance = @klass.new(@env) - end - - context "executing" do - should "call all or single for the method" do - @instance.expects(:all_or_single).with([], :resume) - @instance.execute - end - end - - context "resuming a single VM" do - setup do - @foo_vm = mock("vm") - @foo_vm.stubs(:env).returns(@env) - vms = { :foo => @foo_vm } - @env.stubs(:vms).returns(vms) - end - - should "error and exit if the VM doesn't exist" do - @env.stubs(:vms).returns({}) - @instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once - @instance.resume_single(:foo) - end - - should "resume if its created" do - @foo_vm.stubs(:created?).returns(true) - @foo_vm.expects(:resume).once - @instance.execute(["foo"]) - end - - should "do nothing if its not created" do - @foo_vm.stubs(:created?).returns(false) - @foo_vm.expects(:resume).never - @instance.resume_single(:foo) - end - end -end diff --git a/test/vagrant/commands/ssh_config_test.rb b/test/vagrant/commands/ssh_config_test.rb deleted file mode 100644 index 3a3d6c6f6..000000000 --- a/test/vagrant/commands/ssh_config_test.rb +++ /dev/null @@ -1,77 +0,0 @@ -require "test_helper" - -class CommandsSSHConfigTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::SSHConfig - - @env = mock_environment - @env.stubs(:require_root_path) - @instance = @klass.new(@env) - end - - context "executing" do - setup do - @instance.stubs(:show_single) - end - - should "require root path" do - @env.expects(:require_root_path).once - @instance.execute - end - - should "call show_single with given argument" do - @instance.expects(:show_single).with("foo").once - @instance.execute(["foo"]) - end - end - - context "showing a single entry" do - setup do - @ssh = mock("ssh") - @ssh.stubs(:port).returns(2197) - - @bar = mock("vm") - @bar.stubs(:env).returns(mock_environment) - @bar.stubs(:ssh).returns(@ssh) - - @vms = {:bar => @bar} - @env.stubs(:multivm?).returns(true) - @env.stubs(:vms).returns(@vms) - - @data = { - :host_key => "vagrant", - :ssh_user => @bar.env.config.ssh.username, - :ssh_port => @bar.ssh.port, - :private_key_path => @bar.env.config.ssh.private_key_path - } - - @instance.stubs(:puts) - end - - should "error if name is nil and multivm" do - @env.stubs(:multivm?).returns(true) - @instance.expects(:error_and_exit).with(:ssh_config_multivm).once - @instance.show_single(nil) - end - - should "error if the VM is not found" do - @instance.expects(:error_and_exit).with(:unknown_vm, :vm => "foo").once - @instance.show_single("foo") - end - - should "output rendered template" do - result = mock("result") - Vagrant::Util::TemplateRenderer.expects(:render).with("ssh_config", @data).returns(result) - - @instance.expects(:puts).with(result).once - @instance.show_single(:bar) - end - - should "render with the given host name if given" do - host = "foo" - @data[:host_key] = host - Vagrant::Util::TemplateRenderer.expects(:render).with("ssh_config", @data) - @instance.execute(["bar", "--host", host]) - end - end -end diff --git a/test/vagrant/commands/ssh_test.rb b/test/vagrant/commands/ssh_test.rb deleted file mode 100644 index 4a621ce14..000000000 --- a/test/vagrant/commands/ssh_test.rb +++ /dev/null @@ -1,129 +0,0 @@ -require "test_helper" - -class CommandsSSHTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::SSH - - @env = mock_environment - @instance = @klass.new(@env) - end - - context "executing" do - should "connect to the given argument" do - @instance.expects(:ssh_connect).with("foo").once - @instance.execute(["foo"]) - end - - should "connect with nil name if none is given" do - @instance.expects(:ssh_connect).with(nil).once - @instance.execute - end - - should "execute if commands are given" do - @env.stubs(:vms).returns(:foo => mock("foo")) - @instance.expects(:ssh_execute).with("foo", @env.vms[:foo]).once - @instance.execute(["foo","-e","bar"]) - end - - should "execute over every VM if none is specified with a command" do - vms = { - :foo => mock("foo"), - :bar => mock("bar") - } - - @env.stubs(:vms).returns(vms) - vms.each do |key, vm| - @instance.expects(:ssh_execute).with(key, vm).once - end - - @instance.execute(["--execute", "bar"]) - end - end - - context "ssh executing" do - setup do - @name = :foo - - @ssh_conn = mock("connection") - @ssh_conn.stubs(:exec!) - - @ssh = mock("ssh") - @ssh.stubs(:execute).yields(@ssh_conn) - - @vm = mock("vm") - @vm.stubs(:created?).returns(true) - @vm.stubs(:ssh).returns(@ssh) - @vm.stubs(:env).returns(@env) - end - - should "error and exit if invalid VM given" do - @instance.expects(:error_and_exit).with(:unknown_vm, :vm => @name).once - @instance.ssh_execute(@name, nil) - end - - should "error and exit if VM isn't created" do - @vm.stubs(:created?).returns(false) - @instance.expects(:error_and_exit).with(:environment_not_created).once - @instance.ssh_execute(@name, @vm) - end - - should "execute each command" do - commands = [:a,:b,:c] - @instance.stubs(:options).returns(:execute => commands) - commands.each do |cmd| - @ssh_conn.expects(:exec!).with(cmd).once - end - - @instance.ssh_execute(@name, @vm) - end - end - - context "ssh connecting" do - setup do - @vm = mock("vm") - @vm.stubs(:created?).returns(true) - - @vms = {:bar => @vm} - @env.stubs(:vms).returns(@vms) - @env.stubs(:multivm?).returns(false) - end - - should "error and exit if no VM is specified and multivm and no primary VM" do - @env.stubs(:multivm?).returns(true) - @env.stubs(:primary_vm).returns(nil) - @instance.expects(:error_and_exit).with(:ssh_multivm).once - @instance.ssh_connect(nil) - end - - should "use the primary VM if it exists and no name is specified" do - vm = mock("vm") - ssh = mock("ssh") - vm.stubs(:created?).returns(true) - vm.stubs(:ssh).returns(ssh) - - @env.stubs(:multivm?).returns(true) - @env.stubs(:primary_vm).returns(vm) - ssh.expects(:connect).once - @instance.ssh_connect(nil) - end - - should "error and exit if VM is nil" do - @instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once - @instance.ssh_connect(:foo) - end - - should "error and exit if VM isn't created" do - @vm.stubs(:created?).returns(false) - @instance.expects(:error_and_exit).with(:environment_not_created).once - @instance.ssh_connect(:bar) - end - - should "ssh connect" do - ssh = mock("ssh") - @vm.stubs(:ssh).returns(ssh) - ssh.expects(:connect) - - @instance.ssh_connect(:bar) - end - end -end diff --git a/test/vagrant/commands/status_test.rb b/test/vagrant/commands/status_test.rb deleted file mode 100644 index 9049b4908..000000000 --- a/test/vagrant/commands/status_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require "test_helper" - -class CommandsStatusTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Status - - @persisted_vm = mock("persisted_vm") - @persisted_vm.stubs(:execute!) - - @env = mock_environment - @env.stubs(:require_persisted_vm) - @env.stubs(:vm).returns(@persisted_vm) - - @instance = @klass.new(@env) - end - - context "executing" do - should "show local status by default" do - @instance.expects(:show_local_status).once - @instance.expects(:show_global_status).never - @instance.execute - end - - should "show global status if flagged" do - @instance.expects(:show_local_status).never - @instance.expects(:show_global_status).once - @instance.execute(["--global"]) - end - - should "show help if too many args are given" do - @instance.expects(:show_help).once - @instance.execute(["1","2","3"]) - end - - should "pass the VM name to local status if given" do - @instance.expects(:show_local_status).with("foo").once - @instance.execute(["foo"]) - end - end -end diff --git a/test/vagrant/commands/suspend_test.rb b/test/vagrant/commands/suspend_test.rb deleted file mode 100644 index 841defd78..000000000 --- a/test/vagrant/commands/suspend_test.rb +++ /dev/null @@ -1,44 +0,0 @@ -require "test_helper" - -class CommandsSuspendTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Suspend - - @env = mock_environment - @instance = @klass.new(@env) - end - - context "executing" do - should "call all or single for the method" do - @instance.expects(:all_or_single).with([], :suspend) - @instance.execute - end - end - - context "suspending a single VM" do - setup do - @foo_vm = mock("vm") - @foo_vm.stubs(:env).returns(@env) - vms = { :foo => @foo_vm } - @env.stubs(:vms).returns(vms) - end - - should "error and exit if the VM doesn't exist" do - @env.stubs(:vms).returns({}) - @instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once - @instance.suspend_single(:foo) - end - - should "suspend if its created" do - @foo_vm.stubs(:created?).returns(true) - @foo_vm.expects(:suspend).once - @instance.execute(["foo"]) - end - - should "do nothing if its not created" do - @foo_vm.stubs(:created?).returns(false) - @foo_vm.expects(:suspend).never - @instance.suspend_single(:foo) - end - end -end diff --git a/test/vagrant/commands/up_test.rb b/test/vagrant/commands/up_test.rb deleted file mode 100644 index e3e25ed84..000000000 --- a/test/vagrant/commands/up_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require "test_helper" - -class CommandsUpTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Commands::Up - - @env = mock_environment - @env.stubs(:require_root_path) - @instance = @klass.new(@env) - end - - context "executing" do - should "call all or single for the method" do - seq = sequence("seq") - @env.expects(:require_root_path).in_sequence(seq) - @instance.expects(:all_or_single).with([], :up).in_sequence(seq) - @instance.execute - end - end - - context "upping a single VM" do - setup do - @vm = mock("vm") - @vm.stubs(:env).returns(@env) - - @vms = {:foo => @vm} - @env.stubs(:vms).returns(@vms) - end - - should "error and exit if the VM doesn't exist" do - @env.stubs(:vms).returns({}) - @instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once - @instance.up_single(:foo) - end - - should "start created VMs" do - @vm.stubs(:created?).returns(true) - @vm.expects(:start).once - @instance.up_single(:foo) - end - - should "up non-created VMs" do - @vm.stubs(:created?).returns(false) - @vm.expects(:up).once - @vm.expects(:start).never - @instance.up_single(:foo) - end - end -end diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index fc8d12652..66cfca560 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -226,7 +226,6 @@ class EnvironmentTest < Test::Unit::TestCase Vagrant::Environment.expects(:check_virtualbox!).once.in_sequence(call_seq) @env.expects(:load_vm!).once.in_sequence(call_seq) @env.expects(:load_active_list!).once.in_sequence(call_seq) - @env.expects(:load_commands!).once.in_sequence(call_seq) @env.expects(:load_actions!).once.in_sequence(call_seq) assert_equal @env, @env.load! end @@ -617,19 +616,6 @@ class EnvironmentTest < Test::Unit::TestCase end end - context "loading the commands" do - setup do - @env = mock_environment - end - - should "initialize the Commands object with the given environment" do - commands = mock("commands") - Vagrant::Command.expects(:new).with(@env).returns(commands) - @env.load_commands! - assert_equal commands, @env.commands - end - end - context "loading actions" do setup do @env = mock_environment