Li Zhu 665fa12a79 Tech debt: move portions of dcorch.common.consts into dccommon.consts
Parts of dcorch.common.consts: such as ENDPOINT_TYPE_*,
ENDPOINT_TYPES_LIST, SYNC_STATUS_*, and so on, are shared by
dcmanager, so they should be moved into the dccommon.consts.

Test Plan:

PASSED:

All distributedcloud sanity tests.

Closes-Bug: 1978334
Change-Id: I13d7ec72e2863171138b39cd8f982d69e87d60b8
2022-06-16 12:28:44 -04:00

125 lines
5.3 KiB
Python

# Copyright (c) 2017-2022 Wind River Systems, Inc.
# 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 mock
from dccommon import consts as dccommon_consts
from dccommon.drivers.openstack import sysinv_v1
from dccommon.tests import base
from dccommon.tests import utils
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(dccommon_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(dccommon_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(dccommon_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(dccommon_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