Merge "Skip route creation if a route is configured"
This commit is contained in:
commit
8b2855a7d2
|
@ -17,6 +17,7 @@ import hashlib
|
|||
import os
|
||||
|
||||
from cgtsclient.exc import HTTPBadRequest
|
||||
from cgtsclient.exc import HTTPConflict
|
||||
from cgtsclient.exc import HTTPNotFound
|
||||
from oslo_log import log
|
||||
from oslo_utils import encodeutils
|
||||
|
@ -293,13 +294,25 @@ class SysinvClient(base.DriverBase):
|
|||
"""Create a static route on an interface."""
|
||||
|
||||
LOG.info("Creating route: interface: %s dest: %s/%s "
|
||||
"gateway: %s metric %s" % (interface_uuid, network,
|
||||
prefix, gateway, metric))
|
||||
self.sysinv_client.route.create(interface_uuid=interface_uuid,
|
||||
network=network,
|
||||
prefix=prefix,
|
||||
gateway=gateway,
|
||||
metric=metric)
|
||||
"gateway: %s metric: %s" % (interface_uuid, network,
|
||||
prefix, gateway, metric))
|
||||
try:
|
||||
self.sysinv_client.route.create(interface_uuid=interface_uuid,
|
||||
network=network,
|
||||
prefix=prefix,
|
||||
gateway=gateway,
|
||||
metric=metric)
|
||||
except HTTPConflict:
|
||||
# The route already exists
|
||||
LOG.warning("Failed to create route, route: interface: %s dest: "
|
||||
"%s/%s gateway: %s metric: %s already exists" %
|
||||
(interface_uuid, network, prefix, gateway, metric))
|
||||
except Exception as e:
|
||||
LOG.error("Failed to create route: route: interface: %s dest: "
|
||||
"%s/%s gateway: %s metric: %s" % (interface_uuid,
|
||||
network, prefix,
|
||||
gateway, metric))
|
||||
raise e
|
||||
|
||||
def delete_route(self, interface_uuid, network, prefix, gateway, metric):
|
||||
"""Delete a static route."""
|
||||
|
@ -310,8 +323,8 @@ class SysinvClient(base.DriverBase):
|
|||
if (route.network == network and route.prefix == prefix and
|
||||
route.gateway == gateway and route.metric == metric):
|
||||
LOG.info("Deleting route: interface: %s dest: %s/%s "
|
||||
"gateway: %s metric %s" % (interface_uuid, network,
|
||||
prefix, gateway, metric))
|
||||
"gateway: %s metric: %s" % (interface_uuid, network,
|
||||
prefix, gateway, metric))
|
||||
self.sysinv_client.route.delete(route.uuid)
|
||||
return
|
||||
|
||||
|
@ -505,7 +518,8 @@ class SysinvClient(base.DriverBase):
|
|||
|
||||
def _validate_certificate(self, signature, certificate):
|
||||
# JKUNG need to look at the crypto public serial id
|
||||
certificate_sig = hashlib.md5(encodeutils.safe_encode(certificate)).hexdigest()
|
||||
certificate_sig = hashlib.md5(
|
||||
encodeutils.safe_encode(certificate)).hexdigest()
|
||||
|
||||
if certificate_sig == signature:
|
||||
return True
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2015 Ericsson AB
|
||||
# Copyright (c) 2020-2021 Wind River Systems, Inc.
|
||||
# Copyright (c) 2020-2023 Wind River Systems, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
|
@ -30,6 +30,12 @@ ROUTE_0 = [
|
|||
"fd01:2::", 64, "fd01:1::1", 1, 9
|
||||
]
|
||||
|
||||
ROUTE_1 = [
|
||||
"2018-04-11 17:01:49.654734", "NULL", "NULL", 1,
|
||||
"3a07ca95-d6fe-48cb-9393-b949f800b552", 6,
|
||||
"fd01:3::", 64, "fd01:1::1", 1, 9
|
||||
]
|
||||
|
||||
|
||||
class DCCommonTestCase(base.BaseTestCase):
|
||||
"""Test case base class for all unit tests."""
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright (c) 2017-2022 Wind River Systems, Inc.
|
||||
# Copyright (c) 2017-2023 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
|
||||
|
@ -152,4 +152,40 @@ class TestSysinvClient(base.DCCommonTestCase):
|
|||
|
||||
@mock.patch.object(sysinv_v1.SysinvClient, '__init__')
|
||||
def test_delete_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.delete = mock.MagicMock()
|
||||
sysinv_client.sysinv_client.route.list_by_interface = mock.MagicMock()
|
||||
existing_route_0 = FakeRoute(utils.create_route_dict(base.ROUTE_0))
|
||||
existing_route_1 = FakeRoute(utils.create_route_dict(base.ROUTE_1))
|
||||
sysinv_client.sysinv_client.route.list_by_interface.return_value = [
|
||||
existing_route_0, existing_route_1]
|
||||
sysinv_client.delete_route(fake_route['uuid'],
|
||||
fake_route['network'],
|
||||
fake_route['prefix'],
|
||||
fake_route['gateway'],
|
||||
fake_route['metric'])
|
||||
sysinv_client.sysinv_client.route.delete.assert_called_with(
|
||||
existing_route_0.uuid)
|
||||
|
||||
@mock.patch.object(sysinv_v1.SysinvClient, '__init__')
|
||||
def test_delete_route_not_exist(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.delete = mock.MagicMock()
|
||||
sysinv_client.sysinv_client.route.list_by_interface = mock.MagicMock()
|
||||
existing_route_1 = FakeRoute(utils.create_route_dict(base.ROUTE_1))
|
||||
sysinv_client.sysinv_client.route.list_by_interface.return_value = [
|
||||
existing_route_1]
|
||||
sysinv_client.delete_route(fake_route['uuid'],
|
||||
fake_route['network'],
|
||||
fake_route['prefix'],
|
||||
fake_route['gateway'],
|
||||
fake_route['metric'])
|
||||
sysinv_client.sysinv_client.route.delete.assert_not_called()
|
||||
|
|
|
@ -26,7 +26,6 @@ import shutil
|
|||
import threading
|
||||
import time
|
||||
|
||||
from cgtsclient.exc import HTTPConflict
|
||||
from eventlet import greenpool
|
||||
from fm_api import constants as fm_const
|
||||
from fm_api import fm_api
|
||||
|
@ -2319,9 +2318,6 @@ class SubcloudManager(manager.Manager):
|
|||
region_clients=None).keystone_client
|
||||
self._create_subcloud_route(payload, m_ks_client,
|
||||
subcloud.systemcontroller_gateway_ip)
|
||||
except HTTPConflict:
|
||||
# The route already exists
|
||||
LOG.warning("Failed to create route to subcloud %s" % subcloud_name)
|
||||
except Exception:
|
||||
LOG.exception(
|
||||
"Failed to create route to subcloud %s." % subcloud_name)
|
||||
|
|
Loading…
Reference in New Issue