diff --git a/congress_tempest_tests/services/policy/policy_client.py b/congress_tempest_tests/services/policy/policy_client.py index 7e15717ab..76e576bf0 100644 --- a/congress_tempest_tests/services/policy/policy_client.py +++ b/congress_tempest_tests/services/policy/policy_client.py @@ -41,8 +41,9 @@ class PolicyClient(rest_client.RestClient): driver = '/v1/system/drivers' driver_path = '/v1/system/drivers/%s' - def _resp_helper(self, resp, body): - body = json.loads(body) + def _resp_helper(self, resp, body=None): + if body: + body = json.loads(body) return rest_client.ResponseBody(resp, body) def create_policy(self, body): @@ -150,6 +151,12 @@ class PolicyClient(rest_client.RestClient): self.datasource_path % datasource) return self._resp_helper(resp, body) + def update_datasource_row(self, datasource_name, table_id, rows): + body = json.dumps(rows) + resp, body = self.put( + self.datasource_rows % (datasource_name, table_id), body) + return self._resp_helper(resp) + def execute_datasource_action(self, service_name, action, body): body = json.dumps(body) uri = "?action=%s" % (action) diff --git a/congress_tempest_tests/tests/scenario/congress_datasources/test_doctor.py b/congress_tempest_tests/tests/scenario/congress_datasources/test_doctor.py new file mode 100644 index 000000000..ee58fe8ad --- /dev/null +++ b/congress_tempest_tests/tests/scenario/congress_datasources/test_doctor.py @@ -0,0 +1,78 @@ +# Copyright 2016 NTT All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tempest.lib import exceptions +from tempest import test + +from congress_tempest_tests.tests.scenario import manager_congress + + +class TestDoctorDriver(manager_congress.ScenarioPolicyBase): + def setUp(self): + super(TestDoctorDriver, self).setUp() + doctor_setting = { + 'name': 'doctor', + 'driver': 'doctor', + 'config': None, + } + self.client = self.admin_manager.congress_client + + response = self.client.create_datasource(doctor_setting) + self.datasource_id = response['id'] + + def tearDown(self): + super(TestDoctorDriver, self).tearDown() + self.client.delete_datasource(self.datasource_id) + + def _list_datasource_rows(self, datasource, table): + return self.client.list_datasource_rows(datasource, table) + + @test.attr(type='smoke') + def test_doctor_event_tables(self): + rows = [ + { + "id": "0123-4567-89ab", + "time": "2016-02-22T11:48:55Z", + "type": "compute.host.down", + "details": { + "hostname": "compute1", + "status": "down", + "monitor": "zabbix1", + "monitor_event_id": "111" + } + } + ] + + expected_row = [ + "0123-4567-89ab", + "2016-02-22T11:48:55Z", + "compute.host.down", + "compute1", + "down", + "zabbix1", + "111" + ] + + 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) diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 352aa7608..5146572de 100755 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -79,6 +79,7 @@ function configure_congress { CONGRESS_DRIVERS+="congress.datasources.murano_driver.MuranoDriver," CONGRESS_DRIVERS+="congress.datasources.ironic_driver.IronicDriver," CONGRESS_DRIVERS+="congress.datasources.heatv1_driver.HeatV1Driver," + CONGRESS_DRIVERS+="congress.datasources.doctor_driver.DoctorDriver," CONGRESS_DRIVERS+="congress.tests.fake_datasource.FakeDataSource" iniset $CONGRESS_CONF DEFAULT drivers $CONGRESS_DRIVERS @@ -109,7 +110,6 @@ function configure_congress_datasources { _configure_service ironic ironic _configure_service heat heat - } function _configure_service {