-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from v-zhuravlev/encaps_tests
Better tests and add deploy
- Loading branch information
Showing
14 changed files
with
485 additions
and
484 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
|
||
host_default = "172.16.238.2:5020" | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--host", action="store", default=host_default, help="Setup connection string" | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def host(request): | ||
return request.config.getoption("--host") |
26 changes: 11 additions & 15 deletions
26
tests/test_modbus_connection_string.py → tests/test_00modbus_connection_string.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,25 @@ | ||
import unittest | ||
|
||
import pytest | ||
from zabbix_get import zabbix_get | ||
|
||
class ModbusConnectionStringTestCase(unittest.TestCase): | ||
|
||
class TestModbusConnectionString(object): | ||
|
||
host = "172.16.238.2:5020" | ||
host_rtutcp = "172.16.238.2:5021" | ||
|
||
|
||
# test enc:// (rtu over tcp) | ||
|
||
def test_modbus_test_rtutcp(self): | ||
key = "modbus_read[enc://"+self.host_rtutcp+",1,0,3,uint16]" | ||
self.assertEqual(zabbix_get(key),'49807') | ||
assert zabbix_get(key) == '49807' | ||
# test tcp:// (plain tcp) | ||
|
||
def test_modbus_tcp(self): | ||
key = "modbus_read[tcp://"+self.host+",1,1,3,uint16]" | ||
self.assertEqual(zabbix_get(key),'49677') | ||
assert zabbix_get(key) == '49677' | ||
|
||
# test serial /dev/ttyS0 | ||
@unittest.skip("implement this first") | ||
def test_modbus_serial(self): | ||
@pytest.mark.skip("implement this first") | ||
def test_modbus_serial(self, host): | ||
key = "modbus_read[/dev/ttyS0,1,1,3,uint16]" | ||
self.assertEqual(zabbix_get(key),'49677') | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main(verbosity=2) | ||
assert zabbix_get(key) == '49677' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import pytest | ||
from zabbix_get import zabbix_get | ||
|
||
class TestModbusErrors(object): | ||
|
||
|
||
# test errors | ||
def test_empty(self, host): | ||
"""Test Empty""" | ||
key = "modbus_read" | ||
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Invalid number of parameters.' | ||
def test_empty_squares(self, host): | ||
"""Test empty squares""" | ||
key = "modbus_read[]" | ||
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Invalid number of parameters.' | ||
|
||
def test_no_IP(self, host): | ||
"""Test no IP""" | ||
key = "modbus_read_registers[,3,14,3,uint32,BE,0]" | ||
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: No connection address provided.' | ||
def test_bad_IP(self, host): | ||
"""Test bad IP""" | ||
key = "modbus_read_registers[badIP,3,14,3,uint32,BE,0]" | ||
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Network is unreachable' | ||
|
||
def test_no_slaveID(self, host): | ||
key = "modbus_read_registers[{HOST.CONN},,14,3,uint32,BE,0]" | ||
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: No slave id provided.' | ||
def test_no_function(self, host): | ||
key = "modbus_read_registers["+host+",3,14,,uint32,BE,0]" | ||
assert zabbix_get(key),'ZBX_NOTSUPPORTED: No Modbus function provided! Please provide either 1,2,3 == 4.' | ||
|
||
def test_bad_PDU_flag_integer(self, host): | ||
key = "modbus_read_registers["+host+",3,14,3,uint32,BE,3]" | ||
assert zabbix_get(key),'ZBX_NOTSUPPORTED: Check addressing scheme(PDU == PROTOCOL) used' | ||
def test_bad_PDU_flag_string(self, host): | ||
key = "modbus_read_registers["+host+",3,14,3,uint32,BE,bad]" | ||
assert zabbix_get(key),'ZBX_NOTSUPPORTED: Check addressing scheme(PDU == PROTOCOL) used' | ||
|
||
|
||
def test_bad_LE_flag_integer(self, host): | ||
key = "modbus_read_registers["+host+",3,14,3,uint32,5,0]" | ||
assert zabbix_get(key),'ZBX_NOTSUPPORTED: Check endiannes used: BE,LE,MLE == MBE.' | ||
|
||
def test_bad_LE_flag_string(self, host): | ||
key = "modbus_read_registers["+host+",3,14,3,uint32,bad,0]" | ||
assert zabbix_get(key),'ZBX_NOTSUPPORTED: Check endiannes used: BE,LE,MLE == MBE.' | ||
|
||
|
||
def test_bad_function_integer(self, host): | ||
key = "modbus_read_registers["+host+",3,14,5,uint32,BE,0]" | ||
assert zabbix_get(key),'ZBX_NOTSUPPORTED: Check function (1,2,3 == 4) used' | ||
def test_bad_function_string(self, host): | ||
key = "modbus_read_registers["+host+",3,14,bad,uint32,BE,0]" | ||
assert zabbix_get(key),'ZBX_NOTSUPPORTED: Check function (1,2,3 == 4) used' | ||
|
||
def test_bad_register_out_of_bounds_integer(self, host): | ||
key = "modbus_read_registers["+host+",3,1000,3,uint32,BE,0]" | ||
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Illegal data address' | ||
def test_bad_register_string(self, host): | ||
key = "modbus_read_registers["+host+",3,bad,3,uint32,BE,0]" | ||
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Check register to read' | ||
|
||
def test_bad_slaveid_integer(self, host): | ||
key = "modbus_read_registers["+host+",5000,99,3,uint32,BE,0]" | ||
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Illegal data address' | ||
def test_bad_slaveid_string(self, host): | ||
key = "modbus_read_registers["+host+",bad,1,3,uint32,BE,0]" | ||
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Check slaveid parameter' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import pytest | ||
from zabbix_get import zabbix_get | ||
|
||
|
||
class TestModbusShort(object): | ||
|
||
# test coils(bits) | ||
|
||
def test_modbus_datatype_short_bit_0(self, host): | ||
key = "modbus_read["+host+",1,1,1,b]" | ||
assert zabbix_get(key) == '1' | ||
|
||
# 16bit, all tests are PDU (start from 0 address) | ||
# INT16,Big Endian | ||
def test_modbus_datatype_short_signed_1(self, host): | ||
key = "modbus_read["+host+",1,1,3,s,1]" | ||
assert zabbix_get(key) == '-15859.000000' | ||
|
||
# UINT16,Big Endian, i | ||
def test_modbus_datatype_short_unsigned_2(self, host): | ||
key = "modbus_read["+host+",1,1,3,i,1]" | ||
assert zabbix_get(key) == '49677' | ||
|
||
# 32bit. | ||
# Float. In 32bit float we are looking for "-71.879005" | ||
# Big Endian (ABCD) | ||
def test_modbus_datatype_short_float_32bit_be_abcd_0(self, host): | ||
key = "modbus_read["+host+",1,0,3,f,1]" | ||
assert zabbix_get(key) == '-71.879005' | ||
# Little Endian with Wordswap or Mid-Little Endian (CDAB) | ||
|
||
def test_modbus_datatype_short_float_32bit_mle_cdab_0(self, host): | ||
key = "modbus_read["+host+",1,4,3,f,0]" | ||
assert zabbix_get(key) == '-71.879005' | ||
# Big Endian with WordSwap or Mid-Big Endian (BADC) | ||
|
||
def test_modbus_datatype_short_float_32bit_mbe_badc_0(self, host): | ||
key = "modbus_read["+host+",1,2,3,f,2]" | ||
assert zabbix_get(key) == '-71.879005' | ||
# Little Endian (DCBA) | ||
|
||
def test_modbus_datatype_short_float_32bit_le_dcba_0(self, host): | ||
key = "modbus_read["+host+",1,6,3,f,3]" | ||
assert zabbix_get(key) == '-71.879005' | ||
|
||
# UINT32,unsigned,long: | ||
# Big Endian (ABCD) | ||
def test_modbus_datatype_short_long_32bit_be_abcd_0(self, host): | ||
key = "modbus_read["+host+",1,0,3,l,1]" | ||
assert zabbix_get(key) == '3264201229' | ||
|
||
# INT32(Signed) | ||
# Big Endian (ABCD) | ||
def test_modbus_datatype_short_int32_be_0(self, host): | ||
key = "modbus_read["+host+",1,12,3,S,1]" | ||
assert zabbix_get(key) == '-562.000000' | ||
|
||
# UNSIGNED INT64 | ||
# Big Endian | ||
|
||
def test_modbus_datatype_short_uint64_64bit_be_0(self, host): | ||
key = "modbus_read["+host+",1,14,3,I,1]" | ||
assert zabbix_get(key) == '13816931967501922940' | ||
|
||
# FLOAT64(double) | ||
# Big Endian | ||
def test_modbus_datatype_short_double_64bit_be_0(self, host): | ||
key = "modbus_read["+host+",1,14,3,d,1]" | ||
assert zabbix_get(key) == '-0.123450' |
Oops, something went wrong.