Helper methods for the Batch cmdlet scenario tests
        public void TestRemoveComputeNodes()
        {
            BatchController     controller = BatchController.NewInstance;
            BatchAccountContext context    = null;
            string removeNodePoolId        = "removenodepool";

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-RemoveComputeNodes '{0}'", removeNodePoolId) }); },
                () =>
            {
                context = new ScenarioTestContext();
                ScenarioTestHelpers.CreateTestPool(controller, context, removeNodePoolId, targetDedicated: 2, targetLowPriority: 0);
                ScenarioTestHelpers.WaitForSteadyPoolAllocation(controller, context, removeNodePoolId);
            },
                () =>
            {
                ScenarioTestHelpers.DeletePool(controller, context, removeNodePoolId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
        public void TestRebootAndReimageComputeNode()
        {
            BatchController     controller = BatchController.NewInstance;
            BatchAccountContext context    = null;
            string computeNodeId           = null;
            string computeNodeId2          = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-RebootAndReimageComputeNode '{0}' '{1}' '{2}'", poolId, computeNodeId, computeNodeId2) }); },
                () =>
            {
                context        = new ScenarioTestContext();
                computeNodeId  = ScenarioTestHelpers.GetComputeNodeId(controller, context, poolId, 0);
                computeNodeId2 = ScenarioTestHelpers.GetComputeNodeId(controller, context, poolId, 1);
                ScenarioTestHelpers.WaitForIdleComputeNode(controller, context, poolId, computeNodeId);
                ScenarioTestHelpers.WaitForIdleComputeNode(controller, context, poolId, computeNodeId2);
            },
                null,
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
        public void TestDisableEnableTerminateJobSchedule()
        {
            BatchController controller    = BatchController.NewInstance;
            string          jobScheduleId = "testDisableEnableTerminateJobSchedule";

            BatchAccountContext context = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-DisableEnableTerminateJobSchedule '{0}'", jobScheduleId) }); },
                () =>
            {
                context = new ScenarioTestContext();
                ScenarioTestHelpers.CreateTestJobSchedule(controller, context, jobScheduleId, null);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteJobSchedule(controller, context, jobScheduleId);
            },
                MethodBase.GetCurrentMethod().ReflectedType?.ToString(),
                MethodBase.GetCurrentMethod().Name);
        }
Exemple #4
0
        public void IfJobSetsAutoFailure_ItCompletesWhenAnyTaskFails()
        {
            BatchController     controller = BatchController.NewInstance;
            BatchAccountContext context    = null;
            string     jobId        = "testJobCompletesWhenTaskFails";
            string     taskId       = "taskId-1";
            PSCloudJob completedJob = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("IfJobSetsAutoFailure-ItCompletesWhenAnyTaskFails '{0}' '{1}'", jobId, taskId) }); },
                null,
                () =>
            {
                context      = new ScenarioTestContext();
                completedJob = ScenarioTestHelpers.WaitForJobCompletion(controller, context, jobId, taskId);
                AssertJobIsCompleteDueToTaskFailure(completedJob);
                ScenarioTestHelpers.DeleteJob(controller, context, jobId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
        public void TestChangeOSVersion()
        {
            BatchController     controller = BatchController.NewInstance;
            BatchAccountContext context    = null;
            string poolId = "changeospool";

            controller.RunPsTestWorkflow(
                _logger,
                () => { return(new string[] { string.Format("Test-ChangeOSVersion '{0}' '{1}'", poolId, specificOSVersion) }); },
                () =>
            {
                context = new ScenarioTestContext();
                ScenarioTestHelpers.CreateTestPool(controller, context, poolId, targetDedicated: 0, targetLowPriority: 0);
            },
                () =>
            {
                ScenarioTestHelpers.DeletePool(controller, context, poolId);
            },
                MethodBase.GetCurrentMethod().ReflectedType?.ToString(),
                MethodBase.GetCurrentMethod().Name);
        }
Exemple #6
0
        public void TestDisableEnableTerminateJob()
        {
            BatchController controller = BatchController.NewInstance;
            string          jobId      = "testDisableEnableTerminateJob";

            BatchAccountContext context = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-DisableEnableTerminateJob '{0}'", jobId) }); },
                () =>
            {
                context = new ScenarioTestContext();
                ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteJob(controller, context, jobId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
Exemple #7
0
        public void TestCreateTaskCollection()
        {
            BatchController     controller = BatchController.NewInstance;
            string              jobId      = "createTaskCollectionJob";
            BatchAccountContext context    = null;

            controller.RunPsTestWorkflow(
                _logger,
                () => { return(new string[] { string.Format("Test-CreateTaskCollection '{0}'", jobId) }); },
                () =>
            {
                context = new ScenarioTestContext();
                ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteJob(controller, context, jobId);
            },
                MethodBase.GetCurrentMethod().ReflectedType?.ToString(),
                MethodBase.GetCurrentMethod().Name);
        }
Exemple #8
0
        public void TestNewPool()
        {
            BatchController     controller        = BatchController.NewInstance;
            string              resourceGroupName = "test-new-pool";
            string              accountName       = "testnewpool";
            string              location          = "eastus";
            BatchAccountContext context           = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-NewPool '{0}'", accountName) }); },
                () =>
            {
                context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
            },
                () =>
            {
                ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
Exemple #9
0
        public void TestGetCertificateByThumbprint()
        {
            BatchController     controller = BatchController.NewInstance;
            BatchAccountContext context    = null;
            string thumbprintAlgorithm     = null;
            string thumbprint = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-GetCertificateByThumbprint '{0}' '{1}' '{2}'", accountName, BatchTestHelpers.TestCertificateAlgorithm, thumbprint) }); },
                () =>
            {
                context    = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, accountName);
                thumbprint = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName1);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteTestCertificate(controller, context, BatchTestHelpers.TestCertificateAlgorithm, thumbprint);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
        public void TestUpdatePool()
        {
            BatchController controller = BatchController.NewInstance;
            string          poolId     = "testUpdate";

            BatchAccountContext context = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-UpdatePool '{0}' '{1}'", commonAccountName, poolId) }); },
                () =>
            {
                context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, commonAccountName);
                ScenarioTestHelpers.CreateTestPool(controller, context, poolId, 0);
            },
                () =>
            {
                ScenarioTestHelpers.DeletePool(controller, context, poolId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
Exemple #11
0
        public void TestEnableAutoScaleByPipeline()
        {
            BatchController     controller = BatchController.NewInstance;
            BatchAccountContext context    = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-EnableAutoScale '{0}' '1'", testPoolId) }); },
                () =>
            {
                context = new ScenarioTestContext();
                ScenarioTestHelpers.WaitForSteadyPoolAllocation(controller, context, testPoolId);
                ScenarioTestHelpers.DisableAutoScale(controller, context, testPoolId);
                ScenarioTestHelpers.WaitForSteadyPoolAllocation(controller, context, testPoolId);
            },
                () =>
            {
                ScenarioTestHelpers.DisableAutoScale(controller, context, testPoolId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
Exemple #12
0
        public void TestDisableAndEnableJobSchedule()
        {
            BatchController controller    = BatchController.NewInstance;
            string          jobScheduleId = "testDisableEnableJobSchedule";

            BatchAccountContext context = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-DisableAndEnableJobSchedule '{0}' '{1}' '1'", accountName, jobScheduleId) }); },
                () =>
            {
                context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, accountName);
                ScenarioTestHelpers.CreateTestJobSchedule(controller, context, jobScheduleId, null);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteJobSchedule(controller, context, jobScheduleId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
Exemple #13
0
        public void TestGetAndListTasksWithSelect()
        {
            BatchController     controller = BatchController.NewInstance;
            BatchAccountContext context    = null;
            string jobId  = "selectTaskTest";
            string taskId = "testTask1";

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-GetAndListTasksWithSelect '{0}' '{1}'", jobId, taskId) }); },
                () =>
            {
                context = new ScenarioTestContext();
                ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
                ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteJob(controller, context, jobId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
        public void TestUpdateComputeNodeUser()
        {
            BatchController     controller = BatchController.NewInstance;
            BatchAccountContext context    = null;
            string computeNodeId           = null;
            string userName = "******";

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-UpdateComputeNodeUser '{0}' '{1}' '{2}'", poolId, computeNodeId, userName) }); },
                () =>
            {
                context       = new ScenarioTestContext();
                computeNodeId = ScenarioTestHelpers.GetComputeNodeId(controller, context, poolId);
                ScenarioTestHelpers.CreateComputeNodeUser(controller, context, poolId, computeNodeId, userName);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteComputeNodeUser(controller, context, poolId, computeNodeId, userName);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
Exemple #15
0
        public void TestGetJobByName()
        {
            BatchController     controller   = BatchController.NewInstance;
            string              workItemName = "testName";
            string              jobName      = null;
            BatchAccountContext context      = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-GetJobByName '{0}' '{1}' '{2}'", accountName, workItemName, jobName) }); },
                () =>
            {
                context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, accountName);
                ScenarioTestHelpers.CreateTestWorkItem(controller, context, workItemName);
                jobName = ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteWorkItem(controller, context, workItemName);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
Exemple #16
0
        public void TestGetTaskById()
        {
            BatchController     controller = BatchController.NewInstance;
            string              jobId      = "getTaskJob";
            string              taskId     = "testTask";
            BatchAccountContext context    = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-GetTaskById '{0}' '{1}' '{2}'", accountName, jobId, taskId) }); },
                () =>
            {
                context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, accountName);
                ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
                ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteJob(controller, context, jobId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
Exemple #17
0
        public void TestRebootAndReimageComputeNode()
        {
            BatchController     controller = BatchController.NewInstance;
            BatchAccountContext context    = null;
            string computeNodeId           = null;
            string computeNodeId2          = null;

            controller.RunPsTestWorkflow(
                _logger,
                () => { return(new string[] { string.Format("Test-RebootAndReimageComputeNode '{0}' '{1}' '{2}'", poolId, computeNodeId, computeNodeId2) }); },
                () =>
            {
                context        = new ScenarioTestContext();
                computeNodeId  = ScenarioTestHelpers.GetComputeNodeId(controller, context, poolId, 0);
                computeNodeId2 = ScenarioTestHelpers.GetComputeNodeId(controller, context, poolId, 1);
                ScenarioTestHelpers.WaitForIdleComputeNode(controller, context, poolId, computeNodeId);
                ScenarioTestHelpers.WaitForIdleComputeNode(controller, context, poolId, computeNodeId2);
            },
                null,
                MethodBase.GetCurrentMethod().ReflectedType?.ToString(),
                MethodBase.GetCurrentMethod().Name);
        }
Exemple #18
0
        public void IfJobSetsAutoFailure_ItCompletesWhenAnyTaskFails()
        {
            BatchController     controller = BatchController.NewInstance;
            BatchAccountContext context    = null;
            string     poolId       = "testPool";
            string     jobId        = "testJobCompletesWhenTaskFails";
            string     taskId       = "taskId-1";
            PSCloudJob completedJob = null;

            controller.RunPsTestWorkflow(
                _logger,
                () => { return(new string[] { string.Format("IfJobSetsAutoFailure-ItCompletesWhenAnyTaskFails '{0}' '{1}' '{2}'", poolId, jobId, taskId) }); },
                null,
                () =>
            {
                context      = new ScenarioTestContext();
                completedJob = ScenarioTestHelpers.WaitForJobCompletion(controller, context, jobId, taskId);
                AssertJobIsCompleteDueToTaskFailure(completedJob);
                ScenarioTestHelpers.DeleteJob(controller, context, jobId);
            },
                MethodBase.GetCurrentMethod().ReflectedType?.ToString(),
                MethodBase.GetCurrentMethod().Name);
        }
Exemple #19
0
        public void TestUpdateTask()
        {
            BatchController controller = BatchController.NewInstance;
            string          jobId      = "updateTaskJob";
            string          taskId     = "testTask";

            BatchAccountContext context = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-UpdateTask '{0}' '{1}' '{2}'", accountName, jobId, taskId) }); },
                () =>
            {
                context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, accountName);
                ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
                // Make the task long running so the constraints can be updated
                ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId, "ping -t localhost -w 60");
            },
                () =>
            {
                ScenarioTestHelpers.DeleteJob(controller, context, jobId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
        public void TestListAllCertificates()
        {
            BatchController     controller = BatchController.NewInstance;
            BatchAccountContext context    = null;
            int    count       = 2;
            string thumbprint1 = null;
            string thumbprint2 = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-ListAllCertificates '{0}'", count) }); },
                () =>
            {
                context     = new ScenarioTestContext();
                thumbprint1 = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName1);
                thumbprint2 = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName2);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteTestCertificate(controller, context, BatchTestHelpers.TestCertificateAlgorithm, thumbprint1);
                ScenarioTestHelpers.DeleteTestCertificate(controller, context, BatchTestHelpers.TestCertificateAlgorithm, thumbprint2);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
        public void TestListNodeFilesByTaskWithMaxCount()
        {
            BatchController     controller = BatchController.NewInstance;
            string              jobId      = "nodeFileByTaskMaxJob";
            string              taskId     = "testTask";
            int                 maxCount   = 1;
            BatchAccountContext context    = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-ListNodeFilesByTaskWithMaxCount '{0}' '{1}' '{2}' '{3}'", accountName, jobId, taskId, maxCount) }); },
                () =>
            {
                context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, accountName);
                ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
                ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId);
                ScenarioTestHelpers.WaitForTaskCompletion(controller, context, jobId, taskId);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteJob(controller, context, jobId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
        public void TestListNodeFilesByTaskRecursive()
        {
            BatchController     controller = BatchController.NewInstance;
            string              jobId      = "listNodeFileByTaskRecursiveJob";
            string              taskId     = "testTask";
            string              newFile    = "testFile.txt";
            BatchAccountContext context    = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-ListNodeFilesByTaskRecursive '{0}' '{1}' '{2}' '{3}'", accountName, jobId, taskId, newFile) }); },
                () =>
            {
                context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, accountName);
                ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
                ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId, string.Format("cmd /c echo \"test file\" > {0}", newFile));
                ScenarioTestHelpers.WaitForTaskCompletion(controller, context, jobId, taskId);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteJob(controller, context, jobId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
Exemple #23
0
        public void TestListNodeFileByTaskPipeline()
        {
            BatchController     controller = BatchController.NewInstance;
            string              jobId      = "nodeFileByTaskPipe";
            string              taskId     = "testTask";
            int                 count      = 4; // ProcessEnv, stdout, stderr, wd
            BatchAccountContext context    = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-ListNodeFileByTaskPipeline '{0}' '{1}' '{2}'", jobId, taskId, count) }); },
                () =>
            {
                context = new ScenarioTestContext();
                ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
                ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId);
                ScenarioTestHelpers.WaitForTaskCompletion(controller, context, jobId, taskId);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteJob(controller, context, jobId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
Exemple #24
0
        public void TestGetNodeFileByTaskByName()
        {
            BatchController     controller   = BatchController.NewInstance;
            string              jobId        = "testGetNodeFileByTaskJob";
            string              taskId       = "testTask";
            string              nodeFileName = "stdout.txt";
            BatchAccountContext context      = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-GetNodeFileByTaskByName '{0}' '{1}' '{2}'", jobId, taskId, nodeFileName) }); },
                () =>
            {
                context = new ScenarioTestContext();
                ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
                ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId);
                ScenarioTestHelpers.WaitForTaskCompletion(controller, context, jobId, taskId);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteJob(controller, context, jobId);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }
        public void TestGetWorkItemByName()
        {
            BatchController     controller        = BatchController.NewInstance;
            string              resourceGroupName = "test-get-wi";
            string              accountName       = "testgetwi";
            string              location          = "eastus";
            string              workItemName      = "testName";
            BatchAccountContext context           = null;

            controller.RunPsTestWorkflow(
                () => { return(new string[] { string.Format("Test-GetWorkItemByName '{0}' '{1}'", accountName, workItemName) }); },
                () =>
            {
                context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location);
                ScenarioTestHelpers.CreateTestWorkItem(controller, context, workItemName);
            },
                () =>
            {
                ScenarioTestHelpers.DeleteWorkItem(controller, context, workItemName);
                ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName);
            },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName());
        }