tox ok, externalization from Ironic has been done
This commit is contained in:
@@ -4,3 +4,4 @@
|
||||
|
||||
pbr>=0.6,!=0.7,<1.0
|
||||
Babel>=1.3
|
||||
requests>=2.2.0,!=2.4.0
|
||||
|
0
scciclient/irmc/__init__.py
Normal file
0
scciclient/irmc/__init__.py
Normal file
@@ -1,3 +1,4 @@
|
||||
# Copyright 2015 FUJITSU LIMITED
|
||||
#
|
||||
# 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
|
||||
@@ -20,8 +21,35 @@ import xml.etree.ElementTree as ET
|
||||
|
||||
import requests
|
||||
|
||||
from ironic.common import exception
|
||||
from ironic.common.i18n import _
|
||||
|
||||
class SCCIError(Exception):
|
||||
"""SCCI Error
|
||||
|
||||
This exception is gerenral excetion.
|
||||
"""
|
||||
def __init__(self, message, errorcode=None):
|
||||
super(SCCIError, self).__init__(message)
|
||||
|
||||
|
||||
class SCCIInvalidInputError(SCCIError):
|
||||
"""SCCIInvalidInputError
|
||||
|
||||
This exception is used when invalid inputs are passed to
|
||||
the APIs exposed by this module.
|
||||
"""
|
||||
def __init__(self, message):
|
||||
super(SCCIInvalidInputError, self).__init__(message)
|
||||
|
||||
|
||||
class SCCIClientError(SCCIError):
|
||||
"""SCCIClientError
|
||||
|
||||
This exception is used when a problem is encountered in
|
||||
executing an operation on the iRMC
|
||||
"""
|
||||
def __init__(self, message):
|
||||
super(SCCIClientError, self).__init__(message)
|
||||
|
||||
|
||||
"""
|
||||
List of iRMC S4 supported SCCI commands
|
||||
@@ -183,9 +211,9 @@ def scci_cmd(host, userid, password, cmd,
|
||||
:param auth_method: irmc_username
|
||||
:param client_timeout: timeout for SCCI operations
|
||||
:returns: requests.Response from SCCI server
|
||||
:raises: InvalidParameterValue if port and/or auth_method params
|
||||
:raises: SCCIInvalidInputError if port and/or auth_method params
|
||||
are invalid
|
||||
:raises: IRMCClientError if SCCI failed
|
||||
:raises: SCCIClientError if SCCI failed
|
||||
"""
|
||||
|
||||
auth_obj = None
|
||||
@@ -197,9 +225,9 @@ def scci_cmd(host, userid, password, cmd,
|
||||
}[auth_method.lower()]
|
||||
|
||||
except KeyError:
|
||||
raise exception.InvalidParameterValue(
|
||||
_("Invalid port %(port)d or "
|
||||
"auth_method for method %(auth_method)s") %
|
||||
raise SCCIInvalidInputError(
|
||||
("Invalid port %(port)d or " +
|
||||
"auth_method for method %(auth_method)s") %
|
||||
{'port': port, 'auth_method': auth_method})
|
||||
|
||||
try:
|
||||
@@ -211,27 +239,26 @@ def scci_cmd(host, userid, password, cmd,
|
||||
auth=auth_obj)
|
||||
|
||||
if r.status_code not in (200, 201):
|
||||
raise exception.IRMCClientError(
|
||||
operation=cmd,
|
||||
error='http status = ' + str(r.status_code))
|
||||
raise SCCIClientError(
|
||||
('HTTP PROTOCOL ERROR, STATUS CODE = %s' %
|
||||
str(r.status_code)))
|
||||
|
||||
result_xml = ET.fromstring(r.text)
|
||||
status = result_xml.find("./Value")
|
||||
# severity = result_xml.find("./Severity")
|
||||
# message = result_xml.find("./Message")
|
||||
if not int(status.text) == 0:
|
||||
raise exception.IRMCClientError(operation=cmd,
|
||||
error=result_xml.text)
|
||||
raise SCCIClientError(
|
||||
('SCCI PROTOCOL ERROR, STATUS CODE = %s' %
|
||||
str(status.text)))
|
||||
else:
|
||||
return r
|
||||
|
||||
except ET.ParseError as parse_error:
|
||||
raise exception.IRMCClientError(operation=cmd,
|
||||
error=parse_error)
|
||||
raise SCCIClientError(parse_error)
|
||||
|
||||
except requests.exceptions.RequestException as requests_exception:
|
||||
raise exception.IRMCClientError(operation=cmd,
|
||||
error=requests_exception)
|
||||
raise SCCIClientError(requests_exception)
|
||||
|
||||
|
||||
def get_client(host, userid, password,
|
||||
@@ -328,9 +355,9 @@ def get_report(host, userid, password,
|
||||
:param auth_method: irmc_username
|
||||
:param client_timeout: timeout for SCCI operations
|
||||
:returns: root element of SCCI report
|
||||
:raises: InvalidParameterValue if port and/or auth_method params
|
||||
:raises: ISCCIInvalidInputError if port and/or auth_method params
|
||||
are invalid
|
||||
:raises: IRMCClientError if SCCI failed
|
||||
:raises: SCCIClientError if SCCI failed
|
||||
"""
|
||||
|
||||
auth_obj = None
|
||||
@@ -342,9 +369,9 @@ def get_report(host, userid, password,
|
||||
}[auth_method.lower()]
|
||||
|
||||
except KeyError:
|
||||
raise exception.InvalidParameterValue(
|
||||
_("Invalid port %(port)d or "
|
||||
"auth_method for method %(auth_method)s"),
|
||||
raise SCCIInvalidInputError(
|
||||
("Invalid port %(port)d or " +
|
||||
"auth_method for method %(auth_method)s") %
|
||||
{'port': port, 'auth_method': auth_method})
|
||||
|
||||
try:
|
||||
@@ -355,17 +382,18 @@ def get_report(host, userid, password,
|
||||
auth=auth_obj)
|
||||
|
||||
if r.status_code not in (200, 201):
|
||||
raise exception.IRMCClientError(
|
||||
operation='get_report()',
|
||||
error='http status = ' + str(r.status_code))
|
||||
raise SCCIClientError(
|
||||
('HTTP PROTOCOL ERROR, STATUS CODE = %s' %
|
||||
str(r.status_code)))
|
||||
|
||||
# pprint.pprint(r.text)
|
||||
root = ET.fromstring(r.text)
|
||||
return root
|
||||
|
||||
except ET.ParseError as parse_error:
|
||||
raise SCCIClientError(parse_error)
|
||||
|
||||
except requests.exceptions.RequestException as requests_exception:
|
||||
raise exception.IRMCClientError(operation='get_report()',
|
||||
error=requests_exception)
|
||||
raise SCCIClientError(requests_exception)
|
||||
|
||||
|
||||
def get_sensor_data_records(report):
|
||||
|
@@ -1,23 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2010-2011 OpenStack Foundation
|
||||
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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 oslotest import base
|
||||
|
||||
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
"""Test case base class for all unit tests."""
|
0
scciclient/tests/irmc/__init__.py
Normal file
0
scciclient/tests/irmc/__init__.py
Normal file
@@ -23,8 +23,7 @@ import mock
|
||||
import requests
|
||||
import testtools
|
||||
|
||||
from ironic.common import exception
|
||||
from ironic.drivers.modules.irmc import scci
|
||||
from scciclient.irmc import scci
|
||||
|
||||
|
||||
class SCCITestCase(testtools.TestCase):
|
||||
@@ -123,7 +122,7 @@ class SCCITestCase(testtools.TestCase):
|
||||
'https://github.com', verify=False)
|
||||
self.assertEqual("'member_descriptor' object is not callable", str(e))
|
||||
|
||||
@mock.patch('ironic.drivers.modules.irmc.scci.requests')
|
||||
@mock.patch('scciclient.irmc.scci.requests')
|
||||
def test_scci_cmd_protocol_https_ok(self, mock_requests):
|
||||
https_port = 443
|
||||
mock_requests.post.return_value = mock.Mock(
|
||||
@@ -203,7 +202,7 @@ class SCCITestCase(testtools.TestCase):
|
||||
body="401 Unauthorized",
|
||||
status=401)
|
||||
|
||||
e = self.assertRaises(exception.IRMCClientError,
|
||||
e = self.assertRaises(scci.SCCIClientError,
|
||||
scci.scci_cmd,
|
||||
self.irmc_address,
|
||||
self.irmc_username,
|
||||
@@ -214,13 +213,12 @@ class SCCITestCase(testtools.TestCase):
|
||||
client_timeout=self.irmc_client_timeout)
|
||||
|
||||
self.assertEqual(
|
||||
'iRMC SCCI %(operation)s failed. Reason: %(error)s' %
|
||||
{'operation': scci.POWER_ON, 'error': 'http status = 401'},
|
||||
'HTTP PROTOCOL ERROR, STATUS CODE = 401',
|
||||
str(e))
|
||||
|
||||
def test_scci_cmd_protocol_ng(self):
|
||||
ssh_port = 22
|
||||
e = self.assertRaises(exception.InvalidParameterValue,
|
||||
e = self.assertRaises(scci.SCCIInvalidInputError,
|
||||
scci.scci_cmd,
|
||||
self.irmc_address,
|
||||
self.irmc_username,
|
||||
@@ -236,7 +234,7 @@ class SCCITestCase(testtools.TestCase):
|
||||
|
||||
def test_scci_cmd_auth_method_ng(self):
|
||||
unknown_auth_method = 'unknown'
|
||||
e = self.assertRaises(exception.InvalidParameterValue,
|
||||
e = self.assertRaises(scci.SCCIInvalidInputError,
|
||||
scci.scci_cmd,
|
||||
self.irmc_address,
|
||||
self.irmc_username,
|
||||
@@ -277,13 +275,11 @@ class SCCITestCase(testtools.TestCase):
|
||||
auth_method=self.irmc_auth_method,
|
||||
client_timeout=self.irmc_client_timeout)
|
||||
|
||||
e = self.assertRaises(exception.IRMCClientError,
|
||||
e = self.assertRaises(scci.SCCIClientError,
|
||||
client,
|
||||
scci.POWER_ON)
|
||||
self.assertEqual(
|
||||
'iRMC SCCI %(operation)s failed. Reason: %(error)s' %
|
||||
{'operation': scci.POWER_ON,
|
||||
'error': "not well-formed (invalid token): line 10, column 41"},
|
||||
'not well-formed (invalid token): line 10, column 41',
|
||||
str(e))
|
||||
|
||||
@httpretty.activate
|
||||
@@ -300,12 +296,11 @@ class SCCITestCase(testtools.TestCase):
|
||||
auth_method=self.irmc_auth_method,
|
||||
client_timeout=self.irmc_client_timeout)
|
||||
|
||||
e = self.assertRaises(exception.IRMCClientError,
|
||||
e = self.assertRaises(scci.SCCIClientError,
|
||||
client,
|
||||
scci.POWER_ON)
|
||||
self.assertEqual(
|
||||
'iRMC SCCI %(operation)s failed. Reason: %(error)s' %
|
||||
{'operation': scci.POWER_ON, 'error': 'http status = 302'},
|
||||
'HTTP PROTOCOL ERROR, STATUS CODE = 302',
|
||||
str(e))
|
||||
|
||||
@httpretty.activate
|
||||
@@ -417,7 +412,7 @@ class SCCITestCase(testtools.TestCase):
|
||||
content_type="application/x-www-form-urlencoded",
|
||||
status=302)
|
||||
|
||||
e = self.assertRaises(exception.IRMCClientError,
|
||||
e = self.assertRaises(scci.SCCIClientError,
|
||||
scci.get_report,
|
||||
self.irmc_address,
|
||||
self.irmc_username,
|
||||
@@ -426,8 +421,7 @@ class SCCITestCase(testtools.TestCase):
|
||||
auth_method=self.irmc_auth_method,
|
||||
client_timeout=self.irmc_client_timeout)
|
||||
self.assertEqual(
|
||||
'iRMC SCCI %(operation)s failed. Reason: %(error)s' %
|
||||
{'operation': 'get_report()', 'error': 'http status = 302'},
|
||||
'HTTP PROTOCOL ERROR, STATUS CODE = 302',
|
||||
str(e))
|
||||
|
||||
@httpretty.activate
|
||||
|
@@ -1,28 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# 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.
|
||||
|
||||
"""
|
||||
test_scciclient
|
||||
----------------------------------
|
||||
|
||||
Tests for `scciclient` module.
|
||||
"""
|
||||
|
||||
from scciclient.tests import base
|
||||
|
||||
|
||||
class TestScciclient(base.TestCase):
|
||||
|
||||
def test_something(self):
|
||||
pass
|
@@ -13,3 +13,5 @@ oslotest>=1.1.0.0a1
|
||||
testrepository>=0.0.18
|
||||
testscenarios>=0.4
|
||||
testtools>=0.9.34
|
||||
httpretty!=0.8.1,!=0.8.2,!=0.8.3,>=0.8.0
|
||||
|
||||
|
Reference in New Issue
Block a user