Merge "Node resource for bare-metal service"

This commit is contained in:
Jenkins 2016-12-16 13:49:46 +00:00 committed by Gerrit Code Review
commit 2a9f7feb56
2 changed files with 333 additions and 0 deletions

View File

@ -0,0 +1,135 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from openstack.bare_metal import bare_metal_service
from openstack import resource2 as resource
class Node(resource.Resource):
resources_key = 'nodes'
base_path = '/nodes'
service = bare_metal_service.BareMetalService()
# capabilities
allow_create = True
allow_get = True
allow_update = True
allow_delete = True
allow_list = True
patch_update = True
_query_mapping = resource.QueryParameters(
'associated', 'driver', 'fields', 'provision_state', 'resource_class',
instance_id='instance_uuid',
is_maintenance='maintenance',
)
# Properties
#: The UUID of the chassis associated wit this node. Can be empty or None.
chassis_id = resource.Body("chassis_uuid")
#: The current clean step.
clean_step = resource.Body("clean_step")
#: Timestamp at which the node was last updated.
created_at = resource.Body("created_at")
#: The name of the driver.
driver = resource.Body("driver")
#: All the metadata required by the driver to manage this node. List of
#: fields varies between drivers, and can be retrieved from the
#: :class:`openstack.bare_metal.v1.driver.Driver` resource.
driver_info = resource.Body("driver_info", type=dict)
#: Internal metadata set and stored by node's driver. This is read-only.
driver_internal_info = resource.Body("driver_internal_info", type=dict)
#: A set of one or more arbitrary metadata key and value pairs.
extra = resource.Body("extra")
#: The UUID of the node resource.
id = resource.Body("uuid", alternate_id=True)
#: Information used to customize the deployed image, e.g. size of root
#: partition, config drive in the form of base64 encoded string and other
#: metadata.
instance_info = resource.Body("instance_info")
#: UUID of the nova instance associated with this node.
instance_id = resource.Body("instance_uuid")
#: Whether console access is enabled on this node.
is_console_enabled = resource.Body("console_enabled", type=bool)
#: Whether node is currently in "maintenance mode". Nodes put into
#: maintenance mode are removed from the available resource pool.
is_maintenance = resource.Body("maintenance", type=bool)
#: Any error from the most recent transaction that started but failed to
#: finish.
last_error = resource.Body("last_error")
#: A list of relative links, including self and bookmark links.
links = resource.Body("links", type=list)
#: user settable description of the reason why the node was placed into
#: maintenance mode.
maintenance_reason = resource.Body("maintenance_reason")
#: Human readable identifier for the node. May be undefined. Certain words
#: are reserved. Added in API microversion 1.5
name = resource.Body("name")
#: Network interface provider to use when plumbing the network connections
#: for this node. Introduced in API microversion 1.20.
network_interface = resource.Body("network_interface")
#: Links to the collection of ports on this node.
ports = resource.Body("ports", type=list)
#: Links to the collection of portgroups on this node. Available since
#: API microversion 1.24.
port_groups = resource.Body("portgroups", type=list)
#: The current power state. Usually "power on" or "power off", but may be
#: "None" if service is unable to determine the power state.
power_state = resource.Body("power_state")
#: Physical characteristics of the node. Content populated by the service
#: during inspection.
properties = resource.Body("properties", type=dict)
#: The current provisioning state of the node.
provision_state = resource.Body("provision_state")
#: The current RAID configuration of the node.
raid_config = resource.Body("raid_config")
#: The name of an service conductor host which is holding a lock on this
#: node, if a lock is held.
reservation = resource.Body("reservation")
#: A string to be used by external schedulers to identify this node as a
#: unit of a specific type of resource. Added in API microversion 1.21.
resource_class = resource.Body("resource_class")
#: Links to the collection of states.
states = resource.Body("states", type=list)
#: The requested state if a provisioning action has been requested. For
#: example, ``AVAILABLE``, ``DEPLOYING``, ``DEPLOYWAIT``, ``DEPLOYING``,
#: ``ACTIVE`` etc.
target_provision_state = resource.Body("target_provision_state")
#: The requested state during a state transition.
target_power_state = resource.Body("target_power_state")
#: The requested RAID configration of the node which will be applied when
#: the node next transitions through the CLEANING state.
target_raid_config = resource.Body("target_raid_config")
#: Timestamp at which the node was last updated.
updated_at = resource.Body("updated_at")
class NodeDetail(Node):
base_path = '/nodes/detail'
# capabilities
allow_create = False
allow_get = False
allow_update = False
allow_delete = False
allow_list = True
_query_mapping = resource.QueryParameters(
'associated', 'driver', 'fields', 'provision_state', 'resource_class',
instance_id='instance_uuid',
is_maintenance='maintenance',
)
#: The UUID of the node resource.
id = resource.Body("uuid", alternate_id=True)

View File

@ -0,0 +1,198 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import testtools
from openstack.bare_metal.v1 import node
# NOTE: Sample data from api-ref doc
FAKE = {
"chassis_uuid": "1", # NOTE: missed in api-ref sample
"clean_step": {},
"console_enabled": False,
"created_at": "2016-08-18T22:28:48.643434+00:00",
"driver": "agent_ipmitool",
"driver_info": {
"ipmi_password": "******",
"ipmi_username": "ADMIN"
},
"driver_internal_info": {},
"extra": {},
"inspection_finished_at": None,
"inspection_started_at": None,
"instance_info": {},
"instance_uuid": None,
"last_error": None,
"links": [
{
"href": "http://127.0.0.1:6385/v1/nodes/<NODE_ID>",
"rel": "self"
},
{
"href": "http://127.0.0.1:6385/nodes/<NODE_ID>",
"rel": "bookmark"
}
],
"maintenance": False,
"maintenance_reason": None,
"name": "test_node",
"network_interface": "flat",
"portgroups": [
{
"href": "http://127.0.0.1:6385/v1/nodes/<NODE_ID>/portgroups",
"rel": "self"
},
{
"href": "http://127.0.0.1:6385/nodes/<NODE_ID>/portgroups",
"rel": "bookmark"
}
],
"ports": [
{
"href": "http://127.0.0.1:6385/v1/nodes/<NODE_ID>/ports",
"rel": "self"
},
{
"href": "http://127.0.0.1:6385/nodes/<NODE_ID>/ports",
"rel": "bookmark"
}
],
"power_state": None,
"properties": {},
"provision_state": "enroll",
"provision_updated_at": None,
"raid_config": {},
"reservation": None,
"resource_class": None,
"states": [
{
"href": "http://127.0.0.1:6385/v1/nodes/<NODE_ID>/states",
"rel": "self"
},
{
"href": "http://127.0.0.1:6385/nodes/<NODE_ID>/states",
"rel": "bookmark"
}
],
"target_power_state": None,
"target_provision_state": None,
"target_raid_config": {},
"updated_at": None,
"uuid": "6d85703a-565d-469a-96ce-30b6de53079d"
}
class TestNode(testtools.TestCase):
def test_basic(self):
sot = node.Node()
self.assertIsNone(sot.resource_key)
self.assertEqual('nodes', sot.resources_key)
self.assertEqual('/nodes', sot.base_path)
self.assertEqual('baremetal', sot.service.service_type)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_get)
self.assertTrue(sot.allow_update)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
self.assertTrue(sot.patch_update)
def test_instantiate(self):
sot = node.Node(**FAKE)
self.assertEqual(FAKE['uuid'], sot.id)
self.assertEqual(FAKE['name'], sot.name)
self.assertEqual(FAKE['chassis_uuid'], sot.chassis_id)
self.assertEqual(FAKE['clean_step'], sot.clean_step)
self.assertEqual(FAKE['created_at'], sot.created_at)
self.assertEqual(FAKE['driver'], sot.driver)
self.assertEqual(FAKE['driver_info'], sot.driver_info)
self.assertEqual(FAKE['driver_internal_info'],
sot.driver_internal_info)
self.assertEqual(FAKE['extra'], sot.extra)
self.assertEqual(FAKE['instance_info'], sot.instance_info)
self.assertEqual(FAKE['instance_uuid'], sot.instance_id)
self.assertEqual(FAKE['console_enabled'], sot.is_console_enabled)
self.assertEqual(FAKE['maintenance'], sot.is_maintenance)
self.assertEqual(FAKE['last_error'], sot.last_error)
self.assertEqual(FAKE['links'], sot.links)
self.assertEqual(FAKE['maintenance_reason'], sot.maintenance_reason)
self.assertEqual(FAKE['name'], sot.name)
self.assertEqual(FAKE['network_interface'], sot.network_interface)
self.assertEqual(FAKE['ports'], sot.ports)
self.assertEqual(FAKE['portgroups'], sot.port_groups)
self.assertEqual(FAKE['power_state'], sot.power_state)
self.assertEqual(FAKE['properties'], sot.properties)
self.assertEqual(FAKE['provision_state'], sot.provision_state)
self.assertEqual(FAKE['raid_config'], sot.raid_config)
self.assertEqual(FAKE['reservation'], sot.reservation)
self.assertEqual(FAKE['resource_class'], sot.resource_class)
self.assertEqual(FAKE['states'], sot.states)
self.assertEqual(FAKE['target_provision_state'],
sot.target_provision_state)
self.assertEqual(FAKE['target_power_state'], sot.target_power_state)
self.assertEqual(FAKE['target_raid_config'], sot.target_raid_config)
self.assertEqual(FAKE['updated_at'], sot.updated_at)
class TestNodeDetail(testtools.TestCase):
def test_basic(self):
sot = node.NodeDetail()
self.assertIsNone(sot.resource_key)
self.assertEqual('nodes', sot.resources_key)
self.assertEqual('/nodes/detail', sot.base_path)
self.assertEqual('baremetal', sot.service.service_type)
self.assertFalse(sot.allow_create)
self.assertFalse(sot.allow_get)
self.assertFalse(sot.allow_update)
self.assertFalse(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_instantiate(self):
sot = node.NodeDetail(**FAKE)
self.assertEqual(FAKE['uuid'], sot.id)
self.assertEqual(FAKE['name'], sot.name)
self.assertEqual(FAKE['chassis_uuid'], sot.chassis_id)
self.assertEqual(FAKE['clean_step'], sot.clean_step)
self.assertEqual(FAKE['created_at'], sot.created_at)
self.assertEqual(FAKE['driver'], sot.driver)
self.assertEqual(FAKE['driver_info'], sot.driver_info)
self.assertEqual(FAKE['driver_internal_info'],
sot.driver_internal_info)
self.assertEqual(FAKE['extra'], sot.extra)
self.assertEqual(FAKE['instance_info'], sot.instance_info)
self.assertEqual(FAKE['instance_uuid'], sot.instance_id)
self.assertEqual(FAKE['console_enabled'], sot.is_console_enabled)
self.assertEqual(FAKE['maintenance'], sot.is_maintenance)
self.assertEqual(FAKE['last_error'], sot.last_error)
self.assertEqual(FAKE['links'], sot.links)
self.assertEqual(FAKE['maintenance_reason'], sot.maintenance_reason)
self.assertEqual(FAKE['name'], sot.name)
self.assertEqual(FAKE['network_interface'], sot.network_interface)
self.assertEqual(FAKE['ports'], sot.ports)
self.assertEqual(FAKE['portgroups'], sot.port_groups)
self.assertEqual(FAKE['power_state'], sot.power_state)
self.assertEqual(FAKE['properties'], sot.properties)
self.assertEqual(FAKE['provision_state'], sot.provision_state)
self.assertEqual(FAKE['raid_config'], sot.raid_config)
self.assertEqual(FAKE['reservation'], sot.reservation)
self.assertEqual(FAKE['resource_class'], sot.resource_class)
self.assertEqual(FAKE['states'], sot.states)
self.assertEqual(FAKE['target_provision_state'],
sot.target_provision_state)
self.assertEqual(FAKE['target_power_state'], sot.target_power_state)
self.assertEqual(FAKE['target_raid_config'], sot.target_raid_config)
self.assertEqual(FAKE['updated_at'], sot.updated_at)