File: interface_spec.rb

package info (click to toggle)
puppet 4.8.2-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 20,736 kB
  • ctags: 14,616
  • sloc: ruby: 236,754; xml: 1,586; sh: 1,178; lisp: 299; sql: 103; yacc: 72; makefile: 52
file content (129 lines) | stat: -rw-r--r-- 4,794 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#! /usr/bin/env ruby
require 'spec_helper'

describe Puppet::Type.type(:interface) do

  it "should have a 'name' parameter'" do
    expect(Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1")[:name]).to eq("FastEthernet 0/1")
  end

  it "should have a 'device_url' parameter'" do
    expect(Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :device_url => :device)[:device_url]).to eq(:device)
  end

  it "should have an ensure property" do
    expect(Puppet::Type.type(:interface).attrtype(:ensure)).to eq(:property)
  end

  it "should be applied on device" do
    expect(Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1")).to be_appliable_to_device
  end

  [:description, :speed, :duplex, :native_vlan, :encapsulation, :mode, :allowed_trunk_vlans, :etherchannel, :ipaddress].each do |p|
    it "should have a #{p} property" do
      expect(Puppet::Type.type(:interface).attrtype(p)).to eq(:property)
    end
  end

  describe "when validating attribute values" do
    before do
      @provider = stub 'provider', :class => Puppet::Type.type(:interface).defaultprovider, :clear => nil
      Puppet::Type.type(:interface).defaultprovider.stubs(:new).returns(@provider)
    end

    it "should support :present as a value to :ensure" do
      Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ensure => :present)
    end

    it "should support :shutdown as a value to :ensure" do
      Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ensure => :shutdown)
    end

    it "should support :no_shutdown as a value to :ensure" do
      Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ensure => :no_shutdown)
    end

    describe "especially speed" do
      it "should allow a number" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :speed => "100")
      end

      it "should allow :auto" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :speed => :auto)
      end
    end

    describe "especially duplex" do
      it "should allow :half" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :duplex => :half)
      end

      it "should allow :full" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :duplex => :full)
      end

      it "should allow :auto" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :duplex => :auto)
      end
    end

    describe "interface mode" do
      it "should allow :access" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :mode => :access)
      end

      it "should allow :trunk" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :mode => :trunk)
      end

      it "should allow 'dynamic auto'" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :mode => 'dynamic auto')
      end

      it "should allow 'dynamic desirable'" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :mode => 'dynamic desirable')
      end
    end

    describe "interface encapsulation" do
      it "should allow :dot1q" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :encapsulation => :dot1q)
      end

      it "should allow :isl" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :encapsulation => :isl)
      end

      it "should allow :negotiate" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :encapsulation => :negotiate)
      end
    end

    describe "especially ipaddress" do
      it "should allow ipv4 addresses" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => "192.168.0.1/24")
      end

      it "should allow arrays of ipv4 addresses" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => ["192.168.0.1/24", "192.168.1.0/24"])
      end

      it "should allow ipv6 addresses" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => "f0e9::/64")
      end

      it "should allow ipv6 options" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => "f0e9::/64 link-local")
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => "f0e9::/64 eui-64")
      end

      it "should allow a mix of ipv4 and ipv6" do
        Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => ["192.168.0.1/24", "f0e9::/64 link-local"])
      end

      it "should munge ip addresses to a computer format" do
        expect(Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => "192.168.0.1/24")[:ipaddress]).to eq([[24, IPAddr.new('192.168.0.1'), nil]])
      end
    end
  end
end