diff --git a/compute/disks/createComputeHyperdiskFromPool.js b/compute/disks/createComputeHyperdiskFromPool.js index 47fdbbb964d..342d854bad2 100644 --- a/compute/disks/createComputeHyperdiskFromPool.js +++ b/compute/disks/createComputeHyperdiskFromPool.js @@ -37,7 +37,7 @@ async function main() { // The name of the new disk const diskName = 'disk-name'; // The name of the storage pool - const storagePoolName = 'storage-pool-hyperdisk'; + const storagePoolName = 'storage-pool-name'; // Link to the storagePool you want to use. Use format: // https://www.googleapis.com/compute/v1/projects/{projectId}/zones/{zone}/storagePools/{storagePoolName} const storagePool = `https://www.googleapis.com/compute/v1/projects/${projectId}/zones/${zone}/storagePools/${storagePoolName}`; diff --git a/compute/test/createComputeHyperdiskFromPool.test.js b/compute/test/createComputeHyperdiskFromPool.test.js index 46a36f7652c..3cbc7a15e35 100644 --- a/compute/test/createComputeHyperdiskFromPool.test.js +++ b/compute/test/createComputeHyperdiskFromPool.test.js @@ -20,7 +20,10 @@ const path = require('path'); const {assert} = require('chai'); const {describe, it} = require('mocha'); const cp = require('child_process'); -const {StoragePoolsClient} = require('@google-cloud/compute'); +const { + StoragePoolsClient, + ZoneOperationsClient, +} = require('@google-cloud/compute'); const {DisksClient} = require('@google-cloud/compute').v1; const {createStoragePool, deleteStoragePool, deleteDisk} = require('./util'); @@ -30,29 +33,39 @@ const cwd = path.join(__dirname, '..'); describe('Create compute hyperdisk from pool', async () => { const diskName = 'disk-name'; const zone = 'europe-central2-b'; - const storagePoolName = 'storage-pool-hyperdisk'; + const storagePoolName = 'storage-pool-name'; const disksClient = new DisksClient(); const storagePoolsClient = new StoragePoolsClient(); + const zoneOperationsClient = new ZoneOperationsClient(); + let projectId; before(async () => { projectId = await disksClient.getProjectId(); - await createStoragePool( - storagePoolsClient, - projectId, - zone, - storagePoolName - ); + // await createStoragePool( + // storagePoolsClient, + // zoneOperationsClient, + // projectId, + // zone, + // storagePoolName + // ); }); after(async () => { - await deleteDisk(disksClient, projectId, zone, diskName); - await deleteStoragePool( - storagePoolsClient, + await deleteDisk( + disksClient, + zoneOperationsClient, projectId, zone, - storagePoolName + diskName ); + // await deleteStoragePool( + // storagePoolsClient, + // zoneOperationsClient, + // projectId, + // zone, + // storagePoolName + // ); }); it('should create a new hyperdisk from pool', () => { diff --git a/compute/test/util.js b/compute/test/util.js index b8416f80cf9..1b521cb57b5 100644 --- a/compute/test/util.js +++ b/compute/test/util.js @@ -82,13 +82,29 @@ async function deleteInstance(zone, instanceName) { } } -async function deleteDisk(disksClient, projectId, zone, diskName) { +async function deleteDisk( + disksClient, + zoneOperationsClient, + projectId, + zone, + diskName +) { try { - await disksClient.delete({ + const [response] = await disksClient.delete({ project: projectId, disk: diskName, zone, }); + let operation = response.latestResponse; + + // Wait for the delete operation to complete. + while (operation.status !== 'DONE') { + [operation] = await zoneOperationsClient.wait({ + operation: operation.name, + project: projectId, + zone: operation.zone.split('/').pop(), + }); + } } catch (err) { console.error('Deleting job failed: ', err); throw new Error(err); @@ -97,12 +113,13 @@ async function deleteDisk(disksClient, projectId, zone, diskName) { async function createStoragePool( storagePoolsClient, + zoneOperationsClient, projectId, zone, storagePoolName ) { try { - await storagePoolsClient.insert({ + const [response] = await storagePoolsClient.insert({ project: projectId, storagePoolResource: { name: storagePoolName, @@ -115,6 +132,16 @@ async function createStoragePool( }, zone, }); + let operation = response.latestResponse; + + // Wait for the delete operation to complete. + while (operation.status !== 'DONE') { + [operation] = await zoneOperationsClient.wait({ + operation: operation.name, + project: projectId, + zone: operation.zone.split('/').pop(), + }); + } } catch (err) { console.error('Creating storage pool failed: ', err); throw new Error(err); @@ -123,16 +150,27 @@ async function createStoragePool( async function deleteStoragePool( storagePoolsClient, + zoneOperationsClient, projectId, zone, storagePoolName ) { try { - await storagePoolsClient.delete({ + const [response] = await storagePoolsClient.delete({ project: projectId, storagePool: storagePoolName, zone, }); + let operation = response.latestResponse; + + // Wait for the delete operation to complete. + while (operation.status !== 'DONE') { + [operation] = await zoneOperationsClient.wait({ + operation: operation.name, + project: projectId, + zone: operation.zone.split('/').pop(), + }); + } } catch (err) { console.error('Deleting storage pool failed: ', err); throw new Error(err);