예제 #1
0
    def test_doctor_event_tables(self):
        rows = [
            {
                "time": "2016-02-22T11:48:55Z",
                "type": "compute.host.down",
                "details": {
                    "hostname": "compute1",
                    "status": "down",
                    "monitor": "zabbix1",
                    "monitor_event_id": "111"
                    }
                }
            ]

        expected_row = [
            "2016-02-22T11:48:55Z",
            "compute.host.down",
            "compute1",
            "down",
            "zabbix1",
            "111"
            ]

        # Check if service is up
        @helper.retry_on_exception
        def _check_service():
            self.client.list_datasource_status(self.datasource_id)
            return True

        if not test_utils.call_until_true(func=_check_service,
                                          duration=60, sleep_for=1):
            raise exceptions.TimeoutException("Doctor dataservice is not up")

        self.client.update_datasource_row(self.datasource_id, 'events', rows)
        results = self._list_datasource_rows(self.datasource_id, 'events')
        if len(results['results']) != 1:
            error_msg = ('Unexpected additional rows are '
                         'inserted. row details: %s' % results['results'])
            raise exceptions.InvalidStructure(error_msg)

        if results['results'][0]['data'] != expected_row:
            msg = ('inserted row %s is not expected row %s'
                   % (results['data'], expected_row))
            raise exceptions.InvalidStructure(msg)
예제 #2
0
def details_multiple(output_lines, with_label=False):
    """Return list of dicts with item details from cli output tables.

    If with_label is True, key '__label' is added to each items dict.
    For more about 'label' see OutputParser.tables().
    """
    items = []
    tables_ = tables(output_lines)
    for table_ in tables_:
        if ('Property' not in table_['headers']
                or 'Value' not in table_['headers']):
            raise exceptions.InvalidStructure()
        item = {}
        for value in table_['values']:
            item[value[0]] = value[1]
        if with_label:
            item['__label'] = table_['label']
        items.append(item)
    return items
예제 #3
0
    def details_multiple(self, output_lines, with_label=False):
        """Return list of dicts with item details from cli output tables.

        If with_label is True, key '__label' is added to each items dict.
        For more about 'label' see OutputParser.tables().

        NOTE(sileht): come from tempest-lib just because cliff use
        Field instead of Property as first columun header.
        """
        items = []
        tables_ = self.parser.tables(output_lines)
        for table_ in tables_:
            if ('Field' not in table_['headers']
                    or 'Value' not in table_['headers']):
                raise exceptions.InvalidStructure()
            item = {}
            for value in table_['values']:
                item[value[0]] = value[1]
            if with_label:
                item['__label'] = table_['label']
            items.append(item)
        return items