Skip to content

Commit

Permalink
1. add command: network front-door load-balancing update (Azure#2531)
Browse files Browse the repository at this point in the history
2. add test scenarios for backend-pool, frontend-endpoint, load-balancing, probe and route-rule
kairu-ms authored Nov 5, 2020
1 parent 8c49f10 commit a5c765f
Showing 15 changed files with 5,482 additions and 252 deletions.
5 changes: 5 additions & 0 deletions src/front-door/azext_front_door/_help.py
Original file line number Diff line number Diff line change
@@ -158,6 +158,11 @@
short-summary: Delete Front Door load-balancing settings.
"""

helps['network front-door load-balancing update'] = """
type: command
short-summary: Update Front Door load-balancing settings.
"""

# endregion

# region FrontDoor HealthProbeSettings
2 changes: 1 addition & 1 deletion src/front-door/azext_front_door/_params.py
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ def load_arguments(self, _):
with self.argument_context('network front-door load-balancing') as c:
c.argument('additional_latency', type=int, help='The additional latency in milliseconds for probes to fall in the lowest latency bucket.')
c.argument('sample_size', type=int, help='The number of samples to consider for load balancing decisions.')
c.argument('successful_samples_required', type=int, help='The number of samples within the sample period that must succeed.')
c.argument('successful_samples_required', options_list=['--successful-samples-required', '-s'], type=int, help='The number of samples within the sample period that must succeed.')

with self.argument_context('network front-door probe') as c:
c.argument('path', help='Path to probe.')
24 changes: 11 additions & 13 deletions src/front-door/azext_front_door/commands.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
# pylint: disable=too-many-locals, too-many-statements
def load_command_table(self, _):

frontdoor_custom = CliCommandType(operations_tmpl='azext_front_door.custom#{}')
# frontdoor_custom = CliCommandType(operations_tmpl='azext_front_door.custom#{}')

frontdoor_sdk = CliCommandType(
operations_tmpl='azext_front_door.vendored_sdks.operations._front_doors_operations#FrontDoorsOperations.{}',
@@ -81,22 +81,20 @@ def load_command_table(self, _):
'routing_rules': 'routing-rule'
}
for subresource, alias in property_map.items():
with self.command_group('network front-door {}'.format(alias), frontdoor_custom) as g:
g.command('create', 'create_fd_{}'.format(subresource))
g.command('list', list_frontdoor_resource_property('front_doors', subresource))
g.show_command('show', get_frontdoor_resource_property_entry('front_doors', subresource))
g.command('delete', delete_frontdoor_resource_property_entry('front_doors', subresource))

# with self.command_group('network front-door backend-pool', fd_backend_pool_sdk) as g:
# g.custom_command('create', 'create_fd_backend_pool')
# g.command('delete', 'delete')
# g.command('list', 'list_by_front_door')
# g.show_command('show', 'get')
# g.generic_update_command('update', custom_func_name='update_fd_backend_pool')
with self.command_group('network front-door {}'.format(alias), frontdoor_sdk) as g:
g.custom_command('create', 'create_fd_{}'.format(subresource))
g.custom_command('list', list_frontdoor_resource_property('front_doors', subresource))
g.custom_show_command('show', get_frontdoor_resource_property_entry('front_doors', subresource))
g.custom_command('delete', delete_frontdoor_resource_property_entry('front_doors', subresource))

with self.command_group('network front-door probe', frontdoor_sdk) as g:
g.custom_command('update', 'update_fd_health_probe_settings')

with self.command_group('network front-door load-balancing', frontdoor_sdk) as g:
g.generic_update_command('update', custom_func_name='update_fd_load_balancing_settings',
setter_arg_name='front_door_parameters',
child_collection_prop_name='load_balancing_settings')

with self.command_group('network front-door backend-pool backend', frontdoor_sdk) as g:
g.custom_command('add', 'add_fd_backend')
g.custom_command('list', 'list_fd_backends')
36 changes: 18 additions & 18 deletions src/front-door/azext_front_door/custom.py
Original file line number Diff line number Diff line change
@@ -272,15 +272,15 @@ def create_fd_frontend_endpoints(cmd, resource_group_name, front_door_name, item
endpoint, 'name')


def update_fd_frontend_endpoints(instance, host_name=None, session_affinity_enabled=None,
session_affinity_ttl=None, waf_policy=None):
from azext_front_door.vendored_sdks.models import SubResource
with UpdateContext(instance) as c:
c.update_param('hostName', host_name, False)
c.update_param('sessionAffinityEnabledState', session_affinity_enabled, False)
c.update_param('sessionAffinityTtlSeconds', session_affinity_ttl, False)
c.update_param('webApplicationFirewallPolicyLink', SubResource(id=waf_policy) if waf_policy else None, False)
return instance
# def update_fd_frontend_endpoints(instance, host_name=None, session_affinity_enabled=None,
# session_affinity_ttl=None, waf_policy=None):
# from azext_front_door.vendored_sdks.models import SubResource
# with UpdateContext(instance) as c:
# c.update_param('hostName', host_name, False)
# c.update_param('sessionAffinityEnabledState', session_affinity_enabled, False)
# c.update_param('sessionAffinityTtlSeconds', session_affinity_ttl, False)
# c.update_param('webApplicationFirewallPolicyLink', SubResource(id=waf_policy) if waf_policy else None, False)
# return instance


def configure_fd_frontend_endpoint_disable_https(cmd, resource_group_name, front_door_name, item_name):
@@ -371,13 +371,13 @@ def create_fd_backend_pools(cmd, resource_group_name, front_door_name, item_name
return _upsert_frontdoor_subresource(cmd, resource_group_name, front_door_name, 'backend_pools', pool, 'name')


def update_fd_backend_pools(instance, load_balancing_settings=None, probe_settings=None):
from azext_front_door.vendored_sdks.models import SubResource
with UpdateContext(instance) as c:
c.update_param('loadBalancingSettings', SubResource(id=load_balancing_settings)
if load_balancing_settings else None, False)
c.update_param('healthProbeSettings', SubResource(id=probe_settings) if probe_settings else None, False)
return instance
# def update_fd_backend_pools(instance, load_balancing_settings=None, probe_settings=None):
# from azext_front_door.vendored_sdks.models import SubResource
# with UpdateContext(instance) as c:
# c.update_param('loadBalancingSettings', SubResource(id=load_balancing_settings)
# if load_balancing_settings else None, False)
# c.update_param('healthProbeSettings', SubResource(id=probe_settings) if probe_settings else None, False)
# return instance


def add_fd_backend(cmd, resource_group_name, front_door_name, backend_pool_name, address,
@@ -494,13 +494,13 @@ def create_fd_load_balancing_settings(cmd, resource_group_name, front_door_name,
settings, 'name')


def update_fd_load_balancing_settings(instance, sample_size=None, successful_samples_required=None,
def update_fd_load_balancing_settings(parent, instance, item_name, sample_size=None, successful_samples_required=None, # pylint: disable=unused-argument
additional_latency=None):
with UpdateContext(instance) as c:
c.update_param('sample_size', sample_size, False)
c.update_param('successful_samples_required', successful_samples_required, False)
c.update_param('additional_latency_milliseconds', additional_latency, False)
return instance
return parent


def routing_rule_usage_helper(route_type, backend_pool=None, custom_forwarding_path=None,

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1,543 changes: 1,543 additions & 0 deletions src/front-door/azext_front_door/tests/latest/recordings/test_probe_basic.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer)


class BackendPoolScenarioTest(ScenarioTest):

@ResourceGroupPreparer(location='westus')
def test_backend_pool_basic(self, resource_group):
self.kwargs.update({
'front_door': self.create_random_name('clifrontdoor', 20),
'bkp1': 'bkp1',
'lb1': 'lb1',
'pb1': 'pb1'
})
self.cmd('network front-door create -g {rg} -n {front_door} --backend-address 202.120.2.3')

self.cmd('network front-door backend-pool create -f {front_door} -g {rg} -n {bkp1} '
'--address 202.120.2.3 '
'--load-balancing DefaultLoadBalancingSettings '
'--probe DefaultProbeSettings ',
checks=[
self.check('backends[0].address', '202.120.2.3'),
self.check('ends_with(loadBalancingSettings.id, `DefaultLoadBalancingSettings`)', True),
self.check('ends_with(healthProbeSettings.id, `DefaultProbeSettings`)', True)
])

self.cmd('network front-door backend-pool list -f {front_door} -g {rg} ',
checks=[
self.check('length(@)', 2),
])
self.cmd('network front-door backend-pool show -f {front_door} -g {rg} -n {bkp1} ')
self.cmd('network front-door backend-pool delete -f {front_door} -g {rg} -n {bkp1} ')
self.cmd('network front-door backend-pool list -f {front_door} -g {rg} ',
checks=[
self.check('length(@)', 1),
])
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer)


class FrontendEndpointScenarioTests(ScenarioTest):

@ResourceGroupPreparer(location='westus')
def test_frontend_endpoint_basic(self, resource_group):
self.kwargs.update({
'front_door': self.create_random_name('clifrontdoor', 20),
})
self.cmd('network front-door create -g {rg} -n {front_door} --backend-address 202.120.2.3 ')
self.cmd('network front-door frontend-endpoint list -f {front_door} -g {rg} ',
checks=[
self.check('length(@)', 1),
])
self.cmd('network front-door frontend-endpoint show -f {front_door} -g {rg} -n DefaultFrontendEndpoint ')
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer)


class LoadBalancingScenarioTest(ScenarioTest):

@ResourceGroupPreparer(location='westus')
def test_load_balancing_basic(self, resource_group):
self.kwargs.update({
'front_door': self.create_random_name('clifrontdoor', 20),
'lb1': 'lb1'
})
self.cmd('network front-door create -g {rg} -n {front_door} --backend-address 202.120.2.3')
self.cmd('network front-door load-balancing create -f {front_door} -g {rg} -n {lb1} '
'--sample-size 5 '
'--successful-samples-required 1 '
'--additional-latency 100 ',
checks=[
self.check('sampleSize', 5),
self.check('successfulSamplesRequired', 1),
self.check('additionalLatencyMilliseconds', 100),
])
self.cmd('network front-door load-balancing update -f {front_door} -g {rg} -n {lb1} '
'--sample-size 4 '
'--successful-samples-required 2 '
'--additional-latency 10 ',
checks=[
self.check('sampleSize', 4),
self.check('successfulSamplesRequired', 2),
self.check('additionalLatencyMilliseconds', 10),
])
self.cmd('network front-door load-balancing list -f {front_door} -g {rg} ',
checks=[
self.check('length(@)', 2),
])
self.cmd('network front-door load-balancing show -f {front_door} -g {rg} -n {lb1} ')
self.cmd('network front-door load-balancing delete -f {front_door} -g {rg} -n {lb1} ')
self.cmd('network front-door load-balancing list -f {front_door} -g {rg} ',
checks=[
self.check('length(@)', 1),
])
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer)


class ProbeScenarioTest(ScenarioTest):

@ResourceGroupPreparer(location='westus')
def test_probe_basic(self, resource_group):
self.kwargs.update({
'front_door': self.create_random_name('clifrontdoor', 20),
'pb1': 'pb1'
})
self.cmd('network front-door create -g {rg} -n {front_door} --backend-address 202.120.2.3')
self.cmd('network front-door probe create -f {front_door} -g {rg} -n {pb1} '
'--interval 100 '
'--path /abc '
'--enabled Disabled '
'--probeMethod GET '
'--protocol Http ',
checks=[
self.check('intervalInSeconds', 100),
self.check('path', '/abc'),
self.check('enabledState', 'Disabled'),
self.check('protocol', 'Http'),
self.check('healthProbeMethod', 'Get'),
])
self.cmd('network front-door probe update -f {front_door} -g {rg} -n {pb1} '
'--interval 10 '
'--path / '
'--enabled Enabled '
'--probeMethod HEAD '
'--protocol Https ',
checks=[
self.check('intervalInSeconds', 10),
self.check('path', '/'),
self.check('enabledState', 'Enabled'),
self.check('protocol', 'Https'),
self.check('healthProbeMethod', 'HEAD'),
])
self.cmd('network front-door probe list -f {front_door} -g {rg} ',
checks=[
self.check('length(@)', 2),
])
self.cmd('network front-door probe show -f {front_door} -g {rg} -n {pb1} ')
self.cmd('network front-door probe delete -f {front_door} -g {rg} -n {pb1} ')
self.cmd('network front-door probe list -f {front_door} -g {rg} ',
checks=[
self.check('length(@)', 1),
])
Original file line number Diff line number Diff line change
@@ -35,3 +35,13 @@ def test_route_rule_basic(self, resource_group):
self.check('patternsToMatch[0]', '/forward3'),
self.check('routeConfiguration.customQueryString', 'querystring2')
])
self.cmd('network front-door routing-rule list -f {front_door} -g {rg} ',
checks=[
self.check('length(@)', 3),
])
self.cmd('network front-door routing-rule delete -f {front_door} -g {rg} -n {rule2} ')
self.cmd('network front-door routing-rule list -f {front_door} -g {rg} ',
checks=[
self.check('length(@)', 2),
])
self.cmd('network front-door routing-rule show -f {front_door} -g {rg} -n {rule1} ')
2 changes: 1 addition & 1 deletion src/front-door/setup.py
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
from codecs import open
from setuptools import setup, find_packages

VERSION = "1.0.9"
VERSION = "1.0.10"

CLASSIFIERS = [
'Development Status :: 4 - Beta',

0 comments on commit a5c765f

Please sign in to comment.