Skip to content

Commit a9ee1f7

Browse files
author
Joanna Grycz
committed
Use mocked TPUClient in tests
1 parent c992903 commit a9ee1f7

7 files changed

+208
-235
lines changed

tpu/queuedResources/createQueuedResourceNetwork.js

+23-24
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@
1616

1717
'use strict';
1818

19-
async function main(
20-
nodeName,
21-
queuedResourceName,
22-
zone,
23-
tpuType,
24-
tpuSoftwareVersion
25-
) {
26-
// [START tpu_queued_resources_create_network]
27-
// Import the TPU library
28-
const {TpuClient} = require('@google-cloud/tpu').v2alpha1;
19+
async function main(tpuClient) {
20+
// [START tpu_queued_resources_network]
21+
// Import the TPUClient
22+
// TODO(developer): Uncomment below line before running the sample.
23+
// const {TpuClient} = require('@google-cloud/tpu').v2alpha1;
2924
const {Node, NetworkConfig, QueuedResource} =
3025
require('@google-cloud/tpu').protos.google.cloud.tpu.v2alpha1;
3126

3227
// Instantiate a tpuClient
33-
const tpuClient = new TpuClient();
28+
// TODO(developer): Uncomment below line before running the sample.
29+
// tpuClient = new TpuClient();
3430

3531
/**
3632
* TODO(developer): Update/uncomment these variables before running the sample.
@@ -42,27 +38,27 @@ async function main(
4238
const networkName = 'compute-tpu-network';
4339

4440
// The region of the network, that you want the node to connect to.
45-
const region = 'europe-west4';
41+
const region = 'us-central1';
4642

4743
// The name for your queued resource.
48-
// queuedResourceName = 'queued-resource-1';
44+
const queuedResourceName = 'queued-resource-1';
4945

5046
// The name for your node.
51-
// nodeName = 'node-name-1';
47+
const nodeName = 'node-name-1';
5248

5349
// The zone in which to create the node.
5450
// For more information about supported TPU types for specific zones,
5551
// see https://cloud.google.com/tpu/docs/regions-zones
56-
// zone = 'europe-west4-a';
52+
const zone = `${zone}-a`;
5753

5854
// The accelerator type that specifies the version and size of the node you want to create.
5955
// For more information about supported accelerator types for each TPU version,
6056
// see https://cloud.google.com/tpu/docs/system-architecture-tpu-vm#versions.
61-
// tpuType = 'v2-8';
57+
const tpuType = 'v2-8';
6258

6359
// Software version that specifies the version of the node runtime to install. For more information,
6460
// see https://cloud.google.com/tpu/docs/runtimes
65-
// tpuSoftwareVersion = 'tpu-vm-tf-2.14.1';
61+
const tpuSoftwareVersion = 'tpu-vm-tf-2.14.1';
6662

6763
async function callCreateQueuedResourceNetwork() {
6864
// Specify the network and subnetwork that you want to connect your TPU to.
@@ -112,13 +108,16 @@ async function main(
112108

113109
// You can wait until TPU Node is READY,
114110
// and check its status using getTpuVm() from `tpu_vm_get` sample.
115-
console.log(JSON.stringify(response));
111+
return response;
116112
}
117-
await callCreateQueuedResourceNetwork();
118-
// [END tpu_queued_resources_create_network]
113+
return await callCreateQueuedResourceNetwork();
114+
// [END tpu_queued_resources_network]
119115
}
120116

121-
main(...process.argv.slice(2)).catch(err => {
122-
console.error(err);
123-
process.exitCode = 1;
124-
});
117+
module.exports = main;
118+
119+
// TODO(developer): Uncomment below lines before running the sample.
120+
// main(...process.argv.slice(2)).catch(err => {
121+
// console.error(err);
122+
// process.exitCode = 1;
123+
// });

tpu/queuedResources/createQueuedResourceStartupScript.js

+21-22
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@
1616

1717
'use strict';
1818

19-
async function main(
20-
nodeName,
21-
queuedResourceName,
22-
zone,
23-
tpuType,
24-
tpuSoftwareVersion
25-
) {
19+
async function main(tpuClient) {
2620
// [START tpu_queued_resources_startup_script]
27-
// Import the TPU library
28-
const {TpuClient} = require('@google-cloud/tpu').v2alpha1;
21+
// Import the TPUClient
22+
// TODO(developer): Uncomment below line before running the sample.
23+
// const {TpuClient} = require('@google-cloud/tpu').v2alpha1;
2924
const {Node, NetworkConfig, QueuedResource} =
3025
require('@google-cloud/tpu').protos.google.cloud.tpu.v2alpha1;
3126

3227
// Instantiate a tpuClient
33-
const tpuClient = new TpuClient();
28+
// TODO(developer): Uncomment below line before running the sample.
29+
// tpuClient = new TpuClient();
3430

3531
/**
3632
* TODO(developer): Update/uncomment these variables before running the sample.
@@ -42,27 +38,27 @@ async function main(
4238
const networkName = 'compute-tpu-network';
4339

4440
// The region of the network, that you want the node to connect to.
45-
const region = 'europe-west4';
41+
const region = 'us-central1';
4642

4743
// The name for your queued resource.
48-
// queuedResourceName = 'queued-resource-1';
44+
const queuedResourceName = 'queued-resource-1';
4945

5046
// The name for your node.
51-
// nodeName = 'node-name-1';
47+
const nodeName = 'node-name-1';
5248

5349
// The zone in which to create the node.
5450
// For more information about supported TPU types for specific zones,
5551
// see https://cloud.google.com/tpu/docs/regions-zones
56-
// zone = 'europe-west4-a';
52+
const zone = `${zone}-a`;
5753

5854
// The accelerator type that specifies the version and size of the node you want to create.
5955
// For more information about supported accelerator types for each TPU version,
6056
// see https://cloud.google.com/tpu/docs/system-architecture-tpu-vm#versions.
61-
// tpuType = 'v2-8';
57+
const tpuType = 'v2-8';
6258

6359
// Software version that specifies the version of the node runtime to install. For more information,
6460
// see https://cloud.google.com/tpu/docs/runtimes
65-
// tpuSoftwareVersion = 'tpu-vm-tf-2.14.1';
61+
const tpuSoftwareVersion = 'tpu-vm-tf-2.14.1';
6662

6763
async function callCreateQueuedResourceStartupScript() {
6864
// Create a node
@@ -116,13 +112,16 @@ async function main(
116112

117113
// You can wait until TPU Node is READY,
118114
// and check its status using getTpuVm() from `tpu_vm_get` sample.
119-
console.log(JSON.stringify(response));
115+
return response;
120116
}
121-
await callCreateQueuedResourceStartupScript();
117+
return await callCreateQueuedResourceStartupScript();
122118
// [END tpu_queued_resources_startup_script]
123119
}
124120

125-
main(...process.argv.slice(2)).catch(err => {
126-
console.error(err);
127-
process.exitCode = 1;
128-
});
121+
module.exports = main;
122+
123+
// TODO(developer): Uncomment below lines before running the sample.
124+
// main(...process.argv.slice(2)).catch(err => {
125+
// console.error(err);
126+
// process.exitCode = 1;
127+
// });

tpu/queuedResources/createQueuedResourceTimeBound.js

+21-22
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@
1616

1717
'use strict';
1818

19-
async function main(
20-
nodeName,
21-
queuedResourceName,
22-
zone,
23-
tpuType,
24-
tpuSoftwareVersion
25-
) {
19+
async function main(tpuClient) {
2620
// [START tpu_queued_resources_time_bound]
27-
// Import the TPU library
28-
const {TpuClient} = require('@google-cloud/tpu').v2alpha1;
21+
// Import the TPUClient
22+
// TODO(developer): Uncomment below line before running the sample.
23+
// const {TpuClient} = require('@google-cloud/tpu').v2alpha1;
2924
const {Node, NetworkConfig, QueuedResource} =
3025
require('@google-cloud/tpu').protos.google.cloud.tpu.v2alpha1;
3126

3227
// Instantiate a tpuClient
33-
const tpuClient = new TpuClient();
28+
// TODO(developer): Uncomment below line before running the sample.
29+
// tpuClient = new TpuClient();
3430

3531
/**
3632
* TODO(developer): Update/uncomment these variables before running the sample.
@@ -42,27 +38,27 @@ async function main(
4238
const networkName = 'compute-tpu-network';
4339

4440
// The region of the network, that you want the node to connect to.
45-
const region = 'europe-west4';
41+
const region = 'us-central1';
4642

4743
// The name for your queued resource.
48-
// queuedResourceName = 'queued-resource-1';
44+
const queuedResourceName = 'queued-resource-1';
4945

5046
// The name for your node.
51-
// nodeName = 'node-name-1';
47+
const nodeName = 'node-name-1';
5248

5349
// The zone in which to create the node.
5450
// For more information about supported TPU types for specific zones,
5551
// see https://cloud.google.com/tpu/docs/regions-zones
56-
// zone = 'europe-west4-a';
52+
const zone = `${zone}-a`;
5753

5854
// The accelerator type that specifies the version and size of the node you want to create.
5955
// For more information about supported accelerator types for each TPU version,
6056
// see https://cloud.google.com/tpu/docs/system-architecture-tpu-vm#versions.
61-
// tpuType = 'v2-8';
57+
const tpuType = 'v2-8';
6258

6359
// Software version that specifies the version of the node runtime to install. For more information,
6460
// see https://cloud.google.com/tpu/docs/runtimes
65-
// tpuSoftwareVersion = 'tpu-vm-tf-2.14.1';
61+
const tpuSoftwareVersion = 'tpu-vm-tf-2.14.1';
6662

6763
async function callCreateQueuedResourceTimeBound() {
6864
// Create a node
@@ -143,13 +139,16 @@ async function main(
143139

144140
// You can wait until TPU Node is READY,
145141
// and check its status using getTpuVm() from `tpu_vm_get` sample.
146-
console.log(JSON.stringify(response));
142+
return response;
147143
}
148-
await callCreateQueuedResourceTimeBound();
144+
return await callCreateQueuedResourceTimeBound();
149145
// [END tpu_queued_resources_time_bound]
150146
}
151147

152-
main(...process.argv.slice(2)).catch(err => {
153-
console.error(err);
154-
process.exitCode = 1;
155-
});
148+
module.exports = main;
149+
150+
// TODO(developer): Uncomment below lines before running the sample.
151+
// main(...process.argv.slice(2)).catch(err => {
152+
// console.error(err);
153+
// process.exitCode = 1;
154+
// });

tpu/queuedResources/forceDeleteQueuedResource.js

-59
This file was deleted.

0 commit comments

Comments
 (0)