Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

build: refactor external rule tests #522

Merged
merged 12 commits into from
Dec 22, 2020
Merged

Conversation

sofisl
Copy link
Contributor

@sofisl sofisl commented Nov 23, 2020

Fixes #520

This test is currently failing because we are attempting to create an external forwarding rule, which I believe gce enforcer is blocking. So, I've tried refactoring the code so that we create an internal forwarding rule and test that.

I tried many different ways of setting up this rule, including following the how-to guides here. I could not get them to work. The only way I was successful was by using the CLI, even after trying to convert the CLI commands into REST API.

I know this is not the ideal solution, but I've got nothing better. Would love to get a second pair of eyes on this if possible.

@sofisl sofisl requested a review from a team as a code owner November 23, 2020 07:46
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 23, 2020
@product-auto-label product-auto-label bot added the api: compute Issues related to the googleapis/nodejs-compute API. label Nov 23, 2020
@bcoe bcoe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 23, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 23, 2020
@sofisl sofisl mentioned this pull request Nov 23, 2020
@sofisl sofisl changed the title build: refactor external rule tests [DRAFT] build: refactor external rule tests Nov 23, 2020
Copy link
Contributor

@stephenplusplus stephenplusplus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through and found our API's comparable methods to the SDK calls.

system-test/compute.js Outdated Show resolved Hide resolved
after(async () => {
const [firewalls] = await compute.getFirewalls();
const firewallsToDelete = firewalls
.filter(x => x.name.includes('network-name'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.filter(x => x.name.includes('network-name'))
.filter(x => x.name.startsWith(TESTS_PREFIX))

.filter(x => x.name.includes('network-name'))
.map(y => y.name);
for (const firewall of firewallsToDelete) {
await deleteFirewallRule(firewall);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the method firewall.delete() work? (You'd have to remove the .map(y => y.name) part above)

Comment on lines 702 to 704
execSync(
`gcloud compute networks create ${NETWORK_NAME} --subnet-mode=custom`
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
execSync(
`gcloud compute networks create ${NETWORK_NAME} --subnet-mode=custom`
);
const [network, operation] = await compute.createNetwork(NETWORK_NAME, {autoCreateSubnetworks: false});
await operation.promise();

^ I'm not sure that's equivalent. Just a guess from the docs: 'When set to true, the VPC network is created in auto mode. When set to false, the VPC network is created in custom mode.'

Comment on lines 705 to 707
execSync(
`gcloud compute networks subnets create ${SUBNETWORK_NAME} --network=${NETWORK_NAME} --range=10.0.1.0/24 --region=us-central1`
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
execSync(
`gcloud compute networks subnets create ${SUBNETWORK_NAME} --network=${NETWORK_NAME} --range=10.0.1.0/24 --region=us-central1`
);
const [subnetwork, operation] = await network.createSubnetwork(SUBNETWORK_NAME, {
region: 'us-central1',
range: '10.0.1.0/24'
});
await operation.promise();

Comment on lines 708 to 710
execSync(
`gcloud compute backend-services create ${BACKEND_SERVICE_NAME} --load-balancing-scheme=INTERNAL --region=us-central1`
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
execSync(
`gcloud compute backend-services create ${BACKEND_SERVICE_NAME} --load-balancing-scheme=INTERNAL --region=us-central1`
);
await computeRequest({
method: 'POST',
uri: '/regions/us-central1/backendServices',
json: {
name: BACKEND_SERVICE_NAME,
loadBalancingScheme: 'INTERNAL',
},
});

Comment on lines 711 to 713
execSync(
`gcloud compute forwarding-rules create ${RULE_NAME} --load-balancing-scheme=INTERNAL --backend-service=${BACKEND_SERVICE_NAME} --subnet=${SUBNETWORK_NAME} --network=${NETWORK_NAME} --region=us-central1 --ports=80-82`
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
execSync(
`gcloud compute forwarding-rules create ${RULE_NAME} --load-balancing-scheme=INTERNAL --backend-service=${BACKEND_SERVICE_NAME} --subnet=${SUBNETWORK_NAME} --network=${NETWORK_NAME} --region=us-central1 --ports=80-82`
);
const region = compute.region('us-central1');
const [rule, operation] = region.createRule(RULE_NAME, {
loadBalancingScheme: 'INTERNAL',
backendService: BACKEND_SERVICE_NAME,
subnetwork: SUBNETWORK_NAME,
network: NETWORK_NAME,
ports: ['80', '81', '82'],
});
await operation.promise();

}
await deleteForwardingRules(RULE_NAME);
await deleteBackendService(BACKEND_SERVICE_NAME);
await deleteSubnetworks(SUBNETWORK_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await deleteSubnetworks(SUBNETWORK_NAME);
const [operation] = await subnetwork.delete();
await operation.promise();

for (const firewall of firewallsToDelete) {
await deleteFirewallRule(firewall);
}
await deleteForwardingRules(RULE_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await deleteForwardingRules(RULE_NAME);
const [operation] = await rule.delete();
await operation.promise():

@codecov
Copy link

codecov bot commented Nov 24, 2020

Codecov Report

Merging #522 (566361e) into master (6e7def6) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #522   +/-   ##
=======================================
  Coverage   99.61%   99.61%           
=======================================
  Files          22       22           
  Lines       11949    11949           
=======================================
  Hits        11903    11903           
  Misses         46       46           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6e7def6...566361e. Read the comment docs.

@sofisl
Copy link
Contributor Author

sofisl commented Nov 24, 2020

@stephenplusplus, I keep getting this error when changing the methods to using the API, which I was getting before I just decided to use the CLI 🙂

Invalid value for field 'resource.subnetwork': 'gcloud-1158ae29-subnetwork-ab80d4bb'. The URL is malformed.

When I try to add the full URI (projects/projectId etc), I get this error:

Error: Invalid value for field 'resource.name': 'projects/long-door-651/regions/us-central1/subnetworks/gcloud-04490660-subnetwork-3a74b658'. Must be a match of regex '(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)'

Do you know how the name should actually be formed?

@stephenplusplus
Copy link
Contributor

@sofisl I ran into similar issues, but I think I was able to get the formatting correct. Here's a diff of what I tried: https://gist.github.com/stephenplusplus/87b66993a0627e114dc296bf6ea132f5

@sofisl sofisl added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 5, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 5, 2020
@sofisl sofisl changed the title [DRAFT] build: refactor external rule tests build: refactor external rule tests Dec 12, 2020
@sofisl sofisl requested a review from bcoe December 12, 2020 09:06
Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 contingent on dropping the gaxios dependency.

package.json Outdated
@@ -57,6 +57,7 @@
"c8": "^7.0.0",
"codecov": "^3.0.2",
"concat-stream": "^2.0.0",
"gaxios": "^4.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop this.

@sofisl sofisl added the automerge: exact Summon MOG for automerging, but approvals need to be against the latest commit label Dec 21, 2020
@gcf-merge-on-green
Copy link
Contributor

Merge-on-green attempted to merge your PR for 6 hours, but it was not mergeable because either one of your required status checks failed, one of your required reviews was not approved, or there is a do not merge label. Learn more about your required status checks here: https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks. You can remove and reapply the label to re-run the bot.

@gcf-merge-on-green gcf-merge-on-green bot removed the automerge: exact Summon MOG for automerging, but approvals need to be against the latest commit label Dec 22, 2020
@sofisl sofisl merged commit 06d0297 into master Dec 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: compute Issues related to the googleapis/nodejs-compute API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compute rules: "before all" hook for "should get a list of rules" failed
4 participants