889 Commits

Author SHA1 Message Date
asarfaty
27077b385c Removing dependency on the "mock" package
Now that we are python3 only, we should move to using the built
in version of mock that supports all of our testing needs and
remove the dependency on the "mock" package.

Also see commit: Ifcaf1c21bea0ec3c35278e49cecc90a101a82113

Change-Id: I11dc8a80471be347f89a30f59c1cc14cdb879726
2020-05-10 17:29:29 +02:00
asarfaty
917ac30039 Add unit tests for the MP router resource
Change-Id: Iccbbafc6e525c11fa28a78b73120d38f694413bb
2020-04-30 13:51:17 +02:00
asarfaty
eb930ded56 Use newest NSX version in unittests
Change-Id: Id15081e9bd5e5b8b8b2b164b77cd8cd90be44fbd
2020-04-26 07:54:11 +02:00
asarfaty
e8047d3aad Remove neutron related apis and add more tests
Change-Id: I53a747563382ca37d0a4bcbdd1045ae12048d77b
2020-04-19 19:15:56 +02:00
Zuul
d073d71c98 Merge "Regenerate token when invalid JWT token is used to connect to NSX" 2020-04-17 20:27:45 +00:00
Yang Ding
cd0f56a8af Regenerate token when invalid JWT token is used to connect to NSX
JWT token used to authenticate with NSX can become invalid before
expiration due to VC service account credentials refresh. When this
case happens nsxlib should immediately re-get-token using the latest
creds and refresh request headers.

Change-Id: I1e3415379926f07e7b30eeaf44e9bcc7e2a26e9e
2020-04-17 11:11:35 -07:00
Anna Khmelnitsky
2c58999d22 Translate exception that grounds cluster
When endpoint goes down, the user should see same exception as
when the cluster is already down (detected by earlier activity).
For this purpose, translate grounding exception to
ServiceClusterUnavaliable.
In addition, display a warning if amount of retries is less than
amount of endpoints, since in this case not all endpoints will be
probed.

Change-Id: Ib4aa5eb95069b917c989b1f6dcd3535880b5a038
2020-04-17 09:57:46 -07:00
Zuul
782ab2c1ed Merge "Expose exception config in nsxlib" 2020-04-17 16:47:30 +00:00
Anna Khmelnitsky
b02092b252 Expose exception config in nsxlib
The user will be able to specify exception config object, that
defines which exceptions bring endpoint down, and which exceptions
trigger retry.
This change removes exception handling from the client class, which
hopefully makes the code more readable and easier to follow.

Change-Id: If4dd5c01e4bc83c9704347c2c7c8638c5ac1d72c
2020-04-16 13:12:55 +00:00
asarfaty
d657cc1d07 Remove deprecated apis & configs
Change-Id: Id08e3f660d11e365110f4adf99dd8b3a9d194fc3
2020-04-16 13:20:07 +02:00
asarfaty
12f0edff2f Add api to remove segment tier1 connectivity
Change-Id: I8550e7797b7e6baa50d1737d32ad4c03041e3cd5
2020-04-15 06:25:50 +00:00
Zuul
7ace65e11c Merge "Add coverage tests" 2020-04-15 04:59:46 +00:00
Shawn Wang
02c1c2e293
Add Per Endpoint API Rate Limit
Currently in nsxlib, there's no client side API rate throttling. In a
scale setup it is deemed to easily overwhelm NSX backend. This patch
introduces a per-endpoint rate limiter that blocks over-limit calls.

Change-Id: Iccd1d2675bed16833d36fa40cc2ef56cf3464652
2020-04-14 15:02:05 -07:00
asarfaty
2bec74a470 Add coverage tests
Change-Id: Ib5fd4421dcc4179aefff5886552d831a271e1866
2020-04-14 13:53:58 +02:00
Zuul
0a76d4e3a1 Merge "Refactor keepalive to execute node health check" 2020-04-14 05:59:00 +00:00
Anna Khmelnitsky
69db9a9167 Refactor keepalive to execute node health check
Before this change, keepalive probe consisted of two separate
configurable roundrip - one based on keepalive_section attribute,
and one on validation_method.
The recommended way to probe NSX appliance is using node/health API,
and tests show that it has best roundtrip time. This nsxlib will
switch to this healthcheck, and not expose keepalive methology to
clients any longer.

Change-Id: Ia972ef3d087fd01fa18d5a4e9dc9c32fbed0eb40
2020-04-08 15:39:44 -07:00
Danting Liu
600d8562e5 Add 'X-Allow-Overwrite' in header for policy API force update
Change-Id: I8449bb9313b7f2e14484ca58b307e80419356246
2020-04-07 20:37:53 -07:00
Zuul
753ed629bb Merge "Support clear ip_pool_id in create_or_overwrite (Tier1)Segment" 2020-04-07 04:57:24 +00:00
asarfaty
f745df2a89 Remove python deprecation warning for raw string
Change-Id: I12781a74479669355e966a9bf972b82ab6518b17
2020-04-06 06:26:37 +02:00
asarfaty
f10af37483 Add retry on StaleRevision errors for PATCH
Change-Id: I5249ce89c6684868b9e6f47256725093669c5150
2020-04-05 09:23:49 +02:00
Zuul
235f626dbb Merge "Make sure endpoint validation is always performed" 2020-03-30 23:27:11 +00:00
Zuul
4b9f0c8df1 Merge "Add more debug info for Manager requests" 2020-03-30 20:53:34 +00:00
asarfaty
2dbcdc1f7a Fix new StaleRevision exception
Commit I561f3f7be47a09876fcd8b717896ee127263a3c7 added code
500090 under the wrong category

Change-Id: I27e6a63390230f138c7215d35aed4c97dfdcbf6d
2020-03-30 13:26:17 +02:00
Shih-Hao Li
952e4889c9 Add more debug info for Manager requests
This can help distinguishing which requests have been
quened waiting for available connection or been retried.

Change-Id: I197ae819afde9333a2969472ba716694893298bd
2020-03-29 15:27:39 -07:00
Anna Khmelnitsky
dafcf8f9bd Make sure endpoint validation is always performed
Endpoint validation was two-fold - first validation_connection_method
was invoked, and then get for keepalive section, if configured.
This change suggest to run only one validation, but makes sure one
is always run:
if keepalive section is configured, validation will be based on it,
otherwise default validation (validation_connection_method) is used.
For policy, suggested default validation is via infra API.

Change-Id: Ib53d09ba6b2d70f99d5dba781950975c3d7195b6
2020-03-27 09:36:56 -07:00
Anna Khmelnitsky
3229ffc138 Fix no-validation init use case
For the case of no validation, endpoint state should be assumed to
be UP.
This is a quick fix to unblock no-validation scenarios. Next patch
will deal with cluster DOWN->UP transition.

Change-Id: Ia2a47e1a8d8aeb0174377b24b469613d866fc805
2020-03-26 08:18:31 -07:00
Zuul
0ffe769415 Merge "Reduce retries during cluster health validation" 2020-03-24 22:54:23 +00:00
asarfaty
394dadd07f Fix segment port attach & detach
1. Support tags in detach
2. Support setting vif_id in detach (reset other attachment
   attributes)
3. Use update instead of create for attach, to keep original
   port attributes

Change-Id: I7093fbf70a76a7560c9174b209259f167b21f74f
2020-03-24 12:36:23 +02:00
Anna Khmelnitsky
1e675ae459 Reduce retries during cluster health validation
This change reduces retries during cluster health validation. There are
multiple retry levels today:
* retry on urllib3 http level
* retry in validating cluster health
* retry in _proxy_internal
This causes retry storm, which brings significant delays to API calls.
This is especially relevant when nsxlib is configured with
cluster_unavailable_retry = True (this is always the case with single
endpoint).
This change reduces configurable retry attempts in cluster health
validation to single retry per endpoint.

In addition, this change fixes scenario when client configures nsxlib
with no validation, in which case cluster should not mark endpoint as
UP in validation related code.

Change-Id: I33b4101a0e0c0f4088e10776e126cc495dabd89c
2020-03-20 15:58:26 -07:00
Yang Ding
f0cc239a83 Dedup conditions before build union condition
NSX will reject expression list of a group if defined like follows:
---
"expression":
  [{"expressions": [
      {"member_type": "LogicalPort", "operator": "EQUALS", "value": "tag1|x"},
      {"conjunction_operator": "AND", "resource_type": "ConjunctionOperator"},
      {member_type": "LogicalPort", "operator": "EQUALS", "value": "tag2|y"}
    ], "resource_type": "NestedExpression"},
   {"conjunction_operator": "OR", "resource_type": "ConjunctionOperator"},
   {"expressions": [
       {"member_type": "LogicalPort", "operator": "EQUALS", "value": "tag1|x"},
       {"conjunction_operator": "AND", "resource_type": "ConjunctionOperator"},
       {member_type": "LogicalPort", "operator": "EQUALS", "value": "tag2|y"}
    ], "resource_type": "NestedExpression"},
   "resource_type": "NestedExpression"}
 ]
---
Because the two NestedExpressions are identical. If patch a group with the
spec above, 'Duplicate expressions specified' error will be returned. This
patch ensures that before a union condition is built, all conditions are
first dedupped.

Change-Id: I0d2d93f6ade992582ad931b3622354e5b9398a1d
Signed-off-by: Yang Ding <dingyang@vmware.com>
2020-03-20 21:38:41 +00:00
asarfaty
8e90b61c27 Add new StaleRevision error
This error can happen when updating policy rules

Change-Id: I561f3f7be47a09876fcd8b717896ee127263a3c7
2020-03-19 12:46:15 +02:00
Danting Liu
c2f048028d Build entry with a list of plain string as group
source_groups and destiniation_groups can be a list of group path and
IP addresses.

Change-Id: Iaac95ca9d6b356f8a8d64f3cbe422c99c701e6ab
2020-03-12 20:15:59 -07:00
Zuul
31756b4941 Merge "Add another error_code for StaleRevision error" 2020-03-12 09:17:34 +00:00
asarfaty
b558f5df9b Add another error_code for StaleRevision error
100148 is returned if a rule in a section has the wrong revision

Change-Id: I8557a6da76b52ca3c41303336c78738e209a134e
2020-03-11 14:48:07 +02:00
asarfaty
6c71cfb145 Use PUT instead of PATCH for segment port detach
Change-Id: Ib411f1898778362030c91ddc707bdd8dc1e07760
2020-03-11 11:15:34 +02:00
Ran Gu
4e80a01b43 Support clear ip_pool_id in create_or_overwrite (Tier1)Segment
Currently nsxlib will generate bad request if ip_pool_id=None
BEFORE: {'address_pool_paths': ['/infra/ip-pools/']}
AFTER: {'address_pool_paths': []}

Change-Id: I10d653abfdb26f919f9a356c2a1e83752b659619
2020-03-10 16:55:19 +08:00
asarfaty
cddf191084 Add nsx version 310
Change-Id: I2897350b241d10275baafa7b3478c86b1fcd1be4
2020-03-04 14:11:25 +02:00
asarfaty
bd54462ad6 Fix firewall section add rule/s retry
Stale revision retry should include the revison number

Change-Id: Ibad52cca60131e970447536fd22c4f4440c66d34
2020-03-01 06:46:37 +00:00
Zuul
505996439f Merge "Disable keepalive if single backend is configured" 2020-02-29 20:31:00 +00:00
Anna Khmelnitsky
52322508db Disable keepalive if single backend is configured
Keepalive can pose an extra load on the backend, especially
when client spawn multiple processes. In addition, some
deployments are using external load balancer with its
own monitoring mechanism, in which case nsxlib probing is
redundant.
Thsi change suggests to avoid keepalive probing in case
only one backend is configured. If cluster is DOWN,
connection will always be retried upon API call.
Change-Id: If6b5542f0444f5bb72c0d60e90942a7819c5d72e
2020-02-28 18:00:35 -08:00
Zuul
a4451a7fe0 Merge "Use reverse-proxy/node/health for connection status check" 2020-02-28 19:04:27 +00:00
Zuul
126e4e1be1 Merge "Allow disabling keepalive_section" 2020-02-27 23:56:58 +00:00
Yang Ding
be629caa47 Use reverse-proxy/node/health for connection status check
Previously nsxlib uses operation/application/status for nsx
connection status check if nsx version is <= 2.3. This endpoint
is known to be of high overhead in scale environments.
Furthermore, since self.nsx_version is not initialized during
the initialization phase, the validate_connection_method tend
to always use the v1 version of check.

Since nsx 2.3 is now out of the support matrix, nsxlib can simply
use reverse-proxy/node/health endpoint to verify connection to
nsx is up, which is very lightweighted.

Change-Id: Ife48d5c357e8afe416e2ad772e5bbb0616089b36
Signed-off-by: Yang Ding <dingyang@vmware.com>
2020-02-27 14:36:39 -08:00
Shawn Wang
49598f4701
Allow disabling keepalive_section
In case validate_connection_method already has the effect to keep alive,
it should be allowed to not perform any extra keep-alive requests.

Currently in MP the default keepalive section is transport-zones, which
is deemed to degrade in performance a lot in scale setup. As a more
light-weighted path reverse-proxy/node/health is already used, we should
allow configuring keepalive section to be disabled.

Change-Id: I26c0af67f90b62533a39827ca5111832d306a153
2020-02-26 15:19:59 -08:00
asarfaty
3cb6408618 Add support for policy DHCP v6
Change-Id: I150cebf2a2a88d0003d015492791126b51ef2bc4
2020-02-25 10:26:18 +00:00
asarfaty
9812774970 Suppress logging of lb services list results if empty
Since lb services list is called often by the vmware_nsx neutron plugin,
adding an option to suppress empty results logging to make logs cleaner

Change-Id: I95e7c20569e87bc2c184965a14a3ceec56e8f8ad
2020-02-24 05:15:43 +00:00
asarfaty
889037c399 Set empty values in segment subnet when not set
This will allow updating subnets witout DHCP settings

Change-Id: I78e795ca9228d92a5d1eb77fa11b842c0f9f145c
2020-02-20 13:03:55 +00:00
asarfaty
3a4fe9b6bb Fix transport zones extraction from the transport node
Support the case of NSX3 with multiple host_switches

Change-Id: Iba17fa861212906f613f866a383841bf7e683474
2020-02-20 09:59:22 +02:00
Zuul
68dc449e80 Merge "Retry all delete calles on StaleRevision exception" 2020-02-20 06:09:55 +00:00
Enhao Cui
886854fc4a Fix group def in Policy API
When updating group with empty conditions list, "expression" list
should be explicitly setting to empty list instead of ignored,
so that group gets updated properly with empty expressions.

Change-Id: I779dca3587721f7d9b0da83385a243e3a1132f7c
2020-02-18 16:27:35 -08:00