Пример #1
0
    def test_job_apis(self):
        client = api_client.ApiClient('http://127.0.0.1:8080/')
        api = batch_v1_api.BatchV1Api(client)

        name = 'test-job-' + str(uuid.uuid4())
        job_manifest = {
            'kind': 'Job',
            'spec': {
                'template':
                    {'spec':
                        {'containers': [
                            {'image': 'busybox',
                             'name': name,
                             'command': ["sh", "-c", "sleep 5"]
                             }],
                            'restartPolicy': 'Never'},
                        'metadata': {'name': name}}},
            'apiVersion': 'batch/v1',
            'metadata': {'name': name}}

        resp = api.create_namespaced_job(
            body=job_manifest, namespace='default')
        self.assertEqual(name, resp.metadata.name)

        resp = api.read_namespaced_job(
            name=name, namespace='default')
        self.assertEqual(name, resp.metadata.name)

        resp = api.delete_namespaced_job(
            name=name, body={}, namespace='default')
Пример #2
0
                            'restartPolicy':
                            'Never'
                        },
                        'metadata': {
                            'name': 'peaktest'
                        }
                    }
                },
                'apiVersion': 'batch/v1',
                'metadata': {
                    'name': 'peaktest' + str(suite_uuid)[:8] + str(i)
                }
            }
            self.k8sclient.create_namespaced_job(
                body=job_manifest,
                namespace=os.environ['OPENSHIFT_BUILD_NAMESPACE'])

        resp.body = json.dumps({'id': str(suite_uuid)})


api = falcon.API(middleware=[PeeweeConnectionMiddleware()])

kubernetes.config.load_incluster_config()
batch_client = batch_v1_api.BatchV1Api()

peak_suite = PeakSuiteResource()
peak_suites = PeakSuitesResource(batch_client)

api.add_route('/suites/', peak_suites)
api.add_route('/suites/{suite_uuid}', peak_suite)