Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vpnaas: Create VPN service #760

Merged
merged 23 commits into from
Feb 18, 2018
Merged

Conversation

@simonre simonre changed the title Vpnaas: Create VPN service [wip]Vpnaas: Create VPN service Feb 13, 2018
@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 13, 2018

Build succeeded.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 73.362% when pulling fe9da82 on simonre:vpnaas-service-create into 6da026c on gophercloud:master.

@coveralls
Copy link

coveralls commented Feb 14, 2018

Coverage Status

Coverage increased (+0.003%) to 73.362% when pulling 2dc358c on simonre:vpnaas-service-create into 6da026c on gophercloud:master.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 14, 2018

Build succeeded.

@simonre
Copy link
Contributor Author

simonre commented Feb 14, 2018

@jtopjian This is ready for review

@simonre simonre changed the title [wip]Vpnaas: Create VPN service Vpnaas: Create VPN service Feb 14, 2018
Copy link
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

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

@simonre Thank you for working on this. This is a really good start.

In general, everything looks good. I've left some comments for some minor changes.

This PR will need two additional items before it can be merged:

  1. A doc.go file similar to this.
  2. An acceptance test. Documentation for acceptance tests can be found here. You can use the existing networking tests as an example.

Please let me know if you have any questions or need any help.

}

// CreateOpts contains all the values needed to create a new VPN service
type CreateOpts struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

doc nit: all fields should have a descriptive comment even if it's something simple like:

Name is the human-readable name of the VPN Service.

RouterID string `json:"router_id" required:"true"`
Description string `json:"description,omitempty"`
AdminStateUp *bool `json:"admin_state_up"`
ProjectID string `json:"project_id"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see project_id defined anywhere here, so maybe it's an internal neutron field? What happens if TenantID and ProjectID are different UUIDs?

// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToVPNServiceCreateMap() (map[string]interface{}, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be ToServiceCreateMap.

}

// ToVPNServiceCreateMap casts a CreateOpts struct to a map.
func (opts CreateOpts) ToVPNServiceCreateMap() (map[string]interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ToServiceCreateMap

)

// Service is a VPN Service
type Service struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

doc nit: these fields should have comments to describe what they are.

// Service is a VPN Service
type Service struct {
TenantID string `json:"tenant_id"`
SubnetID string `json:"subnet_id,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

omitempty isn't valid for results. it can safely be removed.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 15, 2018

Build failed.

@jtopjian
Copy link
Contributor

@simonre Thank you for the updates. Travis is failing due to some gofmt issues. These can be fixed by manually running gofmt on the changed files or configuring your IDE/editor to run gofmt upon save.

The OpenLab failures were a temporary issue with the CI system. I wouldn't worry about those.

@jtopjian
Copy link
Contributor

@simonre Thank you again for the updates.

This looks good to me. Unfortunately I can't test this myself since I don't have access to VPNaaS, but from reviewing the Neutron code, this looks correct. In addition, the acceptance test looks correct, too.

Can you verify that this code works? Meaning: have you tested it yourself to create an actual VPN service? If it works for you, I'll go ahead and merge this.

The inline comments/docs could use some formatting, but I don't consider doc updates to be blocking unless there are other changes required. If you plan on continuing to work on the other parts of the VPNaaS, then maybe fix them there. You can use this file for reference (or really any of the requests.go and results.go files). Note the formatting of the comments for the fields, particularly the space between // and the comment as well as a new line to separate the fields.

The reason we want to make sure formatting is correct is because the inline comments turn into the official godoc reference documentation.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 16, 2018

Build succeeded.

@simonre
Copy link
Contributor Author

simonre commented Feb 16, 2018

@jtopjian Thanks for the quick feedback. I just updated the doc.go sample code to code that I can verify worked for me to create an actual VPN service. I also updated the inline formatting in requests.go, is that what you had in mind? If yes, I'll keep that in mind for the rest of the code and I'll update the other files as well!

@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 16, 2018

Build succeeded.

@jtopjian
Copy link
Contributor

@simonre

I also updated the inline formatting in requests.go, is that what you had in mind?

Yep - That's exactly what I had in mind. Though the same format should be applied to the Service result struct, too. Let me know if you want to fix that now or in another PR.

I can verify worked for me to create an actual VPN service

Perfect - thank you 😄

@simonre
Copy link
Contributor Author

simonre commented Feb 16, 2018

I'll fix it now. Just wanted to make sure I'm actually doing the right thing before doing it for all files.

@jtopjian
Copy link
Contributor

@simonre I apologize - I missed one thing in the unit tests:

There should be a comparison to the struct that is returned from the Create / Extract call:

expected := services.Service{
  RouterID: "66e3b16c-8ce5-40fb-bb49-ab6d8dc3f2aa",
  ...
}

actual, err := services.Create(fake.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, expected, actual)

This same pattern will need to be in the other unit tests (where applicable), so best to get in the habit now :)

@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 16, 2018

Build succeeded.

@simonre
Copy link
Contributor Author

simonre commented Feb 16, 2018

@jtopjian
th.AssertDeepEquals(t, expected, actual)
doesn't seem to work because of the pointer to AdminStateUp. I added individual comparisons like the ones here instead which should do the same.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 16, 2018

Build succeeded.

@jtopjian
Copy link
Contributor

@simonre We definitely want to ensure a struct can be compared successfully, and not just individual fields.

Using "networks" as an example, the AdminStateUp field for the result struct is bool rather than *bool:

https://github.com/gophercloud/gophercloud/blob/master/openstack/networking/v2/networks/results.go#L57

However, the CreateOpts AdminStateUp should probably remain *bool as this is the standard used for the networking services. For example:

https://github.com/gophercloud/gophercloud/blob/master/openstack/networking/v2/networks/requests.go#L69

Unless there's a good reason to keep the result field as *bool, let's change it to bool. The only reason I can think of using *bool is if there are three distinct states for AdminStateUp (true/false/nil). Given the prevalence of AdminStateUp already in Gophercloud, I can't see VPNaaS doing something different.

…rison. Also changed AdminStateUp type from *bool to bool
@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 17, 2018

Build succeeded.

@simonre
Copy link
Contributor Author

simonre commented Feb 17, 2018

@jtopjian You're right. I changed it again. I also did the same in the ipsecpolicy branch.

@jtopjian
Copy link
Contributor

@simonre This looks good to me. Thank you very much for your help and patience.

@jtopjian jtopjian merged commit b922c6e into gophercloud:master Feb 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants