From 4ee3dced06a681a719d42502b3f45a799094f77b Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Thu, 23 Apr 2020 23:27:55 +0200 Subject: [PATCH] Fix looking for ovs agent based on compute node name In neutron agents faults tests module, there is test which looks for neutron-ovs-agent which runs on same host as VM is spawned to stop this neutron-ovs-agent. This usually worked fine, but in case e.g. of TripleO hostname given in neutron agents list contained full domain name and hostname from nova's output containes short name. Because of this missmatch there was no neutron-ovs-agent found to stop and test was failing. This patch fixes this issue by changing comparison of hostnames of vm's host and agent's host. Additionally this patch adds proper handling of the case when neutron-ovs-agent isn't found. Change-Id: If240188392feb6067af4f9a4a82e8ed95b4b99ee --- tobiko/__init__.py | 3 ++ tobiko/common/_utils.py | 18 +++++++++++ tobiko/common/utils/__init__.py | 0 .../faults/agents/test_neutron_agents.py | 9 +++++- tobiko/tests/unit/test_utils.py | 30 +++++++++++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tobiko/common/_utils.py delete mode 100644 tobiko/common/utils/__init__.py create mode 100644 tobiko/tests/unit/test_utils.py diff --git a/tobiko/__init__.py b/tobiko/__init__.py index 31923b8f7..17ab5092d 100644 --- a/tobiko/__init__.py +++ b/tobiko/__init__.py @@ -25,6 +25,7 @@ from tobiko.common import _operation from tobiko.common import _os from tobiko.common import _select from tobiko.common import _skip +from tobiko.common import _utils details_content = _detail.details_content @@ -89,6 +90,8 @@ skip = _skip.skip skip_if = _skip.skip_if skip_unless = _skip.skip_unless +get_short_hostname = _utils.get_short_hostname + from tobiko import config # noqa config.init_config() diff --git a/tobiko/common/_utils.py b/tobiko/common/_utils.py new file mode 100644 index 000000000..c117259b6 --- /dev/null +++ b/tobiko/common/_utils.py @@ -0,0 +1,18 @@ +# Copyright 2020 Red Hat +# +# 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 __future__ import absolute_import + + +def get_short_hostname(hostname): + return hostname.lower().split('.', 1)[0] diff --git a/tobiko/common/utils/__init__.py b/tobiko/common/utils/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tobiko/tests/faults/agents/test_neutron_agents.py b/tobiko/tests/faults/agents/test_neutron_agents.py index 00bf197e5..0561bc99b 100644 --- a/tobiko/tests/faults/agents/test_neutron_agents.py +++ b/tobiko/tests/faults/agents/test_neutron_agents.py @@ -31,6 +31,10 @@ from tobiko.shell import sh LOG = log.getLogger(__name__) +class AgentNotFoundOnHost(tobiko.TobikoException): + message = ("Agent {agent_type!s} not found on the host {host!s}") + + class AgentTestMixin(object): def stop_service_on_agents(self, service_name, agents): @@ -341,9 +345,12 @@ class OvsAgentTest(testtools.TestCase, AgentTestMixin): self.agent_service_name, self.stopped_agents) def _get_agent_from_host(self, host): + host_shortname = tobiko.get_short_hostname(host.name) for agent in self.ovs_agents: - if agent['host'] == host.name: + if host_shortname == tobiko.get_short_hostname(agent['host']): return agent + raise AgentNotFoundOnHost(agent_type="neutron-ovs-agent", + host=host.name) def test_vm_reachability_during_stop_ovs_agent(self): # Check if vm is reachable before test diff --git a/tobiko/tests/unit/test_utils.py b/tobiko/tests/unit/test_utils.py new file mode 100644 index 000000000..7be2da65a --- /dev/null +++ b/tobiko/tests/unit/test_utils.py @@ -0,0 +1,30 @@ +# Copyright 2020 Red Hat +# +# 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 __future__ import absolute_import + +import tobiko +from tobiko.tests import unit + + +class UtilsTests(unit.TobikoUnitTest): + + def test_get_short_hostname(self): + self.assertEqual("testhost", tobiko.get_short_hostname("testhost")) + self.assertEqual("testhost", tobiko.get_short_hostname("TesTHoSt")) + self.assertEqual( + "testhost", tobiko.get_short_hostname("testhost.domain")) + self.assertEqual( + "testhost", tobiko.get_short_hostname("teSthOsT.dOmAin")) + self.assertEqual("testhost", tobiko.get_short_hostname("testhost.")) + self.assertEqual("testhost", tobiko.get_short_hostname("TesTHoSt."))