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

When a newer vSphere version is encountered, an error is thrown #4

Closed
nhinds opened this issue Mar 11, 2017 · 11 comments
Closed

When a newer vSphere version is encountered, an error is thrown #4

nhinds opened this issue Mar 11, 2017 · 11 comments

Comments

@nhinds
Copy link

nhinds commented Mar 11, 2017

When attempting to use vsphere-connect against e.g. ESXi 6.5.0a, it throws an error.

I would expect it to instead use the latest API version it understands (6.0) when it encounters a version which is too new.

Steps to reproduce against ESXi 6.5.0a:

> var connect = require('vsphere-connect');
> connect.createClient({host: 'esxi.example.com'})
Unhandled rejection TypeError: env.versions.join is not a function
    at Object.getSchema (/path/to/vsphere-schema/lib/utils/index.js:59:95)
    at /path/to/vsphere-connect/lib/client/index.js:156:54
...

Forcing the "API Version" to be '6.0' instead of assuming it can use whatever the server returns appears to work around this problem:

> var connect = require('vsphere-connect');
> Object.defineProperty(connect.Client.prototype, 'apiVersion', {get: function() {return '6.0'}})
> connect.createClient({host: 'esxi.example.com'})

The problematic code appears to be in lib/client/index.js where it calls RetrieveServiceContent then assumes that it can understand whatever API version the server returns in 'about.apiVersion', without checking whether this version is understood by the vsphere-schema library.

@bhoriuchi
Copy link
Owner

I'm actually re-writing this library to not rely on vsphere-schema. Please test out the chain branch https://github.com/bhoriuchi/vsphere-connect/tree/chain

The usage is a bit different and the new API is not completely set in stone as I am working on the re-write in my spare time. There are several examples in the examples directory on that branch. The chain branch also caches the parsed wsdl data so the performance should be much better than the current code.

@nhinds
Copy link
Author

nhinds commented Mar 16, 2017

That branch immediately fails with:

Error: Cannot find module 'soap'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/path/to/vsphere-connect/lib/index.js:15:14)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/path/to/myfile.js:3:17)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)

It looks like it's still requiring the "soap" module even though that module is no longer listed as a dependency.

Adding a dependency on "soap" (by copy+pasting the dependency from master), I get "Cannot find module 'nodexml'". "soap-cookie" and "vsphere-schema" are similarly still required, even though they have been removed from package.json.

Finally, after adding these 4 missing dependencies to my package.json, creating a client pointing at an ESXi 6.5 host fails with the exact same error as before: "Unhandled rejection TypeError: env.versions.join is not a function" from getSchema.

I did not see anything different in the example directory on your branch compared to master. Perhaps I am missing something?

@nhinds
Copy link
Author

nhinds commented Mar 16, 2017

Hmm, I see a new src directory, but attempting to require('vsphere-connect/src') fails with

> require('vsphere-connect/src')
/path/to/foo/node_modules/vsphere-connect/src/index.js:1
(function (exports, require, module, __filename, __dirname) { import client from './client/index'
                                                              ^^^^^^
SyntaxError: Unexpected reserved word

...so it seems like the src directory is written in something my node.js does not understand.

I see 'babel' listed as a dev dependency, but I don't see where you've committed/uploaded the transpiled source that's compatible with the normal node.js runtime. Is it published under a different module name, or in another directory?

Or did you want me to perform a local checkout of your code and publish it somewhere myself? At the moment I've just updated my package.json to point at the latest commit on your branch, which does not appear to be working particularly well ("vsphere-connect": "bhoriuchi/vsphere-connect#88cdc702")

@bhoriuchi
Copy link
Owner

I just need to update the package with a build. I'll try to get that committed tonight

@nhinds
Copy link
Author

nhinds commented Mar 16, 2017

Thanks. I've never played with babel so I don't have the first clue how to get it up and running.

@bhoriuchi
Copy link
Owner

bhoriuchi commented Mar 16, 2017

ive added a build and updated the package.json. the examples i was refering to are in /src/examples. unfortunately im running into a bug withthe build library i use rollup and dont have time at the moment to test. It did however build so feel free to test. i will try to test the build tomorrow

@nhinds
Copy link
Author

nhinds commented Mar 16, 2017

Looks like that works. The new API isn't quite what's documented on https://github.com/bhoriuchi/vsphere-connect/wiki/API-V2 (e.g. .logout() does not return a Promise, you have go .logout().run() to actually log out), but it definitely works against ESXi 6.5.

It looks like not all of the functionality is exposed through the top-level API at the moment (e.g. the 'reload' method needs you to chain down to v.client()), but it does solve the problem in this ticket. Thanks very much!

@bhoriuchi
Copy link
Owner

Yeah, I'm still working on the rewrite and documentation. It's a side project so it's a little more slow going. I'll keep this open till I publish a release

@nhinds
Copy link
Author

nhinds commented Mar 17, 2017

I did notice that when there's an error from .reload(), even if I .catch(...) the Promise I still end up with a warning about an unhandled rejection (e.g. "Unhandled rejection (<{"faultCode":"ServerFaultCode","messag...>, no stack trace)" from Bluebird).

It looks like it's because client.reload(...) creates a Promise then calls client.method(...), and client.method(...) also creates a Promise. The Promise from client.method(...) isn't actually used, and never has any error handlers attached to it, because client.reload(...) passes a callback instead of calling .then() on the return value. So when client.method(...) rejects its Promise, bluebird gives a warning that nothing handled the rejection (even though your code propagates the error up to the Promise from client.reload(...)).

You might want to remove the dual functionality of Promise-y methods that are sometimes passed callbacks - if anybody needs callback functionality, they can call .asCallback(callback) on the Promise your methods return. Alternatively, you could call .asCallback(callback) yourself from all such dual-purpose methods (which will stop Bluebird complaining about unhandled errors) and avoid the utility methods resultHandler and errorHandler.

Edit: or the error might be the other way around - the Promise code in client.reload() does return the Promise from client.method(...), so it might be the Promise from client.reload() that never gets an error handler attached to it... either way, there are two rejected promises and only one has a handler attached.

@bhoriuchi
Copy link
Owner

Yeah I like the idea of removing the dual callback promise code and just returning promises.

@bhoriuchi
Copy link
Owner

These issues have been resolved in the current alpha release

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

No branches or pull requests

2 participants