Add neighbor_interface property in EthernetSwitchPort in RSD 2.2
Change-Id: I84f08780e5ccb292ed8c8e57f90bfd57ad874e90
This commit is contained in:
parent
80d6b36b86
commit
adb86fe4bd
@ -15,30 +15,31 @@
|
|||||||
|
|
||||||
from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch \
|
from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch \
|
||||||
as v2_1_ethernet_switch
|
as v2_1_ethernet_switch
|
||||||
|
from rsd_lib.resources.v2_2.ethernet_switch import ethernet_switch_port
|
||||||
from rsd_lib.resources.v2_2.ethernet_switch import metrics
|
from rsd_lib.resources.v2_2.ethernet_switch import metrics
|
||||||
from rsd_lib.resources.v2_2.ethernet_switch import port
|
|
||||||
|
|
||||||
from sushy.resources import base
|
from sushy.resources import base
|
||||||
from sushy import utils
|
from sushy import utils
|
||||||
|
|
||||||
|
|
||||||
class EthernetSwitch(v2_1_ethernet_switch.EthernetSwitch):
|
class EthernetSwitch(v2_1_ethernet_switch.EthernetSwitch):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@utils.cache_it
|
@utils.cache_it
|
||||||
def ports(self):
|
def ports(self):
|
||||||
"""Property to provide reference to `PortCollection` instance
|
"""Property to provide reference to `EthernetSwitchPortCollection` instance
|
||||||
|
|
||||||
It is calculated once when it is queried for the first time. On
|
It is calculated once when it is queried for the first time. On
|
||||||
refresh, this property is reset.
|
refresh, this property is reset.
|
||||||
"""
|
"""
|
||||||
return port.PortCollection(
|
return ethernet_switch_port.EthernetSwitchPortCollection(
|
||||||
self._conn, utils.get_sub_resource_path_by(self, 'Metrics'),
|
self._conn,
|
||||||
redfish_version=self.redfish_version)
|
utils.get_sub_resource_path_by(self, "Metrics"),
|
||||||
|
redfish_version=self.redfish_version,
|
||||||
|
)
|
||||||
|
|
||||||
def _get_metrics_path(self):
|
def _get_metrics_path(self):
|
||||||
"""Helper function to find the Metrics path"""
|
"""Helper function to find the Metrics path"""
|
||||||
return utils.get_sub_resource_path_by(self, 'Metrics')
|
return utils.get_sub_resource_path_by(self, "Metrics")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@utils.cache_it
|
@utils.cache_it
|
||||||
@ -49,12 +50,13 @@ class EthernetSwitch(v2_1_ethernet_switch.EthernetSwitch):
|
|||||||
refresh, this property is reset.
|
refresh, this property is reset.
|
||||||
"""
|
"""
|
||||||
return metrics.Metrics(
|
return metrics.Metrics(
|
||||||
self._conn, self._get_metrics_path(),
|
self._conn,
|
||||||
redfish_version=self.redfish_version)
|
self._get_metrics_path(),
|
||||||
|
redfish_version=self.redfish_version,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EthernetSwitchCollection(base.ResourceCollectionBase):
|
class EthernetSwitchCollection(base.ResourceCollectionBase):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _resource_type(self):
|
def _resource_type(self):
|
||||||
return EthernetSwitch
|
return EthernetSwitch
|
||||||
@ -68,6 +70,6 @@ class EthernetSwitchCollection(base.ResourceCollectionBase):
|
|||||||
:param redfish_version: The version of RedFish. Used to construct
|
:param redfish_version: The version of RedFish. Used to construct
|
||||||
the object according to schema of the given version.
|
the object according to schema of the given version.
|
||||||
"""
|
"""
|
||||||
super(EthernetSwitchCollection, self).__init__(connector,
|
super(EthernetSwitchCollection, self).__init__(
|
||||||
path,
|
connector, path, redfish_version
|
||||||
redfish_version)
|
)
|
||||||
|
@ -0,0 +1,88 @@
|
|||||||
|
# Copyright 2018 Intel, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# 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 sushy.resources import base
|
||||||
|
from sushy import utils
|
||||||
|
|
||||||
|
from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch_port
|
||||||
|
from rsd_lib.resources.v2_1.system import ethernet_interface
|
||||||
|
from rsd_lib.resources.v2_2.ethernet_switch import ethernet_switch_port_metrics
|
||||||
|
from rsd_lib import utils as rsd_lib_utils
|
||||||
|
|
||||||
|
|
||||||
|
class LinksField(base.CompositeField):
|
||||||
|
|
||||||
|
primary_vlan = base.Field(
|
||||||
|
"PrimaryVLAN", adapter=rsd_lib_utils.get_resource_identity
|
||||||
|
)
|
||||||
|
|
||||||
|
switch = base.Field("Switch", adapter=rsd_lib_utils.get_resource_identity)
|
||||||
|
|
||||||
|
member_of_port = base.Field(
|
||||||
|
"MemberOfPort", adapter=rsd_lib_utils.get_resource_identity
|
||||||
|
)
|
||||||
|
|
||||||
|
port_members = base.Field(
|
||||||
|
"PortMembers", adapter=utils.get_members_identities
|
||||||
|
)
|
||||||
|
|
||||||
|
active_acls = base.Field(
|
||||||
|
"ActiveACLs", adapter=utils.get_members_identities
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EthernetSwitchPort(ethernet_switch_port.EthernetSwitchPort):
|
||||||
|
|
||||||
|
links = LinksField("Links")
|
||||||
|
|
||||||
|
def _get_metrics_path(self):
|
||||||
|
"""Helper function to find the Port metrics path"""
|
||||||
|
return utils.get_sub_resource_path_by(self, "Metrics")
|
||||||
|
|
||||||
|
@property
|
||||||
|
@utils.cache_it
|
||||||
|
def metrics(self):
|
||||||
|
"""Property to provide reference to `EthernetSwitchPortMetrics` instance
|
||||||
|
|
||||||
|
It is calculated once when it is queried for the first time. On
|
||||||
|
refresh, this property is reset.
|
||||||
|
"""
|
||||||
|
return ethernet_switch_port_metrics.EthernetSwitchPortMetrics(
|
||||||
|
self._conn,
|
||||||
|
utils.get_sub_resource_path_by(self, "Metrics"),
|
||||||
|
redfish_version=self.redfish_version,
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
@utils.cache_it
|
||||||
|
def neighbor_interface(self):
|
||||||
|
"""Property to provide reference to `EthernetInterface` instance
|
||||||
|
|
||||||
|
It is calculated once when it is queried for the first time. On
|
||||||
|
refresh, this property is reset.
|
||||||
|
"""
|
||||||
|
return ethernet_interface.EthernetInterface(
|
||||||
|
self._conn,
|
||||||
|
utils.get_sub_resource_path_by(self, "NeighborInterface"),
|
||||||
|
redfish_version=self.redfish_version,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EthernetSwitchPortCollection(
|
||||||
|
ethernet_switch_port.EthernetSwitchPortCollection
|
||||||
|
):
|
||||||
|
@property
|
||||||
|
def _resource_type(self):
|
||||||
|
return EthernetSwitchPort
|
@ -0,0 +1,71 @@
|
|||||||
|
# Copyright 2018 Intel, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# 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 sushy.resources import base
|
||||||
|
|
||||||
|
from rsd_lib import utils as rsd_lib_utils
|
||||||
|
|
||||||
|
|
||||||
|
class ReceivedField(base.CompositeField):
|
||||||
|
packets = base.Field("Packets", adapter=rsd_lib_utils.num_or_none)
|
||||||
|
dropped_packets = base.Field(
|
||||||
|
"DroppedPackets", adapter=rsd_lib_utils.num_or_none
|
||||||
|
)
|
||||||
|
error_packets = base.Field(
|
||||||
|
"ErrorPackets", adapter=rsd_lib_utils.num_or_none
|
||||||
|
)
|
||||||
|
broadcast_packets = base.Field(
|
||||||
|
"BroadcastPackets", adapter=rsd_lib_utils.num_or_none
|
||||||
|
)
|
||||||
|
multicast_packets = base.Field(
|
||||||
|
"MulticastPackets", adapter=rsd_lib_utils.num_or_none
|
||||||
|
)
|
||||||
|
errors = base.Field("Errors", adapter=rsd_lib_utils.num_or_none)
|
||||||
|
received_bytes = base.Field("Bytes", adapter=rsd_lib_utils.num_or_none)
|
||||||
|
|
||||||
|
|
||||||
|
class TransmittedField(base.CompositeField):
|
||||||
|
packets = base.Field("Packets", adapter=rsd_lib_utils.num_or_none)
|
||||||
|
dropped_packets = base.Field(
|
||||||
|
"DroppedPackets", adapter=rsd_lib_utils.num_or_none
|
||||||
|
)
|
||||||
|
error_packets = base.Field(
|
||||||
|
"ErrorPackets", adapter=rsd_lib_utils.num_or_none
|
||||||
|
)
|
||||||
|
broadcast_packets = base.Field(
|
||||||
|
"BroadcastPackets", adapter=rsd_lib_utils.num_or_none
|
||||||
|
)
|
||||||
|
multicast_packets = base.Field(
|
||||||
|
"MulticastPackets", adapter=rsd_lib_utils.num_or_none
|
||||||
|
)
|
||||||
|
errors = base.Field("Errors", adapter=rsd_lib_utils.num_or_none)
|
||||||
|
transmitted_bytes = base.Field("Bytes", adapter=rsd_lib_utils.num_or_none)
|
||||||
|
|
||||||
|
|
||||||
|
class EthernetSwitchPortMetrics(base.ResourceBase):
|
||||||
|
name = base.Field("Name")
|
||||||
|
"""The metrics name"""
|
||||||
|
|
||||||
|
identity = base.Field("Id")
|
||||||
|
"""The metrics identity"""
|
||||||
|
|
||||||
|
received = ReceivedField("Received")
|
||||||
|
"""The received packets status"""
|
||||||
|
|
||||||
|
transmitted = TransmittedField("Transmitted")
|
||||||
|
"""The transmitted packets status"""
|
||||||
|
|
||||||
|
collisions = base.Field("Collisions", adapter=rsd_lib_utils.num_or_none)
|
||||||
|
"""The collisions status"""
|
@ -1,57 +0,0 @@
|
|||||||
# Copyright 2018 Intel, Inc.
|
|
||||||
# All Rights Reserved.
|
|
||||||
#
|
|
||||||
# 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 sushy.resources import base
|
|
||||||
from sushy import utils
|
|
||||||
|
|
||||||
from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch_port \
|
|
||||||
as v2_1_port
|
|
||||||
from rsd_lib.resources.v2_2.ethernet_switch import port_metrics
|
|
||||||
|
|
||||||
|
|
||||||
class Port(v2_1_port.EthernetSwitchPort):
|
|
||||||
|
|
||||||
def _get_metrics_path(self):
|
|
||||||
"""Helper function to find the Port metrics path"""
|
|
||||||
return utils.get_sub_resource_path_by(self, 'Metrics')
|
|
||||||
|
|
||||||
@property
|
|
||||||
@utils.cache_it
|
|
||||||
def metrics(self):
|
|
||||||
"""Property to provide reference to `Metrics` instance
|
|
||||||
|
|
||||||
It is calculated once the first time it is queried. On refresh,
|
|
||||||
this property is reset.
|
|
||||||
"""
|
|
||||||
return port_metrics.PortMetrics(
|
|
||||||
self._conn, self._get_metrics_path(),
|
|
||||||
redfish_version=self.redfish_version)
|
|
||||||
|
|
||||||
|
|
||||||
class PortCollection(base.ResourceCollectionBase):
|
|
||||||
|
|
||||||
@property
|
|
||||||
def _resource_type(self):
|
|
||||||
return Port
|
|
||||||
|
|
||||||
def __init__(self, connector, path, redfish_version=None):
|
|
||||||
"""A class representing an Port
|
|
||||||
|
|
||||||
:param connector: A Connector instance
|
|
||||||
:param path: The canonical path to the Port collection resource
|
|
||||||
:param redfish_version: The version of RedFish. Used to construct
|
|
||||||
the object according to schema of the given version.
|
|
||||||
"""
|
|
||||||
super(PortCollection, self).__init__(connector, path, redfish_version)
|
|
@ -1,63 +0,0 @@
|
|||||||
# Copyright 2018 Intel, Inc.
|
|
||||||
# All Rights Reserved.
|
|
||||||
#
|
|
||||||
# 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 sushy.resources import base
|
|
||||||
|
|
||||||
from rsd_lib import utils as rsd_lib_utils
|
|
||||||
|
|
||||||
|
|
||||||
class ReceivedField(base.CompositeField):
|
|
||||||
packets = base.Field('Packets', adapter=rsd_lib_utils.num_or_none)
|
|
||||||
dropped_packets = base.Field('DroppedPackets',
|
|
||||||
adapter=rsd_lib_utils.num_or_none)
|
|
||||||
error_packets = base.Field('ErrorPackets',
|
|
||||||
adapter=rsd_lib_utils.num_or_none)
|
|
||||||
broadcast_packets = base.Field('BroadcastPackets',
|
|
||||||
adapter=rsd_lib_utils.num_or_none)
|
|
||||||
multicast_packets = base.Field('MulticastPackets',
|
|
||||||
adapter=rsd_lib_utils.num_or_none)
|
|
||||||
errors = base.Field('Errors', adapter=rsd_lib_utils.num_or_none)
|
|
||||||
received_bytes = base.Field('Bytes', adapter=rsd_lib_utils.num_or_none)
|
|
||||||
|
|
||||||
|
|
||||||
class TransmittedField(base.CompositeField):
|
|
||||||
packets = base.Field('Packets', adapter=rsd_lib_utils.num_or_none)
|
|
||||||
dropped_packets = base.Field('DroppedPackets',
|
|
||||||
adapter=rsd_lib_utils.num_or_none)
|
|
||||||
error_packets = base.Field('ErrorPackets',
|
|
||||||
adapter=rsd_lib_utils.num_or_none)
|
|
||||||
broadcast_packets = base.Field('BroadcastPackets',
|
|
||||||
adapter=rsd_lib_utils.num_or_none)
|
|
||||||
multicast_packets = base.Field('MulticastPackets',
|
|
||||||
adapter=rsd_lib_utils.num_or_none)
|
|
||||||
errors = base.Field('Errors', adapter=rsd_lib_utils.num_or_none)
|
|
||||||
transmitted_bytes = base.Field('Bytes', adapter=rsd_lib_utils.num_or_none)
|
|
||||||
|
|
||||||
|
|
||||||
class PortMetrics(base.ResourceBase):
|
|
||||||
name = base.Field('Name')
|
|
||||||
"""The metrics name"""
|
|
||||||
|
|
||||||
identity = base.Field('Id')
|
|
||||||
"""The metrics identity"""
|
|
||||||
|
|
||||||
received = ReceivedField('Received')
|
|
||||||
"""The received packets status"""
|
|
||||||
|
|
||||||
transmitted = TransmittedField('Transmitted')
|
|
||||||
"""The transmitted packets status"""
|
|
||||||
|
|
||||||
collisions = base.Field('Collisions', adapter=rsd_lib_utils.num_or_none)
|
|
||||||
"""The collisions status"""
|
|
@ -17,153 +17,184 @@ import json
|
|||||||
import mock
|
import mock
|
||||||
|
|
||||||
from rsd_lib.resources.v2_2.ethernet_switch import ethernet_switch
|
from rsd_lib.resources.v2_2.ethernet_switch import ethernet_switch
|
||||||
|
from rsd_lib.resources.v2_2.ethernet_switch import ethernet_switch_port
|
||||||
from rsd_lib.resources.v2_2.ethernet_switch import metrics
|
from rsd_lib.resources.v2_2.ethernet_switch import metrics
|
||||||
from rsd_lib.resources.v2_2.ethernet_switch import port
|
|
||||||
|
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
|
|
||||||
class EthernetSwitchTestCase(testtools.TestCase):
|
class EthernetSwitchTestCase(testtools.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(EthernetSwitchTestCase, self).setUp()
|
super(EthernetSwitchTestCase, self).setUp()
|
||||||
self.conn = mock.Mock()
|
self.conn = mock.Mock()
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
with open(
|
||||||
'ethernet_switch.json', 'r') as f:
|
"rsd_lib/tests/unit/json_samples/v2_2/" "ethernet_switch.json", "r"
|
||||||
|
) as f:
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
|
||||||
self.ethernet_switch_inst = ethernet_switch.EthernetSwitch(
|
self.ethernet_switch_inst = ethernet_switch.EthernetSwitch(
|
||||||
self.conn, '/redfish/v1/EthernetSwitches/Switch1/Ports/Port1',
|
self.conn,
|
||||||
redfish_version='1.0.2')
|
"/redfish/v1/EthernetSwitches/Switch1/Ports/Port1",
|
||||||
|
redfish_version="1.0.2",
|
||||||
|
)
|
||||||
|
|
||||||
def test_ports(self):
|
def test_ports(self):
|
||||||
# | GIVEN |
|
# | GIVEN |
|
||||||
self.conn.get.return_value.json.reset_mock()
|
self.conn.get.return_value.json.reset_mock()
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
with open(
|
||||||
'ethernet_switch_port_collection.json', 'r') as f:
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_port_collection.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
# | WHEN |
|
# | WHEN |
|
||||||
actual_ports = self.ethernet_switch_inst.ports
|
actual_ports = self.ethernet_switch_inst.ports
|
||||||
# | THEN |
|
# | THEN |
|
||||||
self.assertIsInstance(actual_ports,
|
self.assertIsInstance(
|
||||||
port.PortCollection)
|
actual_ports, ethernet_switch_port.EthernetSwitchPortCollection
|
||||||
|
)
|
||||||
self.conn.get.return_value.json.assert_called_once_with()
|
self.conn.get.return_value.json.assert_called_once_with()
|
||||||
|
|
||||||
# reset mock
|
# reset mock
|
||||||
self.conn.get.return_value.json.reset_mock()
|
self.conn.get.return_value.json.reset_mock()
|
||||||
# | WHEN & THEN |
|
# | WHEN & THEN |
|
||||||
# tests for same object on invoking subsequently
|
# tests for same object on invoking subsequently
|
||||||
self.assertIs(actual_ports,
|
self.assertIs(actual_ports, self.ethernet_switch_inst.ports)
|
||||||
self.ethernet_switch_inst.ports)
|
|
||||||
self.conn.get.return_value.json.assert_not_called()
|
self.conn.get.return_value.json.assert_not_called()
|
||||||
|
|
||||||
def test_ports_on_refresh(self):
|
def test_ports_on_refresh(self):
|
||||||
# | GIVEN |
|
# | GIVEN |
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
with open(
|
||||||
'ethernet_switch_port_collection.json', 'r') as f:
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_port_collection.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
# | WHEN & THEN |
|
# | WHEN & THEN |
|
||||||
self.assertIsInstance(self.ethernet_switch_inst.ports,
|
self.assertIsInstance(
|
||||||
port.PortCollection)
|
self.ethernet_switch_inst.ports,
|
||||||
|
ethernet_switch_port.EthernetSwitchPortCollection,
|
||||||
|
)
|
||||||
|
|
||||||
# On refreshing the port instance...
|
# On refreshing the port instance...
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
with open(
|
||||||
'ethernet_switch.json', 'r') as f:
|
"rsd_lib/tests/unit/json_samples/v2_2/" "ethernet_switch.json", "r"
|
||||||
|
) as f:
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
|
||||||
self.ethernet_switch_inst.invalidate()
|
self.ethernet_switch_inst.invalidate()
|
||||||
self.ethernet_switch_inst.refresh(force=False)
|
self.ethernet_switch_inst.refresh(force=False)
|
||||||
|
|
||||||
# | GIVEN |
|
# | GIVEN |
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
with open(
|
||||||
'ethernet_switch_port_collection.json', 'r') as f:
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_port_collection.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
# | WHEN & THEN |
|
# | WHEN & THEN |
|
||||||
self.assertIsInstance(self.ethernet_switch_inst.ports,
|
self.assertIsInstance(
|
||||||
port.PortCollection)
|
self.ethernet_switch_inst.ports,
|
||||||
|
ethernet_switch_port.EthernetSwitchPortCollection,
|
||||||
|
)
|
||||||
|
|
||||||
def test_metrics(self):
|
def test_metrics(self):
|
||||||
# | GIVEN |
|
# | GIVEN |
|
||||||
self.conn.get.return_value.json.reset_mock()
|
self.conn.get.return_value.json.reset_mock()
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
with open(
|
||||||
'ethernet_switch_metrics.json', 'r') as f:
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_metrics.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
# | WHEN |
|
# | WHEN |
|
||||||
actual_metrics = self.ethernet_switch_inst.metrics
|
actual_metrics = self.ethernet_switch_inst.metrics
|
||||||
# | THEN |
|
# | THEN |
|
||||||
self.assertIsInstance(actual_metrics,
|
self.assertIsInstance(actual_metrics, metrics.Metrics)
|
||||||
metrics.Metrics)
|
|
||||||
self.conn.get.return_value.json.assert_called_once_with()
|
self.conn.get.return_value.json.assert_called_once_with()
|
||||||
|
|
||||||
# reset mock
|
# reset mock
|
||||||
self.conn.get.return_value.json.reset_mock()
|
self.conn.get.return_value.json.reset_mock()
|
||||||
# | WHEN & THEN |
|
# | WHEN & THEN |
|
||||||
# tests for same object on invoking subsequently
|
# tests for same object on invoking subsequently
|
||||||
self.assertIs(actual_metrics,
|
self.assertIs(actual_metrics, self.ethernet_switch_inst.metrics)
|
||||||
self.ethernet_switch_inst.metrics)
|
|
||||||
self.conn.get.return_value.json.assert_not_called()
|
self.conn.get.return_value.json.assert_not_called()
|
||||||
|
|
||||||
def test_metrics_on_refresh(self):
|
def test_metrics_on_refresh(self):
|
||||||
# | GIVEN |
|
# | GIVEN |
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
with open(
|
||||||
'ethernet_switch_metrics.json', 'r') as f:
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_metrics.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
# | WHEN & THEN |
|
# | WHEN & THEN |
|
||||||
self.assertIsInstance(self.ethernet_switch_inst.metrics,
|
self.assertIsInstance(
|
||||||
metrics.Metrics)
|
self.ethernet_switch_inst.metrics, metrics.Metrics
|
||||||
|
)
|
||||||
|
|
||||||
# On refreshing the metrics instance...
|
# On refreshing the metrics instance...
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
with open(
|
||||||
'ethernet_switch.json', 'r') as f:
|
"rsd_lib/tests/unit/json_samples/v2_2/" "ethernet_switch.json", "r"
|
||||||
|
) as f:
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
|
||||||
self.ethernet_switch_inst.invalidate()
|
self.ethernet_switch_inst.invalidate()
|
||||||
self.ethernet_switch_inst.refresh(force=False)
|
self.ethernet_switch_inst.refresh(force=False)
|
||||||
|
|
||||||
# | GIVEN |
|
# | GIVEN |
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
with open(
|
||||||
'ethernet_switch_metrics.json', 'r') as f:
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_metrics.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
# | WHEN & THEN |
|
# | WHEN & THEN |
|
||||||
self.assertIsInstance(self.ethernet_switch_inst.metrics,
|
self.assertIsInstance(
|
||||||
metrics.Metrics)
|
self.ethernet_switch_inst.metrics, metrics.Metrics
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EthernetSwitchCollectionTestCase(testtools.TestCase):
|
class EthernetSwitchCollectionTestCase(testtools.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(EthernetSwitchCollectionTestCase, self).setUp()
|
super(EthernetSwitchCollectionTestCase, self).setUp()
|
||||||
self.conn = mock.Mock()
|
self.conn = mock.Mock()
|
||||||
|
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
with open(
|
||||||
'ethernet_switch_collection.json', 'r') as f:
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_collection.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
|
||||||
self.ethernet_switch_col = ethernet_switch.EthernetSwitchCollection(
|
self.ethernet_switch_col = ethernet_switch.EthernetSwitchCollection(
|
||||||
self.conn,
|
self.conn, "redfish/v1/EthernetSwitches", redfish_version="1.0.2"
|
||||||
'redfish/v1/EthernetSwitches',
|
)
|
||||||
redfish_version='1.0.2')
|
|
||||||
|
|
||||||
def test__parse_attributes(self):
|
def test__parse_attributes(self):
|
||||||
self.ethernet_switch_col._parse_attributes()
|
self.ethernet_switch_col._parse_attributes()
|
||||||
self.assertEqual('1.0.2', self.ethernet_switch_col.redfish_version)
|
self.assertEqual("1.0.2", self.ethernet_switch_col.redfish_version)
|
||||||
self.assertEqual('Ethernet Switches Collection',
|
self.assertEqual(
|
||||||
self.ethernet_switch_col.name)
|
"Ethernet Switches Collection", self.ethernet_switch_col.name
|
||||||
self.assertEqual(('/redfish/v1/EthernetSwitches/Switch1',),
|
)
|
||||||
self.ethernet_switch_col.members_identities)
|
self.assertEqual(
|
||||||
|
("/redfish/v1/EthernetSwitches/Switch1",),
|
||||||
|
self.ethernet_switch_col.members_identities,
|
||||||
|
)
|
||||||
|
|
||||||
@mock.patch.object(ethernet_switch, 'EthernetSwitch', autospec=True)
|
@mock.patch.object(ethernet_switch, "EthernetSwitch", autospec=True)
|
||||||
def test_get_member(self, mock_ethernet_switch):
|
def test_get_member(self, mock_ethernet_switch):
|
||||||
self.ethernet_switch_col.get_member(
|
self.ethernet_switch_col.get_member(
|
||||||
'/redfish/v1/EthernetSwitches/Switch1')
|
"/redfish/v1/EthernetSwitches/Switch1"
|
||||||
|
)
|
||||||
|
|
||||||
mock_ethernet_switch.assert_called_once_with(
|
mock_ethernet_switch.assert_called_once_with(
|
||||||
self.ethernet_switch_col._conn,
|
self.ethernet_switch_col._conn,
|
||||||
'/redfish/v1/EthernetSwitches/Switch1',
|
"/redfish/v1/EthernetSwitches/Switch1",
|
||||||
redfish_version=self.ethernet_switch_col.redfish_version
|
redfish_version=self.ethernet_switch_col.redfish_version,
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch.object(ethernet_switch, 'EthernetSwitch', autospec=True)
|
@mock.patch.object(ethernet_switch, "EthernetSwitch", autospec=True)
|
||||||
def test_get_members(self, mock_ethernet_switch):
|
def test_get_members(self, mock_ethernet_switch):
|
||||||
members = self.ethernet_switch_col.get_members()
|
members = self.ethernet_switch_col.get_members()
|
||||||
self.assertEqual(mock_ethernet_switch.call_count, 1)
|
self.assertEqual(mock_ethernet_switch.call_count, 1)
|
||||||
|
@ -0,0 +1,169 @@
|
|||||||
|
# Copyright 2018 Intel, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# 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 json
|
||||||
|
import mock
|
||||||
|
import testtools
|
||||||
|
|
||||||
|
from sushy import exceptions
|
||||||
|
|
||||||
|
from rsd_lib.resources.v2_2.ethernet_switch import ethernet_switch_port
|
||||||
|
from rsd_lib.resources.v2_2.ethernet_switch import ethernet_switch_port_metrics
|
||||||
|
|
||||||
|
|
||||||
|
class PortTestCase(testtools.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(PortTestCase, self).setUp()
|
||||||
|
self.conn = mock.Mock()
|
||||||
|
with open(
|
||||||
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_port.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
|
||||||
|
self.port_inst = ethernet_switch_port.EthernetSwitchPort(
|
||||||
|
self.conn,
|
||||||
|
"/redfish/v1/EthernetSwitches/Switch1/Ports/Port1",
|
||||||
|
redfish_version="1.0.2",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test__get_metrics_path(self):
|
||||||
|
self.assertEqual(
|
||||||
|
"/redfish/v1/EthernetSwitches/Switch1/Ports/Port1/Metrics",
|
||||||
|
self.port_inst._get_metrics_path(),
|
||||||
|
)
|
||||||
|
|
||||||
|
def test__get_metrics_path_missing_ports_attr(self):
|
||||||
|
self.port_inst._json.pop("Metrics")
|
||||||
|
with self.assertRaisesRegex(
|
||||||
|
exceptions.MissingAttributeError, "attribute Metrics"
|
||||||
|
):
|
||||||
|
self.port_inst._get_metrics_path()
|
||||||
|
|
||||||
|
def test_metrics(self):
|
||||||
|
# | GIVEN |
|
||||||
|
self.conn.get.return_value.json.reset_mock()
|
||||||
|
with open(
|
||||||
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_port_metrics.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
# | WHEN |
|
||||||
|
actual_metrics = self.port_inst.metrics
|
||||||
|
# | THEN |
|
||||||
|
self.assertIsInstance(
|
||||||
|
actual_metrics,
|
||||||
|
ethernet_switch_port_metrics.EthernetSwitchPortMetrics,
|
||||||
|
)
|
||||||
|
self.conn.get.return_value.json.assert_called_once_with()
|
||||||
|
|
||||||
|
# reset mock
|
||||||
|
self.conn.get.return_value.json.reset_mock()
|
||||||
|
# | WHEN & THEN |
|
||||||
|
# tests for same object on invoking subsequently
|
||||||
|
self.assertIs(actual_metrics, self.port_inst.metrics)
|
||||||
|
self.conn.get.return_value.json.assert_not_called()
|
||||||
|
|
||||||
|
def test_metrics_on_refresh(self):
|
||||||
|
# | GIVEN |
|
||||||
|
with open(
|
||||||
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_port_metrics.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
# | WHEN & THEN |
|
||||||
|
self.assertIsInstance(
|
||||||
|
self.port_inst.metrics,
|
||||||
|
ethernet_switch_port_metrics.EthernetSwitchPortMetrics,
|
||||||
|
)
|
||||||
|
|
||||||
|
# On refreshing the port instance...
|
||||||
|
with open(
|
||||||
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_port.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
|
||||||
|
self.port_inst.invalidate()
|
||||||
|
self.port_inst.refresh(force=False)
|
||||||
|
|
||||||
|
# | GIVEN |
|
||||||
|
with open(
|
||||||
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_port_metrics.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
# | WHEN & THEN |
|
||||||
|
self.assertIsInstance(
|
||||||
|
self.port_inst.metrics,
|
||||||
|
ethernet_switch_port_metrics.EthernetSwitchPortMetrics,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PortCollectionTestCase(testtools.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(PortCollectionTestCase, self).setUp()
|
||||||
|
self.conn = mock.Mock()
|
||||||
|
with open(
|
||||||
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_port_collection.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
self.port_col = ethernet_switch_port.EthernetSwitchPortCollection(
|
||||||
|
self.conn,
|
||||||
|
"/redfish/v1/EthernetSwitches/Switch1/Ports",
|
||||||
|
redfish_version="1.0.2",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test__parse_attributes(self):
|
||||||
|
self.port_col._parse_attributes()
|
||||||
|
self.assertEqual("1.0.2", self.port_col.redfish_version)
|
||||||
|
self.assertEqual("Ethernet Switch Port Collection", self.port_col.name)
|
||||||
|
self.assertEqual(
|
||||||
|
("/redfish/v1/EthernetSwitches/Switch1/Ports/Port1",),
|
||||||
|
self.port_col.members_identities,
|
||||||
|
)
|
||||||
|
|
||||||
|
@mock.patch.object(
|
||||||
|
ethernet_switch_port, "EthernetSwitchPort", autospec=True
|
||||||
|
)
|
||||||
|
def test_get_member(self, mock_port):
|
||||||
|
self.port_col.get_member(
|
||||||
|
"/redfish/v1/EthernetSwitches/Switch1/Ports/Port1"
|
||||||
|
)
|
||||||
|
mock_port.assert_called_once_with(
|
||||||
|
self.port_col._conn,
|
||||||
|
"/redfish/v1/EthernetSwitches/Switch1/Ports/Port1",
|
||||||
|
redfish_version=self.port_col.redfish_version,
|
||||||
|
)
|
||||||
|
|
||||||
|
@mock.patch.object(
|
||||||
|
ethernet_switch_port, "EthernetSwitchPort", autospec=True
|
||||||
|
)
|
||||||
|
def test_get_members(self, mock_port):
|
||||||
|
members = self.port_col.get_members()
|
||||||
|
mock_port.assert_called_with(
|
||||||
|
self.port_col._conn,
|
||||||
|
"/redfish/v1/EthernetSwitches/Switch1/Ports/Port1",
|
||||||
|
redfish_version=self.port_col.redfish_version,
|
||||||
|
)
|
||||||
|
self.assertIsInstance(members, list)
|
||||||
|
self.assertEqual(1, len(members))
|
@ -18,30 +18,34 @@ import json
|
|||||||
import mock
|
import mock
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from rsd_lib.resources.v2_2.ethernet_switch import port_metrics
|
from rsd_lib.resources.v2_2.ethernet_switch import ethernet_switch_port_metrics
|
||||||
|
|
||||||
|
|
||||||
class PortMetricsTestCase(testtools.TestCase):
|
class PortMetricsTestCase(testtools.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(PortMetricsTestCase, self).setUp()
|
super(PortMetricsTestCase, self).setUp()
|
||||||
self.conn = mock.Mock()
|
self.conn = mock.Mock()
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
with open(
|
||||||
'ethernet_switch_port_metrics.json', 'r') as f:
|
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||||
|
"ethernet_switch_port_metrics.json",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
|
||||||
self.port_metrics_inst = port_metrics.PortMetrics(
|
self.port_metrics_inst = ethernet_switch_port_metrics.\
|
||||||
self.conn,
|
EthernetSwitchPortMetrics(
|
||||||
'/redfish/v1/EthernetSwitches/Switch1/Ports/Port1/Metrics',
|
self.conn,
|
||||||
redfish_version='1.1.0')
|
"/redfish/v1/EthernetSwitches/Switch1/Ports/Port1/Metrics",
|
||||||
|
redfish_version="1.1.0",
|
||||||
|
)
|
||||||
|
|
||||||
def test__parse_attributes(self):
|
def test__parse_attributes(self):
|
||||||
self.port_metrics_inst._parse_attributes()
|
self.port_metrics_inst._parse_attributes()
|
||||||
self.assertEqual('1.1.0', self.port_metrics_inst.redfish_version)
|
self.assertEqual("1.1.0", self.port_metrics_inst.redfish_version)
|
||||||
self.assertEqual('Ethernet Switch Port Metrics',
|
self.assertEqual(
|
||||||
self.port_metrics_inst.name)
|
"Ethernet Switch Port Metrics", self.port_metrics_inst.name
|
||||||
self.assertEqual('Metrics',
|
)
|
||||||
self.port_metrics_inst.identity)
|
self.assertEqual("Metrics", self.port_metrics_inst.identity)
|
||||||
|
|
||||||
self.assertEqual(8, self.port_metrics_inst.received.packets)
|
self.assertEqual(8, self.port_metrics_inst.received.packets)
|
||||||
self.assertEqual(5, self.port_metrics_inst.received.dropped_packets)
|
self.assertEqual(5, self.port_metrics_inst.received.dropped_packets)
|
||||||
@ -52,15 +56,17 @@ class PortMetricsTestCase(testtools.TestCase):
|
|||||||
self.assertEqual(64, self.port_metrics_inst.received.received_bytes)
|
self.assertEqual(64, self.port_metrics_inst.received.received_bytes)
|
||||||
|
|
||||||
self.assertEqual(128, self.port_metrics_inst.transmitted.packets)
|
self.assertEqual(128, self.port_metrics_inst.transmitted.packets)
|
||||||
self.assertEqual(
|
self.assertEqual(1, self.port_metrics_inst.transmitted.dropped_packets)
|
||||||
1, self.port_metrics_inst.transmitted.dropped_packets)
|
|
||||||
self.assertEqual(2, self.port_metrics_inst.transmitted.error_packets)
|
self.assertEqual(2, self.port_metrics_inst.transmitted.error_packets)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
3, self.port_metrics_inst.transmitted.broadcast_packets)
|
3, self.port_metrics_inst.transmitted.broadcast_packets
|
||||||
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
4, self.port_metrics_inst.transmitted.multicast_packets)
|
4, self.port_metrics_inst.transmitted.multicast_packets
|
||||||
|
)
|
||||||
self.assertEqual(5, self.port_metrics_inst.transmitted.errors)
|
self.assertEqual(5, self.port_metrics_inst.transmitted.errors)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
512, self.port_metrics_inst.transmitted.transmitted_bytes)
|
512, self.port_metrics_inst.transmitted.transmitted_bytes
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(0, self.port_metrics_inst.collisions)
|
self.assertEqual(0, self.port_metrics_inst.collisions)
|
@ -1,137 +0,0 @@
|
|||||||
# Copyright 2018 Intel, Inc.
|
|
||||||
# All Rights Reserved.
|
|
||||||
#
|
|
||||||
# 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 json
|
|
||||||
import mock
|
|
||||||
import testtools
|
|
||||||
|
|
||||||
from sushy import exceptions
|
|
||||||
|
|
||||||
from rsd_lib.resources.v2_2.ethernet_switch import port
|
|
||||||
from rsd_lib.resources.v2_2.ethernet_switch import port_metrics
|
|
||||||
|
|
||||||
|
|
||||||
class PortTestCase(testtools.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(PortTestCase, self).setUp()
|
|
||||||
self.conn = mock.Mock()
|
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
|
||||||
'ethernet_switch_port.json', 'r') as f:
|
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
|
||||||
|
|
||||||
self.port_inst = port.Port(
|
|
||||||
self.conn, '/redfish/v1/EthernetSwitches/Switch1/Ports/Port1',
|
|
||||||
redfish_version='1.0.2')
|
|
||||||
|
|
||||||
def test__get_metrics_path(self):
|
|
||||||
self.assertEqual(
|
|
||||||
'/redfish/v1/EthernetSwitches/Switch1/Ports/Port1/Metrics',
|
|
||||||
self.port_inst._get_metrics_path())
|
|
||||||
|
|
||||||
def test__get_metrics_path_missing_ports_attr(self):
|
|
||||||
self.port_inst._json.pop('Metrics')
|
|
||||||
with self.assertRaisesRegex(
|
|
||||||
exceptions.MissingAttributeError, 'attribute Metrics'):
|
|
||||||
self.port_inst._get_metrics_path()
|
|
||||||
|
|
||||||
def test_metrics(self):
|
|
||||||
# | GIVEN |
|
|
||||||
self.conn.get.return_value.json.reset_mock()
|
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
|
||||||
'ethernet_switch_port_metrics.json', 'r') as f:
|
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
|
||||||
# | WHEN |
|
|
||||||
actual_metrics = self.port_inst.metrics
|
|
||||||
# | THEN |
|
|
||||||
self.assertIsInstance(actual_metrics,
|
|
||||||
port_metrics.PortMetrics)
|
|
||||||
self.conn.get.return_value.json.assert_called_once_with()
|
|
||||||
|
|
||||||
# reset mock
|
|
||||||
self.conn.get.return_value.json.reset_mock()
|
|
||||||
# | WHEN & THEN |
|
|
||||||
# tests for same object on invoking subsequently
|
|
||||||
self.assertIs(actual_metrics,
|
|
||||||
self.port_inst.metrics)
|
|
||||||
self.conn.get.return_value.json.assert_not_called()
|
|
||||||
|
|
||||||
def test_metrics_on_refresh(self):
|
|
||||||
# | GIVEN |
|
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
|
||||||
'ethernet_switch_port_metrics.json', 'r') as f:
|
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
|
||||||
# | WHEN & THEN |
|
|
||||||
self.assertIsInstance(self.port_inst.metrics,
|
|
||||||
port_metrics.PortMetrics)
|
|
||||||
|
|
||||||
# On refreshing the port instance...
|
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
|
||||||
'ethernet_switch_port.json', 'r') as f:
|
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
|
||||||
|
|
||||||
self.port_inst.invalidate()
|
|
||||||
self.port_inst.refresh(force=False)
|
|
||||||
|
|
||||||
# | GIVEN |
|
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
|
||||||
'ethernet_switch_port_metrics.json', 'r') as f:
|
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
|
||||||
# | WHEN & THEN |
|
|
||||||
self.assertIsInstance(self.port_inst.metrics,
|
|
||||||
port_metrics.PortMetrics)
|
|
||||||
|
|
||||||
|
|
||||||
class PortCollectionTestCase(testtools.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(PortCollectionTestCase, self).setUp()
|
|
||||||
self.conn = mock.Mock()
|
|
||||||
with open(
|
|
||||||
'rsd_lib/tests/unit/json_samples/v2_2/'
|
|
||||||
'ethernet_switch_port_collection.json', 'r') as f:
|
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
|
||||||
self.port_col = port.PortCollection(
|
|
||||||
self.conn, '/redfish/v1/EthernetSwitches/Switch1/Ports',
|
|
||||||
redfish_version='1.0.2')
|
|
||||||
|
|
||||||
def test__parse_attributes(self):
|
|
||||||
self.port_col._parse_attributes()
|
|
||||||
self.assertEqual('1.0.2', self.port_col.redfish_version)
|
|
||||||
self.assertEqual(
|
|
||||||
'Ethernet Switch Port Collection',
|
|
||||||
self.port_col.name)
|
|
||||||
self.assertEqual(
|
|
||||||
('/redfish/v1/EthernetSwitches/Switch1/Ports/Port1',),
|
|
||||||
self.port_col.members_identities)
|
|
||||||
|
|
||||||
@mock.patch.object(port, 'Port', autospec=True)
|
|
||||||
def test_get_member(self, mock_port):
|
|
||||||
self.port_col.get_member(
|
|
||||||
'/redfish/v1/EthernetSwitches/Switch1/Ports/Port1')
|
|
||||||
mock_port.assert_called_once_with(
|
|
||||||
self.port_col._conn,
|
|
||||||
'/redfish/v1/EthernetSwitches/Switch1/Ports/Port1',
|
|
||||||
redfish_version=self.port_col.redfish_version)
|
|
||||||
|
|
||||||
@mock.patch.object(port, 'Port', autospec=True)
|
|
||||||
def test_get_members(self, mock_port):
|
|
||||||
members = self.port_col.get_members()
|
|
||||||
mock_port.assert_called_with(
|
|
||||||
self.port_col._conn,
|
|
||||||
'/redfish/v1/EthernetSwitches/Switch1/Ports/Port1',
|
|
||||||
redfish_version=self.port_col.redfish_version)
|
|
||||||
self.assertIsInstance(members, list)
|
|
||||||
self.assertEqual(1, len(members))
|
|
Loading…
x
Reference in New Issue
Block a user