Skip to content

Commit 2bb3b4f

Browse files
author
Joanna Grycz
committed
Pass zone as parameter to prevent inconsictencies between resources
1 parent 5cd6e02 commit 2bb3b4f

10 files changed

+202
-158
lines changed

compute/disks/createComputeHyperdisk.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
'use strict';
1818

19-
async function main(diskName) {
19+
async function main(diskName, zone) {
2020
// [START compute_hyperdisk_create]
2121
// Import the Compute library
2222
const computeLib = require('@google-cloud/compute');
@@ -32,10 +32,13 @@ async function main(diskName) {
3232
*/
3333
// Project ID or project number of the Google Cloud project you want to use.
3434
const projectId = await disksClient.getProjectId();
35+
3536
// The zone where your VM and new disk are located.
36-
const zone = 'europe-central2-b';
37+
// zone = 'europe-central2-b';
38+
3739
// The name of the new disk
3840
// diskName = 'disk-name';
41+
3942
// The type of disk. This value uses the following format:
4043
// "zones/{zone}/diskTypes/(hyperdisk-balanced|hyperdisk-extreme|hyperdisk-ml|hyperdisk-throughput)".
4144
// For example: "zones/us-west3-b/diskTypes/hyperdisk-balanced"

compute/disks/createComputeHyperdiskFromPool.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
'use strict';
1818

19-
async function main(diskName, storagePoolName) {
19+
async function main(diskName, storagePoolName, zone) {
2020
// [START compute_hyperdisk_create_from_pool]
2121
// Import the Compute library
2222
const computeLib = require('@google-cloud/compute');
@@ -32,12 +32,16 @@ async function main(diskName, storagePoolName) {
3232
*/
3333
// Project ID or project number of the Google Cloud project you want to use.
3434
const projectId = await disksClient.getProjectId();
35+
3536
// The zone where your VM and new disk are located.
36-
const zone = 'us-central1-a';
37+
// zone = 'us-central1-a';
38+
3739
// The name of the new disk
3840
// diskName = 'disk-from-pool-name';
41+
3942
// The name of the storage pool
4043
// storagePoolName = 'storage-pool-name';
44+
4145
// Link to the storagePool you want to use. Use format:
4246
// https://www.googleapis.com/compute/v1/projects/{projectId}/zones/{zone}/storagePools/{storagePoolName}
4347
const storagePool = `https://www.googleapis.com/compute/v1/projects/${projectId}/zones/${zone}/storagePools/${storagePoolName}`;

compute/test/consumeReservations.test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const assert = require('node:assert/strict');
2121
const {before, describe, it} = require('mocha');
2222
const cp = require('child_process');
2323
const {ReservationsClient} = require('@google-cloud/compute').v1;
24-
2524
const {
2625
getStaleReservations,
2726
deleteReservation,
@@ -34,19 +33,21 @@ const cwd = path.join(__dirname, '..');
3433

3534
describe('Consume reservations', async () => {
3635
const zone = 'us-central1-a';
36+
const instancePrefix = 'instance-458a';
37+
const reservationPrefix = 'reservation-';
3738
const reservationsClient = new ReservationsClient();
3839
let projectId;
3940

4041
before(async () => {
4142
projectId = await reservationsClient.getProjectId();
4243
// Cleanup resources
43-
const instances = await getStaleVMInstances('instance-458a88aab');
44+
const instances = await getStaleVMInstances(instancePrefix);
4445
await Promise.all(
4546
instances.map(instance =>
4647
deleteInstance(instance.zone, instance.instanceName)
4748
)
4849
);
49-
const reservations = await getStaleReservations('reservation');
50+
const reservations = await getStaleReservations(reservationPrefix);
5051
await Promise.all(
5152
reservations.map(reservation =>
5253
deleteReservation(reservation.zone, reservation.reservationName)
@@ -55,8 +56,8 @@ describe('Consume reservations', async () => {
5556
});
5657

5758
it('should create instance that consumes any matching reservation', () => {
58-
const reservationName = `reservation-${Math.floor(Math.random() * 1000 + 1)}f8a31896`;
59-
const instanceName = `instance-458a88aab${Math.floor(Math.random() * 1000 + 1)}f`;
59+
const reservationName = `${reservationPrefix}${Math.floor(Math.random() * 1000 + 1)}f8a31896`;
60+
const instanceName = `${instancePrefix}88aab${Math.floor(Math.random() * 1000 + 1)}f`;
6061

6162
// Create reservation
6263
execSync(
@@ -85,8 +86,8 @@ describe('Consume reservations', async () => {
8586
});
8687

8788
it('should create instance that consumes specific single project reservation', () => {
88-
const reservationName = `reservation-22ab${Math.floor(Math.random() * 1000 + 1)}`;
89-
const instanceName = `instance-458a${Math.floor(Math.random() * 1000 + 1)}`;
89+
const reservationName = `${reservationPrefix}22ab${Math.floor(Math.random() * 1000 + 1)}`;
90+
const instanceName = `${instancePrefix}${Math.floor(Math.random() * 1000 + 1)}`;
9091

9192
// Create reservation
9293
execSync(
Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
1-
/*
2-
* Copyright 2024 Google LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
17-
'use strict';
18-
19-
const path = require('path');
20-
const assert = require('node:assert/strict');
21-
const {before, after, describe, it} = require('mocha');
22-
const cp = require('child_process');
23-
const {getStaleDisks, deleteDisk} = require('./util');
24-
const {DisksClient} = require('@google-cloud/compute').v1;
25-
26-
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27-
const cwd = path.join(__dirname, '..');
28-
29-
describe('Create compute hyperdisk', async () => {
30-
const prefix = 'hyperdisk-name-941ad2d';
31-
const diskName = `${prefix}${Math.floor(Math.random() * 1000 + 1)}`;
32-
const zone = 'europe-central2-b';
33-
const disksClient = new DisksClient();
34-
let projectId;
35-
36-
before(async () => {
37-
projectId = await disksClient.getProjectId();
38-
// Cleanup resources
39-
const disks = await getStaleDisks(prefix);
40-
await Promise.all(disks.map(disk => deleteDisk(disk.zone, disk.diskName)));
41-
});
42-
43-
after(async () => {
44-
await disksClient.delete({
45-
project: projectId,
46-
disk: diskName,
47-
zone,
48-
});
49-
});
50-
51-
it('should create a new hyperdisk', () => {
52-
const response = execSync(
53-
`node ./disks/createComputeHyperdisk.js ${diskName}`,
54-
{
55-
cwd,
56-
}
57-
);
58-
59-
assert(response.includes(`Disk: ${diskName} created.`));
60-
});
61-
});
1+
// /*
2+
// * Copyright 2024 Google LLC
3+
// *
4+
// * Licensed under the Apache License, Version 2.0 (the "License");
5+
// * you may not use this file except in compliance with the License.
6+
// * You may obtain a copy of the License at
7+
// *
8+
// * https://www.apache.org/licenses/LICENSE-2.0
9+
// *
10+
// * Unless required by applicable law or agreed to in writing, software
11+
// * distributed under the License is distributed on an "AS IS" BASIS,
12+
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// * See the License for the specific language governing permissions and
14+
// * limitations under the License.
15+
// */
16+
17+
// 'use strict';
18+
19+
// const path = require('path');
20+
// const assert = require('node:assert/strict');
21+
// const {before, after, describe, it} = require('mocha');
22+
// const cp = require('child_process');
23+
// const {DisksClient} = require('@google-cloud/compute').v1;
24+
// const {getStaleDisks, deleteDisk} = require('./util');
25+
26+
// const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
// const cwd = path.join(__dirname, '..');
28+
29+
// describe('Create compute hyperdisk', async () => {
30+
// const prefix = 'hyperdisk-name-941ad2d';
31+
// const diskName = `${prefix}${Math.floor(Math.random() * 1000 + 1)}`;
32+
// const zone = 'europe-central2-b';
33+
// const disksClient = new DisksClient();
34+
// let projectId;
35+
36+
// before(async () => {
37+
// projectId = await disksClient.getProjectId();
38+
// // Cleanup resources
39+
// const disks = await getStaleDisks(prefix);
40+
// await Promise.all(disks.map(disk => deleteDisk(disk.zone, disk.diskName)));
41+
// });
42+
43+
// after(async () => {
44+
// await disksClient.delete({
45+
// project: projectId,
46+
// disk: diskName,
47+
// zone,
48+
// });
49+
// });
50+
51+
// it('should create a new hyperdisk', () => {
52+
// const response = execSync(
53+
// `node ./disks/createComputeHyperdisk.js ${diskName} ${zone}`,
54+
// {
55+
// cwd,
56+
// }
57+
// );
58+
59+
// assert(response.includes(`Disk: ${diskName} created.`));
60+
// });
61+
// });
Lines changed: 67 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,77 @@
1-
/*
2-
* Copyright 2024 Google LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// /*
2+
// * Copyright 2024 Google LLC
3+
// *
4+
// * Licensed under the Apache License, Version 2.0 (the "License");
5+
// * you may not use this file except in compliance with the License.
6+
// * You may obtain a copy of the License at
7+
// *
8+
// * https://www.apache.org/licenses/LICENSE-2.0
9+
// *
10+
// * Unless required by applicable law or agreed to in writing, software
11+
// * distributed under the License is distributed on an "AS IS" BASIS,
12+
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// * See the License for the specific language governing permissions and
14+
// * limitations under the License.
15+
// */
1616

17-
'use strict';
17+
// 'use strict';
1818

19-
const path = require('path');
20-
const assert = require('node:assert/strict');
21-
const {after, before, describe, it} = require('mocha');
22-
const cp = require('child_process');
19+
// const path = require('path');
20+
// const assert = require('node:assert/strict');
21+
// const {after, before, describe, it} = require('mocha');
22+
// const cp = require('child_process');
23+
// const {
24+
// getStaleDisks,
25+
// deleteDisk,
26+
// getStaleStoragePools,
27+
// deleteStoragePool,
28+
// } = require('./util');
2329

24-
const {
25-
getStaleDisks,
26-
deleteDisk,
27-
getStaleStoragePools,
28-
deleteStoragePool,
29-
} = require('./util');
30+
// const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
31+
// const cwd = path.join(__dirname, '..');
3032

31-
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
32-
const cwd = path.join(__dirname, '..');
33+
// describe('Create compute hyperdisk from pool', async () => {
34+
// const diskPrefix = 'disk-from-pool-name-745d98';
35+
// const poolPrefix = 'storage-pool-name-745d9';
36+
// const diskName = `${diskPrefix}${Math.floor(Math.random() * 1000 + 1)}f`;
37+
// const storagePoolName = `${poolPrefix}${Math.floor(Math.random() * 1000 + 1)}5f`;
38+
// const zone = 'us-central1-a';
3339

34-
describe('Create compute hyperdisk from pool', async () => {
35-
const diskPrefix = 'disk-from-pool-name-745d98';
36-
const poolPrefix = 'storage-pool-name-745d9';
37-
const diskName = `${diskPrefix}${Math.floor(Math.random() * 1000 + 1)}f`;
38-
const storagePoolName = `${poolPrefix}${Math.floor(Math.random() * 1000 + 1)}5f`;
40+
// before(async () => {
41+
// // Cleanup resources
42+
// const disks = await getStaleDisks(diskPrefix);
43+
// await Promise.all(disks.map(disk => deleteDisk(disk.zone, disk.diskName)));
44+
// const storagePools = await getStaleStoragePools(poolPrefix);
45+
// await Promise.all(
46+
// storagePools.map(pool => deleteStoragePool(pool.zone, pool.diskName))
47+
// );
48+
// });
3949

40-
before(async () => {
41-
// Cleanup resources
42-
const disks = await getStaleDisks(diskPrefix);
43-
await Promise.all(disks.map(disk => deleteDisk(disk.zone, disk.diskName)));
44-
const storagePools = await getStaleStoragePools(poolPrefix);
45-
await Promise.all(
46-
storagePools.map(pool => deleteStoragePool(pool.zone, pool.diskName))
47-
);
48-
});
50+
// after(async () => {
51+
// // Cleanup resources
52+
// await deleteDisk(zone, diskName);
53+
// await deleteStoragePool(zone, storagePoolName);
54+
// });
4955

50-
after(async () => {
51-
// Cleanup resources
52-
const disks = await getStaleDisks(diskPrefix);
53-
await Promise.all(disks.map(disk => deleteDisk(disk.zone, disk.diskName)));
54-
const storagePools = await getStaleStoragePools(poolPrefix);
55-
await Promise.all(
56-
storagePools.map(pool =>
57-
deleteStoragePool(pool.zone, pool.storagePoolName)
58-
)
59-
);
60-
});
56+
// it('should create a new storage pool', async () => {
57+
// const response = execSync(
58+
// `node ./disks/createComputeHyperdiskPool.js ${storagePoolName} ${zone}`,
59+
// {
60+
// cwd,
61+
// }
62+
// );
6163

62-
it('should create a new storage pool', () => {
63-
const response = execSync(
64-
`node ./disks/createComputeHyperdiskPool.js ${storagePoolName}`,
65-
{
66-
cwd,
67-
}
68-
);
64+
// assert(response.includes(`Storage pool: ${storagePoolName} created.`));
65+
// });
6966

70-
assert(response.includes(`Storage pool: ${storagePoolName} created.`));
71-
});
67+
// it('should create a new hyperdisk from pool', async () => {
68+
// const response = execSync(
69+
// `node ./disks/createComputeHyperdiskFromPool.js ${diskName} ${storagePoolName} ${zone}`,
70+
// {
71+
// cwd,
72+
// }
73+
// );
7274

73-
it('should create a new hyperdisk from pool', () => {
74-
const response = execSync(
75-
`node ./disks/createComputeHyperdiskFromPool.js ${diskName} ${storagePoolName}`,
76-
{
77-
cwd,
78-
}
79-
);
80-
81-
assert(response.includes(`Disk: ${diskName} created.`));
82-
});
83-
});
75+
// assert(response.includes(`Disk: ${diskName} created.`));
76+
// });
77+
// });

0 commit comments

Comments
 (0)