Merge "segments use neutron_lib placement client"
This commit is contained in:
commit
740a52f50c
@ -1,179 +0,0 @@
|
||||
# Copyright (c) 2016 IBM
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import functools
|
||||
|
||||
from keystoneauth1 import exceptions as ks_exc
|
||||
from keystoneauth1 import loading as ks_loading
|
||||
from neutron_lib.exceptions import placement as placement_exc
|
||||
from oslo_config import cfg
|
||||
|
||||
from neutron._i18n import _
|
||||
|
||||
PLACEMENT_API_WITH_AGGREGATES = 'placement 1.1'
|
||||
|
||||
|
||||
def check_placement_api_available(f):
|
||||
@functools.wraps(f)
|
||||
def wrapper(self, *a, **k):
|
||||
try:
|
||||
return f(self, *a, **k)
|
||||
except ks_exc.EndpointNotFound:
|
||||
raise placement_exc.PlacementEndpointNotFound()
|
||||
return wrapper
|
||||
|
||||
|
||||
class PlacementAPIClient(object):
|
||||
"""Client class for placement ReST API."""
|
||||
|
||||
ks_filter = {'service_type': 'placement',
|
||||
'region_name': cfg.CONF.placement.region_name}
|
||||
|
||||
def __init__(self):
|
||||
auth_plugin = ks_loading.load_auth_from_conf_options(
|
||||
cfg.CONF, 'placement')
|
||||
self._client = ks_loading.load_session_from_conf_options(
|
||||
cfg.CONF, 'placement', auth=auth_plugin)
|
||||
self._disabled = False
|
||||
|
||||
def _get(self, url, **kwargs):
|
||||
return self._client.get(url, endpoint_filter=self.ks_filter,
|
||||
**kwargs)
|
||||
|
||||
def _post(self, url, data, **kwargs):
|
||||
return self._client.post(url, json=data,
|
||||
endpoint_filter=self.ks_filter, **kwargs)
|
||||
|
||||
def _put(self, url, data, **kwargs):
|
||||
return self._client.put(url, json=data, endpoint_filter=self.ks_filter,
|
||||
**kwargs)
|
||||
|
||||
def _delete(self, url, **kwargs):
|
||||
return self._client.delete(url, endpoint_filter=self.ks_filter,
|
||||
**kwargs)
|
||||
|
||||
@check_placement_api_available
|
||||
def create_resource_provider(self, resource_provider):
|
||||
"""Create a resource provider.
|
||||
|
||||
:param resource_provider: The resource provider
|
||||
:type resource_provider: dict: name (required), uuid (required)
|
||||
"""
|
||||
url = '/resource_providers'
|
||||
self._post(url, resource_provider)
|
||||
|
||||
@check_placement_api_available
|
||||
def delete_resource_provider(self, resource_provider_uuid):
|
||||
"""Delete a resource provider.
|
||||
|
||||
:param resource_provider_uuid: UUID of the resource provider
|
||||
:type resource_provider_uuid: str
|
||||
"""
|
||||
url = '/resource_providers/%s' % resource_provider_uuid
|
||||
self._delete(url)
|
||||
|
||||
@check_placement_api_available
|
||||
def create_inventory(self, resource_provider_uuid, inventory):
|
||||
"""Create an inventory.
|
||||
|
||||
:param resource_provider_uuid: UUID of the resource provider
|
||||
:type resource_provider_uuid: str
|
||||
:param inventory: The inventory
|
||||
:type inventory: dict: resource_class (required), total (required),
|
||||
reserved (required), min_unit (required), max_unit (required),
|
||||
step_size (required), allocation_ratio (required)
|
||||
"""
|
||||
url = '/resource_providers/%s/inventories' % resource_provider_uuid
|
||||
self._post(url, inventory)
|
||||
|
||||
@check_placement_api_available
|
||||
def get_inventory(self, resource_provider_uuid, resource_class):
|
||||
"""Get resource provider inventory.
|
||||
|
||||
:param resource_provider_uuid: UUID of the resource provider
|
||||
:type resource_provider_uuid: str
|
||||
:param resource_class: Resource class name of the inventory to be
|
||||
returned
|
||||
:type resource_class: str
|
||||
:raises placement_exc.PlacementInventoryNotFound: For failure to
|
||||
find inventory for a resource provider
|
||||
"""
|
||||
url = '/resource_providers/%s/inventories/%s' % (
|
||||
resource_provider_uuid, resource_class)
|
||||
try:
|
||||
return self._get(url).json()
|
||||
except ks_exc.NotFound as e:
|
||||
if "No resource provider with uuid" in e.details:
|
||||
raise placement_exc.PlacementResourceProviderNotFound(
|
||||
resource_provider=resource_provider_uuid)
|
||||
elif _("No inventory of class") in e.details:
|
||||
raise placement_exc.PlacementInventoryNotFound(
|
||||
resource_provider=resource_provider_uuid,
|
||||
resource_class=resource_class)
|
||||
else:
|
||||
raise
|
||||
|
||||
@check_placement_api_available
|
||||
def update_inventory(self, resource_provider_uuid, inventory,
|
||||
resource_class):
|
||||
"""Update an inventory.
|
||||
|
||||
:param resource_provider_uuid: UUID of the resource provider
|
||||
:type resource_provider_uuid: str
|
||||
:param inventory: The inventory
|
||||
:type inventory: dict
|
||||
:param resource_class: The resource class of the inventory to update
|
||||
:type resource_class: str
|
||||
:raises placement_exc.PlacementInventoryUpdateConflict: For failure to
|
||||
update inventory due to outdated resource_provider_generation
|
||||
"""
|
||||
url = '/resource_providers/%s/inventories/%s' % (
|
||||
resource_provider_uuid, resource_class)
|
||||
try:
|
||||
self._put(url, inventory)
|
||||
except ks_exc.Conflict:
|
||||
raise placement_exc.PlacementInventoryUpdateConflict(
|
||||
resource_provider=resource_provider_uuid,
|
||||
resource_class=resource_class)
|
||||
|
||||
@check_placement_api_available
|
||||
def associate_aggregates(self, resource_provider_uuid, aggregates):
|
||||
"""Associate a list of aggregates with a resource provider.
|
||||
|
||||
:param resource_provider_uuid: UUID of the resource provider
|
||||
:type resource_provider_uuid: str
|
||||
:param aggregates: aggregates to be associated to the resource provider
|
||||
:type aggregates: list of UUIDs
|
||||
"""
|
||||
url = '/resource_providers/%s/aggregates' % resource_provider_uuid
|
||||
self._put(url, aggregates,
|
||||
headers={'openstack-api-version':
|
||||
PLACEMENT_API_WITH_AGGREGATES})
|
||||
|
||||
@check_placement_api_available
|
||||
def list_aggregates(self, resource_provider_uuid):
|
||||
"""List resource provider aggregates.
|
||||
|
||||
:param resource_provider_uuid: UUID of the resource provider
|
||||
:type resource_provider_uuid: str
|
||||
"""
|
||||
url = '/resource_providers/%s/aggregates' % resource_provider_uuid
|
||||
try:
|
||||
return self._get(
|
||||
url, headers={'openstack-api-version':
|
||||
PLACEMENT_API_WITH_AGGREGATES}).json()
|
||||
except ks_exc.NotFound:
|
||||
raise placement_exc.PlacementAggregateNotFound(
|
||||
resource_provider=resource_provider_uuid)
|
@ -29,6 +29,7 @@ from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.exceptions import placement as placement_exc
|
||||
from neutron_lib.placement import client as placement_client
|
||||
from neutron_lib.plugins import directory
|
||||
from novaclient import client as nova_client
|
||||
from novaclient import exceptions as nova_exc
|
||||
@ -44,7 +45,7 @@ from neutron.objects import network as net_obj
|
||||
from neutron.objects import subnet as subnet_obj
|
||||
from neutron.services.segments import db
|
||||
from neutron.services.segments import exceptions
|
||||
from neutron.services.segments import placement_client
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@ -151,7 +152,7 @@ class NovaSegmentNotifier(object):
|
||||
cfg.CONF.send_events_interval, self._send_notifications)
|
||||
|
||||
def _get_clients(self):
|
||||
p_client = placement_client.PlacementAPIClient()
|
||||
p_client = placement_client.PlacementAPIClient(cfg.CONF)
|
||||
|
||||
n_auth = ks_loading.load_auth_from_conf_options(cfg.CONF, 'nova')
|
||||
n_session = ks_loading.load_session_from_conf_options(
|
||||
@ -214,9 +215,8 @@ class NovaSegmentNotifier(object):
|
||||
if event.reserved:
|
||||
ipv4_inventory['reserved'] += event.reserved
|
||||
try:
|
||||
self.p_client.update_inventory(event.segment_id,
|
||||
ipv4_inventory,
|
||||
IPV4_RESOURCE_CLASS)
|
||||
self.p_client.update_resource_provider_inventory(
|
||||
event.segment_id, ipv4_inventory, IPV4_RESOURCE_CLASS)
|
||||
return
|
||||
except placement_exc.PlacementInventoryUpdateConflict:
|
||||
LOG.debug('Re-trying to update Nova IPv4 inventory for '
|
||||
@ -249,7 +249,8 @@ class NovaSegmentNotifier(object):
|
||||
'min_unit': 1, 'max_unit': 1, 'step_size': 1,
|
||||
'allocation_ratio': 1.0,
|
||||
'resource_class': IPV4_RESOURCE_CLASS}
|
||||
self.p_client.create_inventory(segment_id, ipv4_inventory)
|
||||
self.p_client.update_resource_provider_inventories(
|
||||
segment_id, ipv4_inventory)
|
||||
|
||||
def _calculate_inventory_total_and_reserved(self, subnet):
|
||||
total = 0
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
import copy
|
||||
|
||||
from keystoneauth1 import exceptions as ks_exc
|
||||
import mock
|
||||
import netaddr
|
||||
from neutron_lib.api.definitions import ip_allocation as ipalloc_apidef
|
||||
@ -46,9 +45,7 @@ from neutron.extensions import standardattrdescription as ext_stddesc
|
||||
from neutron.objects import network
|
||||
from neutron.services.segments import db
|
||||
from neutron.services.segments import exceptions as segment_exc
|
||||
from neutron.services.segments import placement_client
|
||||
from neutron.services.segments import plugin as seg_plugin
|
||||
from neutron.tests import base
|
||||
from neutron.tests.common import helpers
|
||||
from neutron.tests.unit.db import test_db_base_plugin_v2
|
||||
|
||||
@ -1678,7 +1675,8 @@ class TestNovaSegmentNotifier(SegmentAwareIpamTestCase):
|
||||
self.batch_notifier._notify()
|
||||
self.mock_p_client.get_inventory.assert_called_with(
|
||||
segment_id, seg_plugin.IPV4_RESOURCE_CLASS)
|
||||
self.mock_p_client.update_inventory.assert_not_called()
|
||||
self.mock_p_client.update_resource_provider_inventory.\
|
||||
assert_not_called()
|
||||
name = seg_plugin.SEGMENT_NAME_STUB % segment_id
|
||||
resource_provider = {'name': name, 'uuid': segment_id}
|
||||
self.mock_p_client.create_resource_provider.assert_called_with(
|
||||
@ -1691,14 +1689,16 @@ class TestNovaSegmentNotifier(SegmentAwareIpamTestCase):
|
||||
total, reserved = self._calculate_inventory_total_and_reserved(
|
||||
subnet['subnet'])
|
||||
inventory, _ = self._get_inventory(total, reserved)
|
||||
self.mock_p_client.create_inventory.assert_called_with(
|
||||
segment_id, inventory)
|
||||
self.mock_p_client.update_resource_provider_inventories.\
|
||||
assert_called_with(segment_id, inventory)
|
||||
self.assertEqual(
|
||||
inventory['total'],
|
||||
self.mock_p_client.create_inventory.call_args[0][1]['total'])
|
||||
self.mock_p_client.update_resource_provider_inventories.
|
||||
call_args[0][1]['total'])
|
||||
self.assertEqual(
|
||||
inventory['reserved'],
|
||||
self.mock_p_client.create_inventory.call_args[0][1]['reserved'])
|
||||
self.mock_p_client.update_resource_provider_inventories.
|
||||
call_args[0][1]['reserved'])
|
||||
self.mock_p_client.reset_mock()
|
||||
self.mock_p_client.get_inventory.side_effect = None
|
||||
self.mock_n_client.reset_mock()
|
||||
@ -1765,14 +1765,17 @@ class TestNovaSegmentNotifier(SegmentAwareIpamTestCase):
|
||||
subnet)
|
||||
inventory['total'] += total - original_total
|
||||
inventory['reserved'] += reserved - original_reserved
|
||||
self.mock_p_client.update_inventory.assert_called_with(segment_id,
|
||||
inventory, seg_plugin.IPV4_RESOURCE_CLASS)
|
||||
self.mock_p_client.update_resource_provider_inventory.\
|
||||
assert_called_with(segment_id, inventory,
|
||||
seg_plugin.IPV4_RESOURCE_CLASS)
|
||||
self.assertEqual(
|
||||
inventory['total'],
|
||||
self.mock_p_client.update_inventory.call_args[0][1]['total'])
|
||||
self.mock_p_client.update_resource_provider_inventory.
|
||||
call_args[0][1]['total'])
|
||||
self.assertEqual(
|
||||
inventory['reserved'],
|
||||
self.mock_p_client.update_inventory.call_args[0][1]['reserved'])
|
||||
self.mock_p_client.update_resource_provider_inventory.
|
||||
call_args[0][1]['reserved'])
|
||||
self.mock_p_client.reset_mock()
|
||||
self.mock_n_client.reset_mock()
|
||||
|
||||
@ -2021,14 +2024,17 @@ class TestNovaSegmentNotifier(SegmentAwareIpamTestCase):
|
||||
inventory['reserved'] += num_fixed_ips
|
||||
self.mock_p_client.get_inventory.assert_called_with(
|
||||
segment_id, seg_plugin.IPV4_RESOURCE_CLASS)
|
||||
self.mock_p_client.update_inventory.assert_called_with(segment_id,
|
||||
inventory, seg_plugin.IPV4_RESOURCE_CLASS)
|
||||
self.mock_p_client.update_resource_provider_inventory.\
|
||||
assert_called_with(segment_id, inventory,
|
||||
seg_plugin.IPV4_RESOURCE_CLASS)
|
||||
self.assertEqual(
|
||||
inventory['total'],
|
||||
self.mock_p_client.update_inventory.call_args[0][1]['total'])
|
||||
self.mock_p_client.update_resource_provider_inventory.
|
||||
call_args[0][1]['total'])
|
||||
self.assertEqual(
|
||||
inventory['reserved'],
|
||||
self.mock_p_client.update_inventory.call_args[0][1]['reserved'])
|
||||
self.mock_p_client.update_resource_provider_inventory.
|
||||
call_args[0][1]['reserved'])
|
||||
self.mock_p_client.reset_mock()
|
||||
self.mock_n_client.reset_mock()
|
||||
|
||||
@ -2060,19 +2066,22 @@ class TestNovaSegmentNotifier(SegmentAwareIpamTestCase):
|
||||
'device_owner': constants.DEVICE_OWNER_COMPUTE_PREFIX}
|
||||
self._test_create_port(**kwargs)
|
||||
self.mock_p_client.get_inventory.assert_not_called()
|
||||
self.mock_p_client.update_inventory.assert_not_called()
|
||||
self.mock_p_client.update_resource_provider_inventory.\
|
||||
assert_not_called()
|
||||
|
||||
def test_create_bound_port_dhcp_owned(self):
|
||||
kwargs = {portbindings.HOST_ID: 'fakehost',
|
||||
'device_owner': constants.DEVICE_OWNER_DHCP}
|
||||
self._test_create_port(**kwargs)
|
||||
self.mock_p_client.get_inventory.assert_not_called()
|
||||
self.mock_p_client.update_inventory.assert_not_called()
|
||||
self.mock_p_client.update_resource_provider_inventory.\
|
||||
assert_not_called()
|
||||
|
||||
def test_create_unbound_port(self):
|
||||
self._test_create_port()
|
||||
self.mock_p_client.get_inventory.assert_not_called()
|
||||
self.mock_p_client.update_inventory.assert_not_called()
|
||||
self.mock_p_client.update_resource_provider_inventory.\
|
||||
assert_not_called()
|
||||
|
||||
def test_delete_bound_port(self):
|
||||
kwargs = {portbindings.HOST_ID: 'fakehost'}
|
||||
@ -2115,7 +2124,8 @@ class TestNovaSegmentNotifier(SegmentAwareIpamTestCase):
|
||||
first_subnet, **kwargs)
|
||||
if dhcp_owned or compute_owned:
|
||||
self.mock_p_client.get_inventory.assert_not_called()
|
||||
self.mock_p_client.update_inventory.assert_not_called()
|
||||
self.mock_p_client.update_resource_provider_inventory.\
|
||||
assert_not_called()
|
||||
else:
|
||||
self._assert_inventory_update_port(segment_id, original_inventory,
|
||||
created_fixed_ips)
|
||||
@ -2195,16 +2205,18 @@ class TestNovaSegmentNotifier(SegmentAwareIpamTestCase):
|
||||
reserved=0)
|
||||
inventory, original_inventory = self._get_inventory(100, 2)
|
||||
self.mock_p_client.get_inventory.return_value = inventory
|
||||
self.mock_p_client.update_inventory.side_effect = (
|
||||
placement_exc.PlacementInventoryUpdateConflict(
|
||||
resource_provider=mock.ANY,
|
||||
resource_class=seg_plugin.IPV4_RESOURCE_CLASS))
|
||||
self.mock_p_client.update_resource_provider_inventory.\
|
||||
side_effect = (
|
||||
placement_exc.PlacementInventoryUpdateConflict(
|
||||
resource_provider=mock.ANY,
|
||||
resource_class=seg_plugin.IPV4_RESOURCE_CLASS))
|
||||
self.segments_plugin.nova_updater._update_nova_inventory(event)
|
||||
self.assertEqual(seg_plugin.MAX_INVENTORY_UPDATE_RETRIES,
|
||||
self.mock_p_client.get_inventory.call_count)
|
||||
self.assertEqual(
|
||||
seg_plugin.MAX_INVENTORY_UPDATE_RETRIES,
|
||||
self.mock_p_client.update_inventory.call_count)
|
||||
self.mock_p_client.update_resource_provider_inventory.
|
||||
call_count)
|
||||
self.assertEqual(
|
||||
seg_plugin.MAX_INVENTORY_UPDATE_RETRIES,
|
||||
log_debug.call_count)
|
||||
@ -2311,148 +2323,6 @@ class TestDhcpAgentSegmentScheduling(HostSegmentMappingTestCase):
|
||||
self.assertIn(DHCP_HOSTB, agent_hosts)
|
||||
|
||||
|
||||
class PlacementAPIClientTestCase(base.DietTestCase):
|
||||
"""Test the Placement API client."""
|
||||
|
||||
def setUp(self):
|
||||
super(PlacementAPIClientTestCase, self).setUp()
|
||||
self.mock_load_auth_p = mock.patch(
|
||||
'keystoneauth1.loading.load_auth_from_conf_options')
|
||||
self.mock_load_auth = self.mock_load_auth_p.start()
|
||||
self.mock_request_p = mock.patch(
|
||||
'keystoneauth1.session.Session.request')
|
||||
self.mock_request = self.mock_request_p.start()
|
||||
self.client = placement_client.PlacementAPIClient()
|
||||
|
||||
@mock.patch('keystoneauth1.loading.load_session_from_conf_options')
|
||||
@mock.patch('keystoneauth1.loading.load_auth_from_conf_options')
|
||||
def test_constructor(self, load_auth_mock, load_sess_mock):
|
||||
mock_auth = mock.Mock()
|
||||
load_auth_mock.return_value = mock_auth
|
||||
|
||||
placement_client.PlacementAPIClient()
|
||||
|
||||
load_auth_mock.assert_called_once_with(cfg.CONF, 'placement')
|
||||
load_sess_mock.assert_called_once_with(
|
||||
cfg.CONF, 'placement', auth=mock_auth)
|
||||
|
||||
def test_create_resource_provider(self):
|
||||
expected_payload = 'fake_resource_provider'
|
||||
self.client.create_resource_provider(expected_payload)
|
||||
expected_url = '/resource_providers'
|
||||
self.mock_request.assert_called_once_with(
|
||||
expected_url, 'POST',
|
||||
endpoint_filter={'region_name': mock.ANY,
|
||||
'service_type': 'placement'},
|
||||
json=expected_payload)
|
||||
|
||||
def test_delete_resource_provider(self):
|
||||
rp_uuid = uuidutils.generate_uuid()
|
||||
self.client.delete_resource_provider(rp_uuid)
|
||||
expected_url = '/resource_providers/%s' % rp_uuid
|
||||
self.mock_request.assert_called_once_with(
|
||||
expected_url, 'DELETE',
|
||||
endpoint_filter={'region_name': mock.ANY,
|
||||
'service_type': 'placement'})
|
||||
|
||||
def test_create_inventory(self):
|
||||
expected_payload = 'fake_inventory'
|
||||
rp_uuid = uuidutils.generate_uuid()
|
||||
self.client.create_inventory(rp_uuid, expected_payload)
|
||||
expected_url = '/resource_providers/%s/inventories' % rp_uuid
|
||||
self.mock_request.assert_called_once_with(
|
||||
expected_url, 'POST',
|
||||
endpoint_filter={'region_name': mock.ANY,
|
||||
'service_type': 'placement'},
|
||||
json=expected_payload)
|
||||
|
||||
def test_get_inventory(self):
|
||||
rp_uuid = uuidutils.generate_uuid()
|
||||
resource_class = 'fake_resource_class'
|
||||
self.client.get_inventory(rp_uuid, resource_class)
|
||||
expected_url = '/resource_providers/%s/inventories/%s' % (
|
||||
rp_uuid, resource_class)
|
||||
self.mock_request.assert_called_once_with(
|
||||
expected_url, 'GET',
|
||||
endpoint_filter={'region_name': mock.ANY,
|
||||
'service_type': 'placement'})
|
||||
|
||||
def _test_get_inventory_not_found(self, details, expected_exception):
|
||||
rp_uuid = uuidutils.generate_uuid()
|
||||
resource_class = 'fake_resource_class'
|
||||
self.mock_request.side_effect = ks_exc.NotFound(details=details)
|
||||
self.assertRaises(expected_exception, self.client.get_inventory,
|
||||
rp_uuid, resource_class)
|
||||
|
||||
def test_get_inventory_not_found_no_resource_provider(self):
|
||||
self._test_get_inventory_not_found(
|
||||
"No resource provider with uuid",
|
||||
placement_exc.PlacementResourceProviderNotFound)
|
||||
|
||||
def test_get_inventory_not_found_no_inventory(self):
|
||||
self._test_get_inventory_not_found(
|
||||
"No inventory of class", placement_exc.PlacementInventoryNotFound)
|
||||
|
||||
def test_get_inventory_not_found_unknown_cause(self):
|
||||
self._test_get_inventory_not_found("Unknown cause", ks_exc.NotFound)
|
||||
|
||||
def test_update_inventory(self):
|
||||
expected_payload = 'fake_inventory'
|
||||
rp_uuid = uuidutils.generate_uuid()
|
||||
resource_class = 'fake_resource_class'
|
||||
self.client.update_inventory(rp_uuid, expected_payload, resource_class)
|
||||
expected_url = '/resource_providers/%s/inventories/%s' % (
|
||||
rp_uuid, resource_class)
|
||||
self.mock_request.assert_called_once_with(
|
||||
expected_url, 'PUT',
|
||||
endpoint_filter={'region_name': mock.ANY,
|
||||
'service_type': 'placement'},
|
||||
json=expected_payload)
|
||||
|
||||
def test_update_inventory_conflict(self):
|
||||
rp_uuid = uuidutils.generate_uuid()
|
||||
expected_payload = 'fake_inventory'
|
||||
resource_class = 'fake_resource_class'
|
||||
self.mock_request.side_effect = ks_exc.Conflict
|
||||
self.assertRaises(placement_exc.PlacementInventoryUpdateConflict,
|
||||
self.client.update_inventory, rp_uuid,
|
||||
expected_payload, resource_class)
|
||||
|
||||
def test_associate_aggregates(self):
|
||||
expected_payload = 'fake_aggregates'
|
||||
rp_uuid = uuidutils.generate_uuid()
|
||||
self.client.associate_aggregates(rp_uuid, expected_payload)
|
||||
expected_url = '/resource_providers/%s/aggregates' % rp_uuid
|
||||
self.mock_request.assert_called_once_with(
|
||||
expected_url, 'PUT',
|
||||
endpoint_filter={'region_name': mock.ANY,
|
||||
'service_type': 'placement'},
|
||||
json=expected_payload,
|
||||
headers={'openstack-api-version': 'placement 1.1'})
|
||||
|
||||
def test_list_aggregates(self):
|
||||
rp_uuid = uuidutils.generate_uuid()
|
||||
self.client.list_aggregates(rp_uuid)
|
||||
expected_url = '/resource_providers/%s/aggregates' % rp_uuid
|
||||
self.mock_request.assert_called_once_with(
|
||||
expected_url, 'GET',
|
||||
endpoint_filter={'region_name': mock.ANY,
|
||||
'service_type': 'placement'},
|
||||
headers={'openstack-api-version': 'placement 1.1'})
|
||||
|
||||
def test_list_aggregates_not_found(self):
|
||||
rp_uuid = uuidutils.generate_uuid()
|
||||
self.mock_request.side_effect = ks_exc.NotFound
|
||||
self.assertRaises(placement_exc.PlacementAggregateNotFound,
|
||||
self.client.list_aggregates, rp_uuid)
|
||||
|
||||
def test_placement_api_not_found(self):
|
||||
rp_uuid = uuidutils.generate_uuid()
|
||||
self.mock_request.side_effect = ks_exc.EndpointNotFound
|
||||
self.assertRaises(placement_exc.PlacementEndpointNotFound,
|
||||
self.client.list_aggregates, rp_uuid)
|
||||
|
||||
|
||||
class TestSegmentHostRoutes(TestSegmentML2):
|
||||
|
||||
VLAN_MIN = 200
|
||||
|
Loading…
x
Reference in New Issue
Block a user