Skip to content

Commit

Permalink
Merge pull request #262 from tanjiangyu-ghca/unity_0916
Browse files Browse the repository at this point in the history
change port speed and disk name
  • Loading branch information
tanjiangyu-ghca authored Sep 28, 2021
2 parents ab1bc35 + 2ac74fb commit cf27b5d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 22 deletions.
4 changes: 3 additions & 1 deletion delfin/drivers/dell_emc/unity/alert_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ def parse_queried_alerts(self, alert_model_list, alert_dict, query_para):
alert_model['description'] = content.get('description')
alert_model['resource_type'] = resource_type
alert_model['location'] = location
alert_model_list.append(alert_model)
alert_model['match_key'] = hashlib.md5(
content.get('message').encode()).hexdigest()
if alert_model['severity'] == 'Informational':
continue
alert_model_list.append(alert_model)
except Exception as e:
LOG.error(e)
err_msg = "Failed to build alert model as some attributes " \
Expand Down
2 changes: 2 additions & 0 deletions delfin/drivers/dell_emc/unity/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.

DEFAULT_TIMEOUT = 10
ALERT_TIMEOUT = 20
TRAP_DESC = {
"1:127486a": ["WARNING", "ALRT_LCC_FW_UPGRADE_FAILED",
"The link control card (LCC) will continue to function with "
Expand Down
34 changes: 24 additions & 10 deletions delfin/drivers/dell_emc/unity/rest_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from delfin import cryptor
from delfin import exception
from delfin.drivers.dell_emc.unity import consts
from delfin.drivers.utils.rest_client import RestClient

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -63,7 +64,8 @@ def login(self):
self.session.auth = requests.auth.HTTPBasicAuth(
self.rest_username, cryptor.decode(self.rest_password))
res = self.call_with_token(
RestHandler.REST_AUTH_URL, data, 'GET')
RestHandler.REST_AUTH_URL, data, 'GET',
consts.DEFAULT_TIMEOUT)
if res.status_code == 200:
self.session.headers[RestHandler.AUTH_KEY] = \
cryptor.encode(res.headers[RestHandler.AUTH_KEY])
Expand All @@ -81,44 +83,47 @@ def login(self):
LOG.error("Login error: %s", six.text_type(e))
raise e

def call_with_token(self, url, data, method):
def call_with_token(self, url, data, method, calltimeout):
auth_key = None
if self.session:
auth_key = self.session.headers.get(RestHandler.AUTH_KEY, None)
if auth_key:
self.session.headers[RestHandler.AUTH_KEY] \
= cryptor.decode(auth_key)
res = self.do_call(url, data, method)
res = self.do_call(url, data, method, calltimeout)
if auth_key:
self.session.headers[RestHandler.AUTH_KEY] = auth_key
return res

def logout(self):
try:
if self.san_address:
self.call(RestHandler.REST_LOGOUT_URL, method='POST')
self.call(RestHandler.REST_LOGOUT_URL,
consts.DEFAULT_TIMEOUT,
data={}, method='POST')
if self.session:
self.session.close()
except Exception as e:
err_msg = "Logout error: %s" % (six.text_type(e))
LOG.error(err_msg)
raise e

def get_rest_info(self, url, data=None, method='GET'):
def get_rest_info(self, url, data=None, method='GET',
calltimeout=consts.DEFAULT_TIMEOUT):
result_json = None
res = self.call(url, data, method)
res = self.call(url, calltimeout, data, method)
if res.status_code == 200:
result_json = res.json()
return result_json

def call(self, url, data=None, method=None):
def call(self, url, calltimeout, data=None, method=None):
try:
res = self.call_with_token(url, data, method)
res = self.call_with_token(url, data, method, calltimeout)
if res.status_code == 401:
LOG.error("Failed to get token, status_code:%s,error_mesg:%s" %
(res.status_code, res.text))
self.login()
res = self.call_with_token(url, data, method)
res = self.call_with_token(url, data, method, calltimeout)
elif res.status_code == 503:
raise exception.InvalidResults(res.text)
return res
Expand Down Expand Up @@ -167,7 +172,16 @@ def get_all_alerts(self, page_number):
'messageId,message,description,'
'descriptionId,state',
page_number)
result_json = self.get_rest_info(url)
result_json = self.get_rest_info(url, consts.ALERT_TIMEOUT)
return result_json

def get_all_alerts_without_state(self, page_number):
url = '%s?%s&page=%s' % (RestHandler.REST_ALERTS_URL,
'fields=id,timestamp,severity,component,'
'messageId,message,description,'
'descriptionId',
page_number)
result_json = self.get_rest_info(url, consts.ALERT_TIMEOUT)
return result_json

def remove_alert(self, alert_id):
Expand Down
12 changes: 9 additions & 3 deletions delfin/drivers/dell_emc/unity/unity.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ def list_alerts(self, context, query_para=None):
alert_model_list = []
while True:
alert_list = self.rest_handler.get_all_alerts(page_number)
if not alert_list:
alert_list = self.rest_handler.get_all_alerts_without_state(
page_number)
if alert_list is None:
break
if 'entries' not in alert_list:
Expand Down Expand Up @@ -282,7 +285,8 @@ def get_eth_ports(self):
'health_status': status,
'type': constants.PortType.ETH,
'logical_type': '',
'max_speed': int(content.get('speed')) * units.Mi,
'speed': int(content.get('speed')) * units.M,
'max_speed': int(content.get('speed')) * units.M,
'native_parent_id':
content.get('storageProcessor', {}).get('id'),
'wwn': '',
Expand Down Expand Up @@ -326,8 +330,10 @@ def get_fc_ports(self):
'health_status': status,
'type': constants.PortType.FC,
'logical_type': '',
'speed': int(
content.get('currentSpeed', 0)) * units.G,
'max_speed': int(
content.get('currentSpeed', 0)) * units.Gi,
content.get('currentSpeed', 0)) * units.G,
'native_parent_id':
content.get('storageProcessor', {}).get('id'),
'wwn': content.get('wwn')
Expand Down Expand Up @@ -376,7 +382,7 @@ def list_disks(self, context):
'logical_type': '',
'native_disk_group_id':
content.get('diskGroup', {}).get('id'),
'location': content.get('slotNumber')
'location': content.get('name')
}
disk_list.append(disk_result)
return disk_list
Expand Down
22 changes: 14 additions & 8 deletions delfin/tests/unit/drivers/dell_emc/unity/test_emc_unity.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@
'physical_type': 'sas',
'logical_type': '',
'native_disk_group_id': 'dp1',
'location': 12
'location': 'disk1'
}
]
GET_ALL_ETHPORTS = {
Expand Down Expand Up @@ -667,7 +667,8 @@
'health_status': 'normal',
'type': 'eth',
'logical_type': '',
'max_speed': 10485760000,
'speed': 10000000000,
'max_speed': 10000000000,
'native_parent_id': 'spa',
'wwn': '',
'mac_address': '00:50:56:81:E1:50',
Expand All @@ -684,7 +685,8 @@
'health_status': 'normal',
'type': 'eth',
'logical_type': '',
'max_speed': 10485760000,
'speed': 10000000000,
'max_speed': 10000000000,
'native_parent_id': 'spa',
'wwn': '',
'mac_address': '00:50:56:81:E8:4B',
Expand All @@ -701,7 +703,8 @@
'health_status': 'normal',
'type': 'eth',
'logical_type': '',
'max_speed': 10485760000,
'speed': 10000000000,
'max_speed': 10000000000,
'native_parent_id': 'spa',
'wwn': '',
'mac_address': '00:50:56:81:11:EF',
Expand All @@ -718,7 +721,8 @@
'health_status': 'normal',
'type': 'eth',
'logical_type': '',
'max_speed': 10485760000,
'speed': 10000000000,
'max_speed': 10000000000,
'native_parent_id': 'spa',
'wwn': '',
'mac_address': '00:50:56:81:DB:5D',
Expand All @@ -735,7 +739,8 @@
'health_status': 'normal',
'type': 'eth',
'logical_type': '',
'max_speed': 10485760000,
'speed': 10000000000,
'max_speed': 10000000000,
'native_parent_id': 'spa',
'wwn': '',
'mac_address': '00:50:56:81:E5:05',
Expand All @@ -752,7 +757,8 @@
'health_status': 'normal',
'type': 'fc',
'logical_type': '',
'max_speed': 10737418240,
'speed': 10000000000,
'max_speed': 10000000000,
'native_parent_id': 'spa',
'wwn': 'fffffffffff'
}
Expand Down Expand Up @@ -1394,7 +1400,7 @@ def test_call_and_login(self, mock_token):
self.assertIn('Exception from Storage Backend', str(exc.exception))
RestHandler.login = mock.Mock(return_value=None)
mock_token.return_value = mock.MagicMock(status_code=401)
UnityStorDriver(**ACCESS_INFO).rest_handler.call('')
UnityStorDriver(**ACCESS_INFO).rest_handler.call('', 20)

@mock.patch.object(RestHandler, 'call')
def test_get_rest_info(self, mock_rest):
Expand Down

0 comments on commit cf27b5d

Please sign in to comment.