public async Task CheckConnectivityVmToInternetTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("azsmnet");
            string location          = TestEnvironment.Location;
            var    resourceGroup     = await CreateResourceGroup(resourceGroupName, location);

            string virtualMachineName       = Recording.GenerateAssetName("azsmnet");
            string networkInterfaceName     = Recording.GenerateAssetName("azsmnet");
            string networkSecurityGroupName = virtualMachineName + "-nsg";

            //Deploy VM with a template
            var vm = await CreateWindowsVM(virtualMachineName, networkInterfaceName, location, resourceGroup);

            //Deploy networkWatcherAgent on VM
            await deployWindowsNetworkAgent(virtualMachineName, location, resourceGroup);

            //Create network Watcher
            string networkWatcherName = Recording.GenerateAssetName("azsmnet");
            var    properties         = new NetworkWatcherData {
                Location = location
            };
            await resourceGroup.GetNetworkWatchers().CreateOrUpdateAsync(true, networkWatcherName, properties);

            ConnectivityParameters connectivityParameters =
                new ConnectivityParameters(new ConnectivitySource(vm.Id), new ConnectivityDestination {
                Address = "bing.com", Port = 80
            });

            Operation <ConnectivityInformation> connectivityCheckOperation = await GetResourceGroup("NetworkWatcherRG").GetNetworkWatchers().Get("NetworkWatcher_westus2").Value.CheckConnectivityAsync(true, connectivityParameters);

            Response <ConnectivityInformation> connectivityCheck = await connectivityCheckOperation.WaitForCompletionAsync();;

            //Validation
            Assert.AreEqual("Reachable", connectivityCheck.Value.ConnectionStatus.ToString());
            Assert.AreEqual(0, connectivityCheck.Value.ProbesFailed);
            Assert.AreEqual("Source", connectivityCheck.Value.Hops.FirstOrDefault().Type);
            Assert.AreEqual("Internet", connectivityCheck.Value.Hops.LastOrDefault().Type);
        }
        internal static NetworkWatcherListResult DeserializeNetworkWatcherListResult(JsonElement element)
        {
            Optional <IReadOnlyList <NetworkWatcherData> > value = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <NetworkWatcherData> array = new List <NetworkWatcherData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(NetworkWatcherData.DeserializeNetworkWatcherData(item));
                    }
                    value = array;
                    continue;
                }
            }
            return(new NetworkWatcherListResult(Optional.ToList(value)));
        }
Beispiel #3
0
        public async Task FlowLogApiTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("azsmnet");

            string location = "eastus2euap";
            //string workspaceLocation = "East US";
            var resourceGroup = await CreateResourceGroup(resourceGroupName, location);

            //Create network security group
            string networkSecurityGroupName = Recording.GenerateAssetName("azsmnet");
            var    networkSecurityGroup     = new NetworkSecurityGroupData()
            {
                Location = location,
            };

            // Put Nsg
            var securityGroupCollection = resourceGroup.GetNetworkSecurityGroups();
            var putNsgResponseOperation = await securityGroupCollection.CreateOrUpdateAsync(true, networkSecurityGroupName, networkSecurityGroup);

            await putNsgResponseOperation.WaitForCompletionAsync();;
            // Get NSG
            Response <NetworkSecurityGroup> getNsgResponse = await securityGroupCollection.GetAsync(networkSecurityGroupName);

            string networkWatcherName = Recording.GenerateAssetName("azsmnet");
            var    properties         = new NetworkWatcherData {
                Location = location
            };

            //Create network Watcher
            var networkWatcherCollection = resourceGroup.GetNetworkWatchers();
            await networkWatcherCollection.CreateOrUpdateAsync(true, networkWatcherName, properties);

            //Create storage
            string storageName = Recording.GenerateAssetName("azsmnet");

            //var storageParameters = new StorageAccountCreateParameters(new Sku(SkuName.StandardLRS), Kind.Storage, location);

            //Operation<StorageAccount> storageAccountOperation = await StorageManagementClient.StorageAccounts.CreateAsync(resourceGroupName, storageName, storageParameters);
            //Response<StorageAccount> storageAccount = await storageAccountOperation.WaitForCompletionAsync();;

            //create workspace
            string workspaceName = Recording.GenerateAssetName("azsmnet");

            //TODO:Need OperationalInsightsManagementClient SDK
            //var workSpaceParameters = new Workspace()
            //{
            //    Location = workspaceLocation
            //};
            //var workspace = operationalInsightsManagementClient.Workspaces.CreateOrUpdate(resourceGroupName, workspaceName, workSpaceParameters);

            //FlowLogInformation configParameters = new FlowLogInformation(getNsgResponse.Value.Id, storageAccount.Value.Id, true)
            //{
            //    RetentionPolicy = new RetentionPolicyParameters
            //    {
            //        Days = 5,
            //        Enabled = true
            //    },
            //    FlowAnalyticsConfiguration = new TrafficAnalyticsProperties()
            //    {
            //        NetworkWatcherFlowAnalyticsConfiguration = new TrafficAnalyticsConfigurationProperties()
            //        {
            //            Enabled = true,
            //            //WorkspaceId = workspace.CustomerId,
            //            //WorkspaceRegion = workspace.Location,
            //            //WorkspaceResourceId = workspace.Id
            //        }
            //    }
            //};

            //configure flowlog and TA
            //var configureFlowLog1Operation = await networkWatcherCollection.Get(networkWatcherName).Value.SetFlowLogConfigurationAsync(configParameters);
            //await configureFlowLog1Operation.WaitForCompletionAsync();;

            //var queryFlowLogStatus1Operation = await networkWatcherCollection.Get(networkWatcherName).Value.GetFlowLogStatusAsync(new FlowLogStatusParameters(getNsgResponse.Value.Id));
            //Response<FlowLogInformation> queryFlowLogStatus1 = await queryFlowLogStatus1Operation.WaitForCompletionAsync();;
            ////check both flowlog and TA config and enabled status
            //Assert.AreEqual(queryFlowLogStatus1.Value.TargetResourceId, configParameters.TargetResourceId);
            //Assert.True(queryFlowLogStatus1.Value.Enabled);
            //Assert.AreEqual(queryFlowLogStatus1.Value.StorageId, configParameters.StorageId);
            //Assert.AreEqual(queryFlowLogStatus1.Value.RetentionPolicy.Days, configParameters.RetentionPolicy.Days);
            //Assert.AreEqual(queryFlowLogStatus1.Value.RetentionPolicy.Enabled, configParameters.RetentionPolicy.Enabled);
            //Assert.True(queryFlowLogStatus1.Value.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled);
            //Assert.AreEqual(queryFlowLogStatus1.Value.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceId,
            //    configParameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceId);
            //Assert.AreEqual(queryFlowLogStatus1.Value.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceRegion,
            //    configParameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceRegion);
            //Assert.AreEqual(queryFlowLogStatus1.Value.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceResourceId,
            //    configParameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceResourceId);

            ////disable TA
            //configParameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled = false;
            //var configureFlowLog2Operation = await networkWatcherCollection.Get(networkWatcherName).Value.SetFlowLogConfigurationAsync(configParameters);
            //await configureFlowLog2Operation.WaitForCompletionAsync();;

            //var queryFlowLogStatus2Operation = await networkWatcherCollection.Get(networkWatcherName).Value.GetFlowLogStatusAsync(new FlowLogStatusParameters(getNsgResponse.Value.Id));
            //Response<FlowLogInformation> queryFlowLogStatus2 = await queryFlowLogStatus2Operation.WaitForCompletionAsync();;

            ////check TA disabled and ensure flowlog config is unchanged
            //Assert.AreEqual(queryFlowLogStatus2.Value.StorageId, configParameters.StorageId);
            //Assert.AreEqual(queryFlowLogStatus2.Value.RetentionPolicy.Days, configParameters.RetentionPolicy.Days);
            //Assert.AreEqual(queryFlowLogStatus2.Value.RetentionPolicy.Enabled, configParameters.RetentionPolicy.Enabled);
            //Assert.False(queryFlowLogStatus2.Value.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled);

            ////disable flowlog (and TA)
            //configParameters.Enabled = false;
            //var configureFlowLog3Operation = await networkWatcherCollection.Get(networkWatcherName).Value.SetFlowLogConfigurationAsync(configParameters);
            //await configureFlowLog3Operation.WaitForCompletionAsync();;

            //var queryFlowLogStatus3Operation = await networkWatcherCollection.Get(networkWatcherName).Value.GetFlowLogStatusAsync(new FlowLogStatusParameters(getNsgResponse.Value.Id));
            //Response<FlowLogInformation> queryFlowLogStatus3 = await queryFlowLogStatus3Operation.WaitForCompletionAsync();;

            ////check both flowlog and TA disabled
            //Assert.False(queryFlowLogStatus3.Value.Enabled);
            //Assert.False(queryFlowLogStatus3.Value.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled);
        }
Beispiel #4
0
        public async Task NetworkWatcherApiTest()
        {
            SubscriptionResource subscription = await ArmClient.GetDefaultSubscriptionAsync();

            List <NetworkWatcherResource> allWatchers = await subscription.GetNetworkWatchersAsync().ToEnumerableAsync();

            int countBeforeTest = allWatchers.Count;

            string networkWatcherName = Recording.GenerateAssetName("azsmnet");

            //Create Network Watcher in the resource group
            var networkWatcherCollection = await GetCollection();

            var location   = TestEnvironment.Location;
            var properties = new NetworkWatcherData {
                Location = location
            };
            var createResponse = await networkWatcherCollection.CreateOrUpdateAsync(WaitUntil.Completed, networkWatcherName, properties);

            Assert.AreEqual(networkWatcherName, createResponse.Value.Data.Name);
            Assert.AreEqual(location, createResponse.Value.Data.Location.ToString());
            Assert.IsEmpty(createResponse.Value.Data.Tags);

            //Get Network Watcher by name in the resource group
            Response <NetworkWatcherResource> getResponse = await networkWatcherCollection.GetAsync(networkWatcherName);

            Assert.AreEqual(location, getResponse.Value.Data.Location.ToString());
            Assert.AreEqual(networkWatcherName, getResponse.Value.Data.Name);
            Assert.AreEqual("Succeeded", getResponse.Value.Data.ProvisioningState.ToString());
            Assert.IsEmpty(getResponse.Value.Data.Tags);

            properties.Tags.Add("test", "test");
            var updateResponse = await networkWatcherCollection.CreateOrUpdateAsync(WaitUntil.Completed, networkWatcherName, properties);

            Assert.AreEqual(networkWatcherName, updateResponse.Value.Data.Name);
            Assert.AreEqual(location, updateResponse.Value.Data.Location.ToString());
            Has.One.Equals(updateResponse.Value.Data.Tags);
            Assert.That(updateResponse.Value.Data.Tags, Does.ContainKey("test").WithValue("test"));

            //Get all Network Watchers in the resource group
            List <NetworkWatcherResource> listResponse = await networkWatcherCollection.GetAllAsync().ToEnumerableAsync();

            Has.One.EqualTo(listResponse);
            Assert.AreEqual(networkWatcherName, listResponse[0].Data.Name);
            Assert.AreEqual(location, listResponse[0].Data.Location.ToString());
            Has.One.Equals(listResponse[0].Data.Tags);
            Assert.That(listResponse[0].Data.Tags, Does.ContainKey("test").WithValue("test"));

            //Get all Network Watchers in the subscription
            List <NetworkWatcherResource> listAllResponse = await subscription.GetNetworkWatchersAsync().ToEnumerableAsync();

            Assert.IsNotEmpty(listAllResponse);
            Assert.True(listAllResponse.Any(w => networkWatcherName == w.Data.Name));

            // TODO: need to create cases
            //await getResponse.Value.GetTopologyAsync();
            //await getResponse.Value.VerifyIPFlowAsync();
            //await getResponse.Value.GetNextHopAsync();
            //await getResponse.Value.GetVMSecurityRulesAsync();
            //await getResponse.Value.GetTroubleshootingAsync();
            //await getResponse.Value.GetTroubleshootingResultAsync();
            //await getResponse.Value.SetFlowLogConfigurationAsync();
            //await getResponse.Value.GetFlowLogStatusAsync();
            //await getResponse.Value.CheckConnectivityAsync();
            //await getResponse.Value.GetAzureReachabilityReportAsync();
            //await getResponse.Value.GetAvailableProvidersAsync();
            //await getResponse.Value.GetNetworkConfigurationDiagnosticAsync();

            //Delete Network Watcher
            await getResponse.Value.DeleteAsync(WaitUntil.Completed);

            //Get all Network Watchers in the subscription
            List <NetworkWatcherResource> listAllAfterDeletingResponse = await subscription.GetNetworkWatchersAsync().ToEnumerableAsync();

            Assert.AreEqual(countBeforeTest, listAllAfterDeletingResponse.Count);
            Assert.False(listAllAfterDeletingResponse.Any(w => w.Data.Name == networkWatcherName));
        }