def execute(self, group_id=None): """Statistics on a Group. It returns how many promotions and demotions were executed within a group. Specifically, a list with the following fields are returned: group_id, number of promotions, number of demotions. :param group_id: Group one wants to retrieve information on. """ rset = ResultSet( names=('group_id', 'call_count', 'call_abort'), types=(str, long, long), ) for row in MySQLHandler.group_view(group_id): rset.append_row(row) return CommandResult(None, results=rset)
def test_group_view(self): # Try to retrieve non-existent group. res = MySQLHandler.group_view("non-existent") self.assertEqual(len(res), 0) # Retrieve information on a group and check demote and promote. _LOGGER.debug("Master is being promoted.", extra={ 'subject' : 'group_id_1', 'category' : MySQLHandler.GROUP, 'type' : MySQLHandler.PROMOTE, 'reporter' : 'test_handler' } ) _LOGGER.debug("Master is being demoted.", extra={ 'subject' : 'group_id_1', 'category' : MySQLHandler.GROUP, 'type' : MySQLHandler.DEMOTE, 'reporter' : 'test_handler' } ) _LOGGER.debug("Master is being promoted.", extra={ 'subject' : 'group_id_1', 'category' : MySQLHandler.GROUP, 'type' : MySQLHandler.PROMOTE, 'reporter' : 'test_handler' } ) res = MySQLHandler.group_view("group_id_1") self.assertEqual(len(res), 1) self.assertEqual(res[0][1], 2) self.assertEqual(res[0][2], 1) # Retrieve information on groups with similar name patterns. _LOGGER.debug("Master is being promoted.", extra={ 'subject' : 'group_id_2', 'category' : MySQLHandler.GROUP, 'type' : MySQLHandler.PROMOTE, 'reporter' : 'test_handler' } ) res = MySQLHandler.group_view("group_id_2") self.assertEqual(len(res), 1) self.assertEqual(res[0][1], 1) self.assertEqual(res[0][2], 0) res = MySQLHandler.group_view("group_id") self.assertEqual(len(res), 2) # Retrieve information on groups with different name patterns, # i.e. all groups. _LOGGER.debug("Master is being promoted.", extra={ 'subject' : 'abc_group', 'category' : MySQLHandler.GROUP, 'type' : MySQLHandler.PROMOTE, 'reporter' : 'test_handler' } ) res = MySQLHandler.group_view() self.assertEqual(len(res), 3)