Merge "PortGroup resource for bare-metal service"

This commit is contained in:
Jenkins 2016-12-16 13:50:16 +00:00 committed by Gerrit Code Review
commit 795eb01a70
2 changed files with 186 additions and 0 deletions

View File

@ -0,0 +1,78 @@
# 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 PortGroup(resource.Resource):
resources_key = 'portgroups'
base_path = '/portgroups'
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(
'node', 'address', 'fields',
)
#: The physical hardware address of the portgroup, typically the hardware
#: MAC address. Added in API microversion 1.23.
address = resource.Body('address')
#: Timestamp at which the portgroup was created.
created_at = resource.Body('created_at')
#: A set of one or more arbitrary metadata key and value pairs.
extra = resource.Body('extra', type=dict)
#: The name of the portgroup
name = resource.Body('name')
#: The UUID for the portgroup
id = resource.Body('uuid', alternate_id=True)
#: Internal metadaa set and stored by the portgroup.
internal_info = resource.Body('internal_info')
#: Whether ports that are members of this portgroup can be used as
#: standalone ports. Added in API microversion 1.23.
is_standalone_ports_supported = resource.Body('standalone_ports_supported',
type=bool)
#: A list of relative links, including the self and bookmark links.
links = resource.Body('links', type=list)
#: 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')
#: Timestamp at which the portgroup was last updated.
updated_at = resource.Body('updated_at')
class PortGroupDetail(PortGroup):
base_path = '/portgroups/detail'
allow_create = False
allow_get = False
allow_update = False
allow_delete = False
allow_list = True
_query_mapping = resource.QueryParameters(
'node', 'address',
)
#: The UUID for the portgroup
id = resource.Body('uuid', alternate_id=True)

View File

@ -0,0 +1,108 @@
# 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 port_group
FAKE = {
"address": "11:11:11:11:11:11",
"created_at": "2016-08-18T22:28:48.165105+00:00",
"extra": {},
"internal_info": {},
"links": [
{
"href": "http://127.0.0.1:6385/v1/portgroups/<PG_ID>",
"rel": "self"
},
{
"href": "http://127.0.0.1:6385/portgroups/<PG_ID>",
"rel": "bookmark"
}
],
"name": "test_portgroup",
"node_uuid": "6d85703a-565d-469a-96ce-30b6de53079d",
"ports": [
{
"href": "http://127.0.0.1:6385/v1/portgroups/<PG_ID>/ports",
"rel": "self"
},
{
"href": "http://127.0.0.1:6385/portgroups/<PG_ID>/ports",
"rel": "bookmark"
}
],
"standalone_ports_supported": True,
"updated_at": None,
"uuid": "e43c722c-248e-4c6e-8ce8-0d8ff129387a",
}
class TestPortGroup(testtools.TestCase):
def test_basic(self):
sot = port_group.PortGroup()
self.assertIsNone(sot.resource_key)
self.assertEqual('portgroups', sot.resources_key)
self.assertEqual('/portgroups', 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 = port_group.PortGroup(**FAKE)
self.assertEqual(FAKE['uuid'], sot.id)
self.assertEqual(FAKE['address'], sot.address)
self.assertEqual(FAKE['created_at'], sot.created_at)
self.assertEqual(FAKE['extra'], sot.extra)
self.assertEqual(FAKE['internal_info'], sot.internal_info)
self.assertEqual(FAKE['links'], sot.links)
self.assertEqual(FAKE['name'], sot.name)
self.assertEqual(FAKE['node_uuid'], sot.node_id)
self.assertEqual(FAKE['ports'], sot.ports)
self.assertEqual(FAKE['standalone_ports_supported'],
sot.is_standalone_ports_supported)
self.assertEqual(FAKE['updated_at'], sot.updated_at)
class TestPortGroupDetail(testtools.TestCase):
def test_basic(self):
sot = port_group.PortGroupDetail()
self.assertIsNone(sot.resource_key)
self.assertEqual('portgroups', sot.resources_key)
self.assertEqual('/portgroups/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 = port_group.PortGroupDetail(**FAKE)
self.assertEqual(FAKE['uuid'], sot.id)
self.assertEqual(FAKE['address'], sot.address)
self.assertEqual(FAKE['created_at'], sot.created_at)
self.assertEqual(FAKE['extra'], sot.extra)
self.assertEqual(FAKE['internal_info'], sot.internal_info)
self.assertEqual(FAKE['links'], sot.links)
self.assertEqual(FAKE['name'], sot.name)
self.assertEqual(FAKE['node_uuid'], sot.node_id)
self.assertEqual(FAKE['ports'], sot.ports)
self.assertEqual(FAKE['standalone_ports_supported'],
sot.is_standalone_ports_supported)
self.assertEqual(FAKE['updated_at'], sot.updated_at)