Example #1
0
def test_target():
    target = Target()
    eq_(target.ipmb_address, None)
    eq_(target.routing, None)

    target = Target(0xa0)
    eq_(target.ipmb_address, 0xa0)
    eq_(target.routing, None)

    target = Target(ipmb_address=0xb0)
    eq_(target.ipmb_address, 0xb0)
    eq_(target.routing, None)
Example #2
0
def test_target_routing():
    target = Target(routing=[(0x82, 0x20, 0)])
    eq_(len(target.routing), 1)
    eq_(target.routing[0].rq_sa, 0x82)
    eq_(target.routing[0].rs_sa, 0x20)
    eq_(target.routing[0].channel, 0)

    target = Target(routing=[(0x82, 0x20, 0), (0x20, 0x82, 7)])
    eq_(len(target.routing), 2)
    eq_(target.routing[0].rq_sa, 0x82)
    eq_(target.routing[0].rs_sa, 0x20)
    eq_(target.routing[0].channel, 0)
    eq_(target.routing[1].rq_sa, 0x20)
    eq_(target.routing[1].rs_sa, 0x82)
    eq_(target.routing[1].channel, 7)
Example #3
0
def test_encode_bridged_message():
    payload = array('B', b'\xaa\xbb')
    t = Target(0)
    t.set_routing([(0x81, 0x20, 7), (0x20, 0x72, None)])
    header = IpmbHeaderReq()
    header.netfn = 6
    header.rs_lun = 0
    header.rq_seq = 0x11
    header.rq_lun = 0
    header.cmd_id = 0xaa
    data = encode_bridged_message(t.routing, header, payload, seq=0x22)
    eq_(
        data,
        b'\x20\x18\xc8\x81\x88\x34\x47\x72\x18\x76\x20\x44\xaa\xaa\xbb\x8d\x7c'
    )
Example #4
0
 def __init__(
         self,
         host,
         user,
         password,
         bridge=None,  #0x06,
         target=None,  #0x2c,
         port=623,
         toolname='ipmitool',
         interfacetype='lanplus',
         delay=1):
     self._interfacetype = interfacetype
     self._delay = delay
     try:
         interface = pyipmi.interfaces.create_interface(
             toolname, self._interfacetype)
         self._target = None
         if target is not None:
             self._target = Target(target)
         connection = pyipmi.create_connection(interface)
         connection.target = self._target
         if target is not None:
             connection.target.set_routing([(0, bridge)])
             connection.session.set_session_type_rmcp(host, port)
             connection.session.set_auth_type_user(user, password)
         connection.session.establish()
         self._connection = connection
         self._interface = interface
         self._rc = 0
     except Exception as e:
         self._connection = None
         print(str(e))
Example #5
0
    def __new__(cls, *args, **kwargs):
        if not cls._instanceAardvark:
            cls._instanceAardvark = super(InvokeAadvark,
                                          cls).__new__(cls, *args, **kwargs)
            try:
                jsonpath = os.path.abspath(
                    os.path.dirname(__file__).replace('buildingblocks', '') +
                    r'workthreads/Json/Device.json')
                config = json.loads(open(jsonpath).read())
                slave = int(config['devices'][0]['slaveaddress'], 16)
                port = int(config['devices'][0]['port'], 16)
                bridge = int(config['bridge'], 16)  # 0x06
                target = int(config['target'], 16)  # 0x2c
                interface = pyipmi.interfaces.create_interface(
                    'aardvark', slave, port, None)

                cls._instanceAardvark._target = Target(target)
                connection = pyipmi.create_connection(interface)
                connection.target = cls._instanceAardvark._target
                connection.target.set_routing([(0, bridge)])
                connection.session.establish()
                cls._instanceAardvark._connection = connection
                cls._instanceAardvark._interface = interface
                cls._instanceAardvark._rc = 0
                cls._aadVarkMutex = Lock()
            except Exception as e:
                print(str(e))
        return cls._instanceAardvark
Example #6
0
    def test_send_and_receive_raw_timeout_without_response(self):
        mock = MagicMock()
        mock.return_value = (b'Unable to send RAW command '
                             b'(channel=0x0 netfn=0x6 lun=0x0 cmd=0x1)\n', 1)

        target = Target(0x20)
        self._interface._run_ipmitool = mock
        self._interface.send_and_receive_raw(target, 0, 0x6, b'\x01')
Example #7
0
    def test_send_and_receive_raw_completion_code_not_ok(self):
        mock = MagicMock()
        mock.return_value = (
            b'Unable to send RAW command (channel=0x0 netfn=0x6 lun=0x0 cmd=0x1 rsp=0xcc): Ignore Me\n',
            1)

        target = Target(0x20)
        self._interface._run_ipmitool = mock
        data = self._interface.send_and_receive_raw(target, 0, 0x6, '\x01')

        eq_(data, b'\xcc')
Example #8
0
    def test_send_and_receive_raw_valid(self):
        mock = MagicMock()
        mock.return_value = (b'', 0)
        self._interface._run_ipmitool = mock

        target = Target(0x20)
        self._interface.send_and_receive_raw(target, 0, 0x6, '\x01')

        mock.assert_called_once_with(
            'ipmitool -I lan -H 10.0.1.1 -p 623 -U "admin" -P "secret" -t 0x20 -l 0 raw 0x06 0x01 2>&1'
        )
Example #9
0
    def test_send_and_receive_raw_return_value(self):
        mock = MagicMock()
        mock.return_value = (b' 10 80 01 02 51 bd 98 3a 00 a8 '
                             b'06 00 03 00 00\n', 0)
        self._interface._run_ipmitool = mock

        target = Target(0x20)
        data = self._interface.send_and_receive_raw(target, 0, 0x6, b'\x01')

        eq_(data, b'\x00\x10\x80\x01\x02\x51\xbd\x98\x3a\x00\xa8\x06'
                  b'\x00\x03\x00\x00')
Example #10
0
    def test_send_and_receive_raw_no_auth(self):
        mock = MagicMock()
        mock.return_value = (b'', 0)
        self._interface._run_ipmitool = mock

        self._interface._session.auth_type = Session.AUTH_TYPE_NONE

        target = Target(0x20)
        self._interface.send_and_receive_raw(target, 0, 0x6, b'\x01')

        mock.assert_called_once_with('ipmitool -I lan -H 10.0.1.1 -p 623 '
                                     '-P "" -t 0x20 -l 0 raw 0x06 0x01 2>&1')
Example #11
0
    def test_send_and_receive_raw_lanplus(self):
        interface = Ipmitool(interface_type='lanplus')
        interface.establish_session(self.session)

        mock = MagicMock()
        mock.return_value = (b'', 0)
        interface._run_ipmitool = mock

        target = Target(0x20)
        interface.send_and_receive_raw(target, 0, 0x6, '\x01')

        mock.assert_called_once_with(
            'ipmitool -I lanplus -H 10.0.1.1 -p 623 -U "admin" -P "secret" -t 0x20 -l 0 raw 0x06 0x01 2>&1'
        )
Example #12
0
    def test_send_and_receive_raw_serial(self):
        interface = Ipmitool(interface_type='serial-terminal')
        self.session.set_session_type_serial('/dev/tty2', 115200)
        interface.establish_session(self.session)

        mock = MagicMock()
        mock.return_value = (b'', 0)
        interface._run_ipmitool = mock

        target = Target(0x20)
        data = interface.send_and_receive_raw(target, 0, 0x6, '\x01')

        mock.assert_called_once_with(
            'ipmitool -I serial-terminal -D /dev/tty2:115200 -t 0x20 -l 0 raw 0x06 0x01'
        )
Example #13
0
def test_target_set_routing_from_string():
    target = Target()

    target.set_routing('[(0x11, 0x12, 0x13)]')
    eq_(len(target.routing), 1)
    eq_(target.routing[0].rq_sa, 0x11)
    eq_(target.routing[0].rs_sa, 0x12)
    eq_(target.routing[0].channel, 0x13)

    target.set_routing('[(0x11, 0x12, 0x13), (0x21, 0x22, 0x23)]')
    eq_(len(target.routing), 2)
    eq_(target.routing[0].rq_sa, 0x11)
    eq_(target.routing[0].rs_sa, 0x12)
    eq_(target.routing[0].channel, 0x13)
    eq_(target.routing[1].rq_sa, 0x21)
    eq_(target.routing[1].rs_sa, 0x22)
    eq_(target.routing[1].channel, 0x23)
Example #14
0
 def test_build_ipmitool_target_routing_3(self):
     target = Target(routing=[(0x81, 0x20, 0),
                              (0x20, 0x82, 7),
                              (0x20, 0x72, None)])
     cmd = self._interface._build_ipmitool_target(target)
     eq_(cmd, ' -T 0x82 -B 0 -t 0x72 -b 7')
Example #15
0
 def test_build_ipmitool_target_routing_2(self):
     target = Target(routing=[(0x81, 0x20, 7), (0x20, 0x82, 0)])
     cmd = self._interface._build_ipmitool_target(target)
     eq_(cmd, ' -t 0x82 -b 7')
Example #16
0
 def test_build_ipmitool_target_ipmb_address(self):
     target = Target(0xb0)
     cmd = self._interface._build_ipmitool_target(target)
     eq_(cmd, ' -t 0xb0')