Example #1
0
    def test_setup_task_execution(self, resource_group, location, storage_account, storage_account_key):
        """Tests setup task execution.
        """
        cluster = Helpers.create_cluster(
            self.client, location, resource_group.name, self.cluster_name, 'STANDARD_D1', 1,
            storage_account.name, storage_account_key,
            setup_task_cmd='echo $GREETING $SECRET_GREETING',
            setup_task_env={'GREETING': 'setup task'},
            setup_task_secrets={'SECRET_GREETING': 'has a secret'})  # type: models.Cluster

        # Verify that the cluster is reported in the list of clusters
        Helpers.assert_existing_clusters_are(self, self.client, resource_group.name, [self.cluster_name])

        # Verify that one node is allocated and become available
        self.assertEqual(
            Helpers.wait_for_nodes(self.is_live, self.client, resource_group.name, self.cluster_name, 1,
                                   Helpers.NODE_STARTUP_TIMEOUT_SEC), 1)

        # Check that server doesn't return values for secrets
        self.assertEqual(len(cluster.node_setup.setup_task.secrets), 1)
        self.assertEqual(cluster.node_setup.setup_task.secrets[0].name, 'SECRET_GREETING')
        self.assertIsNone(cluster.node_setup.setup_task.secrets[0].value)
        # Verify that the setup task is completed by checking generated output. BatchAI reports a path which was auto-
        # generated for storing setup output logs.
        setup_task_output_path = cluster.node_setup.setup_task.std_out_err_path_suffix
        nodes = Helpers.get_node_ids(self.client, resource_group.name, self.cluster_name)
        self.assertEqual(len(nodes), 1)
        node_id = nodes[0]
        Helpers.assert_file_in_file_share(self, storage_account.name, storage_account_key,
                                          setup_task_output_path,
                                          'stdout-{0}.txt'.format(node_id),
                                          u'setup task has a secret\n')
        Helpers.assert_file_in_file_share(self, storage_account.name, storage_account_key,
                                          setup_task_output_path, 'stderr-{0}.txt'.format(node_id), u'')
        self.client.clusters.delete(resource_group.name, Helpers.DEFAULT_WORKSPACE_NAME, self.cluster_name).result()
 def test_job_creation_and_deletion(self, resource_group, location, cluster, storage_account, storage_account_key):
     """Tests simple scenario for a job - submit, check results, delete."""
     job = Helpers.create_custom_job(self.client, resource_group.name, cluster.id, 'job', 1,
                                     'echo hi | tee {0}/hi.txt'.format(Helpers.JOB_OUTPUT_DIRECTORY_PATH_ENV),
                                     container=models.ContainerSettings(
                                         image_source_registry=models.ImageSourceRegistry(image='ubuntu'))
                                     )  # type: models.Job
     self.assertEqual(
         Helpers.wait_for_job_completion(self.is_live, self.client, resource_group.name, job.name, Helpers.MINUTE),
         models.ExecutionState.succeeded)
     # Check standard job output
     Helpers.assert_job_files_are(self, self.client, resource_group.name, job.name,
                                  Helpers.STANDARD_OUTPUT_DIRECTORY_ID,
                                  {u'stdout.txt': u'hi\n', u'stderr.txt': u''})
     # Check job's output
     Helpers.assert_job_files_are(self, self.client, resource_group.name, job.name,
                                  Helpers.JOB_OUTPUT_DIRECTORY_ID,
                                  {u'hi.txt': u'hi\n'})
     # Check that we can access the output files directly in storage using path segment returned by the server
     Helpers.assert_file_in_file_share(self, storage_account.name, storage_account_key,
                                       job.job_output_directory_path_segment + '/' + Helpers.STDOUTERR_FOLDER_NAME,
                                       'stdout.txt', u'hi\n')
     self.client.jobs.delete(resource_group.name, Helpers.DEFAULT_WORKSPACE_NAME, Helpers.DEFAULT_EXPERIMENT_NAME,
                             job.name).result()
     self.assertRaises(CloudError, lambda: self.client.jobs.get(resource_group.name, Helpers.DEFAULT_WORKSPACE_NAME,
                                                                Helpers.DEFAULT_EXPERIMENT_NAME, job.name))