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 309d99fa..1a4821c7 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 325b1295..03aa2aa3 100644 --- a/vmware_nsxlib/v3/policy/lb_defs.py +++ b/vmware_nsxlib/v3/policy/lb_defs.py @@ -276,6 +276,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( @@ -344,7 +346,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 252c4bee..097db380 100644 --- a/vmware_nsxlib/v3/policy/lb_resources.py +++ b/vmware_nsxlib/v3/policy/lb_resources.py @@ -796,7 +796,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, @@ -815,7 +816,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 @@ -849,7 +852,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, @@ -873,7 +877,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()