Revision 8681584e

View differences:

share/hooks/OpenNebulaVLAN.rb
99 99

  
100 100

  
101 101
class OpenNebulaVLAN
102
    attr_reader :vm_info, :hypervisor
102
    attr_reader :vm_info, :hypervisor, :nics
103 103

  
104 104
    def initialize(vm_tpl, hypervisor=nil)
105 105
        @vm_root = REXML::Document.new(vm_tpl).root
......
212 212
    end
213 213

  
214 214
    def ebtables(rule)
215
        system "#{CONF[:ebtables]} -A #{rule}"
215
        system("#{CONF[:ebtables]} -A #{rule}")
216 216
    end
217 217

  
218 218
    def activate
share/hooks/spec/OpenNebulaVLAN_spec.rb
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
share/hooks/spec/output/kvm_lsmod
1
Module                  Size  Used by
2
xts                     2421  8 
3
gf128mul                5690  1 xts
4
dm_crypt               15457  1 
5
dm_mod                 64396  3 dm_crypt
6
kvm_intel              49771  6 
7
kvm                   314766  1 kvm_intel
8
ip6table_filter         1420  0 
9
ip6_tables             17584  1 ip6table_filter
10
tun                    15525  12 
11
ipt_REJECT              2337  2 
12
xt_CHECKSUM             1223  1 
13
iptable_mangle          1576  1 
14
xt_tcpudp               2495  5 
15
nls_cp437               5913  1 
16
vfat                   10143  1 
17
fat                    47937  1 vfat
18
ipt_MASQUERADE          1666  4 
19
bridge                 70237  0 
20
stp                     1600  1 bridge
21
llc                     3521  2 bridge,stp
22
ipv6                  277133  29 bridge
23
cryptd                  7661  0 
24
aes_x86_64              7436  17 
25
aes_generic            26066  1 aes_x86_64
26
hid_logitech           12032  0 
27
ff_memless              4635  1 hid_logitech
28
xt_state                1255  2 
29
iptable_filter          1480  1 
30
iptable_nat             3920  1 
31
nf_nat                 14980  2 ipt_MASQUERADE,iptable_nat
32
nf_conntrack_ipv4      11177  5 iptable_nat,nf_nat
33
nf_conntrack           56218  5 ipt_MASQUERADE,xt_state,iptable_nat,nf_nat,nf_conntrack_ipv4
34
nf_defrag_ipv4          1363  1 nf_conntrack_ipv4
35
ip_tables              16295  3 iptable_mangle,iptable_filter,iptable_nat
36
x_tables               16643  11 ip6table_filter,ip6_tables,ipt_REJECT,xt_CHECKSUM,iptable_mangle,xt_tcpudp,ipt_MASQUERADE,xt_state,iptable_filter,iptable_nat,ip_tables
37
snd_hda_codec_hdmi     22282  4 
38
usbhid                 33814  1 hid_logitech
39
hid                    76802  2 hid_logitech,usbhid
40
uvcvideo               60799  0 
41
videodev               65175  1 uvcvideo
42
btusb                  11153  0 
43
v4l2_compat_ioctl32     6716  1 videodev
44
bluetooth              55377  1 btusb
45
arc4                    1402  2 
46
ecb                     2033  2 
47
nvidia              10481030  45 
48
joydev                  9767  0 
49
snd_hda_codec_realtek   294053  1 
50
fuse                   64542  3 
51
snd_hda_intel          21738  4 
52
snd_hda_codec          73739  3 snd_hda_codec_hdmi,snd_hda_codec_realtek,snd_hda_intel
53
iwlagn                385759  0 
54
vboxnetflt             19108  0 
55
snd_hwdep               6134  1 snd_hda_codec
56
snd_pcm                71032  4 snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec
57
snd_timer              18992  2 snd_pcm
58
mmc_block               9580  2 
59
snd                    55132  13 snd_hda_codec_hdmi,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_timer
60
iwlcore               103238  1 iwlagn
61
soundcore               5986  1 snd
62
firewire_ohci          28105  0 
63
mac80211              202222  2 iwlagn,iwlcore
64
snd_page_alloc          7017  2 snd_hda_intel,snd_pcm
65
sony_laptop            25073  0 
66
i2c_i801                7987  0 
67
firewire_core          47790  1 firewire_ohci
68
vboxdrv              1760003  1 vboxnetflt
69
crc_itu_t               1321  1 firewire_core
70
ehci_hcd               39113  0 
71
cfg80211              141484  3 iwlagn,iwlcore,mac80211
72
usbcore               134923  5 usbhid,uvcvideo,btusb,ehci_hcd
73
wmi                     8083  0 
74
rfkill                 14810  3 bluetooth,sony_laptop,cfg80211
75
i2c_core               18740  3 videodev,nvidia,i2c_i801
76
thermal                 7631  0 
77
atl1c                  31559  0 
78
ac                      3193  0 
79
sg                     24917  0 
80
button                  4794  0 
81
battery                10410  0 
82
video                  10996  0 
83
serio_raw               4222  0 
84
processor              23608  0 
85
sdhci_pci               8202  0 
86
iTCO_wdt               11053  0 
87
intel_agp              10480  0 
88
iTCO_vendor_support     1857  1 iTCO_wdt
89
sdhci                  17061  1 sdhci_pci
90
intel_gtt              13943  1 intel_agp
91
pcspkr                  1843  0 
92
mmc_core               63886  2 mmc_block,sdhci
93
psmouse                52944  0 
94
intel_ips              10885  0 
95
evdev                   9178  24 
96
loop                   17358  2 
97
ext4                  332976  4 
98
mbcache                 5649  1 ext4
99
jbd2                   69632  1 ext4
100
crc16                   1321  1 ext4
101
sr_mod                 14247  0 
102
cdrom                  35689  1 sr_mod
103
sd_mod                 26276  5 
104
ahci                   20441  4 
105
libahci                17966  1 ahci
106
libata                167694  2 ahci,libahci
107
scsi_mod              123282  4 sg,sr_mod,sd_mod,libata
share/hooks/spec/output/kvm_uname_a
1
Linux rama 2.6.38-ARCH #1 SMP PREEMPT Wed Mar 30 08:47:36 CEST 2011 x86_64 Intel(R) Core(TM) i5 CPU M 450 @ 2.40GHz GenuineIntel GNU/Linux
share/hooks/spec/output/virsh_dumpxml
1
<domain type='kvm' id='3'>
2
  <name>one-2</name>
3
  <uuid>bea46e50-c328-7299-afbd-b5ba4c74b651</uuid>
4
  <memory>65536</memory>
5
  <currentMemory>65536</currentMemory>
6
  <vcpu>1</vcpu>
7
  <os>
8
    <type arch='i686' machine='pc-0.14'>hvm</type>
9
    <boot dev='hd'/>
10
  </os>
11
  <clock offset='utc'/>
12
  <on_poweroff>destroy</on_poweroff>
13
  <on_reboot>restart</on_reboot>
14
  <on_crash>destroy</on_crash>
15
  <devices>
16
    <emulator>/usr/bin/kvm</emulator>
17
    <disk type='file' device='disk'>
18
      <driver name='qemu' type='raw'/>
19
      <source file='/home/jmelis/work/git/one/one/var//2/images/disk.0'/>
20
      <target dev='sda' bus='scsi'/>
21
      <alias name='scsi0-0-0'/>
22
      <address type='drive' controller='0' bus='0' unit='0'/>
23
    </disk>
24
    <controller type='scsi' index='0'>
25
      <alias name='scsi0'/>
26
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
27
    </controller>
28
    <interface type='bridge'>
29
      <mac address='02:00:ac:10:00:64'/>
30
      <source bridge='br0'/>
31
      <target dev='vnet0'/>
32
      <alias name='net0'/>
33
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
34
    </interface>
35
    <interface type='bridge'>
36
      <mac address='02:00:0a:01:01:01'/>
37
      <source bridge='br1'/>
38
      <target dev='vnet1'/>
39
      <alias name='net1'/>
40
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
41
    </interface>
42
    <interface type='bridge'>
43
      <mac address='02:00:0a:01:02:01'/>
44
      <source bridge='br2'/>
45
      <target dev='vnet2'/>
46
      <alias name='net2'/>
47
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
48
    </interface>
49
    <memballoon model='virtio'>
50
      <alias name='balloon0'/>
51
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
52
    </memballoon>
53
  </devices>
54
</domain>
55

  

Also available in: Unified diff