Fix Nova rescheduling tear down problem

If something fails in the spawn() method (e.g driver parameters, node
in maintenance mode) nova will try to rescheduler the instance (in case
the retry filter is enabled) as part of the rescheduling process nova
will call destroy() on that instance which was cause another problem
when Ironic tried to undeploy a node that wasn't deployed. This patch
is fixing the tear down problem by checking the provision_state of the
node before requesting Ironic to undeploy the node.

Also, the relevant code and tests underwent some refactoring to make
the code shorter and less nested.

Closes-Bug: #1300288
Co-Authored-By: Dmitry Tantsur <dtantsur@redhat.com>
Change-Id: I4c7037d6c7b99548a646ef6665b29479277fb4d5
Move duplicated _get_node(s)_mac_addresses()

Move duplicated _get_node(s)_mac_addresses() from pxe and ssh drivers
to a common place.

Change-Id: I27d1df6d3b63f3421d59d14d2b5b9f2c874d6580
Fix self.fields on API Node object

All fields from objects.Node were being added to self.fields in
the API Node object. Because of this, when someone would POST, there'd
be an entry for {'id': None} in the dictionary passed to
dbapi.create_node(). We should only set fields we're exposing.

This also required fixing PATCH to not try to look at fields not set
on the API Node object when mapping to objects.Node.

A later patchset removes the direct dbapi call to create_node() in
flavor of using the objects.Node object where trying to set 'id' of None
would fail prior to this fix.

Change-Id: I92c03d9ff2a56e7999a685f9de38efec5aacbe47
Sync base object code with Nova's

This brings Ironic's base object code more in line with nova's since the
time it was copied. There's still a large difference in the field/type
declarations that we should resolve at some point. (Would be helpful if
this was in oslo, maybe. :)

A couple of these changes are needed for my future patchsets for object
cleanup.

Change-Id: I7e233fb448e9ce56f707d230dc5b2558bdb0a1f9
Fix seamicro power.validate() method definition

* Add task param to the power.validate method definition
* Also add unit tests for the power.validate method

This was not caught when unit testing Ironic using python-seamicroclient
because there is no unit test cover for this method.

Change-Id: I9ed175cffa29b8c10a32c7e121525142e4b170a5
Closes-Bug: #1303670
Supports filtering port by address

This patch add support for getting a port by searching by its mac address
(/ports?address=<address>).

Change-Id: I6f501f52ad50e9d45e0c9637abf7451671d1b4ea
Fix hosts mapping for conductor's periodic tasks

If node has a driver which does not supported by some conductors
_sync_power_states and _check_deploy_timeouts periodical tasks
will be broken for this conductors (KeyError raised in mapping
check).
New _mapped_to_this_conductor() method with fix added to
ConductorManager.

Change-Id: I4bceabab0b931e970ea7136a66ea8762ce99a52b
Remove usage of Glance from PXE clean_up()

Save uuids of instance kernel and ramdisk from Glance into node driver_info
('pxe_kernel' and 'pxe_ramdisk'). Stored values used in PXE clean_up()
method.

Closes-Bug: #1300602
Change-Id: I59b3dbd4f66c59060e5b229eae00b80fdc4702e5
Updated from global requirements

Change-Id: I76cdfdb0693d041310ae6ff64dab6edb8b1a88c4
JsonPatch add operation on existing property

Before a validation code in Ironic was preventing any 'add' operation
to the root of the document, but this create an inconsistency with
multi-level attributes (e.g extra) where 'add' operations works
interchangeable if used on existing properties, this behavior is expect
as per RFC 6902. So this patch makes it possible to use 'add' operations
to replace the values of the properties at the root of the document.

It's important to note that as per Ironic design we do not allow to add
new properties to the root of the document.

Change-Id: Ie448ec46273d7a849c135940084d72d66b9b8a53
Closes-Bug: #1278441
Merge "Fix self.fields on API Node object"
Merge "Sync base object code with Nova's"
Handling validation in conductor consistently

Change where we do validation in change_node_power_state to follow
where we do it for do_node_deploy and vendor_passthrough. That
is, we perform validation synchronously before we spawn off a
thread to perform the longer running action.

Change-Id: Ic1f791bb5ef49c033e4baff8d3f6900091dbf332
Closes-bug: #1294676
Merge "Fix seamicro power.validate() method definition"
Merge "Fix hosts mapping for conductor's periodic tasks"
Merge "Handling validation in conductor consistently"
Replace sfdisk with parted

Replace the current sfdisk which is broken with parted. This patch is
a short-term fix for the Icehouse RC1 release.

Closes-Bug: #1297925
Change-Id: I0c3763db0e29f58b33e998d1f7efb23337604960
Factor hash ring management out of the conductor

This patch pulls some logic around querying and instantiating hash
rings out of the ConductorManager into a new HashRingManager.

Change-Id: I523cb77aae287c44f59b40783e54f6557bc924bc
Cleanup running conductor services in tests

The conductor manager tests are not stopping services that are
started, instead relying strickly on database cleanup.  This is
causing condcutor periodic tasks to bleed into other test cases
and cause occasional unrelated deadlocks in logging later on during
test runs.

Change-Id: I7502df5dec7c42fe1a20bebad8f9ad393572d17d
Closes-bug: #1300420
Merge "Replace sfdisk with parted"