Statistics
| Branch: | Tag: | Revision:

one / share / hooks / spec / OpenNebulaVLAN_spec.rb @ 3113f007

History | View | Annotate | Download (2.94 KB)

1
#!/usr/bin/env ruby
2

    
3
require 'rubygems'
4
require 'rspec'
5
require 'SystemMock'
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
include SystemMock
17

    
18
RSpec.configure do |config|
19
    config.before(:all) do
20
        $capture_commands = Hash.new
21
        $collector = Hash.new
22
    end
23
end
24

    
25
describe 'networking' do
26
    it "get all nics in kvm" do
27
        $capture_commands = {
28
            /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml]
29
        }
30
        onevlan = OpenNebulaVLAN.new(OUTPUT[:onevm_show],"kvm")
31
        nics_expected = [{:bridge=>"br0",
32
                      :ip=>"172.16.0.100",
33
                      :mac=>"02:00:ac:10:00:64",
34
                      :network=>"Small network",
35
                      :network_id=>"0",
36
                      :tap=>"vnet0"},
37
                     {:bridge=>"br1",
38
                      :ip=>"10.1.1.1",
39
                      :mac=>"02:00:0a:01:01:01",
40
                      :network=>"r1",
41
                      :network_id=>"1",
42
                      :tap=>"vnet1"},
43
                     {:bridge=>"br2",
44
                      :ip=>"10.1.2.1",
45
                      :mac=>"02:00:0a:01:02:01",
46
                      :network=>"r2",
47
                      :network_id=>"2",
48
                      :tap=>"vnet2"}]
49
        onevlan.nics.should == nics_expected
50
    end
51
end
52

    
53
describe 'ebtables' do
54
    it "generate ebtable rules in kvm" do
55
        $capture_commands = {
56
            /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml],
57
            /ebtables/       => nil
58
        }
59
        onevlan = EbtablesVLAN.new(OUTPUT[:onevm_show],"kvm")
60
        onevlan.activate
61
        ebtables_cmds = [
62
        "sudo /sbin/ebtables -A FORWARD -s ! 02:00:ac:10:00:00/ff:ff:ff:ff:ff:00 -o vnet0 -j DROP",
63
        "sudo /sbin/ebtables -A FORWARD -s ! 02:00:ac:10:00:64 -i vnet0 -j DROP",
64
        "sudo /sbin/ebtables -A FORWARD -s ! 02:00:0a:01:01:00/ff:ff:ff:ff:ff:00 -o vnet1 -j DROP",
65
        "sudo /sbin/ebtables -A FORWARD -s ! 02:00:0a:01:01:01 -i vnet1 -j DROP",
66
        "sudo /sbin/ebtables -A FORWARD -s ! 02:00:0a:01:02:00/ff:ff:ff:ff:ff:00 -o vnet2 -j DROP",
67
        "sudo /sbin/ebtables -A FORWARD -s ! 02:00:0a:01:02:01 -i vnet2 -j DROP"]
68
        $collector[:system].should == ebtables_cmds
69
    end
70
end
71

    
72
describe 'openvswitch' do
73
    it "tag tun/tap devices with vlans in kvm" do
74
        $capture_commands = {
75
            /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml],
76
            /ovs-vsctl/      => nil
77
        }
78
        onevlan = OpenvSwitchVLAN.new(OUTPUT[:onevm_show],"kvm")
79
        onevlan.activate
80
        openvswitch_tags = [
81
            "sudo /usr/local/bin/ovs-vsctl set Port vnet0 tap=2",
82
            "sudo /usr/local/bin/ovs-vsctl set Port vnet1 tap=3",
83
            "sudo /usr/local/bin/ovs-vsctl set Port vnet2 tap=4"
84
            ]
85

    
86
        $collector[:system].should == openvswitch_tags
87
    end
88
end