Best Python code snippet using autotest_python
monitor_db_cleanup.py
Source:monitor_db_cleanup.py  
...168        if query.count() != 0:169            subject = ('%d queue entries found with active=complete=1'170                       % query.count())171            lines = [str(entry.get_object_dict()) for entry in query]172            self._send_inconsistency_message(subject, lines)173    def _check_for_multiple_platform_hosts(self):174        rows = self._db.execute("""175            SELECT hosts.id, hostname, COUNT(1) AS platform_count,176                   GROUP_CONCAT(labels.name)177            FROM hosts178            INNER JOIN hosts_labels ON hosts.id = hosts_labels.host_id179            INNER JOIN labels ON hosts_labels.label_id = labels.id180            WHERE labels.platform181            GROUP BY hosts.id182            HAVING platform_count > 1183            ORDER BY hostname""")184        if rows:185            subject = '%s hosts with multiple platforms' % self._db.rowcount186            lines = [' '.join(str(item) for item in row)187                     for row in rows]188            self._send_inconsistency_message(subject, lines)189    def _check_for_no_platform_hosts(self):190        rows = self._db.execute("""191            SELECT hostname192            FROM hosts193            LEFT JOIN hosts_labels194              ON hosts.id = hosts_labels.host_id195              AND hosts_labels.label_id IN (SELECT id FROM labels196                                            WHERE platform)197            WHERE NOT hosts.invalid AND hosts_labels.host_id IS NULL""")198        if rows:199            subject = '%s hosts with no platform' % self._db.rowcount200            self._send_inconsistency_message(201                subject, [', '.join(row[0] for row in rows)])202    def _check_for_multiple_atomic_group_hosts(self):203        rows = self._db.execute("""204            SELECT hosts.id, hostname, COUNT(1) AS atomic_group_count,205                   GROUP_CONCAT(labels.name), GROUP_CONCAT(atomic_groups.name)206            FROM hosts207            INNER JOIN hosts_labels ON hosts.id = hosts_labels.host_id208            INNER JOIN labels ON hosts_labels.label_id = labels.id209            INNER JOIN atomic_groups ON210                       labels.atomic_group_id = atomic_groups.id211            WHERE NOT hosts.invalid AND NOT labels.invalid212            GROUP BY hosts.id213            HAVING atomic_group_count > 1214            ORDER BY hostname""")215        if rows:216            subject = '%s hosts with multiple atomic groups' % self._db.rowcount217            lines = [' '.join(str(item) for item in row)218                     for row in rows]219            self._send_inconsistency_message(subject, lines)220    def _send_inconsistency_message(self, subject, lines):221        logging.error(subject)222        message = '\n'.join(lines)223        if len(message) > 5000:224            message = message[:5000] + '\n(truncated)\n'...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
