def test_generate_collectd_snmp_config_raises_SystemExit_for_model_error(
            self):
        self.session.get_model.side_effect = models.Error('whoops')

        with self.assertRaises(SystemExit):
            disco_config.generate_collectd_snmp_config(self.session, 'hostname',
                                                       'community1')
    def test_generate_collectd_snmp_config_raises_SystemExit_for_ifindex_error(
            self):
        self.session.get_model.return_value = self.model_cisco
        self.session.auto_discover_ifindex.side_effect = discovery.Error(
            'whoops')

        with self.assertRaises(SystemExit):
            disco_config.generate_collectd_snmp_config(self.session, 'hostname',
                                                       'community1')
    def test_generate_collectd_snmp_config(self):
        expected_plugin_config = """LoadPlugin snmp
<Plugin snmp>
  <Data "uplink_discards">
    Type "ifx_discards"
    Table false
    Instance "uplink"
    Values "rx.10" "tx.10"
  </Data>

  <Host "hostname">
    Address "hostname"
    Version 2
    Community "community1"
    Collect "uplink_discards"
    Interval 10
  </Host>
</Plugin>"""

        self.session.get_model.return_value = self.model_cisco
        self.session.auto_discover_ifindex.return_value = [('uplink', '10')]

        actual = disco_config.generate_collectd_snmp_config(
            self.session, 'hostname', 'community1')

        self.assertEqual(expected_plugin_config, actual)