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

ipam vnv bug fix #26609

Merged
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
25 changes: 15 additions & 10 deletions src/Network/Network.Test/ScenarioTests/NetworkManagerTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1528,16 +1528,16 @@ function Test-NetworkManagerIpamPoolStaticCidrCRUD
New-AzNetworkManagerIpamPool -ResourceGroupName $rgName -NetworkManagerName $networkManagerName -Name $ipamPoolName -Location $rglocation -AddressPrefix $addressPrefixes

# Create static cidr
New-AzNetworkManagerIpamPoolStaticCidr -ResourceGroupName $rgName -NetworkManagerName $networkManagerName -PoolName $ipamPoolName -Name $staticCidrName -AddressPrefix $addressPrefixes
New-AzNetworkManagerIpamPoolStaticCidr -ResourceGroupName $rgName -NetworkManagerName $networkManagerName -IpamPoolName $ipamPoolName -Name $staticCidrName -AddressPrefix $addressPrefixes

# Get static cidr
$staticCidr = Get-AzNetworkManagerIpamPoolStaticCidr -ResourceGroupName $rgName -NetworkManagerName $networkManagerName -PoolName $ipamPoolName -Name $staticCidrName
$staticCidr = Get-AzNetworkManagerIpamPoolStaticCidr -ResourceGroupName $rgName -NetworkManagerName $networkManagerName -IpamPoolName $ipamPoolName -Name $staticCidrName
Assert-NotNull $staticCidr;
Assert-AreEqual $staticCidrName $staticCidr.Name;
Assert-AreEqual $staticCidr.Properties.AddressPrefixes[0] $addressPrefixes[0];

# Remove static cidr
$job = Remove-AzNetworkManagerIpamPoolStaticCidr -ResourceGroupName $rgName -NetworkManagerName $networkManagerName -PoolName $ipamPoolName -Name $staticCidrName -PassThru -Force -AsJob;
$job = Remove-AzNetworkManagerIpamPoolStaticCidr -ResourceGroupName $rgName -NetworkManagerName $networkManagerName -IpamPoolName $ipamPoolName -Name $staticCidrName -PassThru -Force -AsJob;
$job | Wait-Job;
$removeResult = $job | Receive-Job;
}
Expand Down Expand Up @@ -1629,27 +1629,32 @@ function Test-NetworkManagerVerifierWorkspaceReachabilityAnalysisRunCRUD
Assert-NotNull $reachabilityAnalysisRun
Assert-AreEqual $reachabilityAnalysisRunName $reachabilityAnalysisRun.Name

# Get analysis run list
# Get analysis run list
$reachabilityAnalysisRunList = Get-AzNetworkManagerVerifierWorkspaceReachabilityAnalysisRun -ResourceGroupName $rgName -NetworkManagerName $networkManagerName -VerifierWorkspaceName $verifierWorkspaceName
Assert-NotNull $reachabilityAnalysisRunList;
Assert-AreEqual $reachabilityAnalysisRunList.Count 1

Start-TestSleep -Seconds 300
Assert-NotNull $reachabilityAnalysisRun
Assert-AreEqual "DESCription" $reachabilityAnalysisRun.Properties.Description;
Assert-AreEqual $intentId $reachabilityAnalysisRun.Properties.IntentId;
Start-TestSleep -Seconds 300
Assert-NotNull $reachabilityAnalysisRun

# Output the value of AnalysisResult for debugging
Write-Output "AnalysisResult: $($reachabilityAnalysisRun.Properties.AnalysisResult)"

Assert-NotNull $reachabilityAnalysisRun.Properties.AnalysisResult
Assert-AreEqual "DESCription" $reachabilityAnalysisRun.Properties.Description;
Assert-AreEqual $intentId $reachabilityAnalysisRun.Properties.IntentId;

# Delete analysis run
$job = Remove-AzNetworkManagerVerifierWorkspaceReachabilityAnalysisRun -ResourceGroupName $rgName -NetworkManagerName $networkManagerName -Name $reachabilityAnalysisRunName -VerifierWorkspaceName $verifierWorkspaceName -PassThru -Force -AsJob;
$job | Wait-Job;
$removeResult = $job | Receive-Job;

# Delete analysis intent
# Delete analysis intent
$job = Remove-AzNetworkManagerVerifierWorkspaceReachabilityAnalysisIntent -ResourceGroupName $rgName -NetworkManagerName $networkManagerName -VerifierWorkspaceName $verifierWorkspaceName -Name $reachabilityAnalysisIntentName -PassThru -Force -AsJob;
$job | Wait-Job;
$removeResult = $job | Receive-Job;

# Delete verifier workspace
# Delete verifier workspace
$job = Remove-AzNetworkManagerVerifierWorkspace -ResourceGroupName $rgName -NetworkManagerName $networkManagerName -Name $verifierWorkspaceName -PassThru -Force -AsJob;
$job | Wait-Job;
$removeResult = $job | Receive-Job;
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/Network/Network/Models/NetworkManager/PSIntentContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace Microsoft.Azure.Commands.Network.Models.NetworkManager
{
public class PSIntentContent
{
public string SourceResourceId { get; }
public string DestinationResourceId { get; }
public PSIPTraffic IpTraffic { get; }
public string SourceResourceId { get; set; }
public string DestinationResourceId { get; set; }
public PSIPTraffic IpTraffic { get; set; }

[JsonIgnore]
public string IntentContentText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class PSReachabilityAnalysisRunProperties
public string Description { get; set; }

public string IntentId { get; set; }
public PSIntentContent IntentContent { get; }
public string AnalysisResult { get; }
public string ErrorMessage { get; }
public PSIntentContent IntentContent { get; set; }
public string AnalysisResult { get; set; }
public string ErrorMessage { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class PSVerifierWorkspaceProperties

public string Description { get; set; }

public string DisplayName { get; set; }

public string VerifierWorkspaceName { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ public class GetAzNetworkManagerIpamPoolStaticCidrCommand : IpamPoolStaticCidrBa
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
[SupportsWildcards]
public virtual string PoolName { get; set; }
public virtual string IpamPoolName { get; set; }

public override void Execute()
{
base.Execute();
if (this.Name != null)
{
var staticCidr = this.GetStaticCidr(this.ResourceGroupName, this.NetworkManagerName, this.PoolName, this.Name);
var staticCidr = this.GetStaticCidr(this.ResourceGroupName, this.NetworkManagerName, this.IpamPoolName, this.Name);
staticCidr.ResourceGroupName = this.ResourceGroupName;
staticCidr.NetworkManagerName = this.NetworkManagerName;
WriteObject(staticCidr);
}
else
{
IPage<StaticCidr> staticCidrPage;
staticCidrPage = this.StaticCidrClient.List(this.ResourceGroupName, this.NetworkManagerName, this.PoolName);
staticCidrPage = this.StaticCidrClient.List(this.ResourceGroupName, this.NetworkManagerName, this.IpamPoolName);

// Get all resources by polling on next page link
var staticCidrList = ListNextLink<StaticCidr>.GetAllResourcesByPollingNextLink(staticCidrPage, this.StaticCidrClient.ListNext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public IStaticCidrsOperations StaticCidrClient
}
}

public bool IsStaticCidrPresent(string resourceGroupName, string networkManagerName, string poolName, string staticCidrName)
public bool IsStaticCidrPresent(string resourceGroupName, string networkManagerName, string ipamPoolName, string staticCidrName)
{
try
{
GetStaticCidr(resourceGroupName, networkManagerName, poolName, staticCidrName);
GetStaticCidr(resourceGroupName, networkManagerName, ipamPoolName, staticCidrName);
}
catch (Microsoft.Azure.Management.Network.Models.CommonErrorResponseException exception)
{
Expand All @@ -49,13 +49,13 @@ public bool IsStaticCidrPresent(string resourceGroupName, string networkManagerN
return true;
}

public PSStaticCidr GetStaticCidr(string resourceGroupName, string networkManagerName, string poolName, string staticCidrName)
public PSStaticCidr GetStaticCidr(string resourceGroupName, string networkManagerName, string ipamPoolName, string staticCidrName)
{
var staticCidr = this.StaticCidrClient.Get(resourceGroupName, networkManagerName, poolName, staticCidrName);
var staticCidr = this.StaticCidrClient.Get(resourceGroupName, networkManagerName, ipamPoolName, staticCidrName);
var psStaticCidr = ToPsStaticCidr(staticCidr);
psStaticCidr.ResourceGroupName = resourceGroupName;
psStaticCidr.NetworkManagerName = networkManagerName;
psStaticCidr.PoolName = poolName;
psStaticCidr.PoolName = ipamPoolName;
psStaticCidr.Name = staticCidrName;
return psStaticCidr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class NewAzNetworkManagerIpamPoolStaticCidrCommand : IpamPoolStaticCidrBa
ValueFromPipelineByPropertyName = true,
HelpMessage = "IP Address Manager Pool resource name.")]
[ValidateNotNullOrEmpty]
public virtual string PoolName { get; set; }
public virtual string IpamPoolName { get; set; }

[Parameter(
Mandatory = false,
Expand All @@ -70,7 +70,7 @@ public class NewAzNetworkManagerIpamPoolStaticCidrCommand : IpamPoolStaticCidrBa
public virtual string NumberOfIPAddressesToAllocate { get; set; }

[Parameter(
Mandatory = true,
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "List of IP address prefixes of the resource.")]
public virtual List<string> AddressPrefix { get; set; }
Expand All @@ -91,7 +91,7 @@ public class NewAzNetworkManagerIpamPoolStaticCidrCommand : IpamPoolStaticCidrBa
public override void Execute()
{
base.Execute();
var present = this.IsStaticCidrPresent(this.ResourceGroupName, this.NetworkManagerName, this.PoolName, this.Name);
var present = this.IsStaticCidrPresent(this.ResourceGroupName, this.NetworkManagerName, this.IpamPoolName, this.Name);
ConfirmAction(
Force.IsPresent,
string.Format(Properties.Resources.OverwritingResource, Name),
Expand Down Expand Up @@ -128,9 +128,9 @@ private PSStaticCidr CreateStaticCidr()
// Map to the sdk object
var staticCidrModel = NetworkResourceManagerProfile.Mapper.Map<MNM.StaticCidr>(staticCidr);

// Execute the Create Network call string resourceGroupName, string networkManagerName, string poolName, string staticCidrName
this.StaticCidrClient.Create(this.ResourceGroupName, this.NetworkManagerName, this.PoolName, this.Name, staticCidrModel);
var psStaticCidr = this.GetStaticCidr(this.ResourceGroupName, this.NetworkManagerName, this.PoolName, this.Name);
// Execute the Create Network call string resourceGroupName, string networkManagerName, string IpamPoolName, string staticCidrName
this.StaticCidrClient.Create(this.ResourceGroupName, this.NetworkManagerName, this.IpamPoolName, this.Name, staticCidrModel);
var psStaticCidr = this.GetStaticCidr(this.ResourceGroupName, this.NetworkManagerName, this.IpamPoolName, this.Name);
return psStaticCidr;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class RemoveAzNetworkManagerIpamPoolStaticCidrCommand : IpamPoolStaticCid
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
[SupportsWildcards]
public virtual string PoolName { get; set; }
public virtual string IpamPoolName { get; set; }

[Parameter(
Mandatory = false,
Expand All @@ -76,7 +76,7 @@ public override void Execute()
Name,
() =>
{
this.StaticCidrClient.Delete(this.ResourceGroupName, this.NetworkManagerName, this.PoolName, this.Name);
this.StaticCidrClient.Delete(this.ResourceGroupName, this.NetworkManagerName, this.IpamPoolName, this.Name);
if (PassThru.IsPresent)
{
WriteObject(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Microsoft.Azure.Management.Network;
using System.Net;
using Microsoft.Azure.Commands.Network.Models.NetworkManager;
using Newtonsoft.Json.Linq;
using System;

namespace Microsoft.Azure.Commands.Network
{
Expand All @@ -37,16 +39,71 @@ public bool IsAnalysisIntentPresent(string resourceGroupName, string networkMana
}
catch (Microsoft.Azure.Management.Network.Models.CommonErrorResponseException exception)
{
if (exception.Response.StatusCode == HttpStatusCode.NotFound)
// Use the concise error handling method
HandleError(exception);
return false;
}

return true;
}

// Helper method for concise error handling
private void HandleError(Microsoft.Azure.Management.Network.Models.CommonErrorResponseException exception)
{
switch (exception.Response.StatusCode)
{
case HttpStatusCode.BadRequest:
// Specific handling for Bad Request with detailed message
DisplayDetailedErrorMessage(exception);
break;

case HttpStatusCode.NotFound:
WriteWarning("Error: Not Found - The specified resource could not be found.");
break;

case HttpStatusCode.Forbidden:
WriteWarning("Error: Forbidden - You do not have permission to perform this operation.");
break;

case HttpStatusCode.InternalServerError:
WriteWarning("Error: Internal Server Error - The server encountered an unexpected condition. Try again later.");
break;

default:
WriteWarning($"Error: {exception.Response.StatusCode} - {exception.Message}");
break;
}
}

// Method to display a detailed error message for BadRequest (400) responses
private void DisplayDetailedErrorMessage(Microsoft.Azure.Management.Network.Models.CommonErrorResponseException exception)
{
string errorMessage = "Bad Request: An unknown error occurred.";

// Check if the response content is available
if (!string.IsNullOrEmpty(exception.Response.Content))
{
try
{
// Resource is not present
return false;
// Parse the JSON response content to get the "message" field
var errorContent = JObject.Parse(exception.Response.Content);
errorMessage = errorContent["message"]?.ToString() ?? errorMessage;
}
catch
{
// Fallback if parsing fails
WriteWarning($"Bad Request: Unable to parse error details. Raw response: {exception.Response.Content}");
return;
}

throw;
}
else
{
// If there is no content, default message
errorMessage = "Bad Request: The request was invalid. Please check your parameters.";
}

return true;
// Display the error message to the user
WriteWarning(errorMessage);
}

public PSReachabilityAnalysisIntent GetAnalysisIntent(string resourceGroupName, string networkManagerName, string workspaceName, string analysisIntentName)
Expand Down
Loading