Skip to content

Fix for showing on GET and persisting Tags on SET (if not given) for Database, Server and Elastic Pool #3206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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