CA-233454: Fix the action test

Added an extra parameter to the CreateVmFastAction constructor, which is used to specify whether to set the VM's property IsBeingCreated. In order to set this property, we need to wait for the newly created VM to appear in the cache. But we cannot do this in the action test, because the cache is not being updated. Therefore the action needs skip this step when running from the tests. The IsBeingCreated property is only used in the UI, to refresh the PVS tab after the VM is created, so the accuracy of the action test (CreateVMFastActionTest) is not affected by this change.

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2016-12-01 12:09:03 +00:00
parent 235b173ad4
commit c395a8ce14
2 changed files with 16 additions and 6 deletions

View File

@ -41,7 +41,7 @@ namespace XenAdminTests.XenModelTests.ActionTests
protected override CreateVMFastAction NewAction()
{
VM template = GetAnyUserTemplate(VmIsInstant);
return new CreateVMFastAction(template.Connection, template);
return new CreateVMFastAction(template.Connection, template, false);
}
protected override bool VerifyResult(CreateVMFastAction action)

View File

@ -43,12 +43,14 @@ namespace XenAdmin.Actions.VMActions
public class CreateVMFastAction : AsyncAction
{
private readonly String _nameLabel;
private readonly bool _markVmAsBeingCreated;
public CreateVMFastAction(IXenConnection connection, VM template)
public CreateVMFastAction(IXenConnection connection, VM template, bool markVmAsBeingCreated = true)
: base(connection, Messages.INSTANT_VM_CREATE_TITLE, string.Format(Messages.INSTANT_VM_CREATE_DESCRIPTION, Helpers.DefaultVMName(Helpers.GetName(template), connection), Helpers.GetName(template)))
{
Template = template;
_nameLabel = Helpers.DefaultVMName(Helpers.GetName(Template), Connection);
_markVmAsBeingCreated = markVmAsBeingCreated;
ApiMethodsToRoleCheck.AddRange(Role.CommonTaskApiList);
ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList);
@ -64,18 +66,26 @@ namespace XenAdmin.Actions.VMActions
PollToCompletion(0, 80);
string new_vm_ref = Result;
VM = Connection.WaitForCache(new XenRef<VM>(new_vm_ref));
VM.IsBeingCreated = true;
if (_markVmAsBeingCreated)
{
VM = Connection.WaitForCache(new XenRef<VM>(new_vm_ref));
VM.IsBeingCreated = true;
}
XenAdminConfigManager.Provider.HideObject(new_vm_ref);
RelatedTask = XenAPI.VM.async_provision(Session, new_vm_ref);
PollToCompletion(80, 90);
VM.set_name_label(Session, new_vm_ref, _nameLabel);
VM.name_label = _nameLabel; //the set_name_label method takes some time, we want to show the VM right away
XenAdminConfigManager.Provider.ShowObject(new_vm_ref);
VM.IsBeingCreated = false;
if (_markVmAsBeingCreated)
{
VM.name_label = _nameLabel; //the set_name_label method takes some time, we want to show the VM right away
VM.IsBeingCreated = false;
}
Result = new_vm_ref;
}