Revision 3113f007 share/hooks/spec/OpenNebulaVLAN_spec.rb

View differences:

share/hooks/spec/OpenNebulaVLAN_spec.rb
2 2

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

  
8 8
require File.expand_path(File.dirname(__FILE__) + '/../OpenNebulaVLAN')
......
13 13
    OUTPUT[key] = File.read(f)
14 14
end
15 15

  
16
def execute_cmd(cmd)
17
    if $capture_commands
18
        $capture_commands.each do |regex, output|
19
            if cmd.match(regex)
20
                return output
21
            end
22
        end
23
    end
24
    Open3.popen3(cmd){|stdin, stdout, stderr| stdout.read}
25
end
26

  
27
def `(cmd)
28
    log_command(:backtick, cmd)
29
    execute_cmd(cmd)
30
end
31

  
32
def system(cmd)
33
    log_command(:system, cmd)
34
    execute_cmd(cmd)
35
    nil
36
end
37

  
38
def log_command(facility, msg)
39
    $collector = Hash.new if !$collector
40
    $collector[facility] = Array.new if !$collector[facility]
41
    $collector[facility] << msg
42
end
16
include SystemMock
43 17

  
44 18
RSpec.configure do |config|
45 19
    config.before(:all) do
......
94 68
        $collector[:system].should == ebtables_cmds
95 69
    end
96 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

Also available in: Unified diff