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

Fix DF Check for Creating Extension Identity #77

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/k8s-extension/azext_k8s_extension/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
EXTENSION_PACKAGE_NAME = "azext_k8s_extension"
PROVIDER_NAMESPACE = 'Microsoft.KubernetesConfiguration'
REGISTERED = "Registered"
DF_RM_ENDPOINT = 'https://api-dogfood.resources.windows-int.net/'
DF_RM_HOSTNAME = 'api-dogfood.resources.windows-int.net'
7 changes: 4 additions & 3 deletions src/k8s-extension/azext_k8s_extension/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import json
from knack.log import get_logger
from urllib.parse import urlparse

from azure.cli.core.azclierror import ResourceNotFoundError, MutuallyExclusiveArgumentError, \
InvalidArgumentValueError, CommandNotFoundError, RequiredArgumentMissingError
Expand Down Expand Up @@ -138,7 +139,7 @@ def create_k8s_extension(cmd, client, resource_group_name, cluster_name, name, c

# Create identity, if required
# We don't create the identity if we are in DF
if create_identity and not __is_dogfood_cluster(cmd):
if create_identity and not is_dogfood_cluster(cmd):
extension_instance.identity, extension_instance.location = \
__create_identity(cmd, resource_group_name, cluster_name, cluster_type, cluster_rp)

Expand Down Expand Up @@ -291,5 +292,5 @@ def __read_config_settings_file(file_path):
raise Exception("File {} is not a valid JSON file".format(file_path)) from ex


def __is_dogfood_cluster(cmd):
return cmd.cli_ctx.cloud.endpoints.resource_manager == consts.DF_RM_ENDPOINT
def is_dogfood_cluster(cmd):
return urlparse(cmd.cli_ctx.cloud.endpoints.resource_manager).hostname == consts.DF_RM_HOSTNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# --------------------------------------------------------------------------------------------
# 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.core import AzCommandsLoader


class MockCommand:
def __init__(self):
self.cli_ctx = MockCLIContext()

class MockCLIContext:
def __init__(self):
self.cloud = MockCloud()

class MockCloud:
def __init__(self):
self.endpoints = Endpoints()

class Endpoints:
def __init__(self):
self.resource_manager = ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
from typing import no_type_check
import unittest

from .MockClasses import MockCLIContext, MockCommand
from azext_k8s_extension.custom import is_dogfood_cluster


class TestIsDogfoodCluster(unittest.TestCase):
def test_dogfood_cluster(self):
cmd = MockCommand()
cmd.cli_ctx.cloud.endpoints.resource_manager = "https://api-dogfood.resources.windows-int.net"
assert is_dogfood_cluster(cmd)

def test_dogfood_cluster_with_slash(self):
cmd = MockCommand()
cmd.cli_ctx.cloud.endpoints.resource_manager = "https://api-dogfood.resources.windows-int.net/"
assert is_dogfood_cluster(cmd)

def test_longer_hostname(self):
cmd = MockCommand()
cmd.cli_ctx.cloud.endpoints.resource_manager = "https://api-dogfood.resources.windows-int.otherwebsite.net/"
assert not is_dogfood_cluster(cmd)

def malformed_url(self):
cmd = MockCommand()
cmd.cli_ctx.cloud.endpoints.resource_manager = "htmalformed~2987493"
assert not is_dogfood_cluster(cmd)

def test_prod_cluster(self):
cmd = MockCommand()
cmd.cli_ctx.cloud.endpoints.resource_manager = "https://management.azure.com"
assert not is_dogfood_cluster(cmd)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from azure.cli.core.azclierror import InvalidArgumentValueError
from azext_k8s_extension.partner_extensions.OpenServiceMesh import _get_tested_distros

TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))

class TestOpenServiceMesh(unittest.TestCase):
def test_bad_osm_arc_version(self):
Expand Down