Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spring cloud gateway cli #8037

Merged
merged 15 commits into from
Oct 16, 2024
Prev Previous commit
Next Next commit
update tests
  • Loading branch information
Wenhao Zhang committed Oct 10, 2024
commit 28bcc6430120c7cfe24fc50e4b89f8cdc7aff28d
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ def test_containerapp_java_component(self, resource_group):
config_name = "myconfig"
eureka_name = "myeureka"
sba_name = "mysba"
gateway_name = "mygateway"

create_containerapp_env(self, env_name, resource_group)
env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()
@@ -64,47 +63,14 @@ def test_containerapp_java_component(self, resource_group):
JMESPathCheck('properties.componentType', "SpringBootAdmin"),
JMESPathCheck('properties.ingress.fqdn', sba_name + "-azure-java.ext." + default_domain),
JMESPathCheck('properties.provisioningState', "Succeeded"),
JMESPathCheck('properties.scale.minReplicas', 2),
JMESPathCheck('properties.scale.maxReplicas', 2)
JMESPathCheck('properties.scale.minReplicas', 2),
JMESPathCheck('properties.scale.maxReplicas', 2)
])

# List Java Components
java_component_list = self.cmd("containerapp env java-component list -g {} --environment {}".format(resource_group, env_name)).get_output_in_json()
self.assertTrue(len(java_component_list) == 3)

route_yaml_text_create = f"""
springCloudGatewayRoutes:
- id: "route1"
uri: "https://otherjavacomponent.myenvironment.test.net"
predicates:
- "Path=/v1/path1"
- "After=2024-01-01T00:00:00.000-00:00[America/Denver]"
filters:
- "SetPath=/filter1"
- id: "route2"
uri: "https://otherjavacomponent.myenvironment.test.net"
predicates:
- "Path=/v2/path2"
- "After=2024-01-01T00:00:00.000-00:00[America/Denver]"
filters:
- "SetPath=/filter2"
"""
route_yaml_name_create = f"{self._testMethodName}_route_create.yml"

write_test_file(route_yaml_name_create, route_yaml_text_create)
self.cmd("containerapp env java-component gateway-for-spring create -g {} -n {} --environment {} --route-yaml {}".format(resource_group, gateway_name, env_name, route_yaml_name_create), checks=[
JMESPathCheck('name', gateway_name),
JMESPathCheck('properties.componentType', "SpringCloudGateway"),
JMESPathCheck('properties.provisioningState', "Succeeded"),
JMESPathCheck('length(properties.springCloudGatewayRoutes)', 2),
JMESPathCheck('properties.scale.minReplicas', 1),
JMESPathCheck('properties.scale.maxReplicas', 1)
])

# List Java Components
java_component_list = self.cmd("containerapp env java-component list -g {} --environment {}".format(resource_group, env_name)).get_output_in_json()
self.assertTrue(len(java_component_list) == 4)

# Update Java Components
self.cmd(
'containerapp env java-component config-server-for-spring update -g {} -n {} --environment {} --configuration spring.cloud.config.server.git.uri=https://github.com/Azure-Samples/piggymetrics-config.git'.format(
@@ -134,21 +100,6 @@ def test_containerapp_java_component(self, resource_group):
JMESPathCheck('properties.scale.maxReplicas', 1)
])

route_yaml_text_update = f"""
springCloudGatewayRoutes:
"""
route_yaml_name_update = f"{self._testMethodName}_route_update.yml"

write_test_file(route_yaml_name_update, route_yaml_text_update)
self.cmd("containerapp env java-component gateway-for-spring update -g {} -n {} --environment {} --route-yaml {}".format(resource_group, gateway_name, env_name, route_yaml_name_update), checks=[
JMESPathCheck('name', gateway_name),
JMESPathCheck('properties.componentType', "SpringCloudGateway"),
JMESPathCheck('properties.provisioningState', "Succeeded"),
JMESPathCheck('length(properties.springCloudGatewayRoutes)', 0),
JMESPathCheck('properties.scale.minReplicas', 1),
JMESPathCheck('properties.scale.maxReplicas', 1)
])

# Show Java Components
self.cmd('containerapp env java-component config-server-for-spring show -g {} -n {} --environment {}'.format(resource_group, config_name, env_name), checks=[
JMESPathCheck('name', config_name),
@@ -175,14 +126,6 @@ def test_containerapp_java_component(self, resource_group):
JMESPathCheck('properties.scale.minReplicas', 1),
JMESPathCheck('properties.scale.maxReplicas', 1)
])
self.cmd("containerapp env java-component gateway-for-spring update -g {} -n {} --environment {}".format(resource_group, gateway_name, env_name, route_yaml_name_update), checks=[
JMESPathCheck('name', gateway_name),
JMESPathCheck('properties.componentType', "SpringCloudGateway"),
JMESPathCheck('properties.provisioningState', "Succeeded"),
JMESPathCheck('length(properties.springCloudGatewayRoutes)', 0),
JMESPathCheck('properties.scale.minReplicas', 1),
JMESPathCheck('properties.scale.maxReplicas', 1)
])

# Create App with wrong binding name
self.cmd('containerapp create -n {} -g {} --environment {} --bind {}:my-config'.format(ca_name, resource_group, env_name, config_name), expect_failure=True)
@@ -208,19 +151,118 @@ def test_containerapp_java_component(self, resource_group):
JMESPathCheck('length(properties.template.serviceBinds)', 2)
])

# Update App with unbind
self.cmd('containerapp update -n {} -g {} --unbind {} {}'.format(ca_name, resource_group, config_name, eureka_name), expect_failure=False, checks=[
JMESPathCheck('properties.provisioningState', "Succeeded")
])

# Delete Java Components
self.cmd('containerapp env java-component config-server-for-spring delete -g {} -n {} --environment {} --yes'.format(resource_group, config_name, env_name), expect_failure=False)
self.cmd('containerapp env java-component eureka-server-for-spring delete -g {} -n {} --environment {} --yes'.format(resource_group, eureka_name, env_name), expect_failure=False)
self.cmd('containerapp env java-component admin-for-spring delete -g {} -n {} --environment {} --yes'.format(resource_group, sba_name, env_name), expect_failure=False)

# List Java Components
java_component_list = self.cmd("containerapp env java-component list -g {} --environment {}".format(resource_group, env_name)).get_output_in_json()
self.assertTrue(len(java_component_list) == 0)

class ContainerappGatewayForSpringTests(ScenarioTest):
@ResourceGroupPreparer(location='eastus')
def test_containerapp_gateway_for_spring_component(self, resource_group):
# type "linkers" is not available in North Central US (Stage), if the TEST_LOCATION is "northcentralusstage", use francecentral as location
location = TEST_LOCATION
if format_location(location) == format_location(STAGE_LOCATION):
location = "francecentral"
self.cmd('configure --defaults location={}'.format(location))
env_name = self.create_random_name(prefix='aca-java-env', length=24)
ca_name = self.create_random_name(prefix='javaapp1', length=24)
gateway_name = "mygateway"

create_containerapp_env(self, env_name, resource_group)
env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

# List Java Components
java_component_list = self.cmd("containerapp env java-component list -g {} --environment {}".format(resource_group, env_name)).get_output_in_json()
self.assertTrue(len(java_component_list) == 0)


route_yaml_text_create = f"""
springCloudGatewayRoutes:
- id: "route1"
uri: "https://otherjavacomponent.myenvironment.test.net"
predicates:
- "Path=/v1/path1"
- "After=2024-01-01T00:00:00.000-00:00[America/Denver]"
filters:
- "SetPath=/filter1"
- id: "route2"
uri: "https://otherjavacomponent.myenvironment.test.net"
predicates:
- "Path=/v2/path2"
- "After=2024-01-01T00:00:00.000-00:00[America/Denver]"
filters:
- "SetPath=/filter2"
"""
route_yaml_name_create = f"{self._testMethodName}_route_create.yml"
write_test_file(route_yaml_name_create, route_yaml_text_create)

# Create Gateway for spring with route files
self.cmd("containerapp env java-component gateway-for-spring create -g {} -n {} --environment {} --route-yaml {}".format(resource_group, gateway_name, env_name, route_yaml_name_create), checks=[
JMESPathCheck('name', gateway_name),
JMESPathCheck('properties.componentType', "SpringCloudGateway"),
JMESPathCheck('properties.provisioningState', "Succeeded"),
JMESPathCheck('length(properties.configurations)', 0),
JMESPathCheck('length(properties.springCloudGatewayRoutes)', 2),
JMESPathCheck('properties.springCloudGatewayRoutes[0].id', "route1"),
JMESPathCheck('properties.springCloudGatewayRoutes[0].uri', "https://otherjavacomponent.myenvironment.test.net"),
JMESPathCheck('length(properties.springCloudGatewayRoutes[0].predicates)', 2),
JMESPathCheck('properties.springCloudGatewayRoutes[0].predicates[0]', "Path=/v1/path1"),
JMESPathCheck('properties.springCloudGatewayRoutes[0].predicates[1]', "After=2024-01-01T00:00:00.000-00:00[America/Denver]"),
JMESPathCheck('length(properties.springCloudGatewayRoutes[0].filters)', 1),
JMESPathCheck('properties.springCloudGatewayRoutes[0].filters[0]', "SetPath=/filter1"),
JMESPathCheck('properties.scale.minReplicas', 1),
JMESPathCheck('properties.scale.maxReplicas', 1)
])

# Update Gateway for spring without route files
self.cmd("containerapp env java-component gateway-for-spring update -g {} -n {} --environment {} --configuration spring.cloud.gateway.fail-on-route-definition-error=true".format(resource_group, gateway_name, env_name, route_yaml_name_create), checks=[
JMESPathCheck('name', gateway_name),
JMESPathCheck('properties.componentType', "SpringCloudGateway"),
JMESPathCheck('properties.provisioningState', "Succeeded"),
JMESPathCheck('length(properties.springCloudGatewayRoutes)', 2),
JMESPathCheck('length(properties.configurations)', 1),
JMESPathCheck('properties.scale.minReplicas', 1),
JMESPathCheck('properties.scale.maxReplicas', 1)
])

route_yaml_text_update = f"""
springCloudGatewayRoutes:
"""
route_yaml_name_update = f"{self._testMethodName}_route_update.yml"

# Update Gateway for spring with empty route files
write_test_file(route_yaml_name_update, route_yaml_text_update)
self.cmd("containerapp env java-component gateway-for-spring update -g {} -n {} --environment {} --route-yaml {}".format(resource_group, gateway_name, env_name, route_yaml_name_update), checks=[
JMESPathCheck('name', gateway_name),
JMESPathCheck('properties.componentType', "SpringCloudGateway"),
JMESPathCheck('properties.provisioningState', "Succeeded"),
JMESPathCheck('length(properties.springCloudGatewayRoutes)', 0),
JMESPathCheck('length(properties.configurations)', 1),
JMESPathCheck('properties.scale.minReplicas', 1),
JMESPathCheck('properties.scale.maxReplicas', 1)
])

self.cmd("containerapp env java-component gateway-for-spring show -g {} -n {} --environment {}".format(resource_group, gateway_name, env_name), checks=[
JMESPathCheck('name', gateway_name),
JMESPathCheck('properties.componentType', "SpringCloudGateway"),
JMESPathCheck('properties.provisioningState', "Succeeded"),
JMESPathCheck('length(properties.springCloudGatewayRoutes)', 0),
JMESPathCheck('length(properties.configurations)', 1),
JMESPathCheck('properties.scale.minReplicas', 1),
JMESPathCheck('properties.scale.maxReplicas', 1)
])

# Delete Gateway for spring
self.cmd("containerapp env java-component gateway-for-spring delete -g {} -n {} --environment {} --yes".format(resource_group, gateway_name, env_name), expect_failure=False)

# List Java Components
java_component_list = self.cmd("containerapp env java-component list -g {} --environment {}".format(resource_group, env_name)).get_output_in_json()
self.assertTrue(len(java_component_list) == 0)

clean_up_test_file(route_yaml_name_create)
# Clean up route files
clean_up_test_file(route_yaml_name_create)
clean_up_test_file(route_yaml_name_update)
Loading