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."))