예제 #1
0
def try_assign_self_as_master(client: batch.BatchServiceClient, pool: batchmodels.CloudPool):
    current_metadata = pool.metadata or []
    new_metadata = current_metadata + [{"name": MASTER_NODE_METADATA_KEY, "value": config.node_id}]

    try:
        client.pool.patch(
            config.pool_id,
            batchmodels.PoolPatchParameter(metadata=new_metadata),
            batchmodels.PoolPatchOptions(if_match=pool.e_tag),
        )
        return True
    except (BatchErrorException, ClientRequestError):
        print("Couldn't assign itself as master the pool because the pool was modified since last get.")
        return False
예제 #2
0
    def update_pool(self, new_command, new_resource_files):
        """Updates the pool with a new start task command and resource files

        Args:
            new_command: command to run when each node joins the bool formatted as a string
            new_resource_files: list of file references (of type azure.batch.models.ResourceFile)
                from Azure Storage to download to each node

        Returns:
            success: Boolean. True if nodes update and reboot, False otherwise.
        """

        logging.info("Updating pool [{}] with new start task".format(
            self.pool_id))
        self.wait_for_all_nodes_not_state(
            batch_models.ComputeNodeState.running)
        self.batch_client.pool.patch(
            self.pool_id,
            pool_patch_parameter=batch_models.PoolPatchParameter(
                start_task=BatchPool._create_start_task(
                    new_command, new_resource_files)))
        return self.reboot_pool()
    def test_batch_update_pools(self, **kwargs):
        client = self.create_sharedkey_client(**kwargs)
        # Test Create Paas Pool
        test_paas_pool = models.PoolAddParameter(
            id=self.get_resource_name('batch_paas_'),
            vm_size='small',
            cloud_service_configuration=models.CloudServiceConfiguration(
                os_family='5'
            ),
            start_task=models.StartTask(
                command_line="cmd.exe /c \"echo hello world\"",
                resource_files=[models.ResourceFile('https://blobsource.com', 'filename.txt')],
                environment_settings=[models.EnvironmentSetting('ENV_VAR', 'env_value')],
                user_identity=models.UserIdentity(
                    auto_user=models.AutoUserSpecification(
                        elevation_level=models.ElevationLevel.admin
                    )
                )
            )
        )
        response = client.pool.add(test_paas_pool)
        self.assertIsNone(response)

        # Test Upgrade Pool OS
        self.assertBatchError(
            "PoolVersionEqualsUpgradeVersion",
            client.pool.upgrade_os,
            test_paas_pool.id,
            "*"
        )

        # Test Update Pool Parameters
        params = models.PoolUpdatePropertiesParameter([], [], [models.MetadataItem('foo', 'bar')])
        response = client.pool.update_properties(test_paas_pool.id, params)
        self.assertIsNone(response)

        # Test Patch Pool Parameters
        params = models.PoolPatchParameter(metadata=[models.MetadataItem('foo2', 'bar2')])
        response = client.pool.patch(test_paas_pool.id, params)
        self.assertIsNone(response)

        # Test Pool Exists
        response = client.pool.exists(test_paas_pool.id)
        self.assertTrue(response)

        # Test Get Pool
        pool = client.pool.get(test_paas_pool.id)
        self.assertIsInstance(pool, models.CloudPool)
        self.assertEqual(pool.id, test_paas_pool.id)
        self.assertEqual(pool.state, models.PoolState.active)
        self.assertEqual(pool.allocation_state, models.AllocationState.steady)
        self.assertEqual(pool.cloud_service_configuration.os_family, '5')
        self.assertEqual(pool.vm_size, 'small')
        self.assertIsNone(pool.start_task)
        self.assertEqual(pool.metadata[0].name, 'foo2')
        self.assertEqual(pool.metadata[0].value, 'bar2')

        # Test Get Pool with OData Clauses
        options = models.PoolGetOptions(select='id,state', expand='stats')
        pool = client.pool.get(test_paas_pool.id, options)
        self.assertIsInstance(pool, models.CloudPool)
        self.assertEqual(pool.id, test_paas_pool.id)
        self.assertEqual(pool.state, models.PoolState.active)
        self.assertIsNone(pool.allocation_state)
        self.assertIsNone(pool.vm_size)

        # Test Delete Pool
        response = client.pool.delete(test_paas_pool.id)
        self.assertIsNone(response)