Example #1
0
        public void TestListStorageCache()
        {
            this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
            using (StorageCacheTestContext context = new StorageCacheTestContext(this))
            {
                var client = context.GetClient <StorageCacheManagementClient>();
                client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
                IList <Cache> cacheListResponse = client.Caches.List().Value;
                Assert.True(cacheListResponse.Count >= 1);
                bool found = false;
                foreach (Cache response in cacheListResponse)
                {
                    if (string.Equals(response.Name, this.fixture.Cache.Name))
                    {
                        found = true;
                        Assert.Equal(this.fixture.Cache.Id, response.Id, ignoreCase: true);
                        Assert.Equal(this.fixture.Cache.Name, response.Name);
                        Assert.Equal(this.fixture.Cache.CacheSizeGB, response.CacheSizeGB);
                        Assert.Equal(this.fixture.Cache.Location, response.Location);
                        Assert.Equal(this.fixture.Cache.Subnet, response.Subnet);
                        Assert.Equal(this.fixture.Cache.Sku.Name, response.Sku.Name);
                    }
                }

                Assert.True(found, string.Format("Cache {0} not found in the list response.", this.fixture.Cache.Name));
            }
        }
Example #2
0
        public void TestGetUsageModels()
        {
            this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
            using (StorageCacheTestContext context = new StorageCacheTestContext(this))
            {
                string[] array = { "READ_HEAVY_INFREQ", "WRITE_WORKLOAD_15", "WRITE_AROUND", "WRITE_WORKLOAD_CHECK_30", "WRITE_WORKLOAD_CHECK_60", "WRITE_WORKLOAD_CLOUDWS", "READ_HEAVY_CHECK_180" };

                var client = context.GetClient <StorageCacheManagementClient>();
                client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
                IList <UsageModel> usageModelResponse = client.UsageModels.List().Value;
                Assert.True(usageModelResponse.Count >= 1);
                foreach (UsageModel usageModel in usageModelResponse)
                {
                    this.testOutputHelper.WriteLine("Usage Model display - {0}", usageModel.Display.Description);
                    this.testOutputHelper.WriteLine("Usage Model type - {0}", usageModel.TargetType);
                    this.testOutputHelper.WriteLine("Usage Model name - {0}", usageModel.ModelName);

                    if (string.Equals(usageModel.TargetType, "Nfs"))
                    {
                        Assert.Contains(usageModel.ModelName, array);
                    }
                }

                UsageModelsResult result = UsageModelsExtensions.List(client.UsageModels);
                if (result.Value != null)
                {
                    IList <UsageModel> usageModels = result.Value;
                    foreach (UsageModel usageModel in usageModels)
                    {
                        testOutputHelper.WriteLine(usageModel.ModelName);
                        Assert.Contains(usageModel.ModelName, array);
                    }
                }
            }
        }
Example #3
0
 public void TestStorageTargetInvalidTargetType()
 {
     this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
     using (StorageCacheTestContext context = new StorageCacheTestContext(this))
     {
         var client = context.GetClient <StorageCacheManagementClient>();
         client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
         this.fixture.CacheHelper.StoragecacheManagementClient = client;
         StorageTarget storageTargetParameters = this.fixture.CacheHelper.CreateClfsStorageTargetParameters(
             "storageAccount",
             "blobContainer",
             "junction");
         storageTargetParameters.TargetType = "invalid";
         CloudErrorException ex = Assert.Throws <CloudErrorException>(
             () =>
             this.fixture.CacheHelper.CreateStorageTarget(
                 this.fixture.Cache.Name,
                 "invalidst",
                 storageTargetParameters,
                 this.testOutputHelper,
                 maxRequestTries: 0));
         this.testOutputHelper.WriteLine($"{ex.Body.Error.Message}");
         this.testOutputHelper.WriteLine($"{ex.Body.Error.Code}");
         this.testOutputHelper.WriteLine($"{ex.Body.Error.Target}");
         Assert.Contains("InvalidParameter", ex.Body.Error.Code);
         Assert.Equal("storageTarget.targetType", ex.Body.Error.Target);
     }
 }
Example #4
0
        public void TestGetClfsStorageTarget()
        {
            this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
            using (StorageCacheTestContext context = new StorageCacheTestContext(this))
            {
                var client = context.GetClient <StorageCacheManagementClient>();
                client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
                this.fixture.CacheHelper.StoragecacheManagementClient = client;
                StorageTarget storageTarget;
                try
                {
                    storageTarget = this.fixture.CacheHelper.GetStorageTarget(this.fixture.Cache.Name, this.fixture.ResourceGroup.Name);
                }
                catch (CloudErrorException)
                {
                    storageTarget = this.storageAccountsFixture.AddClfsStorageAccount(context, waitForStorageTarget: false, waitForPermissions: false, testOutputHelper: this.testOutputHelper);
                }

                var response = this.fixture.CacheHelper.GetStorageTarget(this.fixture.Cache.Name, storageTarget.Name);
                Assert.Equal(storageTarget.Name, response.Name);
                Assert.Equal(storageTarget.Id, response.Id, ignoreCase: true);
                Assert.Equal(storageTarget.TargetType, response.TargetType);
                Assert.Equal(storageTarget.Clfs.Target, response.Clfs.Target);
                Assert.Equal(storageTarget.Name, response.Name);
            }
        }
Example #5
0
 public void TestStorageAccountPermission()
 {
     this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
     using (StorageCacheTestContext context = new StorageCacheTestContext(this))
     {
         var client = context.GetClient <StorageCacheManagementClient>();
         client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
         this.fixture.CacheHelper.StoragecacheManagementClient = client;
         CloudErrorException ex = Assert.Throws <CloudErrorException>(
             () =>
             this.storageAccountsFixture.AddClfsStorageAccount(
                 context,
                 "perm",
                 waitForStorageTarget: false,
                 addPermissions: false,
                 testOutputHelper: this.testOutputHelper,
                 waitForPermissions: false,
                 maxRequestTries: 0));
         this.testOutputHelper.WriteLine($"{ex.Body.Error.Message}");
         this.testOutputHelper.WriteLine($"{ex.Body.Error.Code}");
         this.testOutputHelper.WriteLine($"{ex.Body.Error.Target}");
         Assert.Contains("InvalidParameter", ex.Body.Error.Code);
         Assert.Equal("storageTarget.clfs.target", ex.Body.Error.Target);
         Assert.Contains("hasn't sufficient permissions", ex.Body.Error.Message);
     }
 }
        public void TestClfsTargetInvalidNameSpace()
        {
            this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
            this.testOutputHelper.WriteLine("TestClfsTargetInvalidNamespace 2");
            using (StorageCacheTestContext context = new StorageCacheTestContext(this))
            {
                var client = context.GetClient <StorageCacheManagementClient>();
                client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
                this.fixture.CacheHelper.StoragecacheManagementClient = client;
                var storageAccount = this.storageAccountsFixture.AddStorageAccount(context, this.fixture.ResourceGroup, testOutputHelper: this.testOutputHelper);
                var blobContainer  = this.storageAccountsFixture.AddBlobContainer(context, this.fixture.ResourceGroup, storageAccount, testOutputHelper: this.testOutputHelper);

                StorageTarget storageTargetParameters = this.fixture.CacheHelper.CreateClfsStorageTargetParameters(
                    storageAccount.Name,
                    blobContainer.Name,
                    "Invalid#$%1");
                var exceptionTarget = string.Empty;
                CloudErrorException ex;

                ex = Assert.Throws <CloudErrorException>(
                    () =>
                    this.fixture.CacheHelper.CreateInvalidStorageTarget(
                        this.fixture.Cache.Name,
                        "invalidst",
                        storageTargetParameters,
                        this.testOutputHelper));
                exceptionTarget = ex.Message;
                testOutputHelper.WriteLine($"Exception Message: {ex.Body.Error.Message}");
                testOutputHelper.WriteLine($"Exception Data: {ex.Body.Error.Code}");
                testOutputHelper.WriteLine($"Exception Target: {ex.Body.Error.Target}");
                Assert.Contains("InvalidParameter", ex.Body.Error.Code);
                Assert.Equal("storageTarget.junctions.namespacePath", ex.Body.Error.Target);
                //Assert.Equal("storageTarget.clfs.target", ex.Body.Error.Target);
            }
        }
        public void TestGetSKUList()
        {
            this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
            using (StorageCacheTestContext context = new StorageCacheTestContext(this))
            {
                var client = context.GetClient <StorageCacheManagementClient>();
                client.ApiVersion = Constants.DefaultAPIVersion;
                IList <ResourceSku> cacheSkuResponse = client.Skus.List().Value;
                Assert.True(cacheSkuResponse.Count >= 1);
                foreach (ResourceSku resourceSku in cacheSkuResponse)
                {
                    if (string.Equals(resourceSku.Name, "Standard_2G"))
                    {
                        Assert.Equal("2", resourceSku.Capabilities[0].Value);
                        Assert.Equal("3072,6144,12288", resourceSku.Capabilities[1].Value);
                    }

                    if (string.Equals(resourceSku.Name, "Standard_4G"))
                    {
                        Assert.Equal("4", resourceSku.Capabilities[0].Value);
                        Assert.Equal("6144,12288,24576", resourceSku.Capabilities[1].Value);
                    }

                    if (string.Equals(resourceSku.Name, "Standard_8G"))
                    {
                        Assert.Equal("8", resourceSku.Capabilities[0].Value);
                        Assert.Equal("12288,24576,49152", resourceSku.Capabilities[1].Value);
                    }
                }
            }
        }
Example #8
0
        public void TestCreateClfsStorageTarget()
        {
            this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
            using (StorageCacheTestContext context = new StorageCacheTestContext(this))
            {
                var client = context.GetClient <StorageCacheManagementClient>();
                client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
                this.fixture.CacheHelper.StoragecacheManagementClient = client;
                StorageTarget storageTarget;
                var           suffix = "cre";
                storageTarget = this.storageAccountsFixture.AddClfsStorageAccount(context, suffix: suffix, waitForPermissions: false, testOutputHelper: this.testOutputHelper);
                string id =
                    $"/subscriptions/{this.fixture.SubscriptionID}" +
                    $"/resourceGroups/{this.fixture.ResourceGroup.Name}" +
                    $"/providers/Microsoft.StorageCache/caches/{this.fixture.Cache.Name}" +
                    $"/storageTargets/{this.fixture.ResourceGroup.Name + suffix}";

                string clfsTarget =
                    $"/subscriptions/{this.fixture.SubscriptionID}" +
                    $"/resourceGroups/{this.fixture.ResourceGroup.Name}" +
                    $"/providers/Microsoft.Storage/storageAccounts/{this.fixture.ResourceGroup.Name + suffix}" +
                    $"/blobServices/default/containers/{this.fixture.ResourceGroup.Name + suffix}";
                Assert.Equal(this.fixture.ResourceGroup.Name + suffix, storageTarget.Name);
                Assert.Equal(id, storageTarget.Id, ignoreCase: true);
                Assert.Equal("clfs", storageTarget.TargetType);
                Assert.Equal(clfsTarget, storageTarget.Clfs.Target);
                Assert.Equal("/junction" + suffix, storageTarget.Junctions[0].NamespacePath);
                Assert.Equal("/", storageTarget.Junctions[0].TargetPath);
            }
        }
Example #9
0
 public void TestFlushCacheWithoutStorageTarget()
 {
     this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
     using (StorageCacheTestContext context = new StorageCacheTestContext(this))
     {
         var client = context.GetClient <StorageCacheManagementClient>();
         client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
         client.Caches.Flush(this.fixture.ResourceGroup.Name, this.fixture.Cache.Name);
         this.fixture.CacheHelper.StoragecacheManagementClient = client;
         if (HttpMockServer.Mode == HttpRecorderMode.Record)
         {
             this.fixture.CacheHelper.WaitForCacheState(
                 this.fixture.CacheHelper.GetCacheHealthState,
                 this.fixture.Cache.Name,
                 "Flushing",
                 timeout: 120,
                 polling_delay: 5).GetAwaiter().GetResult();
             this.fixture.CacheHelper.WaitForCacheState(
                 this.fixture.CacheHelper.GetCacheHealthState,
                 this.fixture.Cache.Name,
                 "Healthy",
                 polling_delay: 5).GetAwaiter().GetResult();
         }
     }
 }
        public void TestListStorageCacheByResourceGroup()
        {
            this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
            using (StorageCacheTestContext context = new StorageCacheTestContext(this))
            {
                var client = context.GetClient <StorageCacheManagementClient>();
                client.ApiVersion = Constants.DefaultAPIVersion;
                this.testOutputHelper.WriteLine("Looking for cache in resource group {0}.", this.fixture.ResourceGroup.Name);
                IList <Cache> cacheListResponse = client.Caches.ListByResourceGroup(this.fixture.ResourceGroup.Name).Value;
                Assert.True(cacheListResponse.Count >= 1);
                bool found = false;
                foreach (Cache response in cacheListResponse)
                {
                    if (string.Equals(response.Name, this.fixture.Cache.Name))
                    {
                        found = true;
                        Assert.Equal(this.fixture.Cache.Id, response.Id, ignoreCase: true);
                        Assert.Equal(this.fixture.Cache.Name, response.Name);
                        Assert.Equal(this.fixture.Cache.CacheSizeGB, response.CacheSizeGB);
                        Assert.Equal(this.fixture.Cache.Location, response.Location);
                        Assert.Equal(this.fixture.Cache.Subnet, response.Subnet);
                        Assert.Equal(this.fixture.Cache.Sku.Name, response.Sku.Name);
                    }
                }

                Assert.True(found, "Cache {this.fixture.Cache.Name} not found in the list response.");
            }
        }
Example #11
0
        public void TestClfsTargetInvalidResourceGroup()
        {
            this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
            using (StorageCacheTestContext context = new StorageCacheTestContext(this))
            {
                var client = context.GetClient <StorageCacheManagementClient>();
                client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
                this.fixture.CacheHelper.StoragecacheManagementClient = client;
                var storageAccount = this.storageAccountsFixture.AddStorageAccount(context, this.fixture.ResourceGroup, testOutputHelper: this.testOutputHelper);
                var blobContainer  = this.storageAccountsFixture.AddBlobContainer(context, this.fixture.ResourceGroup, storageAccount);

                StorageTarget storageTargetParameters = this.fixture.CacheHelper.CreateClfsStorageTargetParameters(
                    storageAccount.Name,
                    blobContainer.Name,
                    "/junction",
                    resourceGroupName: "invalidrs");

                CloudErrorException ex = Assert.Throws <CloudErrorException>(
                    () =>
                    this.fixture.CacheHelper.CreateStorageTarget(
                        this.fixture.Cache.Name,
                        "invalidst",
                        storageTargetParameters,
                        this.testOutputHelper,
                        maxRequestTries: 0));
                this.testOutputHelper.WriteLine($"{ex.Body.Error.Message}");
                this.testOutputHelper.WriteLine($"{ex.Body.Error.Code}");
                this.testOutputHelper.WriteLine($"{ex.Body.Error.Target}");
                Assert.Contains("InvalidParameter", ex.Body.Error.Code);
                Assert.Equal("storageTarget.clfs.target", ex.Body.Error.Target);
            }
        }
 public void TestInvalidSku()
 {
     this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
     using (StorageCacheTestContext context = new StorageCacheTestContext(this))
     {
         var client = context.GetClient <StorageCacheManagementClient>();
         client.ApiVersion = Constants.DefaultAPIVersion;
         this.fixture.CacheHelper.StoragecacheManagementClient = client;
         CloudErrorException ex = Assert.Throws <CloudErrorException>(
             () =>
             this.fixture.CacheHelper.Create("InvalidCacheSku", "InvalidSku", 3072));
         this.testOutputHelper.WriteLine($"{ex.Body.Error.Message}");
         Assert.Equal("InvalidParameter", ex.Body.Error.Code);
         Assert.Equal("sku", ex.Body.Error.Target);
     }
 }
 public void TestGetStorageCache()
 {
     this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
     using (StorageCacheTestContext context = new StorageCacheTestContext(this))
     {
         var client = context.GetClient <StorageCacheManagementClient>();
         client.ApiVersion = Constants.DefaultAPIVersion;
         this.fixture.CacheHelper.StoragecacheManagementClient = client;
         Cache response = this.fixture.CacheHelper.Get(this.fixture.Cache.Name);
         Assert.Equal(this.fixture.Cache.Name, response.Name);
         Assert.Equal(this.fixture.Cache.CacheSizeGB, response.CacheSizeGB);
         Assert.Equal(this.fixture.Cache.Location, response.Location);
         Assert.Equal(this.fixture.Cache.Subnet, response.Subnet);
         Assert.Equal(this.fixture.Cache.Sku.Name, response.Sku.Name);
         Assert.Equal(this.fixture.Cache.Id, response.Id);
     }
 }
Example #14
0
 public void TestDeleteClfsStorageTarget()
 {
     this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
     using (StorageCacheTestContext context = new StorageCacheTestContext(this))
     {
         var client = context.GetClient <StorageCacheManagementClient>();
         client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
         this.fixture.CacheHelper.StoragecacheManagementClient = client;
         var storageTarget = this.storageAccountsFixture.AddClfsStorageAccount(context, suffix: "del", waitForPermissions: false, testOutputHelper: this.testOutputHelper);
         TestUtilities.Wait(new TimeSpan(0, 0, 60));
         this.fixture.CacheHelper.DeleteStorageTarget(this.fixture.Cache.Name, storageTarget.Name, this.testOutputHelper);
         TestUtilities.Wait(new TimeSpan(0, 0, 60));
         CloudErrorException ex = Assert.Throws <CloudErrorException>(() => this.fixture.CacheHelper.GetStorageTarget(this.fixture.Cache.Name, storageTarget.Name, true));
         this.testOutputHelper.WriteLine($"{ex.Body.Error.Message}");
         Assert.Contains("NotFound", ex.Body.Error.Code);
     }
 }
Example #15
0
        public void TestClfsTargetEmptyNameSpace()
        {
            this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
            using (StorageCacheTestContext context = new StorageCacheTestContext(this))
            {
                var client = context.GetClient <StorageCacheManagementClient>();
                client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
                this.fixture.CacheHelper.StoragecacheManagementClient = client;
                var storageAccount = this.storageAccountsFixture.AddStorageAccount(context, this.fixture.ResourceGroup, testOutputHelper: this.testOutputHelper);
                var blobContainer  = this.storageAccountsFixture.AddBlobContainer(context, this.fixture.ResourceGroup, storageAccount, testOutputHelper: this.testOutputHelper);

                StorageTarget storageTargetParameters = this.fixture.CacheHelper.CreateClfsStorageTargetParameters(
                    storageAccount.Name,
                    blobContainer.Name,
                    string.Empty);
                storageTargetParameters.Junctions = new List <NamespaceJunction>()
                {
                };
                var exceptionTarget = string.Empty;
                CloudErrorException ex;
                DateTimeOffset      startTime = DateTimeOffset.Now;
                do
                {
                    ex = Assert.Throws <CloudErrorException>(
                        () =>
                        this.fixture.CacheHelper.CreateStorageTarget(
                            this.fixture.Cache.Name,
                            "invalidst",
                            storageTargetParameters,
                            this.testOutputHelper,
                            maxRequestTries: 0));
                    exceptionTarget = ex.Body.Error.Target;
                    if (DateTimeOffset.Now.Subtract(startTime).TotalSeconds > 600)
                    {
                        throw new TimeoutException();
                    }
                }while (exceptionTarget != "storageTarget.junctions");

                this.testOutputHelper.WriteLine($"{ex.Body.Error.Message}");
                this.testOutputHelper.WriteLine($"{ex.Body.Error.Code}");
                this.testOutputHelper.WriteLine($"{ex.Body.Error.Target}");
                Assert.Contains("InvalidParameter", ex.Body.Error.Code);
                Assert.Equal("storageTarget.junctions", ex.Body.Error.Target);
            }
        }
 public void TestInvalidSubscription()
 {
     this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
     using (StorageCacheTestContext context = new StorageCacheTestContext(this))
     {
         var client = context.GetClient <StorageCacheManagementClient>();
         client.ApiVersion     = Constants.DefaultAPIVersion;
         client.SubscriptionId = "4525f627-2e14-411c-96b9-7df2be6eeb93";
         this.fixture.CacheHelper.StoragecacheManagementClient = client;
         CloudErrorException ex = Assert.Throws <CloudErrorException>(
             () =>
             this.fixture.CacheHelper.Create("InvalidSubscriptionId", this.fixture.Cache.Sku.Name, 3072, true));
         this.testOutputHelper.WriteLine($"{ex.Body.Error.Message}");
         Assert.Equal("SubscriptionNotFound", ex.Body.Error.Code);
         client.SubscriptionId = this.fixture.SubscriptionID;
         this.fixture.CacheHelper.StoragecacheManagementClient = client;
     }
 }
Example #17
0
 public void TestInvalidSku()
 {
     this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
     using (StorageCacheTestContext context = new StorageCacheTestContext(this))
     {
         var client = context.GetClient <StorageCacheManagementClient>();
         client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
         this.fixture.CacheHelper.StoragecacheManagementClient = client;
         var cacheIdentity = new CacheIdentity()
         {
             Type = CacheIdentityType.SystemAssigned
         };
         CloudErrorException ex = Assert.Throws <CloudErrorException>(
             () =>
             this.fixture.CacheHelper.Create("InvalidCacheSku", "InvalidSku", 3072, identity: cacheIdentity));
         this.testOutputHelper.WriteLine($"{ex.Body.Error.Message}");
         Assert.Equal("InvalidParameter", ex.Body.Error.Code);
         Assert.Equal("sku", ex.Body.Error.Target);
     }
 }
 public void TestGetStorageCache()
 {
     this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
     using (StorageCacheTestContext context = new StorageCacheTestContext(this))
     {
         var client = context.GetClient <StorageCacheManagementClient>();
         client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
         this.fixture.CacheHelper.StoragecacheManagementClient = client;
         Cache response = this.fixture.CacheHelper.Get(this.fixture.Cache.Name);
         Assert.Equal(this.fixture.Cache.Name, response.Name);
         Assert.Equal(this.fixture.Cache.CacheSizeGB, response.CacheSizeGB);
         Assert.Equal(this.fixture.Cache.Location, response.Location);
         Assert.Equal(this.fixture.Cache.Subnet, response.Subnet);
         Assert.Equal(this.fixture.Cache.Sku.Name, response.Sku.Name);
         Assert.Equal(this.fixture.Cache.Id, response.Id);
         Assert.Equal(this.fixture.Cache.Identity.Type, response.Identity.Type);
         Assert.Equal(this.fixture.Cache.Identity.PrincipalId, response.Identity.PrincipalId);
         Assert.Equal(this.fixture.Cache.Identity.TenantId, response.Identity.TenantId);
         Assert.Equal(this.fixture.Cache.SecuritySettings.RootSquash, response.SecuritySettings.RootSquash);
     }
 }
Example #19
0
 public void TestInvalidSubscription()
 {
     this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
     using (StorageCacheTestContext context = new StorageCacheTestContext(this))
     {
         var client = context.GetClient <StorageCacheManagementClient>();
         client.ApiVersion     = StorageCacheTestEnvironmentUtilities.APIVersion;
         client.SubscriptionId = "4525f627-2e14-411c-96b9-7df2be6eeb93";
         this.fixture.CacheHelper.StoragecacheManagementClient = client;
         var cacheIdentity = new CacheIdentity()
         {
             Type = CacheIdentityType.SystemAssigned
         };
         CloudErrorException ex = Assert.Throws <CloudErrorException>(
             () =>
             this.fixture.CacheHelper.Create("InvalidSubscriptionId", this.fixture.Cache.Sku.Name, 3072, identity: cacheIdentity, skipGet: true));
         this.testOutputHelper.WriteLine($"{ex.Body.Error.Message}");
         Assert.Equal("SubscriptionNotFound", ex.Body.Error.Code);
         client.SubscriptionId = this.fixture.SubscriptionID;
         this.fixture.CacheHelper.StoragecacheManagementClient = client;
     }
 }
 public void TestGetUsageModels()
 {
     this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
     using (StorageCacheTestContext context = new StorageCacheTestContext(this))
     {
         var client = context.GetClient <StorageCacheManagementClient>();
         client.ApiVersion = Constants.DefaultAPIVersion;
         IList <UsageModel> usageModelResponse = client.UsageModels.List().Value;
         Assert.True(usageModelResponse.Count >= 1);
         foreach (UsageModel usageModel in usageModelResponse)
         {
             this.testOutputHelper.WriteLine("Usage Model display - {0}", usageModel.Display.Description);
             this.testOutputHelper.WriteLine("Usage Model type - {0}", usageModel.TargetType);
             this.testOutputHelper.WriteLine("Usage Model name - {0}", usageModel.ModelName);
             string[] array = { "READ_HEAVY_INFREQ", "WRITE_WORKLOAD_15", "WRITE_AROUND" };
             if (string.Equals(usageModel.TargetType, "Nfs"))
             {
                 Assert.Contains(usageModel.ModelName, array);
             }
         }
     }
 }
Example #21
0
        public void TestListStorageTargetByCache()
        {
            this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
            using (StorageCacheTestContext context = new StorageCacheTestContext(this))
            {
                var client = context.GetClient <StorageCacheManagementClient>();
                client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
                this.fixture.CacheHelper.StoragecacheManagementClient = client;
                StorageTarget storageTarget;
                try
                {
                    storageTarget = this.fixture.CacheHelper.GetStorageTarget(this.fixture.Cache.Name, this.fixture.ResourceGroup.Name);
                }
                catch (CloudErrorException)
                {
                    storageTarget = this.storageAccountsFixture.AddClfsStorageAccount(context, waitForStorageTarget: false, waitForPermissions: false);
                }

                IList <StorageTarget> storageTargetListResponse = this.fixture.CacheHelper.StoragecacheManagementClient.StorageTargets.ListByCache(this.fixture.ResourceGroup.Name, this.fixture.Cache.Name).Value;
                Assert.True(storageTargetListResponse.Count >= 1);
                bool found = false;
                foreach (StorageTarget response in storageTargetListResponse)
                {
                    if (string.Equals(response.Name, storageTarget.Name))
                    {
                        found = true;
                        Assert.Equal(storageTarget.Id, response.Id, ignoreCase: true);
                        Assert.Equal(storageTarget.Clfs.Target, response.Clfs.Target);
                        Assert.Equal(storageTarget.Type, response.Type);
                        Assert.Equal(storageTarget.Junctions[0].NamespacePath, response.Junctions[0].NamespacePath);
                        Assert.Equal(storageTarget.Junctions[0].TargetPath, response.Junctions[0].TargetPath);
                    }
                }

                Assert.True(found, string.Format("Storage target {0} not found in the list response.", storageTarget.Name));
            }
        }
Example #22
0
        public void TestOperationsList()
        {
            testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
            using (StorageCacheTestContext context = new StorageCacheTestContext(this))
            {
                var client = context.GetClient <StorageCacheManagementClient>();
                client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;

                ApiOperationDisplay    stopOperationDisplay = new ApiOperationDisplay("Stop the cache", "Microsoft Azure HPC Cache", "Cache", "Stops the cache");
                ApiOperationListResult result = OperationsExtensions.List(client.Operations);

                IList <MetricSpecification> metrics = new List <MetricSpecification>();

                MetricDimension dim = new MetricDimension
                {
                    DisplayName            = "dname",
                    InternalName           = "iname",
                    Name                   = "name",
                    ToBeExportedForShoebox = false
                };

                IList <MetricDimension> dims = new List <MetricDimension>();
                dims.Add(dim);

                IList <string> aggrTypes = new List <string>();
                aggrTypes.Add("string");

                MetricSpecification metric = new MetricSpecification
                {
                    AggregationType           = "string",
                    Unit                      = "unit",
                    Name                      = "name",
                    MetricClass               = "metricClass",
                    DisplayName               = "displayName",
                    DisplayDescription        = "displayDescription",
                    SupportedAggregationTypes = aggrTypes,
                    Dimensions                = dims
                };

                ApiOperationPropertiesServiceSpecification serviceSpecification = new ApiOperationPropertiesServiceSpecification();
                serviceSpecification.MetricSpecifications = metrics;

                foreach (ApiOperation api in result.Value)
                {
                    if (api.Name == "Microsoft.StorageCache/caches/Stop/action")
                    {
                        Assert.Equal(api.Display.Resource, stopOperationDisplay.Resource);
                        Assert.Equal(api.Display.Provider, stopOperationDisplay.Provider);
                        Assert.Equal(api.Display.Description, stopOperationDisplay.Description);
                        Assert.Equal(api.Display.Operation, stopOperationDisplay.Operation);
                    }
                    if (api.Name == "Microsoft.StorageCache/caches/providers/Microsoft.Insights/metricDefinitions/read")
                    {
                        testOutputHelper.WriteLine("Microsoft.StorageCache/caches/providers/Microsoft.Insights/metricDefinitions/read");
                        testOutputHelper.WriteLine($"isDataAction {api.IsDataAction}");
                        testOutputHelper.WriteLine($"origin {api.Origin}");
                        if (api.Display != null)
                        {
                            ApiOperationDisplay display = api.Display;
                            testOutputHelper.WriteLine($"Display operation {display.Operation}");
                            testOutputHelper.WriteLine($"Display provider {display.Provider}");
                            testOutputHelper.WriteLine($"Display resource {display.Resource}");
                            testOutputHelper.WriteLine($"Display description {display.Description}");
                        }
                        ApiOperationPropertiesServiceSpecification aopss = api.ServiceSpecification;
                        if (aopss != null)
                        {
                            IList <MetricSpecification> mss = aopss.MetricSpecifications;
                            foreach (MetricSpecification ms in mss)
                            {
                                testOutputHelper.WriteLine($"Metric Specification Name {ms.Name}");
                                testOutputHelper.WriteLine($"Metric Specification Display Name {ms.DisplayName}");
                                testOutputHelper.WriteLine($"Metric Specification Display Description {ms.DisplayDescription}");
                                testOutputHelper.WriteLine($"Metric Specification Unit {ms.Unit}");
                                testOutputHelper.WriteLine($"Metric Specification AggrType {ms.AggregationType}");
                                testOutputHelper.WriteLine($"Metric Specification MetricClass {ms.MetricClass}");

                                foreach (string sat in ms.SupportedAggregationTypes)
                                {
                                    testOutputHelper.WriteLine($"Metric Specification Supported Aggr Type {sat}");
                                }
                            }
                        }
                    }
                }
                testOutputHelper.WriteLine($"NextLink {result.NextLink}");
                Assert.True(result.Value.Count > 1);

                // Try one with a null client.
                Assert.Throws <System.NullReferenceException>(() => OperationsExtensions.List(null));
            }
        }
        public void TestCreateClfsStorageTarget()
        {
            testOutputHelper.WriteLine(storageAccountsFixture.notes.ToString());
            this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode.");
            using (StorageCacheTestContext context = new StorageCacheTestContext(this))
            {
                var client = context.GetClient <StorageCacheManagementClient>();
                client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion;
                this.fixture.CacheHelper.StoragecacheManagementClient = client;

                StorageTarget storageTarget;
                var           suffix = "cre";
                storageTarget = this.storageAccountsFixture.AddClfsStorageAccount(context, suffix: suffix, waitForPermissions: false, testOutputHelper: this.testOutputHelper);
                string id =
                    $"/subscriptions/{this.fixture.SubscriptionID}" +
                    $"/resourceGroups/{this.fixture.ResourceGroup.Name}" +
                    $"/providers/Microsoft.StorageCache/caches/{this.fixture.Cache.Name}" +
                    $"/storageTargets/{this.fixture.ResourceGroup.Name + suffix}";

                string clfsTarget =
                    $"/subscriptions/{this.fixture.SubscriptionID}" +
                    $"/resourceGroups/{this.fixture.ResourceGroup.Name}" +
                    $"/providers/Microsoft.Storage/storageAccounts/{this.fixture.ResourceGroup.Name + suffix}" +
                    $"/blobServices/default/containers/{this.fixture.ResourceGroup.Name + suffix}";
                Assert.Equal(this.fixture.ResourceGroup.Name + suffix, storageTarget.Name);
                Assert.Equal(id, storageTarget.Id, ignoreCase: true);
                Assert.Equal("clfs", storageTarget.TargetType);
                Assert.Equal(clfsTarget, storageTarget.Clfs.Target);
                Assert.Equal("/junction" + suffix, storageTarget.Junctions[0].NamespacePath);
                Assert.Equal("/", storageTarget.Junctions[0].TargetPath);

                // Call an invalid DNSRefresh case.
                Models.SystemData systemData = new Models.SystemData("SDK", "Application", DateTime.UtcNow, "SDK", "Application", DateTime.UtcNow);
                StorageTarget     st         = new StorageTarget("clfs", "clfsStorageTarget", null, "StorageTarget", systemData: systemData);
                Models.SystemData sd         = storageTarget.SystemData;
                testOutputHelper.WriteLine($"ST values createdBy {sd.CreatedBy}, createdByType {sd.CreatedByType}, createdAt {sd.CreatedAt}");
                testOutputHelper.WriteLine($"ST values modifiedBy {sd.LastModifiedBy}, modifiedByType {sd.LastModifiedByType}, modifiedAt {sd.LastModifiedAt}");

                CloudErrorException ex = new CloudErrorException();
                ex = Assert.Throws <CloudErrorException>(
                    () => client.StorageTargets.DnsRefresh(fixture.ResourceGroup.Name, fixture.Cache.Name, storageTarget.Name));
                testOutputHelper.WriteLine($"Exception Message: {ex.Body.Error.Message}");
                testOutputHelper.WriteLine($"Request: {ex.Request}");
                testOutputHelper.WriteLine($"Response: {ex.Response}");
                Assert.Contains("BadRequest", ex.Body.Error.Code);

                Microsoft.Rest.ValidationException rex = Assert.Throws <Microsoft.Rest.ValidationException>(
                    () => client.StorageTargets.DnsRefresh(null, fixture.Cache.Name, storageTarget.Name));
                testOutputHelper.WriteLine($"Exception Message: {rex.Message}");
                Assert.Contains("'resourceGroupName' cannot be null", rex.Message);

                rex = Assert.Throws <Microsoft.Rest.ValidationException>(
                    () => client.StorageTargets.DnsRefresh(fixture.ResourceGroup.Name, null, storageTarget.Name));
                testOutputHelper.WriteLine($"Exception Message: {rex.Message}");
                Assert.Contains("'cacheName' cannot be null", rex.Message);

                rex = Assert.Throws <Microsoft.Rest.ValidationException>(
                    () => client.StorageTargets.DnsRefresh(fixture.ResourceGroup.Name, ".badcachename.", storageTarget.Name));
                testOutputHelper.WriteLine($"Exception Message: {rex.Message}");
                Assert.Contains("'cacheName' does not match expected pattern '^[-0-9a-zA-Z_]{1,80}$'", rex.Message);
            }
        }