Skip to content

Commit

Permalink
{AKS} Fix azdev style issues for tests (Azure#7115)
Browse files Browse the repository at this point in the history
  • Loading branch information
FumingZhang authored Dec 26, 2023
1 parent a0f7fac commit 40f07b1
Show file tree
Hide file tree
Showing 9 changed files with 12,920 additions and 8,600 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def process_response(self, response):
response['body']['string'] = self._replace_string_keys(response['body']['string'])
return response

# pylint: disable=no-self-use
def _replace_string_keys(self, val):
import re
if 'secret' in val:
Expand All @@ -41,7 +40,6 @@ def _replace_string_keys(self, val):
.format(MOCK_GUID), val, flags=re.IGNORECASE)
return val

# pylint: disable=no-self-use
def _replace_byte_keys(self, val):
import re
if b'secret' in val:
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

16,976 changes: 10,460 additions & 6,516 deletions src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def test_get_cluster_snapshot(self):
), self.assertRaises(BadRequestError):
get_cluster_snapshot("mock_cli_ctx", "test_sub", "mock_rg", "mock_snapshot_name")


class CheckManagedClusterTestCase(unittest.TestCase):
def setUp(self):
# manually register CUSTOM_MGMT_AKS_PREVIEW
Expand Down
40 changes: 23 additions & 17 deletions src/aks-preview/azext_aks_preview/tests/latest/test_loadbalancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
from azext_aks_preview import _loadbalancer as loadbalancer
from azext_aks_preview.__init__ import register_aks_preview_resource_type
from azext_aks_preview._client_factory import CUSTOM_MGMT_AKS_PREVIEW
from azext_aks_preview.managed_cluster_decorator import (
AKSPreviewManagedClusterModels,
)
from azext_aks_preview.managed_cluster_decorator import AKSPreviewManagedClusterModels
from azext_aks_preview.tests.latest.mocks import MockCLI, MockCmd
from azure.cli.core.azclierror import (
InvalidArgumentValueError,
)


class TestLoadBalancer(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -51,15 +47,17 @@ def test_configure_load_balancer_profile(self):

profile = ManagedClusterLoadBalancerProfile()
# ips -> i_ps due to track 2 naming issue
profile.managed_outbound_i_ps = ManagedClusterLoadBalancerProfileManagedOutboundIPs(
count=2
profile.managed_outbound_i_ps = (
ManagedClusterLoadBalancerProfileManagedOutboundIPs(count=2)
)
# ips -> i_ps due to track 2 naming issue
profile.outbound_i_ps = ManagedClusterLoadBalancerProfileOutboundIPs(
public_i_ps="public_ips"
)
profile.outbound_ip_prefixes = ManagedClusterLoadBalancerProfileOutboundIPPrefixes(
public_ip_prefixes="public_ip_prefixes"
profile.outbound_ip_prefixes = (
ManagedClusterLoadBalancerProfileOutboundIPPrefixes(
public_ip_prefixes="public_ip_prefixes"
)
)

p = loadbalancer.configure_load_balancer_profile(
Expand Down Expand Up @@ -107,17 +105,18 @@ def test_configure_load_balancer_profile_error(self):

profile = ManagedClusterLoadBalancerProfile()
# ips -> i_ps due to track 2 naming issue
profile.managed_outbound_i_ps = ManagedClusterLoadBalancerProfileManagedOutboundIPs(
count=2
profile.managed_outbound_i_ps = (
ManagedClusterLoadBalancerProfileManagedOutboundIPs(count=2)
)
# ips -> i_ps due to track 2 naming issue
profile.outbound_i_ps = ManagedClusterLoadBalancerProfileOutboundIPs(
public_i_ps="public_ips"
)
profile.outbound_ip_prefixes = ManagedClusterLoadBalancerProfileOutboundIPPrefixes(
public_ip_prefixes="public_ip_prefixes"
profile.outbound_ip_prefixes = (
ManagedClusterLoadBalancerProfileOutboundIPPrefixes(
public_ip_prefixes="public_ip_prefixes"
)
)
err = "outbound ip/ipprefix and managed ip should be mutual exclusive."
p = loadbalancer.configure_load_balancer_profile(
managed_outbound_ip_count,
managed_outbound_ipv6_count,
Expand All @@ -131,11 +130,18 @@ def test_configure_load_balancer_profile_error(self):
)
self.assertEqual(p.managed_outbound_i_ps.count, 5)
self.assertEqual(p.managed_outbound_i_ps.count_ipv6, 3)
self.assertEqual(p.outbound_i_ps.public_i_ps, [self.load_balancer_models.ResourceReference(id=x.strip()) for x in ["testpip1","testpip2"]])
self.assertEqual(
p.outbound_i_ps.public_i_ps,
[
self.load_balancer_models.ResourceReference(id=x.strip())
for x in ["testpip1", "testpip2"]
],
)
self.assertEqual(p.outbound_ip_prefixes, None)
self.assertEqual(p.allocated_outbound_ports, 80)
self.assertEqual(p.idle_timeout_in_minutes, 3600)
self.assertEqual(p.backend_pool_type, "nodeIP")

if __name__ == '__main__':

if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import unittest
from types import SimpleNamespace

# from azure.cli.core.util import CLIError
import azext_aks_preview.maintenanceconfiguration as mc
from azext_aks_preview.__init__ import register_aks_preview_resource_type
from azure.cli.command_modules.acs.tests.latest.mocks import MockCLI, MockCmd
from azure.cli.core.azclierror import (
InvalidArgumentValueError,
RequiredArgumentMissingError,
MutuallyExclusiveArgumentError,
RequiredArgumentMissingError,
)
from azext_aks_preview.__init__ import register_aks_preview_resource_type
import azext_aks_preview.maintenanceconfiguration as mc
from azure.cli.command_modules.acs.tests.latest.mocks import MockCLI, MockCmd


class TestAddMaintenanceConfiguration(unittest.TestCase):
def test_add_maintenance_configuration_with_invalid_name(self):
Expand All @@ -24,7 +24,7 @@ def test_add_maintenance_configuration_with_invalid_name(self):
"config_name": "something",
}

err = ("--config-name must be one of default, aksManagedAutoUpgradeSchedule or aksManagedNodeOSUpgradeSchedule, not something")
err = "--config-name must be one of default, aksManagedAutoUpgradeSchedule or aksManagedNodeOSUpgradeSchedule, not something"
with self.assertRaises(InvalidArgumentValueError) as cm:
mc.aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)
Expand All @@ -40,11 +40,11 @@ def test_add_default_maintenance_configuration_with_schedule_type(self):
"schedule_type": "Weekly",
}

err = ("--schedule-type is not supported for default maintenance configuration.")
err = "--schedule-type is not supported for default maintenance configuration."
with self.assertRaises(MutuallyExclusiveArgumentError) as cm:
mc.aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)

def test_add_non_default_schedule_with_weekday(self):
cmd = SimpleNamespace()
raw_parameters = {
Expand All @@ -54,11 +54,11 @@ def test_add_non_default_schedule_with_weekday(self):
"weekday": "Monday",
}

err = ("--weekday and --start-hour are only applicable to default maintenance configuration.")
err = "--weekday and --start-hour are only applicable to default maintenance configuration."
with self.assertRaises(MutuallyExclusiveArgumentError) as cm:
mc.aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)

def test_add_daily_schedule_with_missing_options(self):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
Expand All @@ -70,11 +70,11 @@ def test_add_daily_schedule_with_missing_options(self):
"schedule_type": "Daily",
}

err = ("Please specify --interval-days when using daily schedule.")
err = "Please specify --interval-days when using daily schedule."
with self.assertRaises(RequiredArgumentMissingError) as cm:
mc.aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)

def test_add_daily_schedule_with_invalid_options(self):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
Expand All @@ -88,7 +88,7 @@ def test_add_daily_schedule_with_invalid_options(self):
"day_of_week": "Monday",
}

err = ("--interval-weeks, --interval-months, --day-of-week, --day-of-month and --week-index cannot be used for Daily schedule.")
err = "--interval-weeks, --interval-months, --day-of-week, --day-of-month and --week-index cannot be used for Daily schedule."
with self.assertRaises(MutuallyExclusiveArgumentError) as cm:
mc.aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)
Expand All @@ -107,11 +107,11 @@ def test_add_weekly_schedule_with_invalid_options(self):
"week_index": "First",
}

err = ("--interval-months, --day-of-month and --week-index cannot be used for Weekly schedule.")
err = "--interval-months, --day-of-month and --week-index cannot be used for Weekly schedule."
with self.assertRaises(MutuallyExclusiveArgumentError) as cm:
mc.aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)

def test_add_absolute_monthly_schedule_with_missing_options(self):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
Expand All @@ -125,7 +125,7 @@ def test_add_absolute_monthly_schedule_with_missing_options(self):
"interval_months": 3,
}

err = ("Please specify --interval-months and --day-of-month when using absolute monthly schedule.")
err = "Please specify --interval-months and --day-of-month when using absolute monthly schedule."
with self.assertRaises(RequiredArgumentMissingError) as cm:
mc.aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)
Expand All @@ -144,11 +144,11 @@ def test_add_absolute_monthly_schedule_with_invalid_options(self):
"week_index": "First",
}

err = ("--interval-days, --interval-weeks, --day-of-week and --week-index cannot be used for AbsoluteMonthly schedule.")
err = "--interval-days, --interval-weeks, --day-of-week and --week-index cannot be used for AbsoluteMonthly schedule."
with self.assertRaises(MutuallyExclusiveArgumentError) as cm:
mc.aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)

def test_add_relative_monthly_schedule_with_missing_options(self):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
Expand All @@ -162,11 +162,11 @@ def test_add_relative_monthly_schedule_with_missing_options(self):
"interval_months": 3,
}

err = ("Please specify --interval-months, --day-of-week and --week-index when using relative monthly schedule.")
err = "Please specify --interval-months, --day-of-week and --week-index when using relative monthly schedule."
with self.assertRaises(RequiredArgumentMissingError) as cm:
mc.aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)

def test_add_dedicated_schedule_with_missing_options(self):
register_aks_preview_resource_type()
cli_ctx = MockCLI()
Expand All @@ -181,8 +181,7 @@ def test_add_dedicated_schedule_with_missing_options(self):
"start_time": "00:00",
}

err = ("Please specify --duration for maintenance window.")
err = "Please specify --duration for maintenance window."
with self.assertRaises(RequiredArgumentMissingError) as cm:
mc.aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)

Loading

0 comments on commit 40f07b1

Please sign in to comment.