Skip to content

Sync #3

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 9 commits into from
Sep 3, 2020
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 @@ -48,7 +48,7 @@ public static bool HasProperty(this PSObject source, string name)
/// </summary>
/// <typeparam name="T">The type of the property to look for</typeparam>
/// <param name="source">The PSObject to check</param>
/// <param name="name">The name of the proeprty to look for</param>
/// <param name="name">The name of the property to look for</param>
/// <returns>true if the PSObject has a property with the given name, otherwise false</returns>
public static bool HasProperty<T>(this PSObject source, string name)
{
Expand Down Expand Up @@ -211,7 +211,7 @@ public static void Populate(this IDictionary<string, string> dictionary, string
/// Populate a list from a proprty of the given PSObject
/// </summary>
/// <param name="list">The list to populate</param>
/// <param name="name">The name of the proeprty contiaing the list</param>
/// <param name="name">The name of the property contiaing the list</param>
/// <param name="other">The PSObject to populate the list from</param>
public static void Populate(this IList<string> list, string name, PSObject other)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Accounts/Authentication.Test/PSSerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ IAzureContext GetDefaultContext()
VersionProfile = "2017_09_25"
};

context.SetProperty("ContextProeprty1", "ContextProperty1Value1", "ContextProperty1Value2");
context.SetProperty("ContextProeprty2", "ContextProperty2Value1", "ContextProperty2Value2");
context.SetProperty("ContextProperty1", "ContextProperty1Value1", "ContextProperty1Value2");
context.SetProperty("ContextProperty2", "ContextProperty2Value1", "ContextProperty2Value2");

return context;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Accounts/Authentication/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,14 @@ public void TestInvokeAzVmPatchAssessment()
{
TestRunner.RunTestScript("Test-InvokeAzVmPatchAssessment");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestPatchStatusGetAzVMinstanceview()
{
TestRunner.RunTestScript("Test-PatchStatusGetAzVMinstanceview");
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,47 @@ function Test-InvokeAzVmPatchAssessment
# Cleanup
Clean-ResourceGroup $rgname
}
}


<#
.SYNOPSIS
Test PatchStatus in Get-Azvm instance view
#>
function Test-PatchStatusGetAzVMinstanceview
{
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
$loc = Get-ComputeVMLocation;
$loc = $loc.Replace(' ', '');

New-AzResourceGroup -Name $rgname -Location $loc -Force;

# VM Profile & Hardware
$vmsize = Get-AvailableSku $loc "virtualMachine"
$vmname = 'vm' + $rgname;

$username = "admin01"
$password = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
[string]$domainNameLabel = "$vmname-$vmname".tolower();

$x = New-AzVM -ResourceGroupName $rgname -Name $vmname -Location $loc -Credential $cred -DomainNameLabel $domainNameLabel
$patchResult = invoke-azvmpatchAssessment -resourcegroupname $rgname -vmname $vmname

$vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname -Status;

Assert-NotNull $vm.PatchStatus;
Assert-NotNull $vm.PatchStatus.availablePatchSummary;
Assert-AreEqual "Succeeded" $vm.PatchStatus.availablePatchSummary.status;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Added 'PatchStatus'Property to VirtualMachine Instance View
* Added ``VMHealth`` property to the virtual machine's instance view, which is the returned object when ``Get-AzVm`` is invoked with ``-Status``
* Added 'AssignedHost' field to Get-AzVM and Get-AzVmss's instance views. The field shows the resource id of the virtual machine instance
* Added `SupportAutomaticPlacement` to New-AzHostGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public partial class PSVirtualMachineInstanceView
public IList<VirtualMachineExtensionInstanceView> Extensions { get; set; }
public BootDiagnosticsInstanceView BootDiagnostics { get; set; }
public IList<InstanceViewStatus> Statuses { get; set; }
public VirtualMachinePatchStatus PatchStatus { get; set; }
public VirtualMachineHealthStatus VmHealth { get; set; }

}
Expand Down
2 changes: 2 additions & 0 deletions src/Compute/Compute/Models/PSVirtualMachineInstanceView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class PSVirtualMachineInstanceView
public IList<InstanceViewStatus> Statuses { get; set; }

public MaintenanceRedeployStatus MaintenanceRedeployStatus { get; set; }
public VirtualMachinePatchStatus PatchStatus { get; set; }
public VirtualMachineHealthStatus VMHealth { get; set; }
}

Expand Down Expand Up @@ -72,6 +73,7 @@ public static PSVirtualMachineInstanceView ToPSVirtualMachineInstanceView(
OsName = virtualMachineInstanceView.OsName,
OsVersion = virtualMachineInstanceView.OsVersion,
HyperVGeneration = virtualMachineInstanceView.HyperVGeneration,
PatchStatus = virtualMachineInstanceView.PatchStatus,
VMHealth = virtualMachineInstanceView.VmHealth,
AssignedHost = virtualMachineInstanceView.AssignedHost
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ public void TestDeleteVault()
public void TestSetRemoveAccessPolicyByObjectId()
{
string upn = "";
_data.ResetPreCreatedVault();

KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
controller.RunPsTestWorkflow(
Expand All @@ -168,7 +167,6 @@ public void TestSetRemoveAccessPolicyByObjectId()
public void TestSetRemoveAccessPolicyByUPN()
{
string upn = "";
_data.ResetPreCreatedVault();
KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
_logger,
() =>
Expand All @@ -187,7 +185,6 @@ public void TestSetRemoveAccessPolicyByCompoundId()
{
string upn = "";
Guid? appId = null;
_data.ResetPreCreatedVault();

KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
controller.RunPsTestWorkflow(
Expand All @@ -211,7 +208,6 @@ public void TestRemoveAccessPolicyWithCompoundIdPolicies()

Guid? appId1 = null;
Guid? appId2 = null;
_data.ResetPreCreatedVault();

KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
controller.RunPsTestWorkflow(
Expand All @@ -233,7 +229,6 @@ public void TestSetCompoundIdAccessPolicy()
{
string upn = "";
Guid? appId = null;
_data.ResetPreCreatedVault();

KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
controller.RunPsTestWorkflow(
Expand All @@ -257,7 +252,6 @@ public void TestSetRemoveAccessPolicyBySPN()
ServicePrincipal principal = null;

KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
_data.ResetPreCreatedVault();
controller.RunPsTestWorkflow(
_logger,
//script builder
Expand Down Expand Up @@ -288,7 +282,6 @@ public void TestModifyAccessPolicy()
string upn = "";

KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
_data.ResetPreCreatedVault();

controller.RunPsTestWorkflow(
_logger,
Expand All @@ -310,7 +303,6 @@ public void TestModifyAccessPolicyEnabledForDeployment()
{
string upn = "";

_data.ResetPreCreatedVault();
KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
_logger,
() =>
Expand All @@ -330,7 +322,6 @@ public void TestModifyAccessPolicyEnabledForTemplateDeployment()
{
string upn = "";

_data.ResetPreCreatedVault();
KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
_logger,
() =>
Expand All @@ -349,7 +340,6 @@ public void TestModifyAccessPolicyEnabledForDiskEncryption()
{
string upn = "";

_data.ResetPreCreatedVault();
KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
_logger,
() =>
Expand All @@ -367,14 +357,11 @@ public void TestModifyAccessPolicyEnabledForDiskEncryption()
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestModifyAccessPolicyNegativeCases()
{
string upn = "";

_data.ResetPreCreatedVault();
KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
_logger,
() =>
{
return new[] { string.Format("{0} {1} {2} {3}", "Test-ModifyAccessPolicyNegativeCases", _data.PreCreatedVault, _data.ResourceGroupName, upn) };
return new[] { "Test-ModifyAccessPolicyNegativeCases" };
},
null,
MethodBase.GetCurrentMethod().ReflectedType?.ToString(),
Expand All @@ -387,7 +374,6 @@ public void TestModifyAccessPolicyNegativeCases()
public void TestRemoveNonExistentAccessPolicyDoesNotThrow()
{
string upn = "";
_data.ResetPreCreatedVault();

KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
controller.RunPsTestWorkflow(
Expand Down
114 changes: 1 addition & 113 deletions src/KeyVault/KeyVault.Test/ScenarioTests/KeyVaultTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,144 +12,32 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.KeyVault;
using Microsoft.Azure.Management.KeyVault.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.Azure.Management.Internal.Resources;
using Microsoft.Azure.Management.Internal.Resources.Models;
using Sku = Microsoft.Azure.Management.KeyVault.Models.Sku;

namespace Microsoft.Azure.Commands.KeyVault.Test.ScenarioTests
{
public class KeyVaultTestFixture : RMTestBase, IDisposable
{
private readonly HttpRecorderMode _mode;

public string TagName { get; set; } = "testtag";
public string TagValue { get; set; } = "testvalue";

public string ResourceGroupName { get; set; }
public string Location { get; set; }
public string PreCreatedVault { get; set; }

private bool _initialized;
public KeyVaultTestFixture()
{
// Initialize has bug which causes null reference exception
HttpMockServer.FileSystemUtilsObject = new FileSystemUtils();
_mode = HttpMockServer.GetCurrentMode();
}

public void Initialize(string className)
{
if (_initialized)
return;

if (_mode == HttpRecorderMode.Record)
{
using (MockContext context = MockContext.Start(new StackTrace().GetFrame(1).GetMethod().ReflectedType?.ToString(), new StackTrace().GetFrame(1).GetMethod().Name))
{
var resourcesClient = context.GetServiceClient<ResourceManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
var mgmtClient = context.GetServiceClient<KeyVaultManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
var tenantId = TestEnvironmentFactory.GetTestEnvironment().Tenant;

//Figure out which locations are available for Key Vault
Location = GetKeyVaultLocation(resourcesClient);

//Create a resource group in that location
PreCreatedVault = TestUtilities.GenerateName("pshtestvault");
ResourceGroupName = TestUtilities.GenerateName("pshtestrg");

resourcesClient.ResourceGroups.CreateOrUpdate(ResourceGroupName, new ResourceGroup { Location = Location });
CreateVault(mgmtClient, Location, tenantId);
}
}

_initialized = true;
}

private static string GetKeyVaultLocation(ResourceManagementClient resourcesClient)
{
var provider = resourcesClient.Providers.Get("Microsoft.KeyVault");
var location = provider.ResourceTypes.First(resType => resType.ResourceType.Contains("vaults")).Locations.FirstOrDefault();
return location?.ToLowerInvariant().Replace(" ", "");
// no op
}

private void CreateVault(KeyVaultManagementClient mgmtClient, string location, string tenantId)
{
mgmtClient.Vaults.CreateOrUpdate(
ResourceGroupName,
PreCreatedVault,
new VaultCreateOrUpdateParameters
{
Location = location,
Tags = new Dictionary<string, string> { { TagName, TagValue } },
Properties = new VaultProperties
{
EnabledForDeployment = false,
Sku = new Sku { Name = SkuName.Premium },
TenantId = Guid.Parse(tenantId),
VaultUri = "",
AccessPolicies = new AccessPolicyEntry[]{ }
}
});
}

public void ResetPreCreatedVault()
{
if (_mode == HttpRecorderMode.Record)
{
using (MockContext context = MockContext.Start(new StackTrace().GetFrame(1).GetMethod().ReflectedType?.ToString(), new StackTrace().GetFrame(1).GetMethod().Name))
{
var mgmtClient = context.GetServiceClient<KeyVaultManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
var tenantId = Guid.Parse(TestEnvironmentFactory.GetTestEnvironment().Tenant);

var policies = new AccessPolicyEntry[] { };

mgmtClient.Vaults.CreateOrUpdate(
ResourceGroupName,
PreCreatedVault,
new VaultCreateOrUpdateParameters
{
Location = Location,
Tags = new Dictionary<string, string> { { TagName, TagValue } },
Properties = new VaultProperties
{
EnabledForDeployment = false,
Sku = new Sku { Name = SkuName.Premium },
TenantId = tenantId,
VaultUri = "",
AccessPolicies = policies
}
});
}
}
}
public void Dispose()
{
Dispose(false);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (_mode == HttpRecorderMode.Record && _initialized)
{
using (MockContext context = MockContext.Start(new StackTrace().GetFrame(1).GetMethod().ReflectedType?.ToString(), new StackTrace().GetFrame(1).GetMethod().Name))
{
var resourcesClient = context.GetServiceClient<ResourceManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
resourcesClient.ResourceGroups.Delete(ResourceGroupName);
}
}
}
}
}
}
Loading