From cd91460a0f80eda12fce98cf54c3a0f6654e8514 Mon Sep 17 00:00:00 2001 From: Purnesh Dixit Date: Wed, 10 Jul 2024 20:49:26 +0530 Subject: [PATCH] Resolving comments by sergii --- framework/infrastructure/gcp/api.py | 2 +- framework/infrastructure/gcp/compute.py | 2 +- framework/infrastructure/traffic_director.py | 42 +++++++++++--------- framework/xds_k8s_flags.py | 2 +- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/framework/infrastructure/gcp/api.py b/framework/infrastructure/gcp/api.py index df4ad8ba..84b8446c 100644 --- a/framework/infrastructure/gcp/api.py +++ b/framework/infrastructure/gcp/api.py @@ -157,7 +157,7 @@ def compute(self, version: str): return self._build_from_discovery_v1(api_name, version) elif version == "v1alpha": return self._build_from_discovery_v1(api_name, "alpha") - elif version == "v1beta" or version == "v1beta1": + elif version in ["v1beta", "v1beta1"]: return self._build_from_discovery_v1(api_name, "beta") raise NotImplementedError(f"Compute {version} not supported") diff --git a/framework/infrastructure/gcp/compute.py b/framework/infrastructure/gcp/compute.py index 1e223f42..c8ea532a 100644 --- a/framework/infrastructure/gcp/compute.py +++ b/framework/infrastructure/gcp/compute.py @@ -62,7 +62,7 @@ def __init__( api_manager: gcp.api.GcpApiManager, project: str, gfe_debug_header: Optional[str] = None, - add_dualstack_support: Optional[bool] = False, + add_dualstack_support: bool = False, version: str = "v1", ): super().__init__(api_manager.compute(version), project) diff --git a/framework/infrastructure/traffic_director.py b/framework/infrastructure/traffic_director.py index 247ec630..0f1dbc5c 100644 --- a/framework/infrastructure/traffic_director.py +++ b/framework/infrastructure/traffic_director.py @@ -65,9 +65,11 @@ class TrafficDirectorManager: # pylint: disable=too-many-public-methods URL_MAP_PATH_MATCHER_NAME: Final[str] = "path-matcher" TARGET_PROXY_NAME: Final[str] = "target-proxy" + TARGET_PROXY_NAME_IPV6: Final[str] = "target-proxy-ipv6" ALTERNATIVE_TARGET_PROXY_NAME: Final[str] = "target-proxy-alt" FORWARDING_RULE_NAME: Final[str] = "forwarding-rule" + FORWARDING_RULE_NAME_IPV6: Final[str] = "forwarding-rule_ipv6" ALTERNATIVE_FORWARDING_RULE_NAME: Final[str] = "forwarding-rule-alt" HEALTH_CHECK_NAME: Final[str] = "health-check" @@ -114,7 +116,7 @@ def __init__( project, version=compute_api_version, gfe_debug_header=xds_flags.GFE_DEBUG_HEADER.value, - add_dualstack_support=xds_flags.ADD_DUALSTACK_SUPPORT.value + add_dualstack_support=xds_flags.ADD_DUALSTACK_SUPPORT.value, ) # Settings @@ -604,12 +606,12 @@ def delete_alternative_url_map(self, force=False): self.compute.delete_url_map(name) self.url_map = None - def create_target_proxy(self, ipv6=False): + def create_target_proxy(self, ipv6=False): if ipv6: - name = self.make_resource_name(self.TARGET_PROXY_NAME + "-v6") + name = self.make_resource_name(self.TARGET_PROXY_NAME_IPV6) else: name = self.make_resource_name(self.TARGET_PROXY_NAME) - + if self.backend_service_protocol is BackendServiceProtocol.GRPC: target_proxy_type = "GRPC" create_proxy_fn = self.compute.create_target_grpc_proxy @@ -627,7 +629,7 @@ def create_target_proxy(self, ipv6=False): target_proxy_type, self.url_map.name, ) - + if ipv6: self.target_proxy_v6 = create_proxy_fn(name, self.url_map) else: @@ -638,21 +640,21 @@ def delete_target_grpc_proxy(self, force=False): if ipv6: name = self.make_resource_name(self.TARGET_PROXY_NAME) else: - name = self.make_resource_name(self.TARGET_PROXY_NAME + "-v6") + name = self.make_resource_name(self.TARGET_PROXY_NAME_IPV6) elif self.target_proxy: name = self.target_proxy.name elif self.target_proxy_v6: - name = self.target_proxy_v6.name + name = self.target_proxy_v6.name else: return - + logger.info('Deleting Target GRPC proxy "%s"', name) self.compute.delete_target_grpc_proxy(name) if ipv6: self.target_proxy_v6 = None else: self.target_proxy = None - + self.target_proxy_is_http = False def delete_target_http_proxy(self, force=False, ipv6=False): @@ -660,21 +662,21 @@ def delete_target_http_proxy(self, force=False, ipv6=False): if ipv6: name = self.make_resource_name(self.TARGET_PROXY_NAME) else: - name = self.make_resource_name(self.TARGET_PROXY_NAME + "-v6") + name = self.make_resource_name(self.TARGET_PROXY_NAME_IPV6) elif self.target_proxy and self.target_proxy_is_http: name = self.target_proxy.name elif self.target_proxy_v6 and self.target_proxy_is_http: name = self.target_proxy_v6.name else: return - + logger.info('Deleting HTTP Target proxy "%s"', name) self.compute.delete_target_http_proxy(name) if ipv6: self.target_proxy_v6 = None else: self.target_proxy = None - + self.target_proxy_is_http = False def create_alternative_target_proxy(self): @@ -719,11 +721,11 @@ def find_unused_forwarding_rule_port( raise RuntimeError("Couldn't find unused forwarding rule port") def create_forwarding_rule(self, src_port: int, ipv6=False): - if ipPv6: - name = self.make_resource_name(self.FORWARDING_RULE_NAME + "-v6") + if ipv6: + name = self.make_resource_name(self.FORWARDING_RULE_NAME_IPV6) else: name = self.make_resource_name(self.FORWARDING_RULE_NAME) - + src_port = int(src_port) logging.info( 'Creating forwarding rule "%s" in network "%s": 0.0.0.0:%s -> %s', @@ -735,12 +737,12 @@ def create_forwarding_rule(self, src_port: int, ipv6=False): resource = self.compute.create_forwarding_rule( name, src_port, self.target_proxy, self.network_url ) - + if ipv6: self.forwarding_rule_v6 = resource else: self.forwarding_rule = resource - + return resource def delete_forwarding_rule(self, force=False, ipv6=False): @@ -748,14 +750,16 @@ def delete_forwarding_rule(self, force=False, ipv6=False): if ipv6: name = self.make_resource_name(self.FORWARDING_RULE_NAME) else: - name = self.make_resource_name(self.FORWARDING_RULE_NAME + "-v6") + name = self.make_resource_name( + self.FORWARDING_RULE_NAME + "-v6" + ) elif self.forwarding_rule: name = self.forwarding_rule.name elif self.forwarding_rule_v6: name = self.forwarding_rule_v6.name else: return - + logger.info('Deleting Forwarding rule "%s"', name) self.compute.delete_forwarding_rule(name) if ipv6: diff --git a/framework/xds_k8s_flags.py b/framework/xds_k8s_flags.py index 8070642b..510ddb4c 100644 --- a/framework/xds_k8s_flags.py +++ b/framework/xds_k8s_flags.py @@ -7,7 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, +# distributed under the License is disgtributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.