Implement Ping for vsphere #6778

Merged
merged 1 commit into from Jan 24, 2017

Conversation

Projects
None yet
5 participants
Contributor

natefinch commented Jan 6, 2017

This change updates the stub Ping method to actually attempt
a connection and login to VSphere in order to be more
likely to discover when the user has typoed the endpoint.

QA:

  1. Build juju client
  2. connect to canonical VPN
  3. scp juju to oil-vsphere
  4. run juju add-cloud and add a vsphere cloud with IP 10.245.0.134
  5. it should work.
  6. Try it with a bad ip or ip of non-vsphere machine, should fail.

Please address the comments then LGTM

provider/vsphere/provider.go
+ if err != nil {
+ return errors.New("Invalid endpoint format, please give a full url or IP/hostname.")
+ }
+ } else {
@perrito666

perrito666 Jan 6, 2017

Contributor

if we are going to be forgiving then check also that there is no other protocol passed before just prepending one.

@natefinch

natefinch Jan 6, 2017

Contributor

Is there a valid url we'll be rejecting or an invalid url we'll be accepting?

provider/vsphere/provider.go
+ }
+ // There's no way to get at any type information in the returned error, so
+ // we have to just look at the string value.
+ if err.Error() == "ServerFaultCode: Cannot complete login due to an incorrect user name or password." {
@perrito666

perrito666 Jan 6, 2017

Contributor

Make that string into a const somewhere, we cant ensure we will not need various strings as vsphere evolves and only one string in an if is coming back to bite us.

Contributor

natefinch commented Jan 10, 2017

!!build!!

I had a couple surprises but overall I think LGTM with some tweaks to asserts, etc.

+ // try to be smart and not punish people for adding or forgetting http
+ u, err := url.Parse(endpoint)
+ if err != nil {
+ return errors.New("Invalid endpoint format, please give a full url or IP/hostname.")
@jameinel

jameinel Jan 10, 2017

Owner

URL.Parse works if you pass just a hostname? That seems surprising.

@reedobrien

reedobrien Jan 11, 2017

Contributor

Yes, but it interprets the string as the URL path.

"Parse parses rawurl into a URL structure. The rawurl may be relative or absolute."

@natefinch

natefinch Jan 13, 2017

Contributor

Yep. which is why I then check the scheme, and if it's empty, then I know that they likely just used a hostname, so I prepend https:// and append /sdk

provider/vsphere/provider.go
+ defer logout()
+ err = client.Login(context.TODO(), nil)
+ if err == nil {
+ // shouldn't happen, but can't really complain if it does.
@jameinel

jameinel Jan 10, 2017

Owner

It shouldn't happen that we succeed in logging in? Can you spell out something more concrete like "we logged in without credentials successfully, which is surprising but ..."
I wonder if it would actually be a failure as it could be you succeeded an HTTP request to a static page.
Is the login process more of a conversation?

@natefinch

natefinch Jan 13, 2017

Contributor

The login process is a SOAP conversation. I think it would be quite remarkable if you happened to connect to a machine that responded in the correct way to make us think we're logging into vsphere.

But yes, I can make the explanation more clear.

+ }
+ // There's no way to get at any type information in the returned error, so
+ // we have to just look at the string value.
+ if err.Error() == failedLoginMsg {
@jameinel

jameinel Jan 10, 2017

Owner

I'm worried this is very brittle to vSphere version or library version, etc

@natefinch

natefinch Jan 10, 2017

Contributor

I agree, but there's no type information exposed... the error is an unexported type. Suggestions welcome.

provider/vsphere/provider.go
+ // creds, so return nil.
+ return nil
+ }
+ return errors.Errorf("No VSphere server running at %s", endpoint)
@jameinel

jameinel Jan 10, 2017

Owner

We should at least be logging the original error that leads us to believe something is wrong for debugging purposes.

@natefinch

natefinch Jan 10, 2017

Contributor

Yes, that's true, thanks. I forget that logging actually does something on the client.

provider/vsphere/provider_test.go
+func (pingSuite) TestPingInvalidHost(c *gc.C) {
+ tests := []string{
+ "foo.com",
+ "http://IHopeNoOneEverBuysThisVerySpecificJujuDomainName.com",
@jameinel

jameinel Jan 10, 2017

Owner

.invalid is expressly an invalid tld and I think example.com is also similarly designed for use. But foo.invalid is more what I would use here.

@natefinch

natefinch Jan 10, 2017

Contributor

perfect, thanks

@reedobrien

reedobrien Jan 11, 2017

Contributor

Also .test FWIW.

provider/vsphere/provider_test.go
+ c.Assert(err, jc.ErrorIsNil)
+
+ err = provider.Ping("abc%sdef")
+ if err == nil {
@jameinel

jameinel Jan 10, 2017

Owner

Do you know about c.Assert(err, gc.NotNil)?

@natefinch

natefinch Jan 13, 2017

Contributor

Yeah, I think I used to have more logic inside the if statement. But you're right, it's extraneous now.

provider/vsphere/provider_test.go
+ }
+ expected := "Invalid endpoint format, please give a full url or IP/hostname."
+ if err.Error() != expected {
+ c.Errorf("expected %q got %v", expected, err)
@jameinel

jameinel Jan 10, 2017

Owner

c.Check(err.Error(), gc.Equals, expected)

@natefinch

natefinch Jan 13, 2017

Contributor

yep

provider/vsphere/provider_test.go
+
+ err = provider.Ping("gopher://abcdef.com")
+ if err == nil {
+ c.Fatal("expected error, but got nil.")
Contributor

natefinch commented Jan 13, 2017

$$merge$$

Contributor

jujubot commented Jan 13, 2017

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

Contributor

jujubot commented Jan 13, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10020

Contributor

natefinch commented Jan 13, 2017

Unfortunately, I had to remove the feature test that tested interactive add cloud, because it's not possible to test that successfully unless you have a real vsphere environment to connect to.

Contributor

natefinch commented Jan 13, 2017

$$merge$$

Contributor

jujubot commented Jan 13, 2017

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

Contributor

jujubot commented Jan 13, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10021

Contributor

reedobrien commented Jan 14, 2017

$$wegoagain$$

Contributor

jujubot commented Jan 14, 2017

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

Contributor

jujubot commented Jan 14, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10022

Contributor

reedobrien commented Jan 14, 2017

$$findlxdthistimetrusty$$

Contributor

jujubot commented Jan 14, 2017

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

Contributor

jujubot commented Jan 14, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10023

Contributor

reedobrien commented Jan 14, 2017

$$giveupgiveup$$

Contributor

jujubot commented Jan 14, 2017

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

Contributor

jujubot commented Jan 14, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10024

Implement Ping for vsphere
This change updates the stub Ping method to actually attempt
a connection and login to VSphere in order to be more
likely to discover when the user has typoed the endpoint.
Contributor

natefinch commented Jan 17, 2017

$$merge$$

Contributor

jujubot commented Jan 17, 2017

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

Contributor

jujubot commented Jan 17, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10041

Contributor

natefinch commented Jan 24, 2017

$$merge$$

Contributor

jujubot commented Jan 24, 2017

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

Contributor

jujubot commented Jan 24, 2017

Build failed: Generating tarball failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10102

@jujubot jujubot merged commit 8c993a4 into juju:develop Jan 24, 2017

1 check failed

github-check-merge-juju Built PR, ran unit tests, and tested LXD deploy. Use !!.*!! to request another build. IE, !!build!!, !!retry!!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment