Files
distcloud/distributedcloud/dccommon/tests/unit/drivers/test_sysinv_v1.py
albailey 25c9d6ed38 Removing ddt from unit tests
This cleanup should assist in transitioning to
stestr and fixtures, as well as py3 support.

The ddt data is primarily unused, only subcloud, route
and endpoints were being loaded.

The information in the data files was out of date,
and not necessarily matching the current product model.

Story: 2004515
Task: 39160
Change-Id: Iddd7ed4664b0d59dbc58aae5c3fedd74c9a138c0
Signed-off-by: albailey <Al.Bailey@windriver.com>
2020-03-26 14:40:01 -05:00

130 lines
5.4 KiB
Python

# 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.
#
# Copyright (c) 2017-2020 Wind River Systems, Inc.
#
# The right to copy, distribute, modify, or otherwise make use
# of this software may be licensed only pursuant to the terms
# of an applicable Wind River license agreement.
#
import mock
from dccommon.drivers.openstack import sysinv_v1
from dccommon.tests import base
from dccommon.tests import utils
from dcmanager.common import consts
class FakeInterface(object):
def __init__(self, ifname, uuid):
self.ifname = ifname
self.uuid = uuid
class FakeInterfaceNetwork(object):
def __init__(self, network_type, interface):
self.network_type = network_type
self.interface = interface
class FakeNetwork(object):
def __init__(self, type, pool_uuid):
self.type = type
self.pool_uuid = pool_uuid
class FakeAddressPool(object):
def __init__(self, pool_uuid):
self.pool_uuid = pool_uuid
class FakeRoute(object):
def __init__(self, data):
self.uuid = data['uuid']
self.network = data['network']
self.prefix = data['prefix']
self.gateway = data['gateway']
self.metric = data['metric']
class TestSysinvClient(base.DCCommonTestCase):
def setUp(self):
super(TestSysinvClient, self).setUp()
self.ctx = utils.dummy_context()
@mock.patch.object(sysinv_v1.SysinvClient, '__init__')
def test_get_controller_hosts(self, mock_sysinvclient_init):
controller_list = ['controller-0', 'controller-1']
mock_sysinvclient_init.return_value = None
sysinv_client = sysinv_v1.SysinvClient(consts.DEFAULT_REGION_NAME,
None)
sysinv_client.sysinv_client = mock.MagicMock()
sysinv_client.sysinv_client.ihost.list_personality = mock.MagicMock()
sysinv_client.sysinv_client.ihost.list_personality.return_value = \
controller_list
controllers = sysinv_client.get_controller_hosts()
self.assertEqual(controller_list, controllers)
@mock.patch.object(sysinv_v1.SysinvClient, '__init__')
def test_get_management_interface(self, mock_sysinvclient_init):
interface = FakeInterface('interface', 'uuid')
interface_network = FakeInterfaceNetwork('mgmt', 'interface')
mock_sysinvclient_init.return_value = None
sysinv_client = sysinv_v1.SysinvClient(consts.DEFAULT_REGION_NAME,
None)
sysinv_client.sysinv_client = mock.MagicMock()
sysinv_client.sysinv_client.iinterface.list = mock.MagicMock()
sysinv_client.sysinv_client.iinterface.list.return_value = [interface]
sysinv_client.sysinv_client.interface_network.list_by_interface.\
return_value = [interface_network]
management_interface = sysinv_client.get_management_interface(
'hostname')
self.assertEqual(interface, management_interface)
@mock.patch.object(sysinv_v1.SysinvClient, '__init__')
def test_get_management_address_pool(self, mock_sysinvclient_init):
network = FakeNetwork('mgmt', 'uuid')
pool = FakeAddressPool('uuid')
mock_sysinvclient_init.return_value = None
sysinv_client = sysinv_v1.SysinvClient(consts.DEFAULT_REGION_NAME,
None)
sysinv_client.sysinv_client = mock.MagicMock()
sysinv_client.sysinv_client.network.list = mock.MagicMock()
sysinv_client.sysinv_client.network.list.return_value = [network]
sysinv_client.sysinv_client.address_pool.get = mock.MagicMock()
sysinv_client.sysinv_client.address_pool.get.return_value = pool
management_pool = sysinv_client.get_management_address_pool()
self.assertEqual(pool, management_pool)
@mock.patch.object(sysinv_v1.SysinvClient, '__init__')
def test_create_route(self, mock_sysinvclient_init):
fake_route = utils.create_route_dict(base.ROUTE_0)
mock_sysinvclient_init.return_value = None
sysinv_client = sysinv_v1.SysinvClient(consts.DEFAULT_REGION_NAME,
None)
sysinv_client.sysinv_client = mock.MagicMock()
sysinv_client.sysinv_client.route.create = mock.MagicMock()
sysinv_client.create_route(fake_route['uuid'],
fake_route['network'],
fake_route['prefix'],
fake_route['gateway'],
fake_route['metric'])
sysinv_client.sysinv_client.route.create.assert_called_with(
interface_uuid=fake_route['uuid'],
network=fake_route['network'], prefix=fake_route['prefix'],
gateway=fake_route['gateway'], metric=fake_route['metric'])
@mock.patch.object(sysinv_v1.SysinvClient, '__init__')
def test_delete_route(self, mock_sysinvclient_init):
mock_sysinvclient_init.return_value = None