discoverspaces: Get subnets when provider doesn't support space discovery #7067

Merged
merged 8 commits into from Mar 14, 2017

Conversation

Projects
None yet
4 participants
Member

babbageclunk commented Mar 3, 2017

Description of change

At the moment we only get subnets from the provider if it supports space discovery, but it would be useful to have them for providers that support networking (even if we don't have them tagged with a space). That will allow us to use them to set up ingress rules when a cross-model relation is created.

Change the discover spaces worker to collect subnets (with no associated spaces) if the provider doesn't support space discovery. Also change the AddSubnets API call to allow subnets without a space, and change the ListSubnets API method and command to handle empty space.

Rewrite the worker tests to not use JujuConnSuite.

QA steps

  • Bootstrap on AWS.
  • Run juju subnets to verify that subnets have been imported in by the discoverspaces worker - they'll come back with a blank space tag.
Member

babbageclunk commented Mar 3, 2017

!!build!!

Not 100% on the non-transactional nature of the discovery but it seems that's an existing issue

@@ -55,7 +55,7 @@ func NewAddSubnetsCache(api NetworkBacking) *addSubnetsCache {
// up in the cache (or populates the cache if empty).
func (cache *addSubnetsCache) validateSpace(spaceTag string) (*names.SpaceTag, error) {
if spaceTag == "" {
- return nil, errors.Errorf("SpaceTag is required")
+ return nil, nil
@wallyworld

wallyworld Mar 3, 2017

Owner

Would be great if "" were a valid space name.
That would require a change to the names.v2 package though. But it would avoid all the special case code in this PR.

@babbageclunk

babbageclunk Mar 3, 2017

Member

I'll put a TODO in for this. Maybe linked to a bug?

worker/discoverspaces/discoverspaces.go
if err != nil {
return errors.Trace(err)
}
- stateSubnets, err := facade.ListSubnets(params.SubnetsFilters{})
+ var addSubnetsArgs params.AddSubnetsParams
+ collectMissingSubnets(&addSubnetsArgs, "", stateSubnetIds, subnets)
@wallyworld

wallyworld Mar 3, 2017

Owner

This logic really needs to be server side - it is not transactional as is.
But it seems the existing code suffers from the same problem.....

worker/discoverspaces/discoverspaces.go
@@ -297,3 +296,44 @@ func (dw *discoverspacesWorker) addSubnetsFromArgs(addSubnetsArgs params.AddSubn
return nil
}
+
+func (dw *discoverspacesWorker) getStateSubnets() (set.Strings, error) {
@wallyworld

wallyworld Mar 3, 2017

Owner

can we call this getModelSubnets()
let's not leak the state.State abstraction

worker/discoverspaces/worker_test.go
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
- "gopkg.in/juju/names.v2"
+ //"gopkg.in/juju/names.v2"
- cf.addSubnetsCallback()
- }
- return cf.API.AddSubnets(args)
+ coretesting.BaseSuite
Owner

jameinel commented Mar 3, 2017

Owner

jameinel commented Mar 3, 2017

babbageclunk added some commits Mar 1, 2017

Refactor discoverspaces worker
Rearrange to add a path where we just get subnets when space discovery
isn't supported by the provider. Extract code to get existing
subnets and collect subnets that need to be added into functions that
can be reused from the subnet discovery.
Get subnets when there's no space discovery available
If the provider doesn't support space discovery, we still add
subnets (with no space tag). This enables setting up ingress rules for
cross-model relations.
Rewrite discoverspaces tests without JujuConnSuite
It was getting very tricky to add new tests for other cases using the
full API and dummy provider. Rework the tests to use a fake API facade
and fake provider that we can inject data and errors into more easily.
Member

babbageclunk commented Mar 12, 2017

!!build!!

babbageclunk added some commits Mar 3, 2017

Handle blank space tag in ListSubnets
Subnets obtained from providers with no space discovery will have blank
space tags - the API and client need to handle that.
Send CIDR and VLAN tag in AddSubnets request
This will enable simplifying the discover spaces API. At the moment the
API requests these from the provider itself. It has a lot of extra
complexity for cross-checking the sent subnet information with the details
queried from the provider. This makes sense for the API underpinning
the `juju add-subnet` command, where we want the user to provide either
the provider id or the CIDR, and need to fill in the other fields. But
it's very confusing to make the discover spaces worker go through the
same path, when it has all the necessary info from the provider already.
Implement DiscoverSpaces.AddSubnets API method
Implemented the method standalone rather than using
networkingcommon.AddSubnets. That has far more cleverness than is needed
for this case and it overcomplicated how this worker behaves in tests.
Member

babbageclunk commented Mar 14, 2017

!!build!!

Member

babbageclunk commented Mar 14, 2017

$$merge$$

Contributor

jujubot commented Mar 14, 2017

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit 7c2469e into juju:develop Mar 14, 2017

@babbageclunk babbageclunk deleted the babbageclunk:discover-subnets-tests branch Mar 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment