def afterSetUp(self): self.device = DeviceProxy() self.device.id = "test" self.device.manageIp = "127.0.0.1" self.logger = logging.getLogger('.'.join(['zen', __name__])) ObjectMap.asUnitTest = patch_asUnitTest self.collector = MySQLCollector() self.collector._eventService = MagicMock() self.collector.queries = {'test': 'test'}
class TestMySQLCollector(BaseTestCase): def afterSetUp(self): self.device = DeviceProxy() self.device.id = "test" self.device.manageIp = "127.0.0.1" self.logger = logging.getLogger('.'.join(['zen', __name__])) ObjectMap.asUnitTest = patch_asUnitTest self.collector = MySQLCollector() self.collector._eventService = MagicMock() self.collector.queries = {'test': 'test'} def test_process_data(self): results = modeling_data.RESULT1 server_map, db_map = self.collector.\ process(self.device, results, self.logger) self.assertEquals( { 'data_size': 53423729, 'id': 'root_3306', 'index_size': 4143104, 'master_status': 'OFF', 'percent_full_table_scans': '71.2%', 'size': 57566833, 'slave_status': 'IO running: No; SQL running: ' 'No; Seconds behind: None', 'version': '5.5.28 MySQL Community Server (GPL) (i686)', 'title': 'root_3306' }, server_map.maps[0].asUnitTest()) self.assertEquals( { 'data_size': 0, 'default_character_set_name': 'utf8', 'default_collation_name': 'utf8_general_ci', 'id': 'root_3306(.)information_schema', 'index_size': 9216, 'size': 9216, 'table_count': 40L, 'title': 'information_schema' }, db_map.maps[0].asUnitTest()) @patch('ZenPacks.zenoss.MySqlMonitor.modeler.' 'plugins.MySQLCollector.adbapi') def test_collect(self, mock_adbapi): self.device.zMySQLConnectionString = [ '{"user":"******",' '"passwd":"zenoss",' '"port":"3306"}' ] self.collector.collect(self.device, self.logger) mock_adbapi.ConnectionPool.assert_called_with( 'MySQLdb', passwd='zenoss', port=3306, host='127.0.0.1', user='******', cursorclass=cursors.DictCursor) def test_table_scans(self): self.assertEquals( self.collector._table_scans(modeling_data.SERVER_STATUS1), '71.2%') self.assertEquals( self.collector._table_scans(modeling_data.SERVER_STATUS2), 'N/A') def test_master_status(self): self.assertEquals( self.collector._master_status(modeling_data.MASTER_STATUS1), "ON; File: mysql-bin.000002; Position: 107") self.assertEquals( self.collector._master_status(modeling_data.MASTER_STATUS2), "OFF") def test_slave_status(self): self.assertEquals( self.collector._slave_status(modeling_data.SLAVE_STATUS1), "IO running: No; SQL running: No; Seconds behind: 10") self.assertEquals( self.collector._slave_status(modeling_data.SLAVE_STATUS2), "OFF") def test_version(self): self.assertEquals(self.collector._version(modeling_data.VERSION1), '5.5.28 MySQL Community Server (GPL) (i686)')
class TestMySQLCollector(BaseTestCase): def afterSetUp(self): self.device = DeviceProxy() self.device.id = "test" self.device.manageIp = "127.0.0.1" self.logger = logging.getLogger('.'.join(['zen', __name__])) ObjectMap.asUnitTest = patch_asUnitTest self.collector = MySQLCollector() self.collector._eventService = MagicMock() self.collector.queries = {'test': 'test'} def test_process_data(self): results = modeling_data.RESULT1 server_map, db_map = self.collector.\ process(self.device, results, self.logger) self.assertEquals({ 'data_size': 53423729, 'id': 'root_3306', 'index_size': 4143104, 'master_status': 'OFF', 'percent_full_table_scans': '0.0%', 'size': 57566833, 'slave_status': 'IO running: No; SQL running: ' 'No; Seconds behind: None', 'version': '5.5.28 MySQL Community Server (GPL) (i686)', 'title': 'root_3306'}, server_map.maps[0].asUnitTest()) self.assertEquals({ 'data_size': 0, 'default_character_set_name': 'utf8', 'default_collation_name': 'utf8_general_ci', 'id': 'root_3306(.)information_schema', 'index_size': 9216, 'size': 9216, 'table_count': 40L, 'title': 'information_schema'}, db_map.maps[0].asUnitTest()) @patch('ZenPacks.zenoss.MySqlMonitor.modeler.' 'plugins.MySQLCollector.adbapi') def test_collect(self, mock_adbapi): self.device.zMySQLConnectionString = ['{"user":"******",' '"passwd":"zenoss",' '"port":"3306"}'] self.collector.collect(self.device, self.logger) mock_adbapi.ConnectionPool.assert_called_with( 'MySQLdb', passwd='zenoss', port=3306, host='127.0.0.1', user='******', cursorclass=cursors.DictCursor ) def test_table_scans(self): self.assertEquals( self.collector._table_scans(modeling_data.SERVER_STATUS1), '0.0%' ) self.assertEquals( self.collector._table_scans(modeling_data.SERVER_STATUS2), 'N/A' ) self.assertEquals( self.collector._table_scans(modeling_data.SERVER_STATUS3), '50.0%' ) def test_master_status(self): self.assertEquals( self.collector._master_status(modeling_data.MASTER_STATUS1), "ON; File: mysql-bin.000002; Position: 107" ) self.assertEquals( self.collector._master_status(modeling_data.MASTER_STATUS2), "OFF" ) def test_slave_status(self): self.assertEquals( self.collector._slave_status(modeling_data.SLAVE_STATUS1), "IO running: No; SQL running: No; Seconds behind: 10" ) self.assertEquals( self.collector._slave_status(modeling_data.SLAVE_STATUS2), "OFF" ) def test_version(self): self.assertEquals( self.collector._version(modeling_data.VERSION1), '5.5.28 MySQL Community Server (GPL) (i686)' )