From 99015e71b1d1145aa2cf11d519b178bd855290ec Mon Sep 17 00:00:00 2001 From: Tao Zou Date: Mon, 30 Nov 2020 14:48:09 +0800 Subject: [PATCH] Add api support for log related parameters Add two parameters access_log_enabled and log_significant_event_only They're supported since nsx-t 3.0.0. 1. for policy, it needs to add extra parameters. 2. for manager, ** kargs supports more parameters, nothing changed. Change-Id: I2b313eef80def69e17d664022ae2074950812897 --- .../tests/unit/v3/policy/test_lb_resources.py | 48 ++++++++++++++++++- vmware_nsxlib/v3/policy/lb_defs.py | 6 ++- vmware_nsxlib/v3/policy/lb_resources.py | 14 ++++-- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py index faa23afb..3f0e64fa 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py @@ -20,9 +20,9 @@ from unittest import mock from vmware_nsxlib.tests.unit.v3 import nsxlib_testcase from vmware_nsxlib.tests.unit.v3.policy import test_resources from vmware_nsxlib.v3 import exceptions as nsxlib_exc +from vmware_nsxlib.v3 import nsx_constants from vmware_nsxlib.v3.policy import constants from vmware_nsxlib.v3.policy import lb_defs - TEST_TENANT = 'test' @@ -1138,6 +1138,52 @@ class TestPolicyLBVirtualServer(test_resources.NsxPolicyLibTestCase): tenant=TEST_TENANT) self.assert_called_with_def(update_call, expected_def) + def test_update_log_parameters(self): + obj_id = '111' + name = 'new name' + description = 'new desc' + vs_name = 'name-name' + with self.mock_get(obj_id, vs_name), \ + self.mock_create_update() as update_call: + self.resourceApi.update(obj_id, + name=name, + description=description, + tenant=TEST_TENANT, + access_log_enabled=True, + log_significant_event_only=True) + expected_def = lb_defs.LBVirtualServerDef( + nsx_version=nsx_constants.NSX_VERSION_3_0_0, + virtual_server_id=obj_id, name=name, + description=description, + tenant=TEST_TENANT, access_log_enabled=True, + log_significant_event_only=True) + self.assert_called_with_def(update_call, expected_def) + + def test_log_parameters_for_version(self): + obj_id = '111' + name = 'new name' + description = 'new desc' + + expected_def = lb_defs.LBVirtualServerDef( + nsx_version=nsx_constants.NSX_VERSION_2_5_0, + virtual_server_id=obj_id, name=name, + description=description, + tenant=TEST_TENANT, access_log_enabled=True, + log_significant_event_only=True) + self.assertFalse('access_log_enabled' in expected_def.get_obj_dict()) + self.assertFalse('log_significant_event_only' in + expected_def.get_obj_dict()) + + expected_def = lb_defs.LBVirtualServerDef( + nsx_version=nsx_constants.NSX_VERSION_3_0_0, + virtual_server_id=obj_id, name=name, + description=description, + tenant=TEST_TENANT, access_log_enabled=True, + log_significant_event_only=True) + self.assertTrue('access_log_enabled' in expected_def.get_obj_dict()) + self.assertTrue('log_significant_event_only' in + expected_def.get_obj_dict()) + def test_non_partial_update(self): obj_id = '111' vs_name = 'name-name' diff --git a/vmware_nsxlib/v3/policy/lb_defs.py b/vmware_nsxlib/v3/policy/lb_defs.py index 14906a88..60cfe016 100644 --- a/vmware_nsxlib/v3/policy/lb_defs.py +++ b/vmware_nsxlib/v3/policy/lb_defs.py @@ -275,6 +275,8 @@ class LBVirtualServerDef(ResourceDef): body = super(LBVirtualServerDef, self).get_obj_dict() self._set_attrs_if_specified( body, ['ip_address', 'ports', 'max_concurrent_connections']) + self._set_attrs_if_supported( + body, ['access_log_enabled', 'log_significant_event_only']) client_ssl_binding = self.get_attr('client_ssl_profile_binding') if client_ssl_binding: self._set_attr_if_specified( @@ -343,7 +345,9 @@ class LBVirtualServerDef(ResourceDef): @property def version_dependant_attr_map(self): - return {'access_list_control': nsx_constants.NSX_VERSION_3_0_0} + return {'access_list_control': nsx_constants.NSX_VERSION_3_0_0, + 'access_log_enabled': nsx_constants.NSX_VERSION_3_0_0, + 'log_significant_event_only': nsx_constants.NSX_VERSION_3_0_0} class ClientSSLProfileBindingDef(object): diff --git a/vmware_nsxlib/v3/policy/lb_resources.py b/vmware_nsxlib/v3/policy/lb_resources.py index 22957a60..a5324c56 100644 --- a/vmware_nsxlib/v3/policy/lb_resources.py +++ b/vmware_nsxlib/v3/policy/lb_resources.py @@ -789,7 +789,8 @@ class NsxPolicyLoadBalancerVirtualServerAPI(NsxPolicyResourceBase): max_concurrent_connections=IGNORE, access_list_control=IGNORE, tenant=constants.POLICY_INFRA_TENANT, - tags=IGNORE): + tags=IGNORE, access_log_enabled=IGNORE, + log_significant_event_only=IGNORE): virtual_server_id = self._init_obj_uuid(virtual_server_id) lbvs_def = self._init_def( virtual_server_id=virtual_server_id, @@ -808,7 +809,9 @@ class NsxPolicyLoadBalancerVirtualServerAPI(NsxPolicyResourceBase): waf_profile_binding=waf_profile_binding, max_concurrent_connections=max_concurrent_connections, access_list_control=access_list_control, - tags=tags + tags=tags, + access_log_enabled=access_log_enabled, + log_significant_event_only=log_significant_event_only ) self._create_or_store(lbvs_def) return virtual_server_id @@ -842,7 +845,8 @@ class NsxPolicyLoadBalancerVirtualServerAPI(NsxPolicyResourceBase): access_list_control=IGNORE, tags=IGNORE, tenant=constants.POLICY_INFRA_TENANT, - allow_partial_updates=True): + allow_partial_updates=True, access_log_enabled=IGNORE, + log_significant_event_only=IGNORE): @utils.retry_upon_exception( nsxlib_exc.StaleRevision, @@ -866,7 +870,9 @@ class NsxPolicyLoadBalancerVirtualServerAPI(NsxPolicyResourceBase): max_concurrent_connections=max_concurrent_connections, access_list_control=access_list_control, tags=tags, - allow_partial_updates=allow_partial_updates) + allow_partial_updates=allow_partial_updates, + access_log_enabled=access_log_enabled, + log_significant_event_only=log_significant_event_only) _update()