Skip to content

Commit

Permalink
Fix for showing on GET and persisting Tags on SET (if not given) for …
Browse files Browse the repository at this point in the history
…Database, Server and Elastic Pool (#3206)

* Fixed Azure Sql Tags for Database, server and elastic pools.

* Fixed Azure Sql Tags for Database, server and elastic pools on both GET and SET.
Fixed SET server command.

* Added tests and addressed comments from code review.

* Added tests and addressed comments from code review.
  • Loading branch information
vaishali33 authored and shahabhijeet committed Nov 30, 2016
1 parent 58f4edd commit 3d906ff
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using ProjectResources = Microsoft.Azure.Commands.ResourceManager.Common.Properties.Resources;

namespace Microsoft.Azure.Commands.ResourceManager.Common.Tags
Expand Down Expand Up @@ -93,5 +94,20 @@ public static Hashtable CreateTagHashtable(IDictionary<string, string> dictionar
}
return tagsHashtable;
}

public static Dictionary<string, string> ReadOrFetchTags(PSCmdlet cmdlet, Dictionary<string,string> tagsFromModel)
{
object tagsFromCli;
if (cmdlet.MyInvocation.BoundParameters.TryGetValue("Tags", out tagsFromCli))
{
Hashtable tags = tagsFromCli as Hashtable;
return TagsConversionHelper.CreateTagDictionary(tags, validate: true);
}
else
{
return tagsFromModel;
}
}

}
}
5 changes: 4 additions & 1 deletion src/ResourceManager/Sql/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
- RetentionInDays
* Removed the unsupported param "AuditAction" from Set-AzureSqlDatabaseServerAuditingPolicy
* Added new param "AuditAction" to Set-AzureSqlDatabaseAuditingPolicy

* Fix for showing on GET and persisting Tags on SET (if not given) for Database, Server and Elastic Pool
- If Tags is used in command it will save tags, if not it will not wipe out tags on resource.
## Version 2.3.0
* Fix for showing on GET and persisting Tags on SET (if not given) for Database, Server and Elastic Pool
- If Tags is used in command it will save tags, if not it will not wipe out tags on resource.
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,28 @@ function Test-CreateDatabaseInternal ($serverVersion, $location = "Japan East")
# Create with all parameters
$databaseName = Get-DatabaseName
$db = New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName `
-CollationName "Japanese_Bushu_Kakusu_100_CS_AS" -MaxSizeBytes 1GB -Edition Basic -RequestedServiceObjectiveName Basic
-CollationName "Japanese_Bushu_Kakusu_100_CS_AS" -MaxSizeBytes 1GB -Edition Basic -RequestedServiceObjectiveName Basic -Tags @{"tag_key"="tag_value"}
Assert-AreEqual $db.DatabaseName $databaseName
Assert-AreEqual $db.MaxSizeBytes 1GB
Assert-AreEqual $db.Edition Basic
Assert-AreEqual $db.CurrentServiceObjectiveName Basic
Assert-AreEqual $db.CollationName "Japanese_Bushu_Kakusu_100_CS_AS"
Assert-NotNull $db.Tags
Assert-AreEqual True $db.Tags.ContainsKey("tag_key")
Assert-AreEqual "tag_value" $db.Tags["tag_key"]

# Create with all parameters
$databaseName = Get-DatabaseName
$db = $server | New-AzureRmSqlDatabase -DatabaseName $databaseName `
-CollationName "Japanese_Bushu_Kakusu_100_CS_AS" -MaxSizeBytes 1GB -Edition Basic -RequestedServiceObjectiveName Basic
-CollationName "Japanese_Bushu_Kakusu_100_CS_AS" -MaxSizeBytes 1GB -Edition Basic -RequestedServiceObjectiveName Basic -Tags @{"tag_key"="tag_value"}
Assert-AreEqual $db.DatabaseName $databaseName
Assert-AreEqual $db.MaxSizeBytes 1GB
Assert-AreEqual $db.Edition Basic
Assert-AreEqual $db.CurrentServiceObjectiveName Basic
Assert-AreEqual $db.CollationName "Japanese_Bushu_Kakusu_100_CS_AS"
Assert-NotNull $db.Tags
Assert-AreEqual True $db.Tags.ContainsKey("tag_key")
Assert-AreEqual "tag_value" $db.Tags["tag_key"]
}
finally
{
Expand Down Expand Up @@ -142,20 +148,26 @@ function Test-UpdateDatabaseInternal ($serverVersion, $location = "Japan East")
{
# Alter all properties
$db1 = Set-AzureRmSqlDatabase -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName `
-MaxSizeBytes 1GB -Edition Basic -RequestedServiceObjectiveName Basic
-MaxSizeBytes 1GB -Edition Basic -RequestedServiceObjectiveName Basic -Tags @{"tag_key"="tag_new_value"}
Assert-AreEqual $db1.DatabaseName $db.DatabaseName
Assert-AreEqual $db1.MaxSizeBytes 1GB
Assert-AreEqual $db1.Edition Basic
Assert-AreEqual $db1.CurrentServiceObjectiveName Basic
Assert-AreEqual $db1.CollationName $db.CollationName
Assert-NotNull $db.Tags
Assert-AreEqual True $db.Tags.ContainsKey("tag_key")
Assert-AreEqual "tag_new_value" $db.Tags["tag_key"]

# Alter all properties using piping
$db2 = $db1 | Set-AzureRmSqlDatabase -MaxSizeBytes 100GB -Edition Standard -RequestedServiceObjectiveName S1
$db2 = $db1 | Set-AzureRmSqlDatabase -MaxSizeBytes 100GB -Edition Standard -RequestedServiceObjectiveName S1 -Tags @{"tag_key"="tag_new_value"}
Assert-AreEqual $db2.DatabaseName $db.DatabaseName
Assert-AreEqual $db2.MaxSizeBytes 100GB
Assert-AreEqual $db2.Edition Standard
Assert-AreEqual $db2.CurrentServiceObjectiveName S1
Assert-AreEqual $db2.CollationName $db.CollationName
Assert-NotNull $db.Tags
Assert-AreEqual True $db.Tags.ContainsKey("tag_key")
Assert-AreEqual "tag_new_value" $db.Tags["tag_key"]

# Create and alter data warehouse database.
$databaseName = Get-DatabaseName
Expand All @@ -176,20 +188,26 @@ function Test-UpdateDatabaseInternal ($serverVersion, $location = "Japan East")
{
# Alter all properties
$db1 = Set-AzureRmSqlDatabase -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName `
-MaxSizeBytes 1GB -Edition Basic -RequestedServiceObjectiveName Basic
-MaxSizeBytes 1GB -Edition Basic -RequestedServiceObjectiveName Basic -Tags @{"tag_key"="tag_new_value"}
Assert-AreEqual $db1.DatabaseName $db.DatabaseName
Assert-AreEqual $db1.MaxSizeBytes 250GB
Assert-AreEqual $db1.Edition Standard
Assert-AreEqual $db1.CurrentServiceObjectiveName S0
Assert-AreEqual $db1.CollationName $db.CollationName
Assert-NotNull $db.Tags
Assert-AreEqual True $db.Tags.ContainsKey("tag_key")
Assert-AreEqual "tag_new_value" $db.Tags["tag_key"]

# Alter all properties using piping
$db2 = $db1 | Set-AzureRmSqlDatabase -MaxSizeBytes 100GB -Edition Standard -RequestedServiceObjectiveName S1
$db2 = $db1 | Set-AzureRmSqlDatabase -MaxSizeBytes 100GB -Edition Standard -RequestedServiceObjectiveName S1 -Tags @{"tag_key"="tag_new_value"}
Assert-AreEqual $db2.DatabaseName $db.DatabaseName
Assert-AreEqual $db2.MaxSizeBytes 1GB
Assert-AreEqual $db2.Edition Basic
Assert-AreEqual $db2.CurrentServiceObjectiveName Basic
Assert-AreEqual $db2.CollationName $db.CollationName
Assert-NotNull $db.Tags
Assert-AreEqual True $db.Tags.ContainsKey("tag_key")
Assert-AreEqual "tag_new_value" $db.Tags["tag_key"]
}
}
finally
Expand Down
Loading

0 comments on commit 3d906ff

Please sign in to comment.