kubeflowTrainingService.test.ts 2.24 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
2
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
3
4
5

'use strict';

6
7
8
9
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import fs from 'fs';
import tmp from 'tmp';
10
11
import * as component from '../../common/component';
import { cleanupUnitTest, prepareUnitTest } from '../../common/utils';
liuzhe-lz's avatar
liuzhe-lz committed
12
13
import { TrialConfigMetadataKey } from '../../training_service/common/trialConfigMetadataKey';
import { KubeflowTrainingService } from '../../training_service/kubernetes/kubeflow/kubeflowTrainingService';
14
15
16

// TODO: copy mockedTrail.py to local folder
const localCodeDir: string = tmp.dirSync().name
liuzhe-lz's avatar
liuzhe-lz committed
17
const mockedTrialPath: string = './test/mock/mockedTrial.py'
18
19
20
21
22
23
24
25
fs.copyFileSync(mockedTrialPath, localCodeDir + '/mockedTrial.py')

describe('Unit Test for KubeflowTrainingService', () => {
    let skip: boolean = false;
    let testKubeflowConfig: any;
    let testKubeflowTrialConfig : any;
    try {
        testKubeflowConfig = JSON.parse(fs.readFileSync('../../.vscode/kubeflowCluster.json', 'utf8'));
26
        testKubeflowTrialConfig = `{\"command\":\"python3 mnist.py\",\"codeDir\":\"/tmp/nni/examples/trials/mnist",\"gpuNum\":\"1\",\"cpuNum\":\"2\",\"memoryMB\":\"8196\",\"image\":\"msranni/nni:latest\"}`;
27
    } catch (err) {
28
29
        console.log('Please configure kubeflowCluster.json to enable kubeflow training service unit test.');
        skip = true;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    }

    let kubeflowTrainingService: KubeflowTrainingService;

    console.log(tmp.dirSync().name);

    before(() => {
        chai.should();
        chai.use(chaiAsPromised);
        prepareUnitTest();
    });

    after(() => {
        cleanupUnitTest();
    });

    beforeEach(() => {
        if (skip) {
            return;
        }
50
        kubeflowTrainingService = component.get(KubeflowTrainingService);
51
52
53
54
55
56
57
58
59
    });

    afterEach(() => {
        if (skip) {
            return;
        }
        kubeflowTrainingService.cleanUp();
    });

60
    it('Set cluster metadata', async () => {
61
62
63
        if (skip) {
            return;
        }
64
        await kubeflowTrainingService.setClusterMetadata(TrialConfigMetadataKey.KUBEFLOW_CLUSTER_CONFIG, testKubeflowConfig),
65
        await kubeflowTrainingService.setClusterMetadata(TrialConfigMetadataKey.TRIAL_CONFIG, testKubeflowTrialConfig);
66
    });
liuzhe-lz's avatar
liuzhe-lz committed
67
});