Add helper to get uuids of machines w/OVN chassis
Refactor get_machines_for_application as generator function instead of building and passing on static List.
This commit is contained in:
@@ -101,8 +101,8 @@ class TestJujuUtils(ut_utils.BaseTestCase):
|
||||
|
||||
# Machine data
|
||||
self.assertEqual(
|
||||
juju_utils.get_machines_for_application(self.application),
|
||||
[self.machine])
|
||||
next(juju_utils.get_machines_for_application(self.application)),
|
||||
self.machine)
|
||||
self.get_application_status.assert_called_once()
|
||||
|
||||
# Subordinate application has no units
|
||||
@@ -115,9 +115,9 @@ class TestJujuUtils(ut_utils.BaseTestCase):
|
||||
self.get_application_status.side_effect = _get_application_status
|
||||
|
||||
self.assertEqual(
|
||||
juju_utils.get_machines_for_application(
|
||||
self.subordinate_application),
|
||||
[self.machine])
|
||||
next(juju_utils.get_machines_for_application(
|
||||
self.subordinate_application)),
|
||||
self.machine)
|
||||
|
||||
def test_get_unit_name_from_host_name(self):
|
||||
unit_mock1 = mock.MagicMock()
|
||||
@@ -151,8 +151,9 @@ class TestJujuUtils(ut_utils.BaseTestCase):
|
||||
self.get_machines_for_application.return_value = [self.machine]
|
||||
|
||||
self.assertEqual(
|
||||
juju_utils.get_machine_uuids_for_application(self.application),
|
||||
[self.machine_data.get("instance-id")])
|
||||
next(juju_utils.get_machine_uuids_for_application(
|
||||
self.application)),
|
||||
self.machine_data.get("instance-id"))
|
||||
self.get_machines_for_application.assert_called_once_with(
|
||||
self.application)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
import copy
|
||||
import datetime
|
||||
import io
|
||||
import itertools
|
||||
import mock
|
||||
import tenacity
|
||||
|
||||
@@ -814,12 +815,13 @@ class TestOpenStackUtils(ut_utils.BaseTestCase):
|
||||
)
|
||||
|
||||
# No machine returned
|
||||
self._get_machines.return_value = []
|
||||
self._get_machines.side_effect = StopIteration
|
||||
with self.assertRaises(exceptions.ApplicationNotFound):
|
||||
openstack_utils.get_current_os_release_pair()
|
||||
self._get_machines.side_effect = None
|
||||
|
||||
# No series returned
|
||||
self._get_machines.return_value = ['6']
|
||||
self._get_machines.return_value = itertools.repeat('6')
|
||||
self._get_machine_series.return_value = None
|
||||
with self.assertRaises(exceptions.SeriesNotFound):
|
||||
openstack_utils.get_current_os_release_pair()
|
||||
@@ -1165,3 +1167,30 @@ class TestOpenStackUtils(ut_utils.BaseTestCase):
|
||||
'OS_PROJECT_NAME': 'services'},
|
||||
scope='PROJECT',
|
||||
verify=None)
|
||||
|
||||
def test_get_gateway_uuids(self):
|
||||
self.patch_object(openstack_utils.juju_utils,
|
||||
'get_machine_uuids_for_application')
|
||||
self.get_machine_uuids_for_application.return_value = 'ret'
|
||||
self.assertEquals(openstack_utils.get_gateway_uuids(), 'ret')
|
||||
self.get_machine_uuids_for_application.assert_called_once_with(
|
||||
'neutron-gateway')
|
||||
|
||||
def test_get_ovs_uuids(self):
|
||||
self.patch_object(openstack_utils.juju_utils,
|
||||
'get_machine_uuids_for_application')
|
||||
self.get_machine_uuids_for_application.return_value = 'ret'
|
||||
self.assertEquals(openstack_utils.get_ovs_uuids(), 'ret')
|
||||
self.get_machine_uuids_for_application.assert_called_once_with(
|
||||
'neutron-openvswitch')
|
||||
|
||||
def test_get_ovn_uuids(self):
|
||||
self.patch_object(openstack_utils.juju_utils,
|
||||
'get_machine_uuids_for_application')
|
||||
self.get_machine_uuids_for_application.return_value = ['ret']
|
||||
self.assertEquals(list(openstack_utils.get_ovn_uuids()),
|
||||
['ret', 'ret'])
|
||||
self.get_machine_uuids_for_application.assert_has_calls([
|
||||
mock.call('ovn-chassis'),
|
||||
mock.call('ovn-dedicated-chassis'),
|
||||
])
|
||||
|
||||
@@ -81,21 +81,18 @@ def get_machines_for_application(application):
|
||||
|
||||
:param application: Application name
|
||||
:type application: string
|
||||
:returns: List of machines for an application
|
||||
:rtype: list
|
||||
:returns: machines for an application
|
||||
:rtype: Iterator[str]
|
||||
"""
|
||||
status = get_application_status(application)
|
||||
|
||||
# libjuju juju status no longer has units for subordinate charms
|
||||
# Use the application it is subordinate-to to find machines
|
||||
if status.get("units") is None and status.get("subordinate-to"):
|
||||
return get_machines_for_application(status.get("subordinate-to")[0])
|
||||
status = get_application_status(status.get("subordinate-to")[0])
|
||||
|
||||
machines = []
|
||||
for unit in status.get("units").keys():
|
||||
machines.append(
|
||||
status.get("units").get(unit).get("machine"))
|
||||
return machines
|
||||
yield status.get("units").get(unit).get("machine")
|
||||
|
||||
|
||||
def get_unit_name_from_host_name(host_name, application):
|
||||
@@ -151,13 +148,11 @@ def get_machine_uuids_for_application(application):
|
||||
|
||||
:param application: Application name
|
||||
:type application: string
|
||||
:returns: List of machine uuuids for an application
|
||||
:rtype: list
|
||||
:returns: machine uuuids for an application
|
||||
:rtype: Iterator[str]
|
||||
"""
|
||||
uuids = []
|
||||
for machine in get_machines_for_application(application):
|
||||
uuids.append(get_machine_status(machine, key="instance-id"))
|
||||
return uuids
|
||||
yield get_machine_status(machine, key="instance-id")
|
||||
|
||||
|
||||
def get_provider_type():
|
||||
|
||||
@@ -45,6 +45,7 @@ from swiftclient import client as swiftclient
|
||||
|
||||
import datetime
|
||||
import io
|
||||
import itertools
|
||||
import juju_wait
|
||||
import logging
|
||||
import os
|
||||
@@ -55,8 +56,8 @@ import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import tenacity
|
||||
import urllib
|
||||
import textwrap
|
||||
import urllib
|
||||
|
||||
from zaza import model
|
||||
from zaza.openstack.utilities import (
|
||||
@@ -434,7 +435,7 @@ def get_gateway_uuids():
|
||||
"""Return machine uuids for neutron-gateway(s).
|
||||
|
||||
:returns: List of uuids
|
||||
:rtype: list
|
||||
:rtype: Iterator[str]
|
||||
"""
|
||||
return juju_utils.get_machine_uuids_for_application('neutron-gateway')
|
||||
|
||||
@@ -443,12 +444,24 @@ def get_ovs_uuids():
|
||||
"""Return machine uuids for neutron-openvswitch(s).
|
||||
|
||||
:returns: List of uuids
|
||||
:rtype: list
|
||||
:rtype: Iterator[str]
|
||||
"""
|
||||
return (juju_utils
|
||||
.get_machine_uuids_for_application('neutron-openvswitch'))
|
||||
|
||||
|
||||
def get_ovn_uuids():
|
||||
"""Provide machine uuids for OVN Chassis.
|
||||
|
||||
:returns: List of uuids
|
||||
:rtype: Iterator[str]
|
||||
"""
|
||||
return itertools.chain(
|
||||
juju_utils.get_machine_uuids_for_application('ovn-chassis'),
|
||||
juju_utils.get_machine_uuids_for_application('ovn-dedicated-chassis'),
|
||||
)
|
||||
|
||||
|
||||
BRIDGE_MAPPINGS = 'bridge-mappings'
|
||||
NEW_STYLE_NETWORKING = 'physnet1:br-ex'
|
||||
|
||||
@@ -1358,10 +1371,9 @@ def get_current_os_release_pair(application='keystone'):
|
||||
:raises: exceptions.SeriesNotFound
|
||||
:raises: exceptions.OSVersionNotFound
|
||||
"""
|
||||
machines = juju_utils.get_machines_for_application(application)
|
||||
if len(machines) >= 1:
|
||||
machine = machines[0]
|
||||
else:
|
||||
try:
|
||||
machine = next(juju_utils.get_machines_for_application(application))
|
||||
except StopIteration:
|
||||
raise exceptions.ApplicationNotFound(application)
|
||||
|
||||
series = juju_utils.get_machine_series(machine)
|
||||
|
||||
Reference in New Issue
Block a user