Skip to content

Commit

Permalink
vnet and platform version tests (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
solankisamir committed Nov 9, 2021
1 parent 1fac134 commit 30e482f
Show file tree
Hide file tree
Showing 15 changed files with 21,419 additions and 7,703 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="[6.0.0-preview,7.0)" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="10.0.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public void BackupAndRestoreService()
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags);
testBase.tags,
PlatformVersion.Stv2);
// validate apiversion constraint is set
Assert.NotNull(createdService.ApiVersionConstraint);
Assert.Equal("2019-01-01", createdService.ApiVersionConstraint.MinApiVersion);
Expand Down Expand Up @@ -79,7 +80,8 @@ public void BackupAndRestoreService()
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags);
testBase.tags,
PlatformVersion.Stv2);

var restoreServiceResponse = testBase.client.ApiManagementService.Restore(testBase.rgName, testBase.serviceName, parameters);
Assert.NotNull(restoreServiceResponse);
Expand All @@ -91,7 +93,8 @@ public void BackupAndRestoreService()
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags);
testBase.tags,
PlatformVersion.Stv2);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public partial class ApiManagementServiceTests
{
[Fact]
[Trait("owner", "sasolank")]
public async Task CreateInVirtualNetworkTests()
public async Task CreateInVirtualNetworkStv1Tests()
{
Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
using (MockContext context = MockContext.Start(this.GetType()))
Expand Down Expand Up @@ -81,7 +81,8 @@ public async Task CreateInVirtualNetworkTests()
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags);
testBase.tags,
PlatformVersion.Stv1);

Assert.Equal(VirtualNetworkType.External, createdService.VirtualNetworkType);
Assert.NotNull(createdService.VirtualNetworkConfiguration);
Expand Down Expand Up @@ -141,13 +142,200 @@ public async Task CreateInVirtualNetworkTests()
resourceGroupName: testBase.rgName,
serviceName: testBase.serviceName);

Assert.Throws<ErrorResponseException>(() =>
Assert.Throws<Microsoft.Azure.Management.ApiManagement.Models.ErrorResponseException>(() =>
{
testBase.client.ApiManagementService.Get(
resourceGroupName: testBase.rgName,
serviceName: testBase.serviceName);
});
}
}

[Fact]
[Trait("owner", "sasolank")]
public async Task CreateInVirtualNetworkStv2Tests()
{
Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
using (MockContext context = MockContext.Start(this.GetType()))
{
var testBase = new ApiManagementTestBase(context);

var virtualNetworkName = TestUtilities.GenerateName("apimvnet");
var subnetName = TestUtilities.GenerateName("apimsubnet");

// setup NSG
string networkSecurityGroupName = TestUtilities.GenerateName();
var networkSecurityGroup = new NetworkSecurityGroup()
{
Location = testBase.location,
};

// Put Nsg
var putNsgResponse = testBase.networkClient.NetworkSecurityGroups.CreateOrUpdate(testBase.rgName, networkSecurityGroupName, networkSecurityGroup);
Assert.Equal("Succeeded", putNsgResponse.ProvisioningState);

// setup VNET
var vnet = new VirtualNetwork()
{
Location = testBase.location,

AddressSpace = new AddressSpace()
{
AddressPrefixes = new List<string>()
{
"10.0.0.0/16",
}
},
Subnets = new List<Subnet>()
{
new Subnet()
{
Name = subnetName,
AddressPrefix = "10.0.1.0/24",
NetworkSecurityGroup = new NetworkSecurityGroup()
{
Id = putNsgResponse.Id
}
}
}
};

// Put Vnet
var putVnetResponse = testBase.networkClient.VirtualNetworks.CreateOrUpdate(testBase.rgName, virtualNetworkName, vnet);
Assert.Equal("Succeeded", putVnetResponse.ProvisioningState);

var getSubnetResponse = testBase.networkClient.Subnets.Get(testBase.rgName, virtualNetworkName, subnetName);
Assert.NotNull(getSubnetResponse);
Assert.NotNull(getSubnetResponse.Id);

// create public IP
var putPublicIPResponse = await SetupPublicIPAsync(testBase);

testBase.serviceProperties.VirtualNetworkType = VirtualNetworkType.External;
testBase.serviceProperties.VirtualNetworkConfiguration = new VirtualNetworkConfiguration()
{
SubnetResourceId = getSubnetResponse.Id
};
testBase.serviceProperties.PublicIpAddressId = putPublicIPResponse.Id;

var createdService = testBase.client.ApiManagementService.CreateOrUpdate(
resourceGroupName: testBase.rgName,
serviceName: testBase.serviceName,
parameters: testBase.serviceProperties);

ValidateService(createdService,
testBase.serviceName,
testBase.rgName,
testBase.subscriptionId,
testBase.location,
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags,
PlatformVersion.Stv2);

Assert.Equal(VirtualNetworkType.External, createdService.VirtualNetworkType);
Assert.NotNull(createdService.VirtualNetworkConfiguration);
Assert.Equal(getSubnetResponse.Id, createdService.VirtualNetworkConfiguration.SubnetResourceId);
Assert.Equal(putPublicIPResponse.Id, createdService.PublicIpAddressId);

// apply network configuration
var applyNetworkConfigParameters = new ApiManagementServiceApplyNetworkConfigurationParameters()
{
Location = createdService.Location
};

var applyNetworkServiceResponse = testBase.client.ApiManagementService.ApplyNetworkConfigurationUpdates(
resourceGroupName: testBase.rgName,
serviceName: testBase.serviceName,
parameters: applyNetworkConfigParameters);

Assert.NotNull(applyNetworkServiceResponse);
Assert.Equal(createdService.Name, applyNetworkServiceResponse.Name);
Assert.NotNull(applyNetworkServiceResponse.VirtualNetworkConfiguration);
Assert.Equal(VirtualNetworkType.External, applyNetworkServiceResponse.VirtualNetworkType);
// get the network status by service
var serviceNetworkStatus = await testBase.client.NetworkStatus.ListByServiceAsync(
testBase.rgName,
testBase.serviceName);
Assert.NotNull(serviceNetworkStatus);
Assert.Single(serviceNetworkStatus);
Assert.Equal(testBase.location.ToLowerAndRemoveWhiteSpaces(), serviceNetworkStatus.First().Location.ToLowerAndRemoveWhiteSpaces());
Assert.NotNull(serviceNetworkStatus.First().NetworkStatus.ConnectivityStatus);
Assert.NotNull(serviceNetworkStatus.First().NetworkStatus.DnsServers);
Assert.Equal("success", serviceNetworkStatus.First().NetworkStatus.ConnectivityStatus.First().Status, true);
Assert.NotNull(serviceNetworkStatus.First().NetworkStatus.ConnectivityStatus.First().Name);
Assert.NotNull(serviceNetworkStatus.First().NetworkStatus.ConnectivityStatus.First().ResourceType);

// get the network status by location
var serviceNetworkStatusByLocation = await testBase.client.NetworkStatus.ListByLocationAsync(
testBase.rgName,
testBase.serviceName,
createdService.Location);
Assert.NotNull(serviceNetworkStatusByLocation);
Assert.NotNull(serviceNetworkStatusByLocation.ConnectivityStatus);
Assert.NotNull(serviceNetworkStatusByLocation.DnsServers);
Assert.Equal("success", serviceNetworkStatusByLocation.ConnectivityStatus.First().Status, true);
Assert.NotNull(serviceNetworkStatusByLocation.ConnectivityStatus.First().Name);

// Move to Internal Virtual Network
// setup new public ip
var putPublicIPResponse2 = await SetupPublicIPAsync(testBase);

testBase.serviceProperties.VirtualNetworkType = VirtualNetworkType.Internal;
testBase.serviceProperties.PublicIpAddressId = putPublicIPResponse2.Id;

var updatedService = testBase.client.ApiManagementService.CreateOrUpdate(
resourceGroupName: testBase.rgName,
serviceName: testBase.serviceName,
parameters: testBase.serviceProperties);
Assert.Equal(VirtualNetworkType.Internal, updatedService.VirtualNetworkType);
Assert.NotNull(updatedService.VirtualNetworkConfiguration);
Assert.Equal(getSubnetResponse.Id, updatedService.VirtualNetworkConfiguration.SubnetResourceId);
Assert.Equal(putPublicIPResponse2.Id, updatedService.PublicIpAddressId);

// Delete
testBase.client.ApiManagementService.Delete(
resourceGroupName: testBase.rgName,
serviceName: testBase.serviceName);

Assert.Throws<Microsoft.Azure.Management.ApiManagement.Models.ErrorResponseException>(() =>
{
testBase.client.ApiManagementService.Get(
resourceGroupName: testBase.rgName,
serviceName: testBase.serviceName);
});
}
}

async Task<PublicIPAddress> SetupPublicIPAsync(ApiManagementTestBase testBase)
{
// put Public IP
string publicIpName = TestUtilities.GenerateName();
string domainNameLabel = TestUtilities.GenerateName(testBase.rgName);

var publicIp = new PublicIPAddress()
{
Location = testBase.location,
Tags = new Dictionary<string, string>()
{
{"key","value"}
},
PublicIPAllocationMethod = IPAllocationMethod.Static,
PublicIPAddressVersion = "IPv4",
DnsSettings = new PublicIPAddressDnsSettings()
{
DomainNameLabel = domainNameLabel
},
Sku = new PublicIPAddressSku()
{
Name = "Standard"
}
};
var putPublicIPResponse = await testBase.networkClient.PublicIPAddresses.CreateOrUpdateAsync(testBase.rgName, publicIpName, publicIp);
Assert.Equal("Succeeded", putPublicIPResponse.ProvisioningState);

return putPublicIPResponse;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public void CreateListDelete()
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags);
testBase.tags,
PlatformVersion.Stv2);

// skuoperations api at service level
var apimSkus = testBase.client.ApiManagementServiceSkus.ListAvailableServiceSkus(testBase.rgName, testBase.serviceName);
Expand Down Expand Up @@ -78,7 +79,8 @@ public void CreateListDelete()
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags);
testBase.tags,
PlatformVersion.Stv2);

// get sso token
var ssoTokenResponse = testBase.client.ApiManagementService.GetSsoToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public void CreateMultiHostNameZoneAwareService()
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags);
testBase.tags,
PlatformVersion.Stv2);

Assert.Equal(2, createdService.Sku.Capacity);
Assert.Equal(2, createdService.Zones.Count);
Expand Down Expand Up @@ -139,14 +140,25 @@ public void CreateMultiHostNameZoneAwareService()

// update the service
int intialTagsCount = createdService.Tags.Count;
createdService.Tags.Add("client", "test");
var updatedService = testBase.client.ApiManagementService.CreateOrUpdate(testBase.rgName,

var updateParameters = new ApiManagementServiceUpdateParameters()
{
Zones = new[] { "2", "3" },
Tags = new Dictionary<string, string>()
{
{ "client", "test" }
}
};
var updatedService = testBase.client.ApiManagementService.Update(testBase.rgName,
testBase.serviceName,
createdService);
updateParameters);
Assert.NotNull(updatedService);
Assert.NotEmpty(updatedService.Tags);
Assert.Equal(intialTagsCount + 1, updatedService.Tags.Count);
Assert.Equal(1, updatedService.Tags.Count);
Assert.Equal(5, updatedService.HostnameConfigurations.Count());
Assert.Equal(2, updatedService.Zones.Count);
Assert.True(updatedService.Zones.Contains("2"));
Assert.True(updatedService.Zones.Contains("3"));

hostnameConfigurationToValidate = updatedService.HostnameConfigurations
.Where(h => !h.HostName.Equals(defaultHostname, StringComparison.InvariantCultureIgnoreCase));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public void CreateMultiRegionService()
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags);
testBase.tags,
PlatformVersion.Stv2);

Assert.NotNull(createdService.AdditionalLocations);
Assert.Single(createdService.AdditionalLocations);
Expand All @@ -76,7 +77,8 @@ public void CreateMultiRegionService()
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags);
testBase.tags,
PlatformVersion.Stv2);

// validate primary region is disabled
Assert.True(createdService.DisableGateway);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public void InstallIntermediateCertificatesTest()
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags);
testBase.tags,
PlatformVersion.Stv2);

Assert.NotNull(createdService.Certificates);
Assert.Single(createdService.Certificates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public partial class ApiManagementServiceTests : TestBase
string expectedPublisherEmail,
string expectedPublisherName,
string expectedSkuName,
Dictionary<string, string> expectedTags)
Dictionary<string, string> expectedTags,
string platformVersion)
{
Assert.NotNull(service);

Expand All @@ -46,6 +47,8 @@ public partial class ApiManagementServiceTests : TestBase
}
Assert.Equal(expectedPublisherName, service.PublisherName);
Assert.Equal(expectedPublisherEmail, service.PublisherEmail);
Assert.Equal(platformVersion, service.PlatformVersion);
Assert.Equal("Enabled", service.PublicNetworkAccess);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void SetupSystemAssignedMsiTests()
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags);
testBase.tags,
PlatformVersion.Mtv1);

Assert.NotNull(createdService.Identity);
Assert.Equal("SystemAssigned", createdService.Identity.Type);
Expand Down Expand Up @@ -113,7 +114,8 @@ public void SetupUserAssignedMsiTests()
testBase.serviceProperties.PublisherEmail,
testBase.serviceProperties.PublisherName,
testBase.serviceProperties.Sku.Name,
testBase.tags);
testBase.tags,
PlatformVersion.Mtv1);

Assert.NotNull(createdService.Identity);
Assert.NotNull(createdService.Identity.Type);
Expand Down

0 comments on commit 30e482f

Please sign in to comment.