Changeset 225

Show
Ignore:
Timestamp:
08/31/08 19:52:58 (4 months ago)
Author:
pwh
Message:
  • device_test.rb: Added fixtures, and tests for has_inventory, get_table
    and get_oid.
  • devices.yml: Added snmp_test_device, which should be locally configured
    to be a device to which ifTable and sysName.0 can be retrieved.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nethorus/test/fixtures/devices.yml

    r111 r225  
     1snmp_test_device: 
     2  id:                12345 
     3  hostname:          localhost 
     4  ipv4_address:      127.0.0.1 
     5  ipv4_address_long: 2130706433 
     6  snmp_community:    public 
     7  description:       SNMP test device 
     8  site_id:           1 
     9 
    110test_device_1: 
    211  id:                1 
  • nethorus/test/unit/device_test.rb

    r216 r225  
    2424Unit tests for the Device model. 
    2525 
     26= SNMP testing 
     27 
     28In order to test the get_table and get_oid functions, the test script must 
     29have SNMP read-only access to a device which will return the values of 
     30sysUpTime.0 and the ifTable when queried. 
     31 
     32This device should be configured in the fixtures devices.yml and named 
     33'snmp_test_device'. 
     34 
    2635=end 
    2736 
     
    2938 
    3039class DeviceTest < ActiveSupport::TestCase 
     40 
     41  fixtures :devices 
     42 
    3143 
    3244  # Verify that a new device isn't valid unless its attributes have been 
     
    297309  end 
    298310 
     311 
     312  # Verify the has_inventory? method 
     313   
     314  def test_has_inventory 
     315   
     316    new_device = Device.new 
     317    assert(!new_device.has_inventory?, "A new device should not have an inventory") 
     318     
     319    device = devices(:test_device_1) 
     320    assert(device.has_inventory?, "The device 'test_device_1' should have an inventory") 
     321   
     322  end 
     323 
     324 
     325  # Verify the get_table method 
     326   
     327  def test_get_table 
     328   
     329    snmp_test_device = devices(:snmp_test_device) 
     330    iftable = snmp_test_device.get_table('ifTable') 
     331 
     332    # TODO: Check the format of the returned data 
     333     
     334    original_proxy_port = APP_CONFIG['snmpproxy']['port'] 
     335    APP_CONFIG['snmpproxy']['port'] = 1 
     336 
     337    # TODO: Check an SNMP proxy request on an invalid port 
     338     
     339    APP_CONFIG['snmpproxy']['port'] = original_proxy_port 
     340     
     341  end 
     342   
     343   
     344  # Verify the get_oid method 
     345   
     346  def test_get_oid 
     347   
     348    snmp_test_device = devices(:snmp_test_device) 
     349    sysname_unformatted = snmp_test_device.get_oid([['sysName.0']], { :format => :no }) 
     350     
     351    # TODO: Check the format of the returned data 
     352 
     353    sysname_formatted = snmp_test_device.get_oid([['sysName.0']], { :format => :yes }) 
     354   
     355  end 
     356 
    299357end