diff --git a/compute/disks/createComputeHyperdisk.js b/compute/disks/createComputeHyperdisk.js index cd004ac181..016bdb1dcd 100644 --- a/compute/disks/createComputeHyperdisk.js +++ b/compute/disks/createComputeHyperdisk.js @@ -78,15 +78,7 @@ async function main(diskName) { }); } - const hyperdisk = ( - await disksClient.get({ - project: projectId, - zone, - disk: diskName, - }) - )[0]; - - console.log(JSON.stringify(hyperdisk)); + console.log(`Disk: ${diskName} created.`); } await callCreateComputeHyperdisk(); diff --git a/compute/disks/createComputeHyperdiskFromPool.js b/compute/disks/createComputeHyperdiskFromPool.js index ccda1c9c35..369a13a830 100644 --- a/compute/disks/createComputeHyperdiskFromPool.js +++ b/compute/disks/createComputeHyperdiskFromPool.js @@ -84,15 +84,7 @@ async function main(diskName, storagePoolName) { }); } - const hyperdisk = ( - await disksClient.get({ - project: projectId, - zone, - disk: diskName, - }) - )[0]; - - console.log(JSON.stringify(hyperdisk)); + console.log(`Disk: ${diskName} created.`); } await callCreateComputeHyperdiskFromPool(); diff --git a/compute/disks/createComputeHyperdiskPool.js b/compute/disks/createComputeHyperdiskPool.js index c18e02a3db..845b92a250 100644 --- a/compute/disks/createComputeHyperdiskPool.js +++ b/compute/disks/createComputeHyperdiskPool.js @@ -79,15 +79,7 @@ async function main(storagePoolName) { }); } - const createdStoragePool = ( - await storagePoolClient.get({ - project: projectId, - zone, - storagePool: storagePoolName, - }) - )[0]; - - console.log(JSON.stringify(createdStoragePool)); + console.log(`Storage pool: ${storagePoolName} created.`); } await callCreateComputeHyperdiskPool(); diff --git a/compute/reservations/createReservationFromProperties.js b/compute/reservations/createReservationFromProperties.js index 1b685ce1c6..05b38361ca 100644 --- a/compute/reservations/createReservationFromProperties.js +++ b/compute/reservations/createReservationFromProperties.js @@ -96,15 +96,7 @@ async function main(reservationName) { }); } - const createdReservation = ( - await reservationsClient.get({ - project: projectId, - zone, - reservation: reservationName, - }) - )[0]; - - console.log(JSON.stringify(createdReservation)); + console.log(`Reservation: ${reservationName} created.`); } await callCreateComputeReservationFromProperties(); diff --git a/compute/reservations/createReservationInstanceTemplate.js b/compute/reservations/createReservationInstanceTemplate.js index d262580447..94e2a5ea98 100644 --- a/compute/reservations/createReservationInstanceTemplate.js +++ b/compute/reservations/createReservationInstanceTemplate.js @@ -87,15 +87,7 @@ async function main(reservationName, location, instanceTemplateName) { }); } - const createdReservation = ( - await reservationsClient.get({ - project: projectId, - zone, - reservation: reservationName, - }) - )[0]; - - console.log(JSON.stringify(createdReservation)); + console.log(`Reservation: ${reservationName} created.`); } await callCreateComputeReservationInstanceTemplate(); diff --git a/compute/reservations/createSharedReservation.js b/compute/reservations/createSharedReservation.js index 697a3b69c6..ec584e2e0f 100644 --- a/compute/reservations/createSharedReservation.js +++ b/compute/reservations/createSharedReservation.js @@ -88,15 +88,7 @@ async function main(reservationName, instanceTemplateName) { }); } - const createdReservation = ( - await reservationsClient.get({ - project: projectId, - zone, - reservation: reservationName, - }) - )[0]; - - console.log(createdReservation); + console.log(`Reservation: ${reservationName} created.`); } await callCreateComputeSharedReservation(); diff --git a/compute/reservations/deleteReservation.js b/compute/reservations/deleteReservation.js index 338e59b4f7..6c948a8019 100644 --- a/compute/reservations/deleteReservation.js +++ b/compute/reservations/deleteReservation.js @@ -50,6 +50,8 @@ async function main(reservationName) { zone: operation.zone.split('/').pop(), }); } + + console.log(`Reservation: ${reservationName} deleted.`); } await callDeleteReservation(); // [END compute_reservation_delete] diff --git a/compute/reservations/reservationVmsUpdate.js b/compute/reservations/reservationVmsUpdate.js index 4a294a5280..23a7387921 100644 --- a/compute/reservations/reservationVmsUpdate.js +++ b/compute/reservations/reservationVmsUpdate.js @@ -61,15 +61,7 @@ async function main(reservationName) { }); } - const updatedReservation = ( - await reservationsClient.get({ - project: projectId, - zone, - reservation: reservationName, - }) - )[0]; - - console.log(JSON.stringify(updatedReservation)); + console.log(`Reservation: ${reservationName} updated.`); } await callComputeReservationVmsUpdate(); diff --git a/compute/reservations/sharedReservationConsumerProjectsUpdate.js b/compute/reservations/sharedReservationConsumerProjectsUpdate.js index dcb9f00571..2a787b98c7 100644 --- a/compute/reservations/sharedReservationConsumerProjectsUpdate.js +++ b/compute/reservations/sharedReservationConsumerProjectsUpdate.js @@ -34,11 +34,11 @@ async function main(reservationName) { // The ID of the owner project, which is the project used to create the shared reservation. const projectId = await reservationsClient.getProjectId(); // The zone where the shared reservation is located. - const zone = 'us-central1-a'; + // const zone = 'us-central1-a'; // The name of an existing shared reservation. // const reservationName = 'reservation-01'; // The ID of project to share the reservation with. - const consumerId = 'newConsumerId'; + // const consumerId = 'newConsumerId'; async function callComputeSharedReservationConsumerProjectsUpdate() { // Update the reservation. @@ -46,24 +46,25 @@ async function main(reservationName) { project: projectId, reservation: reservationName, /** + * TODO(developer): Uncomment `paths, zone, reservationResource` variables before running the sample. * Define `paths` field for each consumer, that you want to allow/not allow to consume a shared resevation, e.g. * to allow 2 projects to consume a shared reservation, you need to specify 2 paths: * paths: 'shareSettings.projectMap.{consumerId1}', * paths: 'shareSettings.projectMap.{consumerId2}' * */ - paths: `shareSettings.projectMap.${consumerId}`, - zone, - reservationResource: { - name: reservationName, - // To stop allowing one or more projects to consume a shared reservation, comment shareSettings object. - shareSettings: { - projectMap: { - newConsumerId: { - projectId: `${consumerId}`, - }, - }, - }, - }, + // paths: `shareSettings.projectMap.${consumerId}`, + // zone, + // reservationResource: { + // name: reservationName, + // // To stop allowing one or more projects to consume a shared reservation, comment shareSettings object. + // shareSettings: { + // projectMap: { + // newConsumerId: { + // projectId: `${consumerId}`, + // }, + // }, + // }, + // }, }); let operation = response.latestResponse; @@ -77,15 +78,7 @@ async function main(reservationName) { }); } - const updatedReservation = ( - await reservationsClient.get({ - project: projectId, - zone, - reservation: reservationName, - }) - )[0]; - - console.log(updatedReservation); + console.log(`Reservation: ${reservationName} updated.`); } await callComputeSharedReservationConsumerProjectsUpdate(); diff --git a/compute/test/createComputeHyperdisk.test.js b/compute/test/createComputeHyperdisk.test.js index 63554a742e..dfcaa43e07 100644 --- a/compute/test/createComputeHyperdisk.test.js +++ b/compute/test/createComputeHyperdisk.test.js @@ -26,7 +26,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cwd = path.join(__dirname, '..'); describe('Create compute hyperdisk', async () => { - const diskName = `hyperdisk-name-941ad2d${Math.floor(Math.random() * 10 + 1)}`; + const diskName = `hyperdisk-name-941ad2d${Math.floor(Math.random() * 1000 + 1)}`; const zone = 'europe-central2-b'; const disksClient = new DisksClient(); let projectId; @@ -44,12 +44,13 @@ describe('Create compute hyperdisk', async () => { }); it('should create a new hyperdisk', () => { - const response = JSON.parse( - execSync(`node ./disks/createComputeHyperdisk.js ${diskName}`, { + const response = execSync( + `node ./disks/createComputeHyperdisk.js ${diskName}`, + { cwd, - }) + } ); - assert.equal(response.name, diskName); + assert.include(response, `Disk: ${diskName} created.`); }); }); diff --git a/compute/test/createComputeHyperdiskFromPool.test.js b/compute/test/createComputeHyperdiskFromPool.test.js index 08c3fe46a3..35dabcec43 100644 --- a/compute/test/createComputeHyperdiskFromPool.test.js +++ b/compute/test/createComputeHyperdiskFromPool.test.js @@ -66,9 +66,9 @@ async function cleanupResources(projectId, zone, diskName, storagePoolName) { } describe('Create compute hyperdisk from pool', async () => { - const diskName = `disk-from-pool-name-745d98${Math.floor(Math.random() * 10 + 1)}f`; + const diskName = `disk-from-pool-name-745d98${Math.floor(Math.random() * 1000 + 1)}f`; const zone = 'us-central1-a'; - const storagePoolName = `storage-pool-name-745d9${Math.floor(Math.random() * 10 + 1)}5f`; + const storagePoolName = `storage-pool-name-745d9${Math.floor(Math.random() * 1000 + 1)}5f`; const disksClient = new DisksClient(); let projectId; @@ -81,28 +81,24 @@ describe('Create compute hyperdisk from pool', async () => { }); it('should create a new storage pool', () => { - const response = JSON.parse( - execSync( - `node ./disks/createComputeHyperdiskPool.js ${storagePoolName}`, - { - cwd, - } - ) + const response = execSync( + `node ./disks/createComputeHyperdiskPool.js ${storagePoolName}`, + { + cwd, + } ); - assert.equal(response.name, storagePoolName); + assert.include(response, `Storage pool: ${storagePoolName} created.`); }); it('should create a new hyperdisk from pool', () => { - const response = JSON.parse( - execSync( - `node ./disks/createComputeHyperdiskFromPool.js ${diskName} ${storagePoolName}`, - { - cwd, - } - ) + const response = execSync( + `node ./disks/createComputeHyperdiskFromPool.js ${diskName} ${storagePoolName}`, + { + cwd, + } ); - assert.equal(response.name, diskName); + assert.include(response, `Disk: ${diskName} created.`); }); }); diff --git a/compute/test/createReservationGlobalInstanceTemplate.test.js b/compute/test/createReservationGlobalInstanceTemplate.test.js index 17d80f67c3..1f962ecfe4 100644 --- a/compute/test/createReservationGlobalInstanceTemplate.test.js +++ b/compute/test/createReservationGlobalInstanceTemplate.test.js @@ -17,7 +17,7 @@ 'use strict'; const path = require('path'); -const assert = require('node:assert/strict'); +const {assert} = require('chai'); const {after, before, describe, it} = require('mocha'); const cp = require('child_process'); const {ReservationsClient} = require('@google-cloud/compute').v1; @@ -26,8 +26,8 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cwd = path.join(__dirname, '..'); describe('Create compute reservation using global instance template', async () => { - const reservationName = `global-reservation-68ef06a${Math.floor(Math.random() * 10 + 1)}`; - const instanceTemplateName = `pernament-global-template-68ef06a${Math.floor(Math.random() * 10 + 1)}`; + const reservationName = `global-reservation-68ef06a${Math.floor(Math.random() * 1000 + 1)}`; + const instanceTemplateName = `pernament-global-template-68ef06a${Math.floor(Math.random() * 1000 + 1)}`; const location = 'global'; const reservationsClient = new ReservationsClient(); let projectId; @@ -58,15 +58,13 @@ describe('Create compute reservation using global instance template', async () = }); it('should create a new reservation', () => { - const response = JSON.parse( - execSync( - `node ./reservations/createReservationInstanceTemplate.js ${reservationName} ${location} ${instanceTemplateName}`, - { - cwd, - } - ) + const response = execSync( + `node ./reservations/createReservationInstanceTemplate.js ${reservationName} ${location} ${instanceTemplateName}`, + { + cwd, + } ); - assert.equal(response.name, reservationName); + assert.include(response, `Reservation: ${reservationName} created.`); }); }); diff --git a/compute/test/createReservationRegionalInstanceTemplate.test.js b/compute/test/createReservationRegionalInstanceTemplate.test.js index 6f9766dc47..b909e0fd7e 100644 --- a/compute/test/createReservationRegionalInstanceTemplate.test.js +++ b/compute/test/createReservationRegionalInstanceTemplate.test.js @@ -17,7 +17,7 @@ 'use strict'; const path = require('path'); -const assert = require('node:assert/strict'); +const {assert} = require('chai'); const {after, describe, it} = require('mocha'); const cp = require('child_process'); @@ -25,7 +25,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cwd = path.join(__dirname, '..'); describe('Create compute reservation using regional instance template', async () => { - const reservationName = `regional-reservation-04bf4ed${Math.floor(Math.random() * 10 + 1)}`; + const reservationName = `regional-reservation-04bf4ed${Math.floor(Math.random() * 1000 + 1)}`; const instanceTemplateName = 'pernament-region-template-name'; const location = 'regions/us-central1'; @@ -37,15 +37,13 @@ describe('Create compute reservation using regional instance template', async () }); it('should create a new reservation', () => { - const response = JSON.parse( - execSync( - `node ./reservations/createReservationInstanceTemplate.js ${reservationName} ${location} ${instanceTemplateName}`, - { - cwd, - } - ) + const response = execSync( + `node ./reservations/createReservationInstanceTemplate.js ${reservationName} ${location} ${instanceTemplateName}`, + { + cwd, + } ); - assert.equal(response.name, reservationName); + assert.include(response, `Reservation: ${reservationName} created.`); }); }); diff --git a/compute/test/reservations.test.js b/compute/test/reservations.test.js index 3cb1a430d9..846ad99364 100644 --- a/compute/test/reservations.test.js +++ b/compute/test/reservations.test.js @@ -17,7 +17,7 @@ 'use strict'; const path = require('path'); -const assert = require('node:assert/strict'); +const {assert} = require('chai'); const {describe, it} = require('mocha'); const cp = require('child_process'); const {ReservationsClient} = require('@google-cloud/compute').v1; @@ -26,27 +26,24 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cwd = path.join(__dirname, '..'); describe('Compute reservation', async () => { - const reservationName = `reservation-1a0bb69e-${Math.floor(Math.random() * 10 + 1)}ec`; + const reservationName = `reservation-1a0bb69e-${Math.floor(Math.random() * 1000 + 1)}ec`; const zone = 'us-central1-a'; const reservationsClient = new ReservationsClient(); let projectId; - let reservation; before(async () => { projectId = await reservationsClient.getProjectId(); }); it('should create a new reservation', () => { - reservation = JSON.parse( - execSync( - `node ./reservations/createReservationFromProperties.js ${reservationName}`, - { - cwd, - } - ) + const response = execSync( + `node ./reservations/createReservationFromProperties.js ${reservationName}`, + { + cwd, + } ); - assert.equal(reservation.name, reservationName); + assert.include(response, `Reservation: ${reservationName} created.`); }); it('should return reservation', () => { diff --git a/compute/test/sharedReservation.test.js b/compute/test/sharedReservation.test.js index 9292534a6f..5a97866364 100644 --- a/compute/test/sharedReservation.test.js +++ b/compute/test/sharedReservation.test.js @@ -16,35 +16,56 @@ 'use strict'; -const {after, describe, it} = require('mocha'); +const {before, after, describe, it} = require('mocha'); const path = require('path'); -const assert = require('node:assert/strict'); +const {assert} = require('chai'); const cp = require('child_process'); +const {ReservationsClient} = require('@google-cloud/compute').v1; const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const cwd = path.join(__dirname, '..'); describe('Compute shared reservation', async () => { - const reservationName = `shared-reservation-e2${Math.floor(Math.random() * 10 + 1)}f`; + const reservationName = `shared-reservation-e2${Math.floor(Math.random() * 1000 + 1)}f`; + const instanceTemplateName = `global-instance-template-e2${Math.floor(Math.random() * 1000 + 1)}f`; + const reservationsClient = new ReservationsClient(); + + let projectId; + + before(async () => { + projectId = await reservationsClient.getProjectId(); + // Create template + execSync( + `node ./create-instance-templates/createTemplate.js ${projectId} ${instanceTemplateName}`, + { + cwd, + } + ); + }); after(() => { // Delete reservation execSync(`node ./reservations/deleteReservation.js ${reservationName}`, { cwd, }); + // Delete template + execSync( + `node ./create-instance-templates/deleteInstanceTemplate.js ${projectId} ${instanceTemplateName}`, + { + cwd, + } + ); }); it('should create new shared reservation', async () => { - const response = JSON.parse( - execSync( - `node ./reservations/createSharedReservation.js ${reservationName}`, - { - cwd, - } - ) + const response = execSync( + `node ./reservations/createSharedReservation.js ${reservationName} ${instanceTemplateName}`, + { + cwd, + } ); - assert.equal(response.name, reservationName); + assert.include(response, `Reservation: ${reservationName} created.`); }); it('should update consumer projects in shared reservation', async () => { @@ -57,6 +78,6 @@ describe('Compute shared reservation', async () => { ) ); - assert.not.equal(response, null); + assert.include(response, `Reservation: ${reservationName} updated.`); }); });