Exemple #1
0
    def test_load_switch_config_raises_BadConfiguration_when_config_misaligned(
            self):
        config_fd = StringIO.StringIO("""
!config
models:
    - !model
      name: procurve
     pattern: <--MISALIGNED

default_oids:
    discards:
        !oid
        rx: abc
        tx: def
""")
        with self.assertRaises(models.BadConfiguration):
            models.load_switch_config(config_fd)
Exemple #2
0
    def test_load_switch_config_raises_BadConfiguration_when_config_misaligned(
            self):
        config_fd = StringIO.StringIO("""
!config
models:
    - !model
      name: procurve
     pattern: <--MISALIGNED

default_oids:
    discards:
        !oid
        rx: abc
        tx: def
""")
        with self.assertRaises(models.BadConfiguration):
            models.load_switch_config(config_fd)
Exemple #3
0
    def test_load_switch_config_load_and_get_model_successfully(self):
        config_fd = StringIO.StringIO("""
!config
models:
    - !model
      name: procurve
      pattern: ProCurve
      oids:
          discards:
              !oid
              rx: dis_model_rx
              tx: dis_model_tx

          broadcast:
              !oid
              rx: bro_rx
              tx: bro_tx

default_oids:
    discards:
        !oid
        rx: dis_default_rx
        tx: dis_default_tx

    octets:
        !oid
        rx: oct_rx
        tx: oct_tx
""")

        config = models.load_switch_config(config_fd)
        model = config.get_model('Fake ProCurve sysDescr message')

        # Check config.
        self.assertEqual(1, len(config.models))
        self.assertEqual('procurve', config.models[0].name)
        self.assertEqual('ProCurve', config.models[0].pattern)
        self.assertEqual(2, len(config.default_oids))
        self.assertEqual('dis_default_rx', config.default_oids['discards'].rx)
        self.assertEqual('dis_default_tx', config.default_oids['discards'].tx)
        self.assertEqual('oct_rx', config.default_oids['octets'].rx)
        self.assertEqual('oct_tx', config.default_oids['octets'].tx)
        # Check model, which inherits default_oids while preserving model oids.
        self.assertEqual(3, len(model.oids))
        self.assertEqual('dis_model_rx', model.oids['discards'].rx)
        self.assertEqual('dis_model_tx', model.oids['discards'].tx)
        self.assertEqual('bro_rx', model.oids['broadcast'].rx)
        self.assertEqual('bro_tx', model.oids['broadcast'].tx)
        self.assertEqual('oct_rx', model.oids['octets'].rx)
        self.assertEqual('oct_tx', model.oids['octets'].tx)
Exemple #4
0
    def test_load_switch_config_load_and_get_model_successfully(self):
        config_fd = StringIO.StringIO("""
!config
models:
    - !model
      name: procurve
      pattern: ProCurve
      oids:
          discards:
              !oid
              rx: dis_model_rx
              tx: dis_model_tx

          broadcast:
              !oid
              rx: bro_rx
              tx: bro_tx

default_oids:
    discards:
        !oid
        rx: dis_default_rx
        tx: dis_default_tx

    octets:
        !oid
        rx: oct_rx
        tx: oct_tx
""")

        config = models.load_switch_config(config_fd)
        model = config.get_model('Fake ProCurve sysDescr message')

        # Check config.
        self.assertEqual(1, len(config.models))
        self.assertEqual('procurve', config.models[0].name)
        self.assertEqual('ProCurve', config.models[0].pattern)
        self.assertEqual(2, len(config.default_oids))
        self.assertEqual('dis_default_rx', config.default_oids['discards'].rx)
        self.assertEqual('dis_default_tx', config.default_oids['discards'].tx)
        self.assertEqual('oct_rx', config.default_oids['octets'].rx)
        self.assertEqual('oct_tx', config.default_oids['octets'].tx)
        # Check model, which inherits default_oids while preserving model oids.
        self.assertEqual(3, len(model.oids))
        self.assertEqual('dis_model_rx', model.oids['discards'].rx)
        self.assertEqual('dis_model_tx', model.oids['discards'].tx)
        self.assertEqual('bro_rx', model.oids['broadcast'].rx)
        self.assertEqual('bro_tx', model.oids['broadcast'].tx)
        self.assertEqual('oct_rx', model.oids['octets'].rx)
        self.assertEqual('oct_tx', model.oids['octets'].tx)