google-cloud-java icon indicating copy to clipboard operation
google-cloud-java copied to clipboard

Fix network quota error in compute integration tests

Open tcoffee-google opened this issue 9 years ago • 30 comments

Remove GCE networks from gcloud-devel project.

https://www.google.com/url?q=https%3A%2F%2Ftravis-ci.org%2FGoogleCloudPlatform%2Fgoogle-cloud-java%2Fjobs%2F239819052&sa=D&sntz=1&usg=AFQjCNHHgq88UgaiKxAPxGs8u8rW4VBFcw

tcoffee-google avatar Jun 06 '17 16:06 tcoffee-google

There appear to be 9 networks from tests (10 total because of default).

gcloud compute networks list | wc -l
11

(subtract one for the header line)

I tried deleting a network:

gcloud compute networks delete xxxxxxx

But it says the network is already being used by a firewall. I tried deleting the firewall:

gcloud compute firewall-rules delete xxxxxxx

This succeeded, but when I went back to delete the network again, it said there was another firewall using it. I did a listing of firewall rules, and there were 79 (after I deleted two):

gcloud compute firewall-rules list | cut -f 1 -d ' ' | grep '^test-'  | wc -l
79

I think there must be an issue in our test cleanup code for compute integration tests where networks aren't getting cleaned up always because of existing firewall rules blocking the deletion of networks.

cc @neozwu

garrettjonesgoogle avatar Jun 08 '17 15:06 garrettjonesgoogle

@neozwu manually cleared out networks from the console.

When rerunning integration tests, one of the runs failed with a compute error. I checked the networks in the console, and 1 new network was left around with 9 firewall rules.

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.google.cloud.compute.it.ITComputeTest
Tests run: 58, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 663.527 sec <<< FAILURE! - in com.google.cloud.compute.it.ITComputeTest
testCreateNetworkAndSubnetwork(com.google.cloud.compute.it.ITComputeTest)  Time elapsed: 51.609 sec  <<< FAILURE!
java.lang.AssertionError: expected null, but was:<Network{generatedId=1683690868081708972, creationTimestamp=1496969539480, networkId=NetworkId{project=gcloud-devel, network=test-0e9d60110b4c494db45809d9-create-subnetwork-network}, description=null, configuration=SubnetNetworkConfiguration{type=SUBNET, autoCreateSubnetworks=false, subnetworks=null}}>
	at com.google.cloud.compute.it.ITComputeTest.testCreateNetworkAndSubnetwork(ITComputeTest.java:1511)
Results :
Failed tests: 
  ITComputeTest.testCreateNetworkAndSubnetwork:1511 expected null, but was:<Network{generatedId=1683690868081708972, creationTimestamp=1496969539480, networkId=NetworkId{project=gcloud-devel, network=test-0e9d60110b4c494db45809d9-create-subnetwork-network}, description=null, configuration=SubnetNetworkConfiguration{type=SUBNET, autoCreateSubnetworks=false, subnetworks=null}}>

garrettjonesgoogle avatar Jun 09 '17 01:06 garrettjonesgoogle

It seems we are having more zombie networks and firewall rules piling up again

neozwu avatar Jun 16 '17 22:06 neozwu

Still investigating this one ...

tcoffee-google avatar Jun 16 '17 22:06 tcoffee-google

This keeps gumming up our integration tests. We should either fix the problem or nuke the tests.

garrettjonesgoogle avatar Jul 17 '17 21:07 garrettjonesgoogle

It appears to me that these networks are being generated by tests for Node.js: https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/packages/compute/system-test/compute.js

The Compute tests in Node.js use a non-standard setup to minimize resource creation, which removes previously-created objects after all tests have finished running. The idea appears to be that, even if a test run fails, the beginning of a subsequent test run will remove objects left behind. It appears that firewalls should be deleted before networks, but there doesn't seem to be any verification that the deletions are successful.

There's a consistent pattern that each network left behind has 9 associated firewall rules of the same configuration. It's not clear to me how these rules are created.

@lukesneeringer @stephenplusplus can you investigate?

tcoffee-google avatar Jul 18 '17 21:07 tcoffee-google

@tcoffee-google thanks for the initial investigation. The networks created by our system tests are done through the project "gcloud-node-regression-tests (ID: long-door-651)"-- how are resources from that project showing up for the Java project?

stephenplusplus avatar Jul 18 '17 21:07 stephenplusplus

In the Node before/after hooks, we delete all resources. One of those functions that executes is:

  function deleteAllGcloudTestObjects(callback) {
    async.eachSeries([
      'getVMs',
      'getAddresses',
      'getAutoscalers',
      'getDisks',
      'getInstanceGroups',
      'getFirewalls',
      'getSubnetworks',
      'getHealthChecks',
      'getNetworks',
      'getRules',
      'getSnapshots',
    ], callAndDeleteGcloudTestObject, callback);
  }

These fire in order, so firewalls are deleted before networks. If a deletion of any of these resource types fails, the system tests will exit with an error (https://github.com/GoogleCloudPlatform/google-cloud-node/blob/425701b9f67885763f22f1547955fbd83a754bcf/packages/compute/system-test/compute.js#L1415):

  function callAndDeleteGcloudTestObject(methodName, callback) {
    compute[methodName]({
      filter: 'name eq ' + TESTS_PREFIX + '.*'
    }, function(err, objects) {
      if (err) {
        callback(err);
        return;
      }

      async.each(objects, function(object, callback) {
        object.delete(compute.execAfterOperation_(callback));
      }, callback);
    });
  }

callAndDeleteGcloudTestObject first gets a list of resources that match our naming convention. The resources we create are always named gcloud-tests-{resource_type}-{uuid}. After getting them, it deletes them-- if the delete fails, the callback is executed with an error, and the system tests process would exit with it.

Looking at all of the places we call a delete method, they all wait for the operation returned to complete, erroring out if it wasn't successful.

Here is what the list of Firewalls for the gcloud-node-regression-tests project looks like in the Console UI (https://console.cloud.google.com/networking/firewalls/list):

image

The default- prefix leads me to believe these aren't being created by any of our tests, and they exist by default for the "default network": https://console.cloud.google.com/networking/networks/details/default -- I don't believe we created that and it doesn't appear we have a way to delete them.

Everything appears to be "clean" for the gcloud-node-regression-tests project, but let me know if I'm not looking in the right place, or missed an important clue from the research you've already done.

stephenplusplus avatar Jul 18 '17 22:07 stephenplusplus

I'm fairly sure that the orphaned networks in the gapic-test project are coming from these tests, since the particular naming pattern appears to result from the (presumably unintended) behavior of https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/packages/compute/system-test/compute.js#L1378 , which I don't see occurring anywhere else. These show up at bottom in the list below: networks

It looks like https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/system-test/env.js reads a project ID from local environment variables --- is it plausible that someone is running the integration tests with local variables set to the gapic-test project?

tcoffee-google avatar Jul 19 '17 03:07 tcoffee-google

It's definitely possible, and apparently the case, since I agree that those networks must have come from our tests.

As far as who ran them: @lukesneeringer any ideas? It's not from myself, Dave (@callmehiphop), or the system tests (AppVeyor and Circle). We don't have access to the gapic-test project.

As far as how it happened: if the tester aborted the process in the middle of the test run, the after hook wouldn't have run to clean them up. And if they didn't run the tests again, the before hook wouldn't have run.

As far as what now: Manually clear them (sorry), try to track down the user running them, and ask that they use another project that won't interfere with other users. If we can't identify the user, the only thing to help would be something like a Travis nightly build that deletes the gcloud-tests-network-* resources. Hopefully it won't get to that point.

stephenplusplus avatar Jul 19 '17 17:07 stephenplusplus

Since it sounds like there's not a legitimate use case for running these tests on the gapic-test project, I've modified our integration test setup to remove them, which I expect will avoid the recurring problem. If someone is running the Node.js integration tests on gapic-test while our CI build begins, this could cause their tests to fail, but that seems preferable to the present issue. Conversely, this issue could also recur if these tests run many times on gapic-test during our CI build, but this seems very unlikely.

tcoffee-google avatar Jul 19 '17 20:07 tcoffee-google

If you search the logging using the network-id, it should be able to tell you the service account that creates the network - that might be useful information.

neozwu avatar Jul 19 '17 20:07 neozwu

The networks I just removed must be old enough that they no longer show up in the logs.

tcoffee-google avatar Jul 19 '17 21:07 tcoffee-google

Still seeing some similar errors despite apparent non-existence of orphaned networks: https://travis-ci.org/GoogleCloudPlatform/google-cloud-java/jobs/255764601

Also need to install gcloud on Travis for this script to work properly.

tcoffee-google avatar Jul 21 '17 23:07 tcoffee-google

Installing gcloud seems like really high overhead when we are just using it to call cloud services... and that's what our client library is for, calling cloud services.

garrettjonesgoogle avatar Jul 24 '17 15:07 garrettjonesgoogle

I was concerned about using our library to set up tests for itself, and it seems fairly simple to install gcloud for the Travis build. Do you think we should clean up the networks internally as part of the integration tests?

tcoffee-google avatar Jul 24 '17 18:07 tcoffee-google

Ok - is it known how long the installation takes (since it will add that time onto every integration test run in Travis)?

garrettjonesgoogle avatar Jul 24 '17 19:07 garrettjonesgoogle

It takes ~10 sec on my local machine. The installation portion may be slower on Travis, but I'd imagine well under a minute.

tcoffee-google avatar Jul 24 '17 19:07 tcoffee-google

Alrighty, that should be fine I think.

garrettjonesgoogle avatar Jul 24 '17 19:07 garrettjonesgoogle

Would it be possible to 'curl' a http request to delete the networks ?

neozwu avatar Jul 24 '17 19:07 neozwu