Ejemplo n.º 1
0
    def test_pdu_outlet_state_changed_on_power_off(self):
        mapping = {('my_pdu', 5): 'test'}
        driver = libvirt_driver.KeepaliveLibvirtDriver('test:///default')

        core_ = core.Core(driver=driver, mapping=mapping)

        pdu_ = apc_rackpdu.APCRackPDU('my_pdu', core_)
        outlet_oid = apc_rackpdu.rPDU_outlet_control_outlet_command + (5, )

        listen_address = '127.0.0.1'
        port = random.randint(20000, 30000)
        community = 'public'

        self.pdu_test_harness = pysnmp_handler.SNMPPDUHarness(
            pdu_, listen_address, port, community)
        self.pdu_test_harness.start()

        snmp_client_ = snmp_client.SnmpClient(cmdgen,
                                              listen_address,
                                              port,
                                              community,
                                              timeout=1,
                                              retries=1)

        snmp_client_.set(outlet_oid,
                         apc_rackpdu.rPDU_power_mappings['immediateOff'])
        self.assertEqual(drivers.POWER_OFF, driver.get_power_state('test'))

        snmp_client_.set(outlet_oid,
                         apc_rackpdu.rPDU_power_mappings['immediateOn'])
        self.assertEqual(drivers.POWER_ON, driver.get_power_state('test'))
Ejemplo n.º 2
0
    def setUp(self):
        super(TestSnmpClient, self).setUp()
        self.command_generator_mock = mock.Mock()
        self.pysnmp_mock = mock.Mock()
        self.oneliner_cmdgen = mock.Mock()

        self.oneliner_cmdgen.CommandGenerator.return_value = \
            self.command_generator_mock

        self.oneliner_cmdgen.CommunityData.return_value = \
            sentinel.community_data

        self.oneliner_cmdgen.UdpTransportTarget.return_value = \
            sentinel.udp_transport_target

        self.snmp_client = snmp_client.SnmpClient(
            oneliner_cmdgen=self.oneliner_cmdgen,
            host=sentinel.hostname,
            port=sentinel.port,
            community=sentinel.community,
            timeout=sentinel.timeout,
            retries=sentinel.retries,
        )

        self.all_error_indications = [
            (errind.__dict__.get(a).__class__.__name__, errind.__dict__.get(a))
            for a in dir(errind)
            if isinstance(errind.__dict__.get(a), ErrorIndication)]
Ejemplo n.º 3
0
    def test_harness_get_next(self):
        mock_pdu = mock.Mock()
        port = randint(20000, 30000)
        harness = pysnmp_handler.SNMPPDUHarness(pdu=mock_pdu,
                                                listen_address='127.0.0.1',
                                                listen_port=port,
                                                community='bleh')

        harness.start()

        client = snmp_client.SnmpClient(oneliner_cmdgen=cmdgen,
                                        host='127.0.0.1',
                                        port=port,
                                        community='bleh',
                                        timeout=1,
                                        retries=1)

        mock_pdu.oid_mapping = dict()
        mock_pdu.oid_mapping[(1, 3, 6, 1, 5)] = mock.Mock()
        mock_pdu.oid_mapping[(1, 3, 6, 1, 5)].value = univ.Integer(42)

        oid, val = client.get_next((1, 3, 6, 1))

        self.assertEqual((1, 3, 6, 1, 5), oid)
        self.assertEqual(42, val)

        harness.stop()
Ejemplo n.º 4
0
 def snmp_get_next(self, oid, community=None):
     s = snmp_client.SnmpClient(cmdgen,
                                self.pdu_test_harness.listen_address,
                                self.pdu_test_harness.listen_port,
                                community or self.community,
                                timeout=1,
                                retries=1)
     return s.get_next(oid)
Ejemplo n.º 5
0
def _turn_off_outlet(community, listen_address, outlet, port):
    outlet_oid = apc_rackpdu.rPDU_outlet_control_outlet_command + (outlet, )
    snmp_client_ = snmp_client.SnmpClient(cmdgen,
                                          listen_address,
                                          port,
                                          community,
                                          timeout=1,
                                          retries=1)
    snmp_client_.set(outlet_oid,
                     apc_rackpdu.rPDU_power_mappings['immediateOff'])
Ejemplo n.º 6
0
def _turn_off_outlet(community, listen_address, outlet, port):
    outlet_oid = apc_rackpdu.rPDU_outlet_control_outlet_command + (outlet, )
    snmp_client_ = snmp_client.SnmpClient(cmdgen,
                                          listen_address,
                                          port,
                                          community,
                                          timeout=1,
                                          retries=1)

    snmp_client_.set(outlet_oid, APCRackPDUOutletControl.states.IMMEDIATE_OFF)
Ejemplo n.º 7
0
    def get_harness_client(self, pdu_):
        listen_address = '127.0.0.1'
        port = random.randint(20000, 30000)
        community = 'public'

        self.pdu_test_harness = pysnmp_handler.SNMPPDUHarness(
            pdu_, listen_address, port, community)
        self.pdu_test_harness.start()

        return snmp_client.SnmpClient(cmdgen,
                                      listen_address,
                                      port,
                                      community,
                                      timeout=1,
                                      retries=1)