Skip to content

Commit 3d1a7ef

Browse files
committed
Implementatioan and test file changes
1 parent fb4655c commit 3d1a7ef

File tree

7 files changed

+49
-142
lines changed

7 files changed

+49
-142
lines changed

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/NetworkWatcherAPITests.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ function Test-FlowLog
511511
$vnetName = Get-ResourceName
512512
$subnetName = Get-ResourceName
513513
$nsgName = Get-ResourceName
514+
$workspaceName = Get-ResourceName
514515

515516
try
516517
{
@@ -541,7 +542,14 @@ function Test-FlowLog
541542
New-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -Name $stoname -Location $location -Type $stotype;
542543
$sto = Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -Name $stoname;
543544

544-
$job = Set-AzureRmNetworkWatcherConfigFlowLog -NetworkWatcher $nw -TargetResourceId $getNsg.Id -EnableFlowLog $true -StorageAccountId $sto.Id -AsJob
545+
# create workspace
546+
$workspaceLocation = "East US"
547+
$workspaceSku = "Standard"
548+
549+
New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $resourceGroupName -Name $workspaceName -Location $workspaceLocation -Sku $workspaceSku
550+
$workspace = Get-AzureRmOperationalInsightsWorkspace -Name $workspaceName -ResourceGroupName $resourceGroupName
551+
552+
$job = Set-AzureRmNetworkWatcherConfigFlowLog -NetworkWatcher $nw -TargetResourceId $getNsg.Id -EnableFlowLog $true -StorageAccountId $sto.Id -EnableTrafficAnalytics $true -WorkspaceResourceId $workspace.Id -WorkspaceLocation $workspace.Location -WorkspaceGUId $workspace.CustomerId -AsJob
545553
$job | Wait-Job
546554
$config = $job | Receive-Job
547555
$job = Get-AzureRmNetworkWatcherFlowLogStatus -NetworkWatcher $nw -TargetResourceId $getNsg.Id -AsJob
@@ -554,11 +562,19 @@ function Test-FlowLog
554562
Assert-AreEqual $config.Enabled $true
555563
Assert-AreEqual $config.RetentionPolicy.Days 0
556564
Assert-AreEqual $config.RetentionPolicy.Enabled $false
565+
Assert-AreEqual $config.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled $true
566+
Assert-AreEqual $config.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceResourceId $workspace.Id
567+
Assert-AreEqual $config.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceId $workspace.CustomerId
568+
Assert-AreEqual $config.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceRegion $workspace.Location
557569
Assert-AreEqual $status.TargetResourceId $getNsg.Id
558570
Assert-AreEqual $status.StorageId $sto.Id
559571
Assert-AreEqual $status.Enabled $true
560572
Assert-AreEqual $status.RetentionPolicy.Days 0
561573
Assert-AreEqual $status.RetentionPolicy.Enabled $false
574+
Assert-AreEqual $status.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled $true
575+
# Assert-AreEqual $status.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceResourceId $workspace.Id
576+
# Assert-AreEqual $status.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceId $workspace.CustomerId
577+
# Assert-AreEqual $status.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceRegion $workspace.Location
562578
}
563579
finally
564580
{

src/ResourceManager/Network/Commands.Network/Commands.Network.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@
185185
<Compile Include="Common\NetworkClient.cs" />
186186
<Compile Include="Common\NetworkCloudException.cs" />
187187
<Compile Include="Common\NetworkResourceManagerProfile.cs" />
188-
<Compile Include="Common\RecordedDelegatingHandler.cs" />
189188
<Compile Include="DdosProtectionPlan\GetAzureRMDdosProtectionPlanCommand.cs" />
190189
<Compile Include="DdosProtectionPlan\NewAzureRMDdosProtectionPlanCommand.cs" />
191190
<Compile Include="DdosProtectionPlan\RemoveAzureRMDdosProtectionPlanCommand.cs" />

src/ResourceManager/Network/Commands.Network/Common/RecordedDelegatingHandler.cs

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/ResourceManager/Network/Commands.Network/NetworkWatcher/SetAzureNetworkWatcherConfigFlowLogCommand.cs

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using System.Management.Automation;
2222
using MNM = Microsoft.Azure.Management.Network.Models;
2323
using Microsoft.Azure.Management.OperationalInsights;
24-
using ResourceGroups.Tests;
2524

2625
namespace Microsoft.Azure.Commands.Network
2726
{
@@ -34,6 +33,9 @@ public class SetAzureNetworkWatcherConfigFlowLogCommand : NetworkWatcherBaseCmdl
3433
private const string SetByNameWithTAByResource = "SetByNameWithTAByResource";
3534
private const string SetByNameWithTAByDetails = "SetByNameWithTAByDetails";
3635
private const string SetByNameWithoutTA = "SetByNameWithoutTA";
36+
private const string SetByResource = "SetByResource";
37+
private const string WithTA = "WithTA";
38+
private const string TAByDetails = "TAByDetails";
3739

3840
[Parameter(
3941
Mandatory = true,
@@ -201,7 +203,7 @@ public class SetAzureNetworkWatcherConfigFlowLogCommand : NetworkWatcherBaseCmdl
201203
ParameterSetName = SetByResourceWithTAByResource)]
202204
[Parameter(
203205
Mandatory = true,
204-
ValueFromPipelineByPropertyName = true,
206+
ValueFromPipeline = true,
205207
HelpMessage = "The WS object which is used to store the traffic analytics data.",
206208
ParameterSetName = SetByNameWithTAByResource)]
207209
[ValidateNotNull]
@@ -212,8 +214,11 @@ public override void Execute()
212214
base.Execute();
213215
string resourceGroupName;
214216
string name;
217+
string WorkspaceResourceId;
218+
string WorkspaceGUId;
219+
string WorkspaceLocation;
215220

216-
if (ParameterSetName.Contains("SetByResource"))
221+
if (ParameterSetName.Contains(SetByResource))
217222
{
218223
resourceGroupName = this.NetworkWatcher.ResourceGroupName;
219224
name = this.NetworkWatcher.Name;
@@ -241,68 +246,50 @@ public override void Execute()
241246
parameters.RetentionPolicy.Days = this.RetentionInDays;
242247
}
243248

244-
if (this.EnableTrafficAnalytics == true || this.EnableTrafficAnalytics == false)
249+
if (ParameterSetName.Contains(WithTA))
245250
{
246251
parameters.FlowAnalyticsConfiguration = new MNM.TrafficAnalyticsProperties();
247252
parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration = new MNM.TrafficAnalyticsConfigurationProperties();
248253

249-
parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled = this.EnableTrafficAnalytics;
254+
parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled = this.EnableTrafficAnalytics.IsPresent;
250255

251-
string[] workspaceDetailsComponents = this.WorkspaceResourceId.Split('/');
252-
string worksapceResourceGroup = "", workspaceName = "";
256+
253257

254-
//Expected format : /subscriptions/-WorkspaceSubscriptionId-/resourcegroups/-WorkspaceResourceGroup-/providers/microsoft.operationalinsights/workspaces/-this.WorkspaceName-
255-
if (workspaceDetailsComponents.Length == 9)
256-
{
257-
worksapceResourceGroup = workspaceDetailsComponents[4];
258-
workspaceName = workspaceDetailsComponents[8];
259-
260-
}
261-
else
262-
{
263-
throw new System.ArgumentException("The given workspace resource id is not in format of: /subscriptions/-WorkspaceSubscriptionId-/resourcegroups/-WorkspaceResourceGroup-/providers/microsoft.operationalinsights/workspaces/-this.WorkspaceName-.");
264-
}
265-
266-
if (Workspace == null)
258+
if (ParameterSetName.Contains(TAByDetails))
267259
{
268260
if (this.WorkspaceResourceId == null || this.WorkspaceGUId == null || this.WorkspaceLocation == null)
269261
{
270262
throw new System.ArgumentException("Either the Workspace parameter or all of WorkspaceResourceId,WorkspaceGUId,WorkspaceLocation must be provided");
271263
}
264+
265+
string[] workspaceDetailsComponents = this.WorkspaceResourceId.Split('/');
266+
267+
//Expected format : /subscriptions/-WorkspaceSubscriptionId-/resourcegroups/-WorkspaceResourceGroup-/providers/microsoft.operationalinsights/workspaces/-this.WorkspaceName-
268+
if (workspaceDetailsComponents.Length != 9)
269+
{
270+
throw new System.ArgumentException("The given workspace resource id is not in format of: /subscriptions/-WorkspaceSubscriptionId-/resourcegroups/-WorkspaceResourceGroup-/providers/microsoft.operationalinsights/workspaces/-this.WorkspaceName-.");
271+
}
272+
273+
WorkspaceResourceId = this.WorkspaceResourceId;
274+
WorkspaceGUId = this.WorkspaceGUId;
275+
WorkspaceLocation = this.WorkspaceLocation;
272276
}
273277
else
274278
{
275-
if (this.WorkspaceResourceId == null)
276-
{
277-
this.WorkspaceResourceId = this.Workspace.Id;
278-
}
279-
else if (this.WorkspaceResourceId != this.Workspace.Id)
279+
if (this.Workspace == null)
280280
{
281-
throw new System.ArgumentException("The Workspace parameter and the WorkspaceResourceId poarameters are conflicting");
281+
throw new System.ArgumentException("Either the Workspace parameter or all of WorkspaceResourceId,WorkspaceGUId,WorkspaceLocation must be provided");
282282
}
283283

284-
if (this.WorkspaceGUId == null)
285-
{
286-
this.WorkspaceGUId = this.Workspace.CustomerId;
287-
}
288-
else if (this.WorkspaceGUId != this.Workspace.CustomerId)
289-
{
290-
throw new System.ArgumentException("The Workspace parameter and the WorkspaceGUId poarameters are conflicting");
291-
}
284+
WorkspaceResourceId = this.Workspace.Id;
285+
WorkspaceGUId = this.Workspace.CustomerId;
286+
WorkspaceLocation = this.Workspace.Location;
292287

293-
if (this.WorkspaceLocation == null)
294-
{
295-
this.WorkspaceLocation = this.Workspace.Location;
296-
}
297-
else if (this.WorkspaceLocation != this.Workspace.Location)
298-
{
299-
throw new System.ArgumentException("The Workspace parameter and the WorkspaceLocation poarameters are conflicting");
300-
}
301288
}
302289

303-
parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceId = this.WorkspaceGUId;
304-
parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceRegion = this.WorkspaceLocation;
305-
parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceResourceId = this.WorkspaceResourceId;
290+
parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceResourceId = WorkspaceResourceId;
291+
parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceId = WorkspaceGUId;
292+
parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceRegion = WorkspaceLocation;
306293
}
307294

308295
PSFlowLog flowLog = new PSFlowLog();
@@ -319,10 +306,5 @@ public PSFlowLog SetFlowLogConfig(string resourceGroupName, string name, MNM.Flo
319306
return psFlowLog;
320307
}
321308

322-
//public static OperationalInsightsManagementClient GetOperationalInsightsManagementClientWithHandler(MockContext context, RecordedDelegatingHandler handler)
323-
//{
324-
// var client = context.GetServiceClient<OperationalInsightsManagementClient>(handlers: handler);
325-
// return client;
326-
//}
327309
}
328310
}

src/StackAdmin/AzureRM/AzureRM.psm1

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

tools/AzureRM/AzureRM.psm1

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)