Skip to content

Commit

Permalink
[GH-22] Unity ethernet port modification support
Browse files Browse the repository at this point in the history
Support modifying the speed and mtu of the ethernet ports on unity system
  • Loading branch information
Tianqi-Tang committed Sep 22, 2016
1 parent 47f4b56 commit 4d14573
Show file tree
Hide file tree
Showing 10 changed files with 467 additions and 6 deletions.
8 changes: 8 additions & 0 deletions storops/exception.py
Expand Up @@ -391,6 +391,14 @@ class UnityFileSystemSizeTooSmallError(UnityException):
error_code = 108008449


class UnityEthernetPortMtuSizeNotSupportError(UnityException):
message = "Specified MTU size is not supported."


class UnityEthernetPortSpeedNotSupportError(UnityException):
message = "Specified Speed is not supported."


class UnityShareTypeNotSupportAccessControlError(UnityException):
message = 'share type does not support access control.'

Expand Down
4 changes: 3 additions & 1 deletion storops/lib/resource.py
Expand Up @@ -158,7 +158,9 @@ def _get_properties(self, dec=0):
elif isinstance(value, (datetime, timedelta)):
value = str(value)
elif isinstance(value, (tuple, list, set)):
value = [v.get_dict_repr(dec - 1) for v in value]
value = [v.get_dict_repr(dec - 1)
if isinstance(v, JsonPrinter) else v
for v in value]
props[name] = value
except AttributeError:
# skip not available attributes
Expand Down
40 changes: 39 additions & 1 deletion storops/unity/resource/port.py
Expand Up @@ -18,6 +18,9 @@
import logging

from storops.unity.resource import UnityResource, UnityResourceList
from storops.exception import UnityEthernetPortMtuSizeNotSupportError
from storops.exception import UnityEthernetPortSpeedNotSupportError
from storops.unity.enums import EPSpeedValuesEnum

__author__ = 'Jay Xu'

Expand Down Expand Up @@ -85,7 +88,42 @@ def get_resource_class(cls):


class UnityEthernetPort(UnityResource):
pass
def modify(self, speed=None, mtu=None):
speed = EPSpeedValuesEnum.parse(speed)
peer = self.get_peer()
self._modify(self, speed, mtu)
self._modify(peer, speed, mtu)

def get_peer(self):
_peer_id = self._get_peer_id(self.get_id())
return UnityEthernetPort(cli=self._cli, _id=_peer_id)

def _modify(self, port, speed, mtu):
if speed is not None:
if speed not in self.supported_speeds:
raise UnityEthernetPortSpeedNotSupportError
if speed == port.requested_speed:
speed = None

if mtu is not None:
if mtu not in self.supported_mtus:
raise UnityEthernetPortMtuSizeNotSupportError
if mtu == port.requested_mtu:
mtu = None

if speed is None and mtu is None:
return

resp = self._cli.modify(self.resource_class,
port.get_id(),
speed=speed, mtuSize=mtu)
resp.raise_if_err()

@staticmethod
def _get_peer_id(_id):
if _id.startswith('spa'):
return _id.replace('spa', 'spb')
return _id.replace('spb', 'spa')


class UnityEthernetPortList(UnityResourceList):
Expand Down
3 changes: 2 additions & 1 deletion test-requirements.txt
Expand Up @@ -8,4 +8,5 @@ pytest-xdist>=1.13.1
pytest-capturelog>=0.7
xmltodict>=0.9.2
cobertura-clover-transform>=1.1.4
fasteners>=0.12.0
fasteners>=0.12.0
ddt>=1.0.1 # MIT
79 changes: 76 additions & 3 deletions test/unity/resource/test_port.py
Expand Up @@ -17,9 +17,13 @@

from unittest import TestCase

from hamcrest import assert_that, equal_to, instance_of

from storops.unity.resource.port import UnityIpPort, UnityIpPortList
import ddt
from hamcrest import assert_that, equal_to, instance_of, only_contains, raises
from storops.exception import UnityEthernetPortSpeedNotSupportError, \
UnityEthernetPortMtuSizeNotSupportError
from storops.unity.enums import ConnectorTypeEnum, EPSpeedValuesEnum
from storops.unity.resource.port import UnityEthernetPort, UnityIpPort, \
UnityIpPortList
from storops.unity.resource.sp import UnityStorageProcessor
from test.unity.rest_mock import t_rest, patch_rest

Expand All @@ -40,3 +44,72 @@ def test_get_properties(self):
def test_get_all(self):
ports = UnityIpPortList(cli=t_rest())
assert_that(len(ports), equal_to(8))


@ddt.ddt
class UnityEthernetPortTest(TestCase):
@patch_rest
def test_get_properties(self):
port = UnityEthernetPort('spa_eth3', cli=t_rest())
assert_that(port.name, equal_to('SP A Ethernet Port 3'))
assert_that(port.mac_address, equal_to("00:60:16:5C:07:0A"))
assert_that(port.parent_storage_processor, equal_to(
UnityStorageProcessor('spa', cli=t_rest())))
assert_that(port.mtu, equal_to(1500))
assert_that(port.requested_mtu, equal_to(1500))
assert_that(port.connector_type, equal_to(ConnectorTypeEnum.RJ45))
assert_that(port.supported_speeds, only_contains(
EPSpeedValuesEnum.AUTO,
EPSpeedValuesEnum._100MbPS,
EPSpeedValuesEnum._1GbPS,
EPSpeedValuesEnum._10GbPS))
assert_that(port.supported_mtus, only_contains(1500, 9000))
assert_that(port.speed, equal_to(None))
assert_that(port.needs_replacement, equal_to(False))
assert_that(port.is_link_up, equal_to(False))
assert_that(port.bond, equal_to(False))

@patch_rest
def test_modify_mtu(self):
port = UnityEthernetPort(cli=t_rest(), _id='spa_eth3')
port.modify(mtu=9000)

@patch_rest
def test_modify_mtu_to_invalid_value(self):
def do():
port = UnityEthernetPort(cli=t_rest(), _id='spb_eth3')
port.modify(mtu=10000)

assert_that(do, raises(UnityEthernetPortMtuSizeNotSupportError))

@patch_rest
def test_modify_mtu_to_same_value(self):
port = UnityEthernetPort(cli=t_rest(), _id='spb_eth3')
port.modify(mtu=1500)

@patch_rest
def test_modify_speed(self):
port = UnityEthernetPort(cli=t_rest(), _id='spa_eth3')
port.modify(speed=100)

@patch_rest
def test_modify_speed_to_same_value(self):
port = UnityEthernetPort(cli=t_rest(), _id='spb_eth3')
port.modify(speed=EPSpeedValuesEnum.AUTO)

@patch_rest
def test_modify_speed_to_invalid_value(self):
def do():
port = UnityEthernetPort(cli=t_rest(), _id='spb_eth3')
port.modify(speed=40000)
assert_that(do, raises(UnityEthernetPortSpeedNotSupportError))

@ddt.data({'port_id': 'spa_eth2',
'peer_id': 'spb_eth2'},
{'port_id': 'spb_eth3',
'peer_id': 'spa_eth3'})
@ddt.unpack
def test_get_peer(self, port_id, peer_id):
port = UnityEthernetPort(cli=t_rest(), _id=port_id)
peer = port.get_peer()
assert_that(peer.get_id(), equal_to(peer_id))
44 changes: 44 additions & 0 deletions test/unity/rest_data/ethernetPort/index.json
@@ -0,0 +1,44 @@
{
"indices": [
{
"url": "/api/types/ethernetPort?compact=True&fields=attributes.description,attributes.displayValue,attributes.initialValue,attributes.name,attributes.type,description,documentation,name,type",
"response": "type.json"
},
{
"url": "/api/instances/ethernetPort/spa_eth3?compact=True&fields=bond,cascadeNames,connectorType,health,id,instanceId,isLinkUp,isRDMACapable,isRSSCapable,linuxDeviceName,macAddress,mtu,name,needsReplacement,operationalStatus,parent,parentIOModule,parentStorageProcessor,portNumber,requestedMtu,requestedSpeed,sfpSupportedProtocols,sfpSupportedSpeeds,shortName,speed,storageProcessor,supportedMtus,supportedSpeeds",
"response": "spa_eth3.json"
},
{
"url": "/api/instances/ethernetPort/spb_eth3?compact=True&fields=bond,cascadeNames,connectorType,health,id,instanceId,isLinkUp,isRDMACapable,isRSSCapable,linuxDeviceName,macAddress,mtu,name,needsReplacement,operationalStatus,parent,parentIOModule,parentStorageProcessor,portNumber,requestedMtu,requestedSpeed,sfpSupportedProtocols,sfpSupportedSpeeds,shortName,speed,storageProcessor,supportedMtus,supportedSpeeds",
"response": "spb_eth3.json"
},
{
"url": "/api/instances/ethernetPort/spa_eth3/action/modify?compact=True",
"body": {
"mtuSize": 9000
},
"response": "success.json"
},
{
"url": "/api/instances/ethernetPort/spb_eth3/action/modify?compact=True",
"body": {
"mtuSize": 9000
},
"response": "success.json"
},
{
"url": "/api/instances/ethernetPort/spb_eth3/action/modify?compact=True",
"body": {
"speed": 100
},
"response": "success.json"
},
{
"url": "/api/instances/ethernetPort/spa_eth3/action/modify?compact=True",
"body": {
"speed": 100
},
"response": "success.json"
}
]
}
59 changes: 59 additions & 0 deletions test/unity/rest_data/ethernetPort/spa_eth3.json
@@ -0,0 +1,59 @@
{
"content": {
"macAddress": "00:60:16:5C:07:0A",
"isRDMACapable": false,
"parentStorageProcessor": {
"id": "spa"
},
"instanceId": "root/emc:EMC_UEM_EthernetPortLeaf%Tag=03:00:00:01",
"portNumber": 3,
"cascadeNames": [
"Ethernet Port 3",
"SP A"
],
"requestedMtu": 1500,
"mtu": 1500,
"connectorType": 1,
"id": "spa_eth3",
"supportedSpeeds": [
1000,
10000,
100,
0
],
"supportedMtus": [
1500,
9000
],
"storageProcessor": {
"id": "spa"
},
"health": {
"descriptionIds": [
"ALRT_PORT_LINK_DOWN_NOT_IN_USE"
],
"descriptions": [
"The port link is down, but not in use. No action is required."
],
"value": 5
},
"parent": {
"resource": "storageProcessor",
"id": "spa"
},
"needsReplacement": false,
"sfpSupportedSpeeds": [],
"sfpSupportedProtocols": [],
"operationalStatus": [
2,
32785
],
"shortName": "Ethernet Port 3",
"requestedSpeed": 0,
"isRSSCapable": false,
"name": "SP A Ethernet Port 3",
"linuxDeviceName": "eth3",
"isLinkUp": false,
"bond": false
}
}
59 changes: 59 additions & 0 deletions test/unity/rest_data/ethernetPort/spb_eth3.json
@@ -0,0 +1,59 @@
{
"content": {
"macAddress": "00:60:16:5C:05:FE",
"isRDMACapable": false,
"parentStorageProcessor": {
"id": "spb"
},
"instanceId": "root/emc:EMC_UEM_EthernetPortLeaf%Tag=03:00:01:01",
"portNumber": 3,
"cascadeNames": [
"Ethernet Port 3",
"SP B"
],
"requestedMtu": 1500,
"mtu": 1500,
"connectorType": 1,
"id": "spb_eth3",
"supportedSpeeds": [
1000,
10000,
100,
0
],
"supportedMtus": [
1500,
9000
],
"storageProcessor": {
"id": "spb"
},
"health": {
"descriptionIds": [
"ALRT_PORT_LINK_DOWN_NOT_IN_USE"
],
"descriptions": [
"The port link is down, but not in use. No action is required."
],
"value": 5
},
"parent": {
"resource": "storageProcessor",
"id": "spb"
},
"needsReplacement": false,
"sfpSupportedSpeeds": [],
"sfpSupportedProtocols": [],
"operationalStatus": [
2,
32785
],
"shortName": "Ethernet Port 3",
"requestedSpeed": 0,
"isRSSCapable": false,
"name": "SP B Ethernet Port 3",
"linuxDeviceName": "eth3",
"isLinkUp": false,
"bond": false
}
}
Empty file.

0 comments on commit 4d14573

Please sign in to comment.