Commit graph

833 commits

Author SHA1 Message Date
Glenn Sarti
8bcf74872a (POOLER-73) Restructure tests to unit and integration directories
Previously all of the spec tests for VM Pooler were all together in the specs
directory.  However some tests require a working local Redis server to operate
and other instead mock all external dependencies.  This commit splits the test
files between unit and integration, where integration tests require a working
Redis instance, and unit tests do not.  This commit also removes the root
`vmpooler` directory as it is not required.  The tests rake test still operates
correctly.

This commit also adds the mock_redis library for testing for the pool_manager.
2017-02-17 13:04:38 -08:00
Glenn Sarti
36310e381a (maint) Add rubocop checks to Travis
This commit adds rubocop checks to Travis for PR CI.  Any rubocop failures will
not fail the build yet.  Fixes for rubocop violations will happen in later
commits.
2017-02-10 13:33:36 -08:00
Glenn Sarti
85a2fa4f20 (maint) Add rubocop for testing
This commit adds the rubocop gem, a rubocop rake task and an initial rubocop
configuration file in prepartion for using rubocop in CI.

This commit also adds a rubocop todo file that exempts existing files from
violations.
2017-02-10 13:33:36 -08:00
Rob Braden
d67db2d380 Merge pull request #180 from glennsarti/ticket/maint/add-dummy-auth
(POOLER-71) Add dummy authentication provider
2017-02-09 16:44:26 -08:00
Ryan McKern
eb67ccad5a (POOLER-71) dummy auth only works in debug mode
If a user attempts to start vmpooler using dummy authentication
without setting the environment variable VMPOOLER_DEBUG, the vmpooler
will now refuse to start.
2017-02-09 16:27:10 -08:00
Glenn Sarti
2c74f4fa3a (POOLER-71) Add dummy authentication provider
Previously it was difficult to do local development as VMPooler requires an LDAP
service for authentication. This commit adds a dummy authentication provider.
The provider has passes authentication if the username and password are
different, and fails if the username and password are the same.  This commit
also updates the documentation in the config YML file.
2017-02-09 16:23:10 -08:00
Rick Sherman
71a5af9e88 Merge pull request #177 from glennsarti/ticket/maint/update-pooler-dev
(maint) Enhance VM Pooler developer experience
2017-02-09 14:38:39 -06:00
Glenn Sarti
8f294c055e (maint) Enable Ctrl-C to kill all threads in developer environment
Previously, if you ran the vpooler via ruby, pressing Ctrl-C would terminate the
Webserver however the PoolManager does not have a handler and would instead
just keep executing.  This commit adds a global Ctrl-C hook which terminates
both the api and manager threads.  This behaviour will only be enabled if the
`VMPOOLER_DEBUG` environment variable exists so that it does not affect VMPooler
when running in production environments.
2017-02-08 17:35:58 -08:00
Glenn Sarti
80c0742e80 (maint) Update Gemfile and gitignore
Previously, a bundle install would not pull in gems from Gemfile.local or
~/.gemfile which are common development workflows in Puppet.  This commit
modifies the Gemfile to pull in these additional gemfiles if they exist.  This
commit also adds common files and folders to gitignore which should not be
committed to this repository.
2017-02-08 17:35:58 -08:00
Michael Stahnke
1fa1909986 Merge pull request #178 from glennsarti/master
(maint) Remove Ruby 1.9.3 testing from Travis
2017-01-31 17:12:17 -06:00
Glenn Sarti
926eb47940 (maint) Remove Ruby 1.9.3 testing from Travis
Ruby 1.9.3 is end of life, and now longer bundles due to later Nokogiri 1.7.0.1
requiring Ruby 2.1 or above.  This commit removes ruby 1.9.3 from Travis
testing.
2017-01-24 14:59:14 -08:00
Rick Bradley
2bf7c4a715 Merge pull request #169 from sschneid/dockerfile
Containerize vmpooler
2016-12-20 13:43:51 -06:00
Scott Schneider
8105503b99 Remove outdated line about template configuration 2016-12-20 10:55:12 -08:00
Scott Schneider
d85f84011f Add instructions for running in a Docker container 2016-12-20 10:54:09 -08:00
Scott Schneider
833e34ce37 Update Dockerfile to move Gemflie*
...instead of Gemfile and Gemfile.lock (if it exists) individually
2016-12-20 10:45:36 -08:00
Scott Schneider
efe21b27cd Allow configuration to be defined in an ENV var
If `ENV['VMPOOLER_CONFIG']` is defined, it is read in as a YAML
configuration.  This allows vmpooler to run in a docker daemon via
`docker run -e VMPOOLER_CONFIG -p 80:4567 -it vmpooler` rather than
embedding a YAML file within the container.
2016-12-20 10:41:45 -08:00
Rick Bradley
1bbd623609 Merge pull request #174 from mattkirby/pooler_48
(POOLER-48) Clear migrations at application start time
2016-12-01 16:40:58 -06:00
wayne
b1d1b6f5b7 Merge pull request #175 from mattkirby/send_clone_errors_up
(POOLER-47) Send clone errors up
2016-12-01 13:40:55 -08:00
kirby@puppetlabs.com
fdc30f44bf Remove duplicate log for check_pool completed VMs 2016-12-01 13:36:57 -08:00
kirby@puppetlabs.com
f859826c65 (POOLER-47) Send clone errors up
This commit updates vmpooler to ensure clone errors, and other pool manager errors are raised to the parent method. Without this change vmpooler gets stuck after a connection fails during clone operations and will not attempt to clone again.
2016-12-01 12:41:01 -08:00
kirby@puppetlabs.com
bf8fb1850e (POOLER-48) Clear migrations at application start time
This commit updates vmpooler to clear the migrations queue at application start time. When the application is shut down it is not considerate of any activities, like migrations, in flight. The result is that when the application is started again any stale entries in vmpooler__migration will be left until manually removed, which can prevent migrations from occurring.
2016-12-01 09:58:29 -08:00
Rob Braden
2d6e5b3a8f Merge pull request #170 from sschneid/fix_dashboard_js_error
Fix JavaScript error on nil `weekly_data`
2016-11-29 15:17:09 -08:00
Rob Braden
e7a71c1088 Merge pull request #171 from sschneid/puma_gem
Add `puma` as required gem
2016-11-29 15:16:43 -08:00
Rob Braden
b7c370f064 Merge pull request #173 from mattkirby/retry_logic
Add retry logic with a delay for vsphere connections
2016-11-29 15:16:08 -08:00
kirby@puppetlabs.com
86aedd0754 Add retry logic with a delay for vsphere connections
This commit adds retry logic and configurable delays to vsphere helper.
Without this change vmpooler instances that have large numbers of pools
can create enough connections in a short period of time to cause vcenter
issues.
2016-11-29 03:43:18 -08:00
wayne
ac55bbbc4e Merge pull request #172 from mattkirby/pooler_44
(POOLER-44) Fix vmpooler.migrate reference
2016-11-23 13:34:10 -08:00
kirby@puppetlabs.com
c43c02bf55 Add a counter for vsphere connections 2016-11-23 11:08:19 -08:00
kirby@puppetlabs.com
4faeb6a9ba (POOLER-44) Fix vmpooler.migrate reference
This commit updates vmpooler.migrate metric to send the pool name. Without this change the VM name is sent. Additionally, counts are added for migrate_from_#host and migrate_to_#host in order to allow tracking host migrations, and correlating them with CPU ready time changes.
2016-11-22 15:05:16 -08:00
mattkirby
705e5d26d8 Merge pull request #167 from mattkirby/migrate_at_checkout
Improve vmpooler scheduling logic
2016-11-22 11:22:12 -08:00
kirby@puppetlabs.com
02327dfcd6 (POOLER-26) Fix lost VMs getting stuck in pending
This commit updates vmpooler to understand how to resolve a situation
where a pending VM does not exist. Without this change a pending VM that
does not exist in vmware inventory gets stuck in the pending state,
preventing the pool from ever reaching its target capacity.

As a part of this change the find_vm method is updated to perform a
light, then heavy search each time find_vm is called and all usage of
find_vm || find_vm_heavy is replaced. This makes find_vm usage
consistent across pool_manager.

Additionally, open_socket method is updated to resolve an incorrect
reference to the host name.
2016-11-22 10:23:16 -08:00
kirby@puppetlabs.com
a6c8c76d31 Use open socket method for opening socket
This commit updates pool manager to use a method for opening a socket
instead of opening it directly from check_pending_vm. Support is added
for specifying the domain of the VM to connect to, which lays the
groundwork for doing away with the assumption of having DNS search
domains set for vmpooler to move VMs to the ready state.

Additionally, this commit adds a block to ensure open_socket closes open connections. Without this change sockets are opened to each VM before moving to the ready state, and never explicitly closed.

Also, use open socket for check_ready_vm
2016-11-22 10:23:16 -08:00
kirby@puppetlabs.com
109f197fe7 Update migration_count method for greater readability and predictability.
Update migrate_vm to make clear when an if block is the end of the line by returning. Use scard instead of smembers.size() for determining migrations in progress.
2016-11-22 10:23:16 -08:00
kirby@puppetlabs.com
e6613d56a0 Update migration spec to call pool manager and validate results
Use mock_redis instead of redis.

Make passing of mock redis to helper calls more clear

Update pool_manager_spec to specify vsphere argument where applicable. Update pool_helper calls to vsphere where needed for tests to pass. Without this change rspec tests for pool_manager_spec exhibit 12 failures.

Update pool_manager_spec test with open_socket

Pool_manager_spec stubs a tcpsocket connection to simulate this happening directly within _check_pending_vm. This commit updates this to look more like its usage with open_socket, which allows the test to pass.
2016-11-22 10:23:13 -08:00
kirby@puppetlabs.com
a15090e005 Simplify vsphere connection handling in order to make it reasonable to test. Simplify migrate_vm method by breaking out some componenents. Improve error handling around migrate_vm.
Add helpers to support setting up redis for migration at checkout
testing.
2016-11-22 10:03:24 -08:00
kirby@puppetlabs.com
12c2c4a09b Return host name with object when finding least used compatible host 2016-11-22 10:03:24 -08:00
kirby@puppetlabs.com
f8bd79a8d9 Handle empty queues in pool manager
Remove unneeded begin block in method

Fix formatting of rescue block in fail_pending_vm
2016-11-22 10:03:10 -08:00
kirby@puppetlabs.com
a244f9b92a Stop reloading configuration file from vspherehelper and instead source credentials from the configuration object that itself loads the configuration file when the application starts. Without this change the configuration file is reloaded every time vspherehelper is called. Additionally, this change makes it more straightforward to test vspherehelper connections.
A method is added to make more clear what's happening when checking if a socket can be opened to a pending VM on port 22. Additionally, the connection appends domain from the configuration, when present, to the VM name so DNS search is not required.
2016-11-22 09:48:28 -08:00
Scott Schneider
dab267a017 Fix JavaScript error on nil weekly_data
Without this patch the dashboard will error-out on unfound `weekly_data`
values.
2016-11-21 17:05:58 -08:00
Scott Schneider
eceb5bcab0 Add puma as required gem
It is much more performant than the Sinatra's built-in WEBrick.
2016-11-19 10:00:17 -08:00
Scott Schneider
c5aedc12cb Add an all-in-one Dockerfile
Built off the [jruby](https://hub.docker.com/_/jruby/) `Dockerfile`,
it installs gem requirements via `bundler`, installs and runs a
`redis-server`, imports the current working directory, starts
`vmpooler`, and tails the logfile.

Creating a `vmpooler.yaml` configuration file in the current working
directory and running the following provides a development environment:

```
docker build -t vmpooler . && docker run -p 80:4567 -it vmpooler
```
2016-11-19 09:54:42 -08:00
Michael Stahnke
3e3bc6fa13 Merge pull request #168 from briancain/update-with-vagrant-vmpooler-plugin
Add vagrant-vmpooler plugin to readme
2016-11-15 15:29:42 -08:00
kirby@puppetlabs.com
58a548bc90 Add support for migrating VMs to pool_manager.
This commit adds a capability to pool_manager to migrate VMs placed in the migrating queue. When a VM is checked out an entry is created in vmpooler__migrating. The existing process for evaluating VM states executes the migrate_vm method for the provided VM, and removes it from the queue. The least used compatible host for the provided VM is selected and, if necessary, a migration to the lesser used host is performed. Migration time and time from the task being queued until completion are both tracked with the redis VM object in 'migration_time' and 'checkout_to_migration'. The migration time is logged in the vmpooler.log, or the VM is reported as not requiring migration. Without this change VMs are not evaluated for checkout at request time.

Add a method to wrap find_vm and find_vm_heavy in order to allow a
single operation to be performed that does both.

This commit also adds support for a configuration setting called
migration_limit that makes migration at checkout optional. Additionally,
logging is added to report a VM parent host when it is checked out. Without this
change vmpooler assumes that migration at checkout is always enabled.
If this setting is not present, or if the setting is 0, then migration
at checkout will be disabled. If the setting is greater than 0 then that
setting will be used to enforce a limit for the number of simultaneous
migrations that will be evaluated.

Documentation of this configuration option is added to the
vmpooler.yaml.example file.
2016-11-08 16:32:10 -08:00
Brian Cain
b1cd79d863 Add vagrant-vmpooler plugin to readme 2016-11-04 13:23:10 -07:00
kirby@puppetlabs.com
538f30af8e Update find_least_used_host method to evaluate hosts based on utilization. Without this change the determination is based on VM count. Additionally, a method is added to find the least used host compatible with the provided VM in order to support migrating a VM at checkout. Lastly, a capability is added to migrate VMs to a provided host, which also supports migrating VMs at checkout.
Add method to check if vsphere connection is alive. Replace repeated usage of checking the current time in a begin/rescue block with this method.
2016-10-28 14:24:28 -07:00
kirby@puppetlabs.com
506c124578 Add vmpooler__migrating__vm at VM checkout 2016-10-14 12:40:33 -07:00
Ryan McKern
8286ec2854 Merge pull request #162 from puppetlabs/per-pool-stats-in-status
[QENG-4181] Add per-pool stats to `/status` API
2016-09-23 10:28:39 -07:00
Rick Bradley
9b44c2ffc4 (maint) Add a temporary shim to fix jruby travis build
This is necessary until the bundler + Jruby issues are resolved:

 - https://github.com/bundler/bundler/issues/4975
 - https://github.com/bundler/bundler/issues/4984
2016-09-14 15:45:36 -07:00
Rick Bradley
5a1d547830 [QENG-4181] Add inline documentation for /status endpoint
It's useful to be able to see, in the code, what sort of output we
are generating with endpoints like `/status`.
2016-09-10 12:36:25 -05:00
Rick Bradley
30dc060731 [QENG-4181] Add per-pool stats to /status API
Prior to this the only per-pool statistics that could be extracted from the API
were a list of empty pools in the "status" section of the returned results of
the `/status` endpoint.

This adds a new "pools" section to the '/status' results which lists, for each
pool, the following results:

 - The number of ready vms in the pool
 - The number of running vms in the pool
 - The number of pending vms in the pool
 - The maximum size of the pool (as specified in the vmpooler configuration)

Example:

```
{
  "boot": {
  "duration": {
    "average": 163.6,
    "min": 65.49,
    "max": 830.07,
    "total": 247744.71000000002
  },
  "count": {
    "total": 1514
  }
  # ...
  "pools": {
    "pool1": {
      "ready":   5,
      "running": 2,
      "pending": 1,
      "max":     15
    },
    "pool2": {
      "ready":   0,
      "running": 10,
      "pending": 0,
      "max:      10
    }
  }
}
```

This includes spec coverage for this change (we could use more specs on `/status` in general); as well as a couple of general spec improvements.
2016-09-09 17:00:47 -05:00
Michael Stahnke
1bf0af2ba5 Merge pull request #157 from erosa/maint/master/update-readme
(maint) update README.md and LICENSE to reflect rebranding
2016-08-09 15:13:22 -07:00