Merge "Update baremetal objects with fields added up to Rocky"

This commit is contained in:
Zuul
2018-09-19 23:47:10 +00:00
committed by Gerrit Code Review
8 changed files with 249 additions and 17 deletions

View File

@@ -129,12 +129,19 @@ class Proxy(proxy.Proxy):
return self._delete(_chassis.Chassis, chassis,
ignore_missing=ignore_missing)
def drivers(self):
def drivers(self, details=False):
"""Retrieve a generator of drivers.
:param bool details: A boolean indicating whether the detailed
information for every driver should be returned.
:returns: A generator of driver instances.
"""
return self._list(_driver.Driver, paginated=False)
kwargs = {}
# NOTE(dtantsur): details are available starting with API microversion
# 1.30. Thus we do not send any value if not needed.
if details:
kwargs['details'] = True
return self._list(_driver.Driver, paginated=False, **kwargs)
def get_driver(self, driver):
"""Get a specific driver.

View File

@@ -27,13 +27,95 @@ class Driver(resource.Resource):
allow_delete = False
allow_list = True
# NOTE: Query mapping?
_query_mapping = resource.QueryParameters(details='detail')
# The BIOS interface fields introduced in 1.40 (Rocky).
_max_microversion = '1.40'
#: The name of the driver
name = resource.Body('name', alternate_id=True)
#: A list of active hosts that support this driver.
hosts = resource.Body('hosts', type=list)
#: A list of relative links, including the self and bookmark links.
links = resource.Body('links', type=list)
#: The name of the driver
name = resource.Body('name', alternate_id=True)
#: A list of links to driver properties.
properties = resource.Body('properties', type=list)
# Hardware interface properties grouped together for convenience,
# available with detail=True.
#: Default BIOS interface implementation.
#: Introduced in API microversion 1.40.
default_bios_interface = resource.Body("default_bios_interface")
#: Default boot interface implementation.
#: Introduced in API microversion 1.30.
default_boot_interface = resource.Body("default_boot_interface")
#: Default console interface implementation.
#: Introduced in API microversion 1.30.
default_console_interface = resource.Body("default_console_interface")
#: Default deploy interface implementation.
#: Introduced in API microversion 1.30.
default_deploy_interface = resource.Body("default_deploy_interface")
#: Default inspect interface implementation.
#: Introduced in API microversion 1.30.
default_inspect_interface = resource.Body("default_inspect_interface")
#: Default management interface implementation.
#: Introduced in API microversion 1.30.
default_management_interface = resource.Body(
"default_management_interface")
#: Default network interface implementation.
#: Introduced in API microversion 1.30.
default_network_interface = resource.Body("default_network_interface")
#: Default port interface implementation.
#: Introduced in API microversion 1.30.
default_power_interface = resource.Body("default_power_interface")
#: Default RAID interface implementation.
#: Introduced in API microversion 1.30.
default_raid_interface = resource.Body("default_raid_interface")
#: Default rescue interface implementation.
#: Introduced in API microversion 1.38.
default_rescue_interface = resource.Body("default_rescue_interface")
#: Default storage interface implementation.
#: Introduced in API microversion 1.33.
default_storage_interface = resource.Body("default_storage_interface")
#: Default vendor interface implementation.
#: Introduced in API microversion 1.30.
default_vendor_interface = resource.Body("default_vendor_interface")
#: Enabled BIOS interface implementations.
#: Introduced in API microversion 1.40.
enabled_bios_interfaces = resource.Body("enabled_bios_interfaces")
#: Enabled boot interface implementations.
#: Introduced in API microversion 1.30.
enabled_boot_interfaces = resource.Body("enabled_boot_interfaces")
#: Enabled console interface implementations.
#: Introduced in API microversion 1.30.
enabled_console_interfaces = resource.Body("enabled_console_interfaces")
#: Enabled deploy interface implementations.
#: Introduced in API microversion 1.30.
enabled_deploy_interfaces = resource.Body("enabled_deploy_interfaces")
#: Enabled inspect interface implementations.
#: Introduced in API microversion 1.30.
enabled_inspect_interfaces = resource.Body("enabled_inspect_interfaces")
#: Enabled management interface implementations.
#: Introduced in API microversion 1.30.
enabled_management_interfaces = resource.Body(
"enabled_management_interfaces")
#: Enabled network interface implementations.
#: Introduced in API microversion 1.30.
enabled_network_interfaces = resource.Body("enabled_network_interfaces")
#: Enabled port interface implementations.
#: Introduced in API microversion 1.30.
enabled_power_interfaces = resource.Body("enabled_power_interfaces")
#: Enabled RAID interface implementations.
#: Introduced in API microversion 1.30.
enabled_raid_interfaces = resource.Body("enabled_raid_interfaces")
#: Enabled rescue interface implementations.
#: Introduced in API microversion 1.38.
enabled_rescue_interfaces = resource.Body("enabled_rescue_interfaces")
#: Enabled storage interface implementations.
#: Introduced in API microversion 1.33.
enabled_storage_interfaces = resource.Body("enabled_storage_interfaces")
#: Enabled vendor interface implementations.
#: Introduced in API microversion 1.30.
enabled_vendor_interfaces = resource.Body("enabled_vendor_interfaces")

View File

@@ -51,21 +51,26 @@ class Node(resource.Resource):
commit_jsonpatch = True
_query_mapping = resource.QueryParameters(
'associated', 'driver', 'fields', 'provision_state', 'resource_class',
'associated', 'conductor_group', 'driver', 'fault', 'fields',
'provision_state', 'resource_class',
instance_id='instance_uuid',
is_maintenance='maintenance',
)
# VIF attach/detach support introduced in 1.28.
_max_microversion = '1.28'
# The conductor_group field introduced in 1.46 (Rocky).
_max_microversion = '1.46'
# 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")
#: Conductor group this node is managed by. Added in API microversion 1.46.
conductor_group = resource.Body("conductor_group")
#: Timestamp at which the node was last updated.
created_at = resource.Body("created_at")
#: The current deploy step. Added in API microversion 1.44.
deploy_step = resource.Body("deploy_step")
#: The name of the driver.
driver = resource.Body("driver")
#: All the metadata required by the driver to manage this node. List of
@@ -76,6 +81,9 @@ class Node(resource.Resource):
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")
#: Fault type that caused the node to enter maintenance mode.
#: Introduced in API microversion 1.42.
fault = resource.Body("fault")
#: 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
@@ -100,9 +108,6 @@ class Node(resource.Resource):
#: 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
@@ -135,9 +140,50 @@ class Node(resource.Resource):
#: The requested RAID configuration of the node which will be applied when
#: the node next transitions through the CLEANING state.
target_raid_config = resource.Body("target_raid_config")
#: Traits of the node. Introduced in API microversion 1.37.
traits = resource.Body("traits", type=list)
#: Timestamp at which the node was last updated.
updated_at = resource.Body("updated_at")
# Hardware interfaces grouped together for convenience.
#: BIOS interface to use when setting BIOS properties of the node.
#: Introduced in API microversion 1.40.
bios_interface = resource.Body("bios_interface")
#: Boot interface to use when configuring boot of the node.
#: Introduced in API microversion 1.31.
boot_interface = resource.Body("boot_interface")
#: Console interface to use when working with serial console.
#: Introduced in API microversion 1.31.
console_interface = resource.Body("console_interface")
#: Deploy interface to use when deploying the node.
#: Introduced in API microversion 1.31.
deploy_interface = resource.Body("deploy_interface")
#: Inspect interface to use when inspecting the node.
#: Introduced in API microversion 1.31.
inspect_interface = resource.Body("inspect_interface")
#: Management interface to use for management actions on the node.
#: Introduced in API microversion 1.31.
management_interface = resource.Body("management_interface")
#: 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")
#: Power interface to use for power actions on the node.
#: Introduced in API microversion 1.31.
power_interface = resource.Body("power_interface")
#: RAID interface to use for configuring RAID on the node.
#: Introduced in API microversion 1.31.
raid_interface = resource.Body("raid_interface")
#: Rescue interface to use for rescuing of the node.
#: Introduced in API microversion 1.38.
rescue_interface = resource.Body("rescue_interface")
#: Storage interface to use when attaching remote storage.
#: Introduced in API microversion 1.33.
storage_interface = resource.Body("storage_interface")
#: Vendor interface to use for vendor-specific actions on the node.
#: Introduced in API microversion 1.31.
vendor_interface = resource.Body("vendor_interface")
def _consume_body_attrs(self, attrs):
if 'provision_state' in attrs and attrs['provision_state'] is None:
# API version 1.1 uses None instead of "available". Make it
@@ -519,7 +565,8 @@ class NodeDetail(Node):
allow_list = True
_query_mapping = resource.QueryParameters(
'associated', 'driver', 'fields', 'provision_state', 'resource_class',
'associated', 'conductor_group', 'driver', 'fault',
'provision_state', 'resource_class',
instance_id='instance_uuid',
is_maintenance='maintenance',
)

View File

@@ -30,11 +30,11 @@ class Port(resource.Resource):
commit_jsonpatch = True
_query_mapping = resource.QueryParameters(
'fields'
'address', 'fields', 'node', 'portgroup',
)
# Port group ID introduced in 1.24
_max_microversion = '1.24'
# The physical_network field introduced in 1.34
_max_microversion = '1.34'
#: The physical hardware address of the network port, typically the
#: hardware MAC address.
@@ -59,6 +59,9 @@ class Port(resource.Resource):
local_link_connection = resource.Body('local_link_connection')
#: The UUID of node this port belongs to
node_id = resource.Body('node_uuid')
#: The name of physical network this port is attached to.
#: Added in API microversion 1.34.
physical_network = resource.Body('physical_network')
#: The UUID of PortGroup this port belongs to. Added in API microversion
#: 1.24.
port_group_id = resource.Body('portgroup_uuid')

View File

@@ -33,8 +33,8 @@ class PortGroup(resource.Resource):
'node', 'address', 'fields',
)
# Port groups introduced in 1.23
_max_microversion = '1.23'
# The mode and properties field introduced in 1.26.
_max_microversion = '1.26'
#: The physical hardware address of the portgroup, typically the hardware
#: MAC address. Added in API microversion 1.23.
@@ -55,11 +55,15 @@ class PortGroup(resource.Resource):
type=bool)
#: A list of relative links, including the self and bookmark links.
links = resource.Body('links', type=list)
#: Port bonding mode. Added in API microversion 1.26.
mode = resource.Body('mode')
#: UUID of the node this portgroup belongs to.
node_id = resource.Body('node_uuid')
#: A list of links to the collection of ports belonging to this portgroup.
#: Added in API microversion 1.24.
ports = resource.Body('ports')
#: Port group properties. Added in API microversion 1.26.
properties = resource.Body('properties', type=dict)
#: Timestamp at which the portgroup was last updated.
updated_at = resource.Body('updated_at')

View File

@@ -0,0 +1,55 @@
# 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 import exceptions
from openstack.tests.functional.baremetal import base
class TestBareMetalDriver(base.BaseBaremetalTest):
def test_fake_hardware_get(self):
driver = self.conn.baremetal.get_driver('fake-hardware')
self.assertEqual('fake-hardware', driver.name)
self.assertNotEqual([], driver.hosts)
def test_fake_hardware_list(self):
drivers = self.conn.baremetal.drivers()
self.assertIn('fake-hardware', [d.name for d in drivers])
def test_driver_negative_non_existing(self):
self.assertRaises(exceptions.ResourceNotFound,
self.conn.baremetal.get_driver, 'not-a-driver')
class TestBareMetalDriverDetails(base.BaseBaremetalTest):
min_microversion = '1.30'
def test_fake_hardware_get(self):
driver = self.conn.baremetal.get_driver('fake-hardware')
self.assertEqual('fake-hardware', driver.name)
for iface in ('boot', 'deploy', 'management', 'power'):
self.assertIn('fake',
getattr(driver, 'enabled_%s_interfaces' % iface))
self.assertEqual('fake',
getattr(driver, 'default_%s_interface' % iface))
self.assertNotEqual([], driver.hosts)
def test_fake_hardware_list_details(self):
drivers = self.conn.baremetal.drivers(details=True)
driver = [d for d in drivers if d.name == 'fake-hardware'][0]
for iface in ('boot', 'deploy', 'management', 'power'):
self.assertIn('fake',
getattr(driver, 'enabled_%s_interfaces' % iface))
self.assertEqual('fake',
getattr(driver, 'default_%s_interface' % iface))

View File

@@ -36,6 +36,23 @@ class TestBareMetalPort(base.BaseBaremetalTest):
self.assertRaises(exceptions.ResourceNotFound,
self.conn.baremetal.get_port, port.id)
def test_port_list(self):
node2 = self.create_node(name='test-node')
port1 = self.create_port(address='11:22:33:44:55:66',
node_id=node2.id)
port2 = self.create_port(address='11:22:33:44:55:77',
node_id=self.node.id)
ports = self.conn.baremetal.ports(address='11:22:33:44:55:77')
self.assertEqual([p.id for p in ports], [port2.id])
ports = self.conn.baremetal.ports(node=node2.id)
self.assertEqual([p.id for p in ports], [port1.id])
ports = self.conn.baremetal.ports(node='test-node')
self.assertEqual([p.id for p in ports], [port1.id])
def test_port_update(self):
port = self.create_port(address='11:22:33:44:55:66')
port.address = '66:55:44:33:22:11'

View File

@@ -34,6 +34,23 @@ class TestBareMetalPortGroup(base.BaseBaremetalTest):
self.assertRaises(exceptions.ResourceNotFound,
self.conn.baremetal.get_port_group, port_group.id)
def test_port_list(self):
node2 = self.create_node(name='test-node')
pg1 = self.create_port_group(address='11:22:33:44:55:66',
node_id=node2.id)
pg2 = self.create_port_group(address='11:22:33:44:55:77',
node_id=self.node.id)
pgs = self.conn.baremetal.port_groups(address='11:22:33:44:55:77')
self.assertEqual([p.id for p in pgs], [pg2.id])
pgs = self.conn.baremetal.port_groups(node=node2.id)
self.assertEqual([p.id for p in pgs], [pg1.id])
pgs = self.conn.baremetal.port_groups(node='test-node')
self.assertEqual([p.id for p in pgs], [pg1.id])
def test_port_group_update(self):
port_group = self.create_port_group()
port_group.extra = {'answer': 42}