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
This commit is contained in:
Slawek Kaplonski 2020-04-23 23:27:55 +02:00 committed by Federico Ressi
parent 0a367b96dd
commit 4ee3dced06
5 changed files with 59 additions and 1 deletions

View File

@ -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()

18
tobiko/common/_utils.py Normal file
View File

@ -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]

View File

@ -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

View File

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