Repository: Azure/azure-cli-extensions

Issue:
Front Door frontend-endpoint session-affinity-enabled param not working, and inconsistent accepted values compared to other params
Extension: Front Door
Setting **--session-affinity-enabled** param with "az network front-door frontend-endpoint" gives the following error:

BadRequest - Property FrontdoorEntity.FrontendEndpoints[0].Properties.SessionAffinityEnabledState' cannot be set to 'False'. Acceptable values are: Enabled, Disabled

Repo Example:
az network front-door frontend-endpoint create --front-door-name "pr-active-frontdoor-demo-2" --host-name "pr-active-frontdoor-demo-2.azurefd.net" --name "DefaultFrontendEndpoint" --resource-group "pr-active-frontdoor-demo-2" --session-affinity-enabled false

Change the session affinity param to Enabled or Disabled gives the following:
az network front-door frontend-endpoint create: 'Enabled' is not a valid value for '--session-affinity-enabled'. See 'az network front-door frontend-endpoint create --help'.

CLI help states the following:
az network front-door frontend-endpoint create --help
--session-affinity-enabled      : Whether to allow session affinity on this host.  Allowed values: **false, true.**

Sample JSON extract of Session Affnity from resource:
"sessionAffinityEnabledState": "Disabled",

Recommend to also change accepted values of --session-affinity-enabled param to be "Enabled, Disabled" to be in line with resource json representation and other params eg --caching 

https://docs.microsoft.com/en-us/cli/azure/ext/front-door/network/front-door/routing-rule?view=azure-cli-latest#ext-front-door-az-network-front-door-routing-rule-create
-----




Discussion:
add to S170
add to S172

Resolving patch:
diff --git a/src/front-door/azext_front_door/_params.py b/src/front-door/azext_front_door/_params.py
--- a/src/front-door/azext_front_door/_params.py
+++ b/src/front-door/azext_front_door/_params.py
@@ -8,12 +8,12 @@
 # pylint: disable=line-too-long
 from enum import Enum
 
-from knack.arguments import CLIArgumentType
-
 from azure.cli.core.commands.parameters import (
     get_resource_name_completion_list, tags_type, get_location_type, get_three_state_flag, get_enum_type)
 from azure.cli.core.commands.validators import get_default_location_from_resource_group
 
+from knack.arguments import CLIArgumentType
+
 from ._completers import get_fd_subresource_completion_list
 from ._validators import (
     validate_waf_policy, validate_load_balancing_settings, validate_probe_settings,
@@ -99,7 +99,7 @@ def load_arguments(self, _):
 
     with self.argument_context('network front-door frontend-endpoint') as c:
         c.argument('host_name', help='Domain name of the frontend endpoint.')
-        c.argument('session_affinity_enabled', arg_type=get_three_state_flag(), help='Whether to allow session affinity on this host.')
+        c.argument('session_affinity_enabled', arg_type=get_three_state_flag(positive_label='Enabled', negative_label='Disabled', return_label=True), help='Whether to allow session affinity on this host.')
         c.argument('session_affinity_ttl', help='The TTL to use in seconds for session affinity.', type=int)
         c.argument('waf_policy', help='Name or ID of a web application firewall policy.', validator=validate_waf_policy)
 
diff --git a/src/front-door/setup.py b/src/front-door/setup.py
--- a/src/front-door/setup.py
+++ b/src/front-door/setup.py
@@ -8,7 +8,7 @@
 from codecs import open
 from setuptools import setup, find_packages
 
-VERSION = "1.0.8"
+VERSION = "1.0.9"
 
 CLASSIFIERS = [
     'Development Status :: 4 - Beta',


Test patch:
diff --git a/src/front-door/azext_front_door/tests/latest/test_front_door_scenarios.py b/src/front-door/azext_front_door/tests/latest/test_front_door_scenarios.py
new file mode 100644
--- /dev/null
+++ b/src/front-door/azext_front_door/tests/latest/test_front_door_scenarios.py
@@ -0,0 +1,25 @@
+# --------------------------------------------------------------------------------------------
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License. See License.txt in the project root for license information.
+# --------------------------------------------------------------------------------------------
+import unittest
+from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer)
+
+
+class FrontDoorBasicScenarioTests(ScenarioTest):
+
+    @unittest.skip("The test is not working due to the service's limitation.")
+    @ResourceGroupPreparer(location='westus')
+    def test_front_door_basic_scenario(self, resource_group):
+        self.kwargs.update({
+            'front_door': self.create_random_name('clifrontdoor', 20),
+            'frontend_endpoint': 'www.mysite.com',
+            'rule1': 'rule1',
+            'rule2': 'rule2'
+        })
+        self.cmd('network front-door create -g {rg} -n {front_door} --backend-address 202.120.2.3')
+        # Custom frontend endpoint must have a CNAME pointing to the default frontend host.
+        # More information can be found in https://docs.microsoft.com/en-us/azure/frontdoor/front-door-custom-domain#create-a-cname-dns-record
+        # Since it's not easy to have a custom domain, we skip this test for now.
+        self.cmd('network front-door frontend-endpoint create -g {rg} -f {front_door} -n myclitest '
+                 '--host-name {frontend_endpoint} --session-affinity-enabled')