From 835c9aeb7822aee8334400c15496932feeea18ae Mon Sep 17 00:00:00 2001 From: dongwenjuan Date: Mon, 17 Sep 2018 10:42:07 +0800 Subject: delete doctor datasource in congress when cleanup If we delete doctor driver in congress configuration when cleanup, the doctor datasource still existed, it will be raise an exeption in congress server and the service can't be started. Change-Id: Icefde9964229ef3d55af09cc2e81680cb8d19813 Signed-off-by: dongwenjuan --- doctor_tests/inspector/congress.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'doctor_tests') diff --git a/doctor_tests/inspector/congress.py b/doctor_tests/inspector/congress.py index fb747ec5..7f918fb2 100644 --- a/doctor_tests/inspector/congress.py +++ b/doctor_tests/inspector/congress.py @@ -31,6 +31,8 @@ class CongressInspector(BaseInspector): def __init__(self, conf, log): super(CongressInspector, self).__init__(conf, log) + self.is_create_doctor_datasource = False + self.doctor_datasource_id = None self.auth = get_identity_auth() self.congress = congress_client(get_session(auth=self.auth)) self._init_driver_and_ds() @@ -48,12 +50,6 @@ class CongressInspector(BaseInspector): 'version < nova_api_min_version(%s)' % self.nova_api_min_version) - # create doctor datasource if it's not exist - if self.doctor_datasource not in datasources: - self.congress.create_datasource( - body={'driver': self.doctor_driver, - 'name': self.doctor_datasource}) - # check whether doctor driver exist drivers = \ {driver['id']: driver for driver in @@ -61,6 +57,14 @@ class CongressInspector(BaseInspector): if self.doctor_driver not in drivers: raise Exception('Do not support doctor driver in congress') + # create doctor datasource if it's not exist + if self.doctor_datasource not in datasources: + response = self.congress.create_datasource( + body={'driver': self.doctor_driver, + 'name': self.doctor_datasource}) + self.doctor_datasource_id = response['id'] + self.is_create_doctor_datasource = True + self.policy_rules = \ {rule['name']: rule for rule in self.congress.list_policy_rules(self.policy)['results']} @@ -86,6 +90,9 @@ class CongressInspector(BaseInspector): for rule_name in self.rules.keys(): self._del_rule(rule_name) + if self.is_create_doctor_datasource: + self.congress.delete_datasource(self.doctor_datasource_id) + def _add_rule(self, rule_name, rule): if rule_name not in self.policy_rules: self.congress.create_policy_rule(self.policy, -- cgit 1.2.3-korg