Statistics
| Branch: | Tag: | Revision:

one / share / hooks / spec / OpenNebulaVLAN_spec.rb @ 8681584e

History | View | Annotate | Download (2.33 KB)

1
#!/usr/bin/env ruby
2

    
3
require 'rubygems'
4
require 'rspec'
5
require 'open3'
6
require 'pp'
7

    
8
require File.expand_path(File.dirname(__FILE__) + '/../OpenNebulaVLAN')
9

    
10
OUTPUT = Hash.new
11
Dir[File.dirname(__FILE__) + "/output/**"].each do |f|
12
    key = File.basename(f).to_sym
13
    OUTPUT[key] = File.read(f)
14
end
15

    
16
$collector = Hash.new
17

    
18
def execute_cmd(cmd)
19
    if cmd =~ /virsh.*dumpxml/
20
        OUTPUT[:virsh_dumpxml]
21
    else
22
        Open3.popen3(cmd){|stdin, stdout, stderr| stdout.read}
23
    end
24
end
25

    
26
def `(cmd)
27
    $collector[:backtick] << cmd
28
    execute_cmd(cmd)
29
end
30

    
31
def system(cmd)
32
    $collector[:system] << cmd
33
    #Kernel::system(cmd)
34
end
35

    
36
RSpec.configure do |config|
37
    config.before(:all) do
38
        $collector[:system]   = Array.new
39
        $collector[:backtick] = Array.new
40
    end
41
end
42

    
43
describe 'networking' do
44
    it "get all nics in kvm" do
45
        onevlan = OpenNebulaVLAN.new(OUTPUT[:onevm_show],"kvm")
46
        nics_expected = [{:bridge=>"br0",
47
                      :ip=>"172.16.0.100",
48
                      :mac=>"02:00:ac:10:00:64",
49
                      :network=>"Small network",
50
                      :network_id=>"0",
51
                      :tap=>"vnet0"},
52
                     {:bridge=>"br1",
53
                      :ip=>"10.1.1.1",
54
                      :mac=>"02:00:0a:01:01:01",
55
                      :network=>"r1",
56
                      :network_id=>"1",
57
                      :tap=>"vnet1"},
58
                     {:bridge=>"br2",
59
                      :ip=>"10.1.2.1",
60
                      :mac=>"02:00:0a:01:02:01",
61
                      :network=>"r2",
62
                      :network_id=>"2",
63
                      :tap=>"vnet2"}]
64
        onevlan.nics.should == nics_expected
65
    end
66
end
67

    
68
describe 'ebtables' do
69
    it "generate ebtable rules in kvm" do
70
        onevlan = EbtablesVLAN.new(OUTPUT[:onevm_show],"kvm")
71
        onevlan.activate
72
        ebtables_cmds = [
73
        " -A FORWARD -s ! 02:00:ac:10:00:00/ff:ff:ff:ff:ff:00 -o vnet0 -j DROP",
74
        " -A FORWARD -s ! 02:00:ac:10:00:64 -i vnet0 -j DROP",
75
        " -A FORWARD -s ! 02:00:0a:01:01:00/ff:ff:ff:ff:ff:00 -o vnet1 -j DROP",
76
        " -A FORWARD -s ! 02:00:0a:01:01:01 -i vnet1 -j DROP",
77
        " -A FORWARD -s ! 02:00:0a:01:02:00/ff:ff:ff:ff:ff:00 -o vnet2 -j DROP",
78
        " -A FORWARD -s ! 02:00:0a:01:02:01 -i vnet2 -j DROP"]
79

    
80
        $collector[:system].should == ebtables_cmds
81
    end
82
end