Commit graph

566 commits

Author SHA1 Message Date
Glenn Sarti
e04f380f42 (maint) Emit console messages when debugging is enabled
Previously all log messages may be written to a text file, however during
development or debugging it is also useful if the log messages are written to
the console.  This commit changes the logger class to emit messages to the
console, via `puts`, if the VMPOOLER_DEBUG environment variable is set.
2017-03-31 17:57:06 -07:00
Glenn Sarti
901ddde7c3 (POOLER-52) Prepare the vSphere Provider for a connection pooler
Previously, all calls to the vSphere API assumed an instance variable called
`@connection`.  This commit prepares the provider for a connection pooler:

- Removes all references to `@connection` where needed and funnels all calls to
  get a vSphere connection through the newly renamed method `get_connection`.
  For the moment, this still uses `@connection` behind the scenes but will make
  it easier in the future to migrate to a connection pooler
- Removes all references and tests for the ensure_connected method as it's no
  longer required
- All methods that explicitly need a connection object will have this as part of
  the method parameters
- The connect_to_vsphere method has been changed so that instead of setting the
  instance level `@connection` object it just returns the newly created connection.
  This can then be easily consumed by a connection pooler later.
2017-03-22 10:23:43 -07:00
Glenn Sarti
e5db02b44f (POOLER-70) Rename conflicting method in vSphere Provider
Previously, the vSphere Provider had two methods called
`find_least_used_compatible_host`: one in the base class and one in the vSphere
helper methods.  This commit renames the vSphere helper methods and tests to
`find_least_used_vsphere_compatible_host` to stop the conflict.
2017-03-22 10:10:51 -07:00
Glenn Sarti
8cf3d043bf (POOLER-70) Copy vSphere helper into the vSphere Provider
This commit copies the code and tests from the vSphere Helper into the vSphere
Provider and modifies the test initialisation for the new class name.
2017-03-22 08:58:35 -07:00
Morgan Rhodes
d4a50e5e56 Merge pull request #208 from glennsarti/maint-rubocop
(maint) Fix rubocop violations
2017-03-21 15:21:20 -07:00
Glenn Sarti
fd93c5bea8 (GH-203) Change use of abort to raise in in vsphere_helper.rb
Previously, in `find_vm` and `find_pool` if in an expected object was found the
entire pool manager, and probably API process, will terminate due to the use of
`abort`.  This commit changes the use of abort to raise so that the error can be
trapped  and handled instead of the entire process being shutdown.  This is also
required so that the methods can be tested, otherwise rspec is shutdown
prematurely.
2017-03-17 10:48:32 -07:00
Glenn Sarti
07eb4f579a (POOLER-73) Update find_pool in vsphere_helper.rb to enable testing
Previously, it was not able to mock objects to impersonate various RBVMOMI
objects.  This commit changes the case statement to use `base.is_a?`
which can be mocked and allow mocked objects to mimic real objects.
2017-03-17 10:47:25 -07:00
Glenn Sarti
06100ddea6 (maint) Fix rubocop violations
This commit fixes minor rubocopy violations in eleven source files.  Minor
violations are those that include formatting, single quotes, and recently added
classes.
2017-03-16 15:39:15 -07:00
Glenn Sarti
88052ac85a (POOLER-73) Update find_folder in vsphere_helper.rb to enable testing
Previously, it was not able to mock objects to impersonate a RbVmomi::VIM::Folder
object.  This commit changes the case statement to an if statement using is_a?
which can be mocked and allow mocked objects to mimic real objects.
2017-03-14 13:05:30 -07:00
mattkirby
42b7d2d222 Merge pull request #200 from glennsarti/fix-vsphere-credential
(maint) Fix credentials in vsphere_helper
2017-03-14 11:10:33 -07:00
Glenn Sarti
c724d90d90 (POOLER-70) Add initial VSphere VM Provider
This commit adds a skeleton VM Provider for VSphere based VM operations.
2017-03-08 17:14:52 -08:00
Glenn Sarti
ac8a34de86 (POOLER-70) Rename the use of vsphere to provider
VM provisioning will be handled by VM Providers.  This commit renames the use of
vsphere to provider where appropriate and changes the per-pool helper from
vsphere to providers to more accurately represent it's intended use.
2017-03-08 17:14:52 -08:00
Glenn Sarti
c502f92cd3 (POOLER-70) Add initial VM Provider service
Previously all of the VM provisioning code was intertwined with the VM lifecycle
code e.g. The VSphere specific code is mixed with Redis code.  This makes it
impossible to add aditional providers or disable VSphere integration.  This
commit begins the process to refactor the VSphere code out of the lifecycle code
by introducing the concept of VM Providers.  A Provider will contain the logic/
code to manage VMs i.e. create/destroy/inquire.  Therefore the Pool Manager can
query a strict interface into one or more Providers.  Initially only a VSphere
provider will be available.

This commit adds the base class for all providers and describes the API or
contract that the Pool Manager will use to manage VMs.
2017-03-08 17:14:12 -08:00
Glenn Sarti
0e0e1c2fac (maint) Fix credentials in vsphere_helper
In commit 03ad7bfa46 the global variables for credentials was change to an
instance variable however one reference was missed.  This commit fixes this
omission.
2017-03-08 16:11:07 -08:00
kirby@puppetlabs.com
80c01eb29d Update usage of global variablesin vsphere_helper
This commit updates usage of global variables in vsphere_helper to be instance variables. They do not need to be global variables as brought up in issue #194. Without this change we are setting global variables when they are not needed.
2017-03-08 15:14:34 -08:00
Rob Braden
04124a0e7a Merge pull request #191 from glennsarti/maint-rubocop
(maint) Fix rubocop offenses
2017-03-08 15:09:12 -08:00
Glenn Sarti
c14403682a (maint) Fix rubocop offenses
This commit updates VM Pooler to fix any existing rubocop offenses and also
fixes any offenses in the lib/vmpooler.rb file.  This commit also regenerates
the Todo file.
2017-03-07 20:17:32 -08:00
Rob Braden
e4cd64e47e Merge pull request #197 from mattkirby/double_connect_open
Remove duplicate of metrics.connect.open
2017-03-07 16:14:22 -08:00
kirby@puppetlabs.com
9eb6788148 Remove duplicate of metrics.connect.open
This commit removes a duplicate increment of the metrics.connect.open count. Without this change two connections will be reported when one is made.
2017-03-06 09:15:54 -08:00
Morgan Rhodes
850919f5db Merge pull request #189 from glennsarti/ticket/maint/rename-moves-and-clonevm
(POOLER-70) Refactor clone_vm to take pool configuration object
2017-03-02 11:39:29 -08:00
Glenn Sarti
ac7d7009d2 (POOLER-70) Refactor clone_vm to take pool configuration object
Previously, the clone_vm method took various VSphere specific parameters e.g.
template folder.  However in order make VMPooler less VSphere specific this
method should just take the pool configuration and then it can determine the
appropriate settings itself.  This commit also moves the threading to a clone_vm
while the actual method which does the work is now _clone_vm as per all other
multithread worker methods in pool_manager.  This commit also updates the spec
tests appropriately.
2017-03-01 21:53:42 -08:00
Glenn Sarti
f433056734 (GH-185) Remove unnecessary checks in check_ready_vm
Previously in check_ready_vm, if the VM is powered off, the VM is moved in
redis however the function doesn't return there, and instead then checks if the
hostname is the same, and then if TCP socket 22 is open. This is unnecessary as
we already know the VM is turned off so of course the hostname is wrong and TCP
22 is unavailable. The same applies for the VM hostname.

This commit instead returns after it is found a VM is no longer ready.  This
commit also amends the spec tests for the correct behaviour.
2017-03-01 20:28:36 -08:00
Glenn Sarti
6f127d32bc (POOLER-73) Add spec tests for check_snapshot_queue
Add spec tests for check_snapshot_queue

Previously the check_snapshot_queue method would execute the loop indefinitely
as it did not have a terminating condition.  This made it impossible to test.
This commit modifies the check_snapshot_queue method so that it can take a
maxloop and delay parameter so that it can be tested.
2017-02-17 15:51:05 -08:00
Glenn Sarti
4dd0c96a78 (POOLER-73) Add spec tests for check_disk_queue
Add spec tests for check_disk_queue

Previously the check_disk_queue method would execute the loop indefinitely as it
did not have a terminating condition.  This made it impossible to test.  This
commit modifies the check_disk_queue method so that it can take a maxloop and
delay parameter so that it can be tested.
2017-02-17 15:51:04 -08:00
Glenn Sarti
daad5c7086 (POOLER-73) Add spec tests for check_pool
Add spec tests for check_pool

Previously the check_pool method would execute the loop indefinitely as it did not
have a terminating condition.  This made it impossible to test.  This commit
modifies the check_pool method so that it can take a maxloop and delay parameter
so that it can be tested.
2017-02-17 15:51:03 -08:00
Glenn Sarti
5e46ace584 (POOLER-73) Add spec tests for execute!
Add spec tests for execute!

Previously the execute! method would execute the loop indefinitely as it did not
have a terminating condition.  This made it impossible to test.  This commit
modifies the execute! method so that it can take a maxloop and delay parameter
so that it can be tested.
2017-02-17 15:51:03 -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 Bradley
2bf7c4a715 Merge pull request #169 from sschneid/dockerfile
Containerize vmpooler
2016-12-20 13:43:51 -06: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
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
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
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
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
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
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
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
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