Call interface changed to function
Since Tacker will support the mTLS authentication method in the future, it will no longer call its own interface internally, but instead call internal functions. Implements: blueprint support-oauth2-mtls Change-Id: Iaec8f2223f21079c4bf34b3a6d05b3e77c2ebcc4
This commit is contained in:
parent
3a979eb625
commit
427985e261
|
@ -16,8 +16,11 @@
|
|||
import threading
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import encodeutils
|
||||
|
||||
from tacker import context as tacker_context
|
||||
from tacker.sol_refactored.common import config as cfg
|
||||
from tacker.sol_refactored.common import http_client
|
||||
from tacker.sol_refactored.common import vnflcm_utils
|
||||
from tacker.sol_refactored.conductor import conductor_rpc_v2 as rpc
|
||||
from tacker.sol_refactored import objects
|
||||
|
||||
|
@ -86,16 +89,6 @@ class ServerNotificationDriverMain(ServerNotificationDriver):
|
|||
def __init__(self):
|
||||
self.timer_map = {}
|
||||
self.expiration_time = CONF.server_notification.timer_interval
|
||||
auth_handle = http_client.KeystonePasswordAuthHandle(
|
||||
auth_url=CONF.keystone_authtoken.auth_url,
|
||||
username=CONF.keystone_authtoken.username,
|
||||
password=CONF.keystone_authtoken.password,
|
||||
project_name=CONF.keystone_authtoken.project_name,
|
||||
user_domain_name=CONF.keystone_authtoken.user_domain_name,
|
||||
project_domain_name=CONF.keystone_authtoken.project_domain_name)
|
||||
self.client = http_client.HttpClient(auth_handle)
|
||||
sn_auth_handle = http_client.NoAuthHandle()
|
||||
self.sn_client = http_client.HttpClient(sn_auth_handle)
|
||||
self.rpc = rpc.VnfLcmRpcApiV2()
|
||||
|
||||
def notify(self, vnf_instance_id, vnfc_instance_ids):
|
||||
|
@ -111,16 +104,16 @@ class ServerNotificationDriverMain(ServerNotificationDriver):
|
|||
|
||||
def request_heal(self, vnf_instance_id, vnfc_instance_ids):
|
||||
heal_req = objects.HealVnfRequest(vnfcInstanceId=vnfc_instance_ids)
|
||||
body = heal_req.to_dict()
|
||||
LOG.info("server_notification auto healing is processed: %s.",
|
||||
vnf_instance_id)
|
||||
ep = CONF.v2_vnfm.endpoint
|
||||
url = f'{ep}/vnflcm/v2/vnf_instances/{vnf_instance_id}/heal'
|
||||
resp, body = self.client.do_request(
|
||||
url, "POST", body=heal_req.to_dict(), version="2.0.0")
|
||||
if resp.status_code != 202:
|
||||
context = tacker_context.get_admin_context()
|
||||
try:
|
||||
vnflcm_utils.heal(context, vnf_instance_id, body)
|
||||
except Exception as exp:
|
||||
LOG.error(str(body))
|
||||
LOG.error("server_notification auto healing is failed: %d.",
|
||||
resp.status_code)
|
||||
LOG.error("server_notification auto healing is failed: %s.",
|
||||
encodeutils.exception_to_unicode(exp))
|
||||
|
||||
def timer_expired(self, vnf_instance_id, vnfc_instance_ids):
|
||||
self.remove_timer(vnf_instance_id)
|
||||
|
|
|
@ -16,8 +16,11 @@
|
|||
import time
|
||||
import webob
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from tacker import context
|
||||
from tacker.sol_refactored.common import http_client
|
||||
from tacker.sol_refactored.common import vnflcm_utils
|
||||
from tacker.sol_refactored.conductor import conductor_v2
|
||||
from tacker.sol_refactored.conductor import server_notification_driver as snd
|
||||
from tacker.sol_refactored import objects
|
||||
|
@ -69,20 +72,26 @@ class TestServerNotification(db_base.SqlTestCase):
|
|||
self.conductor.server_notification_remove_timer(
|
||||
self.context, 'invalid_id')
|
||||
|
||||
@mock.patch.object(http_client.HttpClient, 'do_request')
|
||||
def test_conductor_timer_expired(self, mock_do_request):
|
||||
@mock.patch.object(vnflcm_utils, 'heal')
|
||||
def test_conductor_timer_expired(self, mock_heal):
|
||||
self.config_fixture.config(
|
||||
group='server_notification', server_notification=True)
|
||||
snd.ServerNotificationDriver._instance = None
|
||||
self.conductor.sn_driver = snd.ServerNotificationDriver.instance()
|
||||
resp = webob.Response()
|
||||
resp.status_code = 202
|
||||
mock_do_request.return_value = resp, {}
|
||||
self.conductor.sn_driver.timer_expired('test_id', ['id'])
|
||||
resp.status_code = 503
|
||||
mock_do_request.return_value = resp, {}
|
||||
self.conductor.sn_driver.timer_expired('test_id', ['id'])
|
||||
|
||||
def test_conductor_timer_expired_error(self):
|
||||
self.config_fixture.config(
|
||||
group='server_notification', server_notification=True)
|
||||
snd.ServerNotificationDriver._instance = None
|
||||
self.conductor.sn_driver = snd.ServerNotificationDriver.instance()
|
||||
|
||||
log_name = "tacker.sol_refactored.conductor.server_notification_driver"
|
||||
with self.assertLogs(logger=log_name, level=logging.ERROR) as cm:
|
||||
self.conductor.sn_driver.timer_expired('test_id', ['id'])
|
||||
msg = f'ERROR:{log_name}:server_notification auto healing is failed:'
|
||||
self.assertIn(f'{msg}', cm.output[1])
|
||||
|
||||
def expired(self, id, queue):
|
||||
queue.sort()
|
||||
self.timer_test = (id, queue)
|
||||
|
|
Loading…
Reference in New Issue