diff --git a/Vagrantfile b/Vagrantfile index a75baee5a6424db31299b8108eea8cd3c47435d3..45fc906823b7012ba82a669ed3b612a84ce75ce5 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -26,7 +26,6 @@ require 'getoptlong' require 'yaml' - # Custom options: # --infra <infradir> @@ -53,47 +52,54 @@ puts "custom config file: /infra/#{infra}/rspec.yml" host_rspec_file = "infra/#{infra}/rspec.yml" hosts = YAML.load_file(host_rspec_file) - # Start creating VMS using xenial64 as the base box Vagrant.configure("2") do |config| config.vm.box = "ubuntu/xenial64" - + # Dynamic VMs hosts['hosts'].each do |host| #p host["name"] instance_name = host["name"] config.vm.define instance_name do |instance_config| - # Specify VM properties + + # Specify VM properties instance_config.vm.hostname = instance_name instance_config.disksize.size = host["disk"] instance_config.vm.provider "virtualbox" do |v| v.customize ["modifyvm", :id, "--memory", host["memory"]] v.customize ["modifyvm", :id, "--cpus", host["cpus"]] end - # Configure network + + # Configure network, not that we only expect 1 test to be running so we have one internal network config.vm.network :private_network, ip: "#{host["ip_address"]}", virtualbox__intnet: "clmc-net" - # Port forwarding - puts "Forwarding the following specified ports for #{host["name"]}:" - host['forward_ports'].each do |port| - puts "Forwarding guest:#{port["guest"]} => host:#{port["host"]}" - config.vm.network "forwarded_port", guest: port["guest"], host: port["host"] - end - # Switch case added here to make clmc-service provisioning simple without having to have a complex rspec.yml file - # We only run a service installation script and the agent installation script when creating a specific service VM, not the clmc-service VM - case host - when 'clmc-service' - config.vm.provision :shell, :path => "scripts/clmc-service/#{host["install_script"]}" - config.vm.provision :shell, :path => "scripts/clmc-service/#{host["start_script"]}" - when (not 'clmc-service') - # specific service install - service_install_path = "test/services/#{host["service_name"]}/install-#{host["service_name"]}.sh" - puts "installing service script: #{service_install_path}" - config.vm.provision :shell, :path => service_install_path - # agent install - config.vm.provision :shell, :path => "scripts/clmc-agent/install-clmc-agent.sh", :args => "/vagrant/test/services/#{host["service_name"]}/telegraf_#{host["service_name"]}_template.conf #{host["location"]} #{host["sfc_id"]} #{host["sfc_id_instance"]} #{host["sf_id"]} #{host["sf_id_instance"]} #{host["ipendpoint_id"]} #{host["influxdb_url"]} #{host["database_name"]}" + + # Port forwarding + puts "Forwarding the following specified ports for #{host["name"]}:" + host['forward_ports'].each do |port| + puts "Forwarding guest:#{port["guest"]} => host:#{port["host"]}" + config.vm.network "forwarded_port", guest: port["guest"], host: port["host"] end - end + + # Switch case added here to make clmc-service provisioning simple without having to have a complex rspec.yml file + # We only run a service installation script and the agent installation script when creating a specific service VM, not the clmc-service VM + + puts "Instance name #{instance_name}:" + case instance_name + when 'clmc-service' + config.vm.provision :shell, :path => "scripts/clmc-service/#{host["install_script"]}" + config.vm.provision :shell, :path => "scripts/clmc-service/#{host["start_script"]}" + else + puts "Provisioning #{instance_name}:" + # specific service install + service_install_path = "test/services/#{host["service_name"]}/install-#{host["service_name"]}.sh" + puts "installing service script: #{service_install_path}" + config.vm.provision :shell, :path => service_install_path + # agent install + config.vm.provision :shell, :path => "scripts/clmc-agent/install-clmc-agent.sh", :args => "/vagrant/test/services/#{host["service_name"]}/telegraf_#{host["service_name"]}_template.conf #{host["location"]} #{host["sfc_id"]} #{host["sfc_id_instance"]} #{host["sf_id"]} #{host["sf_id_instance"]} #{host["ipendpoint_id"]} #{host["influxdb_url"]} #{host["database_name"]}" + + end + end end end