summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuya Kusakabe <yuya.kusakabe@gmail.com>2017-01-12 11:42:40 +0900
committerYuya Kusakabe <yuya.kusakabe@gmail.com>2017-01-12 11:42:40 +0900
commit83ddb9a56782a0fa97236289ab9db0e36699bc84 (patch)
treedcc24ef4cd55039f4e638b1a0bbed9e7bc57467a
parent79060076f217eebf8f8e5f829bd035b47adef06a (diff)
downloadvyos-integration-test-83ddb9a56782a0fa97236289ab9db0e36699bc84.tar.gz
vyos-integration-test-83ddb9a56782a0fa97236289ab9db0e36699bc84.zip
Refactor
-rw-r--r--.gitignore1
-rw-r--r--.rubocop.yml2
-rw-r--r--Rakefile10
-rw-r--r--spec/config_spec.rb15
-rw-r--r--spec/one_node/Vagrantfile24
-rw-r--r--spec/one_node/vyos_spec.rb12
-rw-r--r--spec/site_to_site_vpn/Vagrantfile24
-rw-r--r--spec/site_to_site_vpn/vyos1_spec.rb12
-rw-r--r--spec/site_to_site_vpn/vyos2_spec.rb12
-rw-r--r--spec/site_to_site_vpn/vyos3_spec.rb12
-rw-r--r--spec/site_to_site_vpn/vyos4_spec.rb12
11 files changed, 57 insertions, 79 deletions
diff --git a/.gitignore b/.gitignore
index a87d09e..d333f0f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,3 +19,4 @@ tmp
.ruby-version
.rbenv-gemsets
.vagrant
+.rake_tasks~
diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644
index 0000000..c4e4390
--- /dev/null
+++ b/.rubocop.yml
@@ -0,0 +1,2 @@
+Style/FrozenStringLiteralComment:
+ Enabled: false
diff --git a/Rakefile b/Rakefile
index 472f676..cc8bfb1 100644
--- a/Rakefile
+++ b/Rakefile
@@ -4,14 +4,14 @@ require 'yaml'
spec_tasks = []
configs = {}
-tests = Dir.glob("spec/*/").map { |s| s.gsub(/spec\//, '').gsub(/\//, '') }
+tests = Dir.glob('spec/*/').map { |s| s.gsub(%r{spec/}, '').gsub(%r{/}, '') }
tests.each do |test|
spec_tasks.concat(["spec:#{test}"])
configs[test] = YAML.load_file("spec/#{test}/config.yaml")
end
-task :spec => spec_tasks
-task :all => "spec:all"
+task spec: spec_tasks
+task all: 'spec:all'
namespace :spec do
tests.each do |test|
@@ -39,8 +39,8 @@ namespace :spec do
Dir.chdir("spec/#{test}") do
config.keys.each do |host|
RSpec::Core::RakeTask.new(host.to_sym) do |t|
- ENV["TARGET_TEST"] = test
- ENV["TARGET_HOST"] = host
+ ENV['TARGET_TEST'] = test
+ ENV['TARGET_HOST'] = host
t.pattern = "spec/#{test}/#{host}_spec.rb"
end
end
diff --git a/spec/config_spec.rb b/spec/config_spec.rb
new file mode 100644
index 0000000..f9b3980
--- /dev/null
+++ b/spec/config_spec.rb
@@ -0,0 +1,15 @@
+require 'serverspec_vyos_config'
+
+def config_spec
+ test = ENV['TARGET_TEST']
+ host = ENV['TARGET_HOST']
+
+ File.open("spec/#{test}/#{host}_script.sh") do |file|
+ file.each_line do |l|
+ next unless l.start_with?('set')
+ describe vyos_config(l.gsub(/set /, '')) do
+ it { should be_exists }
+ end
+ end
+ end
+end
diff --git a/spec/one_node/Vagrantfile b/spec/one_node/Vagrantfile
index 03b9ff7..bfa380c 100644
--- a/spec/one_node/Vagrantfile
+++ b/spec/one_node/Vagrantfile
@@ -1,28 +1,28 @@
require 'yaml'
-configs = YAML.load_file("config.yaml")
+configs = YAML.load_file('config.yaml')
-Vagrant.configure("2") do |config|
+Vagrant.configure('2') do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.cpu_mode = 'host-passthrough'
end
configs.keys.each do |host|
config.vm.define host.to_sym do |c|
- c.vm.box = "higebu/vyos"
- c.vm.synced_folder "./", "/vagrant",
- :owner => "vagrant",
- :group => "vyattacfg",
- :mount_options => ["dmode=775,fmode=775"]
+ c.vm.box = 'higebu/vyos'
+ c.vm.synced_folder './', '/vagrant',
+ owner: 'vagrant',
+ group: 'vyattacfg',
+ mount_options: ['dmode=775,fmode=775']
c.vm.hostname = host
- if !configs[host].nil? and configs[host].has_key? :networks
+ if !configs[host].nil? && configs[host].key?(:networks)
configs[host][:networks].keys.each do |net|
c.vm.network :private_network,
- :ip => configs[host][:networks][net],
- :libvirt__network_name => net,
- :libvirt__dhcp_enabled => false
+ ip: configs[host][:networks][net],
+ libvirt__network_name: net,
+ libvirt__dhcp_enabled: false
end
end
- c.vm.provision "shell", path: "#{host}_script.sh"
+ c.vm.provision 'shell', path: "#{host}_script.sh"
end
end
end
diff --git a/spec/one_node/vyos_spec.rb b/spec/one_node/vyos_spec.rb
index ec0e11f..76740d4 100644
--- a/spec/one_node/vyos_spec.rb
+++ b/spec/one_node/vyos_spec.rb
@@ -1,12 +1,4 @@
require_relative '../spec_helper'
-require 'serverspec_vyos_config'
+require_relative '../config_spec'
-File.open('spec/one_node/vyos_script.sh') do |file|
- file.each_line do |l|
- if l.start_with?("set")
- describe vyos_config(l.gsub(/set /, '')) do
- it { should be_exists }
- end
- end
- end
-end
+config_spec
diff --git a/spec/site_to_site_vpn/Vagrantfile b/spec/site_to_site_vpn/Vagrantfile
index 03b9ff7..bfa380c 100644
--- a/spec/site_to_site_vpn/Vagrantfile
+++ b/spec/site_to_site_vpn/Vagrantfile
@@ -1,28 +1,28 @@
require 'yaml'
-configs = YAML.load_file("config.yaml")
+configs = YAML.load_file('config.yaml')
-Vagrant.configure("2") do |config|
+Vagrant.configure('2') do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.cpu_mode = 'host-passthrough'
end
configs.keys.each do |host|
config.vm.define host.to_sym do |c|
- c.vm.box = "higebu/vyos"
- c.vm.synced_folder "./", "/vagrant",
- :owner => "vagrant",
- :group => "vyattacfg",
- :mount_options => ["dmode=775,fmode=775"]
+ c.vm.box = 'higebu/vyos'
+ c.vm.synced_folder './', '/vagrant',
+ owner: 'vagrant',
+ group: 'vyattacfg',
+ mount_options: ['dmode=775,fmode=775']
c.vm.hostname = host
- if !configs[host].nil? and configs[host].has_key? :networks
+ if !configs[host].nil? && configs[host].key?(:networks)
configs[host][:networks].keys.each do |net|
c.vm.network :private_network,
- :ip => configs[host][:networks][net],
- :libvirt__network_name => net,
- :libvirt__dhcp_enabled => false
+ ip: configs[host][:networks][net],
+ libvirt__network_name: net,
+ libvirt__dhcp_enabled: false
end
end
- c.vm.provision "shell", path: "#{host}_script.sh"
+ c.vm.provision 'shell', path: "#{host}_script.sh"
end
end
end
diff --git a/spec/site_to_site_vpn/vyos1_spec.rb b/spec/site_to_site_vpn/vyos1_spec.rb
index 6506d93..76740d4 100644
--- a/spec/site_to_site_vpn/vyos1_spec.rb
+++ b/spec/site_to_site_vpn/vyos1_spec.rb
@@ -1,12 +1,4 @@
require_relative '../spec_helper'
-require 'serverspec_vyos_config'
+require_relative '../config_spec'
-File.open('spec/site_to_site_vpn/vyos1_script.sh') do |file|
- file.each_line do |l|
- if l.start_with?("set")
- describe vyos_config(l.gsub(/set /, '')) do
- it { should be_exists }
- end
- end
- end
-end
+config_spec
diff --git a/spec/site_to_site_vpn/vyos2_spec.rb b/spec/site_to_site_vpn/vyos2_spec.rb
index 23a0a57..76740d4 100644
--- a/spec/site_to_site_vpn/vyos2_spec.rb
+++ b/spec/site_to_site_vpn/vyos2_spec.rb
@@ -1,12 +1,4 @@
require_relative '../spec_helper'
-require 'serverspec_vyos_config'
+require_relative '../config_spec'
-File.open('spec/site_to_site_vpn/vyos2_script.sh') do |file|
- file.each_line do |l|
- if l.start_with?("set")
- describe vyos_config(l.gsub(/set /, '')) do
- it { should be_exists }
- end
- end
- end
-end
+config_spec
diff --git a/spec/site_to_site_vpn/vyos3_spec.rb b/spec/site_to_site_vpn/vyos3_spec.rb
index 3aa75d6..6f67d61 100644
--- a/spec/site_to_site_vpn/vyos3_spec.rb
+++ b/spec/site_to_site_vpn/vyos3_spec.rb
@@ -1,15 +1,7 @@
require_relative '../spec_helper'
-require 'serverspec_vyos_config'
+require_relative '../config_spec'
-File.open('spec/site_to_site_vpn/vyos3_script.sh') do |file|
- file.each_line do |l|
- if l.start_with?("set")
- describe vyos_config(l.gsub(/set /, '')) do
- it { should be_exists }
- end
- end
- end
-end
+config_spec
describe host('10.0.3.14') do
it { should be_reachable }
diff --git a/spec/site_to_site_vpn/vyos4_spec.rb b/spec/site_to_site_vpn/vyos4_spec.rb
index 2da7341..b657b9e 100644
--- a/spec/site_to_site_vpn/vyos4_spec.rb
+++ b/spec/site_to_site_vpn/vyos4_spec.rb
@@ -1,15 +1,7 @@
require_relative '../spec_helper'
-require 'serverspec_vyos_config'
+require_relative '../config_spec'
-File.open('spec/site_to_site_vpn/vyos4_script.sh') do |file|
- file.each_line do |l|
- if l.start_with?("set")
- describe vyos_config(l.gsub(/set /, '')) do
- it { should be_exists }
- end
- end
- end
-end
+config_spec
describe host('10.0.2.13') do
it { should be_reachable }