public DeploymentsTest()
        {
            this.registry             = new Mock <RegistryManager>();
            this.tenantHelper         = new Mock <ITenantConnectionHelper>();
            this.packageConfigClient  = new Mock <IConfigClient>();
            this.storageAdapterClient = new Mock <IStorageAdapterClient>();
            this.tenantHelper.Setup(e => e.GetIotHubName()).Returns(this.ioTHubHostName);
            this.tenantHelper.Setup(e => e.GetRegistry()).Returns(this.registry.Object);
            TelemetryClient mockTelemetryClient = this.InitializeMockTelemetryChannel();

            this.devices       = new Mock <IDevices>();
            this.storageClient = new Mock <IStorageClient>();

            MockIdentity.MockClaims("one");
            this.deployments = new Deployments(
                new AppConfig
            {
                Global = new GlobalConfig
                {
                    InstrumentationKey = "instrumentationkey",
                },
            },
                new Mock <ILogger <Deployments> >().Object,
                new Mock <IDeploymentEventLog>().Object,
                this.tenantHelper.Object,
                this.packageConfigClient.Object,
                this.storageAdapterClient.Object,
                this.devices.Object,
                this.storageClient.Object,
                null);
        }
        public string Print()
        {
            var caseDescription = string.IsNullOrWhiteSpace(DeploymentCase)
                    ? "_"
                    : $"\"{DeploymentCase}\"";

            return($"{caseDescription} => \"{string.Join("; ", Deployments.Select(x => x.Name))}\"");
        }
示例#3
0
        public DeploymentsTest()
        {
            this.registry     = new Mock <RegistryManager>();
            this.tenantHelper = new Mock <ITenantConnectionHelper>();
            this.tenantHelper.Setup(e => e.GetIotHubName()).Returns(this.ioTHubHostName);
            this.tenantHelper.Setup(e => e.GetRegistry()).Returns(this.registry.Object);

            MockIdentity.MockClaims("one");
            this.deployments = new Deployments(this.tenantHelper.Object);
        }
        protected override bool IsIdentic(DeploymentCaseModel other)
        {
            if (other == this)
            {
                return(true);
            }

            return(string.Equals(DeploymentCase, other.DeploymentCase) &&
                   Deployments.All2(other.Deployments, (x, y) => x.IsIdentical(y)));
        }
示例#5
0
        public void PromoteProjects()
        {
            var projects = Configs.Property("ProjectsToDeploy");

            if (projects == null)
            {
                return;
            }
            Console.WriteLine("Start to deploy projects");
            foreach (var g in projects.Value)
            {
                var name = g["Name"];

                if (name is null)
                {
                    continue;
                }

                var time     = g["DeployAt"];
                var settings = new SingleReleasePromotingSettings()
                {
                    SourceEnvironmentName = SourceEnvironmentName,

                    TargetEnvironmentName = TargetEnvironmentName,

                    SpecificMachineNames = g["SpecificMachineNames"]?.ToObject <string[]>() ?? new string[0],

                    SkipSteps = g["SkipSteps"]?.ToObject <string[]>() ?? new string[0],

                    WaitingForFinish = g["WaitingForFinish"]?.ToObject <bool>() ?? false,

                    UpdateVariableSetNow = g["UpdateVariableSetNow"]?.ToObject <bool>() ?? false,

                    Force = g["Force"]?.ToObject <bool>() ?? false,

                    DeployAt = time == null ? DateTime.Now  : DateTime.Parse(time.ToString())
                };
                Deployments.PromoteRelease(name.ToString(), settings);
            }
        }
示例#6
0
        public void Validate()
        {
            Dictionary <string, List <Pair> > items = new Dictionary <string, List <Pair> >();

            foreach (DeploymentDTO dto in Deployments.Values)
            {
                CheckReferentialIntegrity("deployment", "site", dto.SiteId, Sites.Keys, ValidationIssues);
                CheckReferentialIntegrity("deployment", "instrument", dto.InstrumentId, Instruments.Keys, ValidationIssues);
                DeploymentDateOrder(dto.StartDate, dto.EndDate);
                InstrumentDeploymentOverlap(dto.StartDate, dto.EndDate, dto.InstrumentId, items);
            }
            items = null;
            foreach (MeasurementDTO dto in Measurements.Values)
            {
                CheckReferentialIntegrity("measurement", "deployment", dto.DeployCode, Deployments.Keys, ValidationIssues);
                if (Deployments.ContainsKey(dto.DeployCode))
                {
                    DeploymentDTO deployment = Deployments[dto.DeployCode];
                    MeasurementDuringDeployment(dto.MeasureDateTime, deployment.StartDate, deployment.EndDate);
                }
            }
        }
        public void ViewNsgRuleApiTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var resourcesClient         = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1);
                var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2);
                var computeManagementClient = NetworkManagementTestUtilities.GetComputeManagementClientWithHandler(context, handler3);

                string location = "westcentralus";

                string resourceGroupName = TestUtilities.GenerateName();
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                string virtualMachineName       = TestUtilities.GenerateName();
                string networkInterfaceName     = TestUtilities.GenerateName();
                string networkSecurityGroupName = virtualMachineName + "-nsg";

                //Deploy VM with template
                Deployments.CreateVm(
                    resourcesClient: resourcesClient,
                    resourceGroupName: resourceGroupName,
                    location: location,
                    virtualMachineName: virtualMachineName,
                    storageAccountName: TestUtilities.GenerateName(),
                    networkInterfaceName: networkInterfaceName,
                    networkSecurityGroupName: networkSecurityGroupName,
                    diagnosticsStorageAccountName: TestUtilities.GenerateName(),
                    deploymentName: TestUtilities.GenerateName()
                    );

                string         networkWatcherName = TestUtilities.GenerateName();
                NetworkWatcher properties         = new NetworkWatcher();
                properties.Location = location;

                //Create network Watcher
                var createNetworkWatcher = networkManagementClient.NetworkWatchers.CreateOrUpdate(resourceGroupName, networkWatcherName, properties);

                var    getVm          = computeManagementClient.VirtualMachines.Get(resourceGroupName, virtualMachineName);
                string localIPAddress = networkManagementClient.NetworkInterfaces.Get(resourceGroupName, networkInterfaceName).IpConfigurations.FirstOrDefault().PrivateIPAddress;

                string securityRule1 = TestUtilities.GenerateName();

                // Add a security rule
                var SecurityRule = new SecurityRule()
                {
                    Name        = securityRule1,
                    Access      = SecurityRuleAccess.Deny,
                    Description = "Test outbound security rule",
                    DestinationAddressPrefix = "*",
                    DestinationPortRange     = "80",
                    Direction           = SecurityRuleDirection.Outbound,
                    Priority            = 501,
                    Protocol            = SecurityRuleProtocol.Tcp,
                    SourceAddressPrefix = "*",
                    SourcePortRange     = "*",
                };

                var nsg = networkManagementClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName);
                nsg.SecurityRules.Add(SecurityRule);
                networkManagementClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, nsg);

                SecurityGroupViewParameters sgvProperties = new SecurityGroupViewParameters()
                {
                    TargetResourceId = getVm.Id
                };

                //Get view security group rules
                var viewNSGRules = networkManagementClient.NetworkWatchers.GetVMSecurityRules(resourceGroupName, networkWatcherName, sgvProperties);

                //Verify effective security rule defined earlier
                var getEffectiveSecurityRule = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.EffectiveSecurityRules.Where(x => x.Name == "UserRule_" + securityRule1);
                Assert.Equal("Tcp", getEffectiveSecurityRule.FirstOrDefault().Protocol);
                Assert.Equal(501, getEffectiveSecurityRule.FirstOrDefault().Priority);
                Assert.Equal("Deny", getEffectiveSecurityRule.FirstOrDefault().Access);
                Assert.Equal("Outbound", getEffectiveSecurityRule.FirstOrDefault().Direction);
                Assert.Equal("0.0.0.0/0", getEffectiveSecurityRule.FirstOrDefault().DestinationAddressPrefix);
                Assert.Equal("80-80", getEffectiveSecurityRule.FirstOrDefault().DestinationPortRange);
                Assert.Equal("0.0.0.0/0", getEffectiveSecurityRule.FirstOrDefault().SourceAddressPrefix);
                Assert.Equal("0-65535", getEffectiveSecurityRule.FirstOrDefault().SourcePortRange);

                //Verify 6 default rules
                var getDefaultSecurityRule1 = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.DefaultSecurityRules.Where(x => x.Name == "AllowVnetInBound");
                Assert.Equal("*", getDefaultSecurityRule1.FirstOrDefault().Protocol);
                Assert.Equal(65000, getDefaultSecurityRule1.FirstOrDefault().Priority);
                Assert.Equal("Allow", getDefaultSecurityRule1.FirstOrDefault().Access);
                Assert.Equal("Inbound", getDefaultSecurityRule1.FirstOrDefault().Direction);
                Assert.Equal("VirtualNetwork", getDefaultSecurityRule1.FirstOrDefault().DestinationAddressPrefix);
                Assert.Equal("*", getDefaultSecurityRule1.FirstOrDefault().DestinationPortRange);
                Assert.Equal("VirtualNetwork", getDefaultSecurityRule1.FirstOrDefault().SourceAddressPrefix);
                Assert.Equal("*", getDefaultSecurityRule1.FirstOrDefault().SourcePortRange);

                var getDefaultSecurityRule2 = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.DefaultSecurityRules.Where(x => x.Name == "AllowAzureLoadBalancerInBound");
                Assert.Equal("*", getDefaultSecurityRule2.FirstOrDefault().Protocol);
                Assert.Equal(65001, getDefaultSecurityRule2.FirstOrDefault().Priority);
                Assert.Equal("Allow", getDefaultSecurityRule2.FirstOrDefault().Access);
                Assert.Equal("Inbound", getDefaultSecurityRule2.FirstOrDefault().Direction);
                Assert.Equal("*", getDefaultSecurityRule2.FirstOrDefault().DestinationAddressPrefix);
                Assert.Equal("*", getDefaultSecurityRule2.FirstOrDefault().DestinationPortRange);
                Assert.Equal("AzureLoadBalancer", getDefaultSecurityRule2.FirstOrDefault().SourceAddressPrefix);
                Assert.Equal("*", getDefaultSecurityRule2.FirstOrDefault().SourcePortRange);

                var getDefaultSecurityRule3 = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.DefaultSecurityRules.Where(x => x.Name == "DenyAllInBound");
                Assert.Equal("*", getDefaultSecurityRule3.FirstOrDefault().Protocol);
                Assert.Equal(65500, getDefaultSecurityRule3.FirstOrDefault().Priority);
                Assert.Equal("Deny", getDefaultSecurityRule3.FirstOrDefault().Access);
                Assert.Equal("Inbound", getDefaultSecurityRule3.FirstOrDefault().Direction);
                Assert.Equal("*", getDefaultSecurityRule3.FirstOrDefault().DestinationAddressPrefix);
                Assert.Equal("*", getDefaultSecurityRule3.FirstOrDefault().DestinationPortRange);
                Assert.Equal("*", getDefaultSecurityRule3.FirstOrDefault().SourceAddressPrefix);
                Assert.Equal("*", getDefaultSecurityRule3.FirstOrDefault().SourcePortRange);

                var getDefaultSecurityRule4 = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.DefaultSecurityRules.Where(x => x.Name == "AllowVnetOutBound");
                Assert.Equal("*", getDefaultSecurityRule4.FirstOrDefault().Protocol);
                Assert.Equal(65000, getDefaultSecurityRule4.FirstOrDefault().Priority);
                Assert.Equal("Allow", getDefaultSecurityRule4.FirstOrDefault().Access);
                Assert.Equal("Outbound", getDefaultSecurityRule4.FirstOrDefault().Direction);
                Assert.Equal("VirtualNetwork", getDefaultSecurityRule4.FirstOrDefault().DestinationAddressPrefix);
                Assert.Equal("*", getDefaultSecurityRule4.FirstOrDefault().DestinationPortRange);
                Assert.Equal("VirtualNetwork", getDefaultSecurityRule4.FirstOrDefault().SourceAddressPrefix);
                Assert.Equal("*", getDefaultSecurityRule4.FirstOrDefault().SourcePortRange);

                var getDefaultSecurityRule5 = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.DefaultSecurityRules.Where(x => x.Name == "AllowInternetOutBound");
                Assert.Equal("*", getDefaultSecurityRule5.FirstOrDefault().Protocol);
                Assert.Equal(65001, getDefaultSecurityRule5.FirstOrDefault().Priority);
                Assert.Equal("Allow", getDefaultSecurityRule5.FirstOrDefault().Access);
                Assert.Equal("Outbound", getDefaultSecurityRule5.FirstOrDefault().Direction);
                Assert.Equal("Internet", getDefaultSecurityRule5.FirstOrDefault().DestinationAddressPrefix);
                Assert.Equal("*", getDefaultSecurityRule5.FirstOrDefault().DestinationPortRange);
                Assert.Equal("*", getDefaultSecurityRule5.FirstOrDefault().SourceAddressPrefix);
                Assert.Equal("*", getDefaultSecurityRule5.FirstOrDefault().SourcePortRange);

                var getDefaultSecurityRule6 = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.DefaultSecurityRules.Where(x => x.Name == "DenyAllOutBound");
                Assert.Equal("*", getDefaultSecurityRule6.FirstOrDefault().Protocol);
                Assert.Equal(65500, getDefaultSecurityRule6.FirstOrDefault().Priority);
                Assert.Equal("Deny", getDefaultSecurityRule6.FirstOrDefault().Access);
                Assert.Equal("Outbound", getDefaultSecurityRule6.FirstOrDefault().Direction);
                Assert.Equal("*", getDefaultSecurityRule6.FirstOrDefault().DestinationAddressPrefix);
                Assert.Equal("*", getDefaultSecurityRule6.FirstOrDefault().DestinationPortRange);
                Assert.Equal("*", getDefaultSecurityRule6.FirstOrDefault().SourceAddressPrefix);
                Assert.Equal("*", getDefaultSecurityRule6.FirstOrDefault().SourcePortRange);
            }
        }
示例#8
0
        public void NextHopApiTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient         = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1);
                var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2);
                var computeManagementClient = NetworkManagementTestUtilities.GetComputeManagementClientWithHandler(context, handler3);

                string location = "westcentralus";

                string resourceGroupName = TestUtilities.GenerateName();
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                string virtualMachineName       = TestUtilities.GenerateName();
                string networkSecurityGroupName = virtualMachineName + "-nsg";
                string networkInterfaceName     = TestUtilities.GenerateName();

                //Deploy VM wih VNet,Subnet and Route Table from template
                Deployments.CreateVm(
                    resourcesClient: resourcesClient,
                    resourceGroupName: resourceGroupName,
                    location: location,
                    virtualMachineName: virtualMachineName,
                    storageAccountName: TestUtilities.GenerateName(),
                    networkInterfaceName: networkInterfaceName,
                    networkSecurityGroupName: networkSecurityGroupName,
                    diagnosticsStorageAccountName: TestUtilities.GenerateName(),
                    deploymentName: TestUtilities.GenerateName()
                    );

                string         networkWatcherName = TestUtilities.GenerateName();
                NetworkWatcher properties         = new NetworkWatcher();
                properties.Location = location;

                //Create Network Watcher
                var    createNetworkWatcher = networkManagementClient.NetworkWatchers.CreateOrUpdate(resourceGroupName, networkWatcherName, properties);
                string sourceIPAddress      = networkManagementClient.NetworkInterfaces.Get(resourceGroupName, networkInterfaceName).IpConfigurations.FirstOrDefault().PrivateIPAddress;

                var getVm = computeManagementClient.VirtualMachines.Get(resourceGroupName, virtualMachineName);

                //Use DestinationIPAddress from Route Table
                NextHopParameters nhProperties1 = new NextHopParameters()
                {
                    TargetResourceId     = getVm.Id,
                    SourceIPAddress      = sourceIPAddress,
                    DestinationIPAddress = "10.1.3.6"
                };

                NextHopParameters nhProperties2 = new NextHopParameters()
                {
                    TargetResourceId     = getVm.Id,
                    SourceIPAddress      = sourceIPAddress,
                    DestinationIPAddress = "12.11.12.14"
                };

                var getNextHop1 = networkManagementClient.NetworkWatchers.GetNextHop(resourceGroupName, networkWatcherName, nhProperties1);
                var getNextHop2 = networkManagementClient.NetworkWatchers.GetNextHop(resourceGroupName, networkWatcherName, nhProperties2);

                var routeTable = networkManagementClient.RouteTables.Get(resourceGroupName, resourceGroupName + "RT");

                //Validation
                Assert.Equal("10.0.1.2", getNextHop1.NextHopIpAddress);
                Assert.Equal(routeTable.Id, getNextHop1.RouteTableId);

                Assert.Equal("Internet", getNextHop2.NextHopType);
                Assert.Equal("System Route", getNextHop2.RouteTableId);
            }
        }
示例#9
0
 public DeploymentsTest()
 {
     this.registry    = new Mock <RegistryManager>();
     this.deployments = new Deployments(this.registry.Object,
                                        "mockIoTHub");
 }
        public void PacketCaptureApiTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var resourcesClient         = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1);
                var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2);
                var computeManagementClient = NetworkManagementTestUtilities.GetComputeManagementClientWithHandler(context, handler3);

                string location = "westcentralus";

                string resourceGroupName = TestUtilities.GenerateName();
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                string virtualMachineName       = TestUtilities.GenerateName();
                string networkInterfaceName     = TestUtilities.GenerateName();
                string networkSecurityGroupName = virtualMachineName + "-nsg";

                //Deploy VM with template
                Deployments.CreateVm(
                    resourcesClient: resourcesClient,
                    resourceGroupName: resourceGroupName,
                    location: location,
                    virtualMachineName: virtualMachineName,
                    storageAccountName: TestUtilities.GenerateName(),
                    networkInterfaceName: networkInterfaceName,
                    networkSecurityGroupName: networkSecurityGroupName,
                    diagnosticsStorageAccountName: TestUtilities.GenerateName(),
                    deploymentName: TestUtilities.GenerateName()
                    );

                var getVm = computeManagementClient.VirtualMachines.Get(resourceGroupName, virtualMachineName);

                //Deploy networkWatcherAgent on VM
                VirtualMachineExtension parameters = new VirtualMachineExtension();
                parameters.Publisher                   = "Microsoft.Azure.NetworkWatcher.Edp";
                parameters.TypeHandlerVersion          = "1.4";
                parameters.VirtualMachineExtensionType = "NetworkWatcherAgentWindows";
                parameters.Location = location;

                var            addExtension       = computeManagementClient.VirtualMachineExtensions.CreateOrUpdate(resourceGroupName, getVm.Name, "NetworkWatcherAgent", parameters);
                string         networkWatcherName = TestUtilities.GenerateName();
                NetworkWatcher properties         = new NetworkWatcher();
                properties.Location = location;

                //Create network Watcher
                var createNetworkWatcher = networkManagementClient.NetworkWatchers.CreateOrUpdate(resourceGroupName, networkWatcherName, properties);

                string pcName1 = "pc1";
                string pcName2 = "pc2";

                PacketCapture pcProperties = new PacketCapture();
                pcProperties.Target = getVm.Id;

                pcProperties.StorageLocation = new PacketCaptureStorageLocation
                {
                    FilePath = @"C:\tmp\Capture.cap"
                };

                var createPacketCapture1 = networkManagementClient.PacketCaptures.Create(resourceGroupName, networkWatcherName, pcName1, pcProperties);
                var getPacketCapture     = networkManagementClient.PacketCaptures.Get(resourceGroupName, networkWatcherName, pcName1);
                var queryPC = networkManagementClient.PacketCaptures.GetStatus(resourceGroupName, networkWatcherName, pcName1);

                //Validation
                Assert.Equal(pcName1, createPacketCapture1.Name);
                Assert.Equal(1073741824, createPacketCapture1.TotalBytesPerSession);
                Assert.Equal(0, createPacketCapture1.BytesToCapturePerPacket);
                Assert.Equal(18000, createPacketCapture1.TimeLimitInSeconds);
                Assert.Equal(@"C:\tmp\Capture.cap", createPacketCapture1.StorageLocation.FilePath);
                Assert.Equal("Succeeded", getPacketCapture.ProvisioningState);

                var createPacketCapture2 = networkManagementClient.PacketCaptures.Create(resourceGroupName, networkWatcherName, pcName2, pcProperties);
                var listPCByRg1          = networkManagementClient.PacketCaptures.List(resourceGroupName, networkWatcherName);
                networkManagementClient.PacketCaptures.Stop(resourceGroupName, networkWatcherName, pcName1);
                var queryPCAfterStop = networkManagementClient.PacketCaptures.GetStatus(resourceGroupName, networkWatcherName, pcName1);
                networkManagementClient.PacketCaptures.Delete(resourceGroupName, networkWatcherName, pcName1);
                var listPCByRg2 = networkManagementClient.PacketCaptures.List(resourceGroupName, networkWatcherName);


                //Validation
                Assert.Equal(2, listPCByRg1.Count());
                Assert.Equal("Stopped", queryPCAfterStop.PacketCaptureStatus);
                Assert.Equal("Manual", queryPCAfterStop.StopReason);
                Assert.Single(listPCByRg2);
            }
        }
示例#11
0
        public void VerifyIpFlowApiTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient         = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1);
                var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2);
                var computeManagementClient = NetworkManagementTestUtilities.GetComputeManagementClientWithHandler(context, handler3);

                string location = "eastus";

                string resourceGroupName = TestUtilities.GenerateName();
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                string virtualMachineName1      = TestUtilities.GenerateName();
                string networkInterfaceName1    = TestUtilities.GenerateName();
                string networkSecurityGroupName = virtualMachineName1 + "-nsg";

                //Deploy VM with a template
                Deployments.CreateVm(
                    resourcesClient: resourcesClient,
                    resourceGroupName: resourceGroupName,
                    location: location,
                    virtualMachineName: virtualMachineName1,
                    storageAccountName: TestUtilities.GenerateName(),
                    networkInterfaceName: networkInterfaceName1,
                    networkSecurityGroupName: networkSecurityGroupName,
                    diagnosticsStorageAccountName: TestUtilities.GenerateName(),
                    deploymentName: TestUtilities.GenerateName()
                    );

                string         networkWatcherName = TestUtilities.GenerateName();
                NetworkWatcher properties         = new NetworkWatcher();
                properties.Location = location;

                //Create network Watcher
                var createNetworkWatcher = networkManagementClient.NetworkWatchers.CreateOrUpdate(resourceGroupName, networkWatcherName, properties);

                var    getVm1         = computeManagementClient.VirtualMachines.Get(resourceGroupName, virtualMachineName1);
                string localIPAddress = networkManagementClient.NetworkInterfaces.Get(resourceGroupName, networkInterfaceName1).IpConfigurations.FirstOrDefault().PrivateIPAddress;


                string securityRule1 = TestUtilities.GenerateName();

                // Add a security rule
                var SecurityRule = new SecurityRule()
                {
                    Name        = securityRule1,
                    Access      = SecurityRuleAccess.Deny,
                    Description = "Test outbound security rule",
                    DestinationAddressPrefix = "*",
                    DestinationPortRange     = "80",
                    Direction           = SecurityRuleDirection.Outbound,
                    Priority            = 501,
                    Protocol            = SecurityRuleProtocol.Tcp,
                    SourceAddressPrefix = "*",
                    SourcePortRange     = "*",
                };

                var nsg = networkManagementClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName);
                nsg.SecurityRules.Add(SecurityRule);
                networkManagementClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, nsg);

                VerificationIPFlowParameters ipFlowProperties = new VerificationIPFlowParameters()
                {
                    TargetResourceId = getVm1.Id,
                    Direction        = "Outbound",
                    Protocol         = "TCP",
                    LocalPort        = "80",
                    RemotePort       = "80",
                    LocalIPAddress   = localIPAddress,
                    RemoteIPAddress  = "12.11.12.14"
                };

                //Verify IP flow from a VM to a location given the configured  rule
                var verifyIpFlow = networkManagementClient.NetworkWatchers.VerifyIPFlow(resourceGroupName, networkWatcherName, ipFlowProperties);

                //Verify validity of the result
                Assert.Equal("Deny", verifyIpFlow.Access);
                Assert.Equal("securityRules/" + securityRule1, verifyIpFlow.RuleName);
            }
        }
示例#12
0
        public void TopologyApiTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient         = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1);
                var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2);
                var computeManagementClient = NetworkManagementTestUtilities.GetComputeManagementClientWithHandler(context, handler3);

                string location = "eastus";

                string resourceGroupName1 = TestUtilities.GenerateName();
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName1,
                                                              new ResourceGroup
                {
                    Location = location
                });

                string virtualMachineName       = TestUtilities.GenerateName();
                string networkSecurityGroupName = virtualMachineName + "-nsg";
                string networkInterfaceName     = TestUtilities.GenerateName();

                //Deploy Vm from template
                Deployments.CreateVm(
                    resourcesClient: resourcesClient,
                    resourceGroupName: resourceGroupName1,
                    location: location,
                    virtualMachineName: virtualMachineName,
                    storageAccountName: TestUtilities.GenerateName(),
                    networkInterfaceName: networkInterfaceName,
                    networkSecurityGroupName: networkSecurityGroupName,
                    diagnosticsStorageAccountName: TestUtilities.GenerateName(),
                    deploymentName: TestUtilities.GenerateName()
                    );

                string resourceGroupName2 = TestUtilities.GenerateName();
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName2,
                                                              new ResourceGroup
                {
                    Location = location
                });

                string         networkWatcherName = TestUtilities.GenerateName();
                NetworkWatcher properties         = new NetworkWatcher();
                properties.Location = location;

                //Create NetworkWatcher
                var createNetworkWatcher = networkManagementClient.NetworkWatchers.CreateOrUpdate(resourceGroupName2, networkWatcherName, properties);

                TopologyParameters tpProperties = new TopologyParameters()
                {
                    TargetResourceGroupName = resourceGroupName1
                };

                var getVm = computeManagementClient.VirtualMachines.Get(resourceGroupName1, virtualMachineName);

                //Get the current network topology of the resourceGroupName1
                var getTopology = networkManagementClient.NetworkWatchers.GetTopology(resourceGroupName2, networkWatcherName, tpProperties);


                //Getting infromation about VM from topology
                TopologyResource vmResource = getTopology.Resources[2];

                //Verify that topology contain right number of resources (9 resources from template)
                Assert.Equal(9, getTopology.Resources.Count);

                //Verify that topology contain information about acreated VM
                Assert.Equal(virtualMachineName, vmResource.Name);
                Assert.Equal(getVm.Id, vmResource.Id);
                Assert.Equal(networkInterfaceName, vmResource.Associations.FirstOrDefault().Name);
                Assert.Equal(getVm.NetworkProfile.NetworkInterfaces.FirstOrDefault().Id, vmResource.Associations.FirstOrDefault().ResourceId);
                Assert.Equal("Contains", vmResource.Associations.FirstOrDefault().AssociationType);
            }
        }
示例#13
0
 /// <summary>
 /// Returns an enumerator that iterates through the resources in this response.
 /// </summary>
 public scg::IEnumerator <Deployment> GetEnumerator() => Deployments.GetEnumerator();