forked from Azure/azure-cli-extensions
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generated from b31be622b4be1b4544665e45275ecbd040551dda
Run npm run multiapi to update all-api-versions blocks
- Loading branch information
SDK Automation
committed
Sep 1, 2020
1 parent
1d40cb0
commit 0228420
Showing
13 changed files
with
287 additions
and
219 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is | ||
# regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
import os | ||
from datetime import datetime | ||
from azure_devtools.scenario_tests import SingleValueReplacer | ||
from azure.cli.testsdk.preparers import NoTrafficRecordingPreparer | ||
from azure.cli.testsdk.exceptions import CliTestError | ||
from azure.cli.testsdk.reverse_dependency import get_dummy_cli | ||
|
||
|
||
KEY_RESOURCE_GROUP = 'rg' | ||
KEY_VIRTUAL_NETWORK = 'vnet' | ||
KEY_VNET_SUBNET = 'subnet' | ||
KEY_VNET_NIC = 'nic' | ||
|
||
|
||
class VirtualNetworkPreparer(NoTrafficRecordingPreparer, SingleValueReplacer): | ||
def __init__(self, name_prefix='clitest.vn', | ||
parameter_name='virtual_network', | ||
resource_group_name=None, | ||
resource_group_key=KEY_RESOURCE_GROUP, | ||
dev_setting_name='AZURE_CLI_TEST_DEV_VIRTUAL_NETWORK_NAME', | ||
random_name_length=24, key=KEY_VIRTUAL_NETWORK): | ||
if ' ' in name_prefix: | ||
raise CliTestError( | ||
'Error: Space character in name prefix \'%s\'' % name_prefix) | ||
super(VirtualNetworkPreparer, self).__init__( | ||
name_prefix, random_name_length) | ||
self.cli_ctx = get_dummy_cli() | ||
self.parameter_name = parameter_name | ||
self.key = key | ||
self.resource_group_name = resource_group_name | ||
self.resource_group_key = resource_group_key | ||
self.dev_setting_name = os.environ.get(dev_setting_name, None) | ||
|
||
def create_resource(self, name, **_): | ||
if self.dev_setting_name: | ||
return {self.parameter_name: self.dev_setting_name, } | ||
|
||
if not self.resource_group_name: | ||
self.resource_group_name = self.test_class_instance.kwargs.get( | ||
self.resource_group_key) | ||
if not self.resource_group_name: | ||
raise CliTestError("Error: No resource group configured!") | ||
|
||
tags = {'product': 'azurecli', 'cause': 'automation', | ||
'date': datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')} | ||
if 'ENV_JOB_NAME' in os.environ: | ||
tags['job'] = os.environ['ENV_JOB_NAME'] | ||
tags = ' '.join(['{}={}'.format(key, value) | ||
for key, value in tags.items()]) | ||
template = 'az network vnet create --resource-group {} --name {} --subnet-name default --tag ' + tags | ||
self.live_only_execute(self.cli_ctx, template.format( | ||
self.resource_group_name, name)) | ||
|
||
self.test_class_instance.kwargs[self.key] = name | ||
return {self.parameter_name: name} | ||
|
||
def remove_resource(self, name, **_): | ||
# delete vnet if test is being recorded and if the vnet is not a dev rg | ||
if not self.dev_setting_name: | ||
self.live_only_execute( | ||
self.cli_ctx, | ||
'az network vnet delete --name {} --resource-group {}'.format(name, self.resource_group_name)) | ||
|
||
|
||
class VnetSubnetPreparer(NoTrafficRecordingPreparer, SingleValueReplacer): | ||
def __init__(self, name_prefix='clitest.vn', | ||
parameter_name='subnet', | ||
resource_group_key=KEY_RESOURCE_GROUP, | ||
vnet_key=KEY_VIRTUAL_NETWORK, | ||
address_prefixes="11.0.0.0/24", | ||
dev_setting_name='AZURE_CLI_TEST_DEV_VNET_SUBNET_NAME', | ||
key=KEY_VNET_SUBNET): | ||
if ' ' in name_prefix: | ||
raise CliTestError( | ||
'Error: Space character in name prefix \'%s\'' % name_prefix) | ||
super(VnetSubnetPreparer, self).__init__(name_prefix, 15) | ||
self.cli_ctx = get_dummy_cli() | ||
self.parameter_name = parameter_name | ||
self.key = key | ||
self.resource_group = [resource_group_key, None] | ||
self.vnet = [vnet_key, None] | ||
self.address_prefixes = address_prefixes | ||
self.dev_setting_name = os.environ.get(dev_setting_name, None) | ||
|
||
def create_resource(self, name, **_): | ||
if self.dev_setting_name: | ||
return {self.parameter_name: self.dev_setting_name, } | ||
|
||
if not self.resource_group[1]: | ||
self.resource_group[1] = self.test_class_instance.kwargs.get( | ||
self.resource_group[0]) | ||
if not self.resource_group[1]: | ||
raise CliTestError("Error: No resource group configured!") | ||
if not self.vnet[1]: | ||
self.vnet[1] = self.test_class_instance.kwargs.get(self.vnet[0]) | ||
if not self.vnet[1]: | ||
raise CliTestError("Error: No vnet configured!") | ||
|
||
self.test_class_instance.kwargs[self.key] = 'default' | ||
return {self.parameter_name: name} | ||
|
||
def remove_resource(self, name, **_): | ||
pass | ||
|
||
|
||
class VnetNicPreparer(NoTrafficRecordingPreparer, SingleValueReplacer): | ||
def __init__(self, name_prefix='clitest.nic', | ||
parameter_name='subnet', | ||
resource_group_key=KEY_RESOURCE_GROUP, | ||
vnet_key=KEY_VIRTUAL_NETWORK, | ||
dev_setting_name='AZURE_CLI_TEST_DEV_VNET_NIC_NAME', | ||
key=KEY_VNET_NIC): | ||
if ' ' in name_prefix: | ||
raise CliTestError( | ||
'Error: Space character in name prefix \'%s\'' % name_prefix) | ||
super(VnetNicPreparer, self).__init__(name_prefix, 15) | ||
self.cli_ctx = get_dummy_cli() | ||
self.parameter_name = parameter_name | ||
self.key = key | ||
self.resource_group = [resource_group_key, None] | ||
self.vnet = [vnet_key, None] | ||
self.dev_setting_name = os.environ.get(dev_setting_name, None) | ||
|
||
def create_resource(self, name, **_): | ||
if self.dev_setting_name: | ||
return {self.parameter_name: self.dev_setting_name, } | ||
|
||
if not self.resource_group[1]: | ||
self.resource_group[1] = self.test_class_instance.kwargs.get( | ||
self.resource_group[0]) | ||
if not self.resource_group[1]: | ||
raise CliTestError("Error: No resource group configured!") | ||
if not self.vnet[1]: | ||
self.vnet[1] = self.test_class_instance.kwargs.get(self.vnet[0]) | ||
if not self.vnet[1]: | ||
raise CliTestError("Error: No vnet configured!") | ||
|
||
template = 'az network nic create --resource-group {} --name {} --vnet-name {} --subnet default ' | ||
self.live_only_execute(self.cli_ctx, template.format( | ||
self.resource_group[1], name, self.vnet[1])) | ||
|
||
self.test_class_instance.kwargs[self.key] = name | ||
return {self.parameter_name: name} | ||
|
||
def remove_resource(self, name, **_): | ||
if not self.dev_setting_name: | ||
self.live_only_execute( | ||
self.cli_ctx, | ||
'az network nic delete --name {} --resource-group {}'.format(name, self.resource_group[1])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters