Ejemplo n.º 1
0
        public void CreateUpdate()
        {
            using (var context = FluentMockContext.Start(GetType().FullName))
            {
                string groupName          = SdkContext.RandomResourceName("rg", 10);
                string clusterName        = SdkContext.RandomResourceName("cluster", 15);
                string vnetName           = SdkContext.RandomResourceName("vnet", 10);
                string saName             = SdkContext.RandomResourceName("sa", 15);
                string shareMountPath     = "azurefileshare";
                string blobFileSystemPath = "myblobsystem";
                string containerName      = "mycontainer";
                string userName           = "******";
                string storageAccountKey  = "dummy_key";
                string fileShareUri       = "dummy_uri";
                string subnetName         = "MySubnet";

                var manager        = TestHelper.CreateBatchAIManager();
                var networkManager = TestHelper.CreateNetworkManager();

                INetwork network = networkManager.Networks.Define(vnetName)
                                   .WithRegion(REGION)
                                   .WithNewResourceGroup(groupName)
                                   .WithAddressSpace("192.168.0.0/16")
                                   .WithSubnet(subnetName, "192.168.200.0/24")
                                   .Create();

                IBatchAICluster cluster = manager.BatchAIClusters.Define(clusterName)
                                          .WithRegion(REGION)
                                          .WithNewResourceGroup(groupName)
                                          .WithVMSize(VirtualMachineSizeTypes.StandardD1V2.Value)
                                          .WithUserName(userName)
                                          .WithPassword("MyPassword")
                                          .WithAutoScale(1, 1)
                                          .WithLowPriority()
                                          .DefineSetupTask()
                                          .WithCommandLine("echo Hello World!")
                                          .WithStdOutErrPath("./outputpath")
                                          .Attach()
                                          .DefineAzureFileShare()
                                          .WithStorageAccountName(saName)
                                          .WithAzureFileUrl(fileShareUri)
                                          .WithRelativeMountPath(shareMountPath)
                                          .WithAccountKey(storageAccountKey)
                                          .Attach()
                                          .DefineAzureBlobFileSystem()
                                          .WithStorageAccountName(saName)
                                          .WithContainerName(containerName)
                                          .WithRelativeMountPath(blobFileSystemPath)
                                          .WithAccountKey(storageAccountKey)
                                          .Attach()
                                          .WithVirtualMachineImage("microsoft-ads", "linux-data-science-vm-ubuntu", "linuxdsvmubuntu")
                                          .WithSubnet(network.Id, subnetName)
                                          .WithAppInsightsComponentId("appinsightsId")
                                          .WithInstrumentationKey("appInsightsKey")
                                          .WithTag("tag1", "value1")
                                          .Create();
                Assert.Equal(AllocationState.Steady, cluster.AllocationState);
                Assert.Equal(userName, cluster.AdminUserName);
                Assert.Equal(VmPriority.Lowpriority, cluster.VMPriority);
                Assert.Equal(1, cluster.NodeSetup.MountVolumes.AzureFileShares.Count);
                Assert.Equal(shareMountPath, cluster.NodeSetup.MountVolumes.AzureFileShares.ElementAt(0).RelativeMountPath);
                Assert.Equal(1, cluster.NodeSetup.MountVolumes.AzureBlobFileSystems.Count);
                Assert.Equal(blobFileSystemPath, cluster.NodeSetup.MountVolumes.AzureBlobFileSystems.ElementAt(0).RelativeMountPath);
                Assert.Equal(network.Id + "/subnets/" + subnetName, cluster.Subnet.Id);
                Assert.Equal("appinsightsId", cluster.NodeSetup.PerformanceCountersSettings.AppInsightsReference.Component.Id);
                Assert.Equal("linux-data-science-vm-ubuntu", cluster.VirtualMachineConfiguration.ImageReference.Offer);

                cluster.Update()
                .WithAutoScale(1, 2, 2)
                .WithTag("tag1", "value2")
                .Apply();
                Assert.Equal(2, cluster.ScaleSettings.AutoScale.MaximumNodeCount);
                string tag1;
                Assert.True(cluster.Tags.TryGetValue("tag1", out tag1));
                Assert.Equal("value2", tag1);

                manager.ResourceManager.ResourceGroups.DeleteByName(groupName);
            }
        }
        public void CreateUpdate()
        {
            using (var context = FluentMockContext.Start(GetType().FullName))
            {
                string groupName          = SdkContext.RandomResourceName("rg", 10);
                string clusterName        = SdkContext.RandomResourceName("cluster", 15);
                string saName             = SdkContext.RandomResourceName("sa", 15);
                string shareName          = "myfileshare";
                string shareMountPath     = "azurefileshare";
                string blobFileSystemPath = "myblobsystem";
                string containerName      = "mycontainer";
                string userName           = "******";
                string storageAccountKey  = "dummy_key";
                string fileShareUri       = "dummy_uri";

                var manager = TestHelper.CreateBatchAIManager();

                IBatchAICluster cluster = manager.BatchAIClusters.Define(clusterName)
                                          .WithRegion(REGION)
                                          .WithNewResourceGroup(groupName)
                                          .WithVMSize(VirtualMachineSizeTypes.StandardD1V2.Value)
                                          .WithUserName(userName)
                                          .WithPassword("MyPassword")
                                          .WithAutoScale(1, 1)
                                          .WithLowPriority()
                                          .DefineSetupTask()
                                          .WithCommandLine("echo Hello World!")
                                          .WithStdOutErrPath("./outputpath")
                                          .Attach()
                                          .DefineAzureFileShare()
                                          .WithStorageAccountName(saName)
                                          .WithAzureFileUrl(fileShareUri)
                                          .WithRelativeMountPath(shareMountPath)
                                          .WithAccountKey(storageAccountKey)
                                          .Attach()
                                          .DefineAzureBlobFileSystem()
                                          .WithStorageAccountName(saName)
                                          .WithContainerName(containerName)
                                          .WithRelativeMountPath(blobFileSystemPath)
                                          .WithAccountKey(storageAccountKey)
                                          .Attach()
                                          .WithTag("tag1", "value1")
                                          .Create();
                Assert.Equal(AllocationState.Steady, cluster.AllocationState);
                Assert.Equal(userName, cluster.AdminUserName);
                Assert.Equal(VmPriority.Lowpriority, cluster.VMPriority);
                Assert.Equal(1, cluster.NodeSetup.MountVolumes.AzureFileShares.Count);
                Assert.Equal(shareMountPath, cluster.NodeSetup.MountVolumes.AzureFileShares.ElementAt(0).RelativeMountPath);
                Assert.Equal(1, cluster.NodeSetup.MountVolumes.AzureBlobFileSystems.Count);
                Assert.Equal(blobFileSystemPath, cluster.NodeSetup.MountVolumes.AzureBlobFileSystems.ElementAt(0).RelativeMountPath);

                cluster.Update()
                .WithAutoScale(1, 2, 2)
                .WithTag("tag1", "value2")
                .Apply();
                Assert.Equal(2, cluster.ScaleSettings.AutoScale.MaximumNodeCount);
                string tag1;
                Assert.True(cluster.Tags.TryGetValue("tag1", out tag1));
                Assert.Equal("value2", tag1);

                manager.ResourceManager.ResourceGroups.DeleteByName(groupName);
            }
        }