fixed requests timeout and virtual media mount/unmount

This commit is contained in:
Naohiro Tamura
2015-02-26 17:23:54 +09:00
parent cf2673489f
commit a4fd5621fd
2 changed files with 27 additions and 20 deletions

View File

@@ -82,6 +82,7 @@ _POWER_CMD = '''
</CMDSEQ> </CMDSEQ>
''' '''
POWER_ON = _POWER_CMD % "PowerOnCabinet" POWER_ON = _POWER_CMD % "PowerOnCabinet"
POWER_OFF = _POWER_CMD % "PowerOffCabinet" POWER_OFF = _POWER_CMD % "PowerOffCabinet"
POWER_CYCLE = _POWER_CMD % "PowerOffOnCabinet" POWER_CYCLE = _POWER_CMD % "PowerOffOnCabinet"
@@ -97,10 +98,12 @@ _VIRTUAL_MEDIA_CMD = '''
</CMDSEQ> </CMDSEQ>
''' '''
MOUNT_CD = _VIRTUAL_MEDIA_CMD % ("ConnectRemoteCdImage", 0)
UNMOUNT_CD = _VIRTUAL_MEDIA_CMD % ("ConnectRemoteCdImage", 1) MOUNT_CD = _VIRTUAL_MEDIA_CMD % ("ConnectRemoteCdImage", 1)
MOUNT_FD = _VIRTUAL_MEDIA_CMD % ("ConnectRemoteFdImage", 0) UNMOUNT_CD = _VIRTUAL_MEDIA_CMD % ("ConnectRemoteCdImage", 0)
UNMOUNT_FD = _VIRTUAL_MEDIA_CMD % ("ConnectRemoteFdImage", 1) MOUNT_FD = _VIRTUAL_MEDIA_CMD % ("ConnectRemoteFdImage", 1)
UNMOUNT_FD = _VIRTUAL_MEDIA_CMD % ("ConnectRemoteFdImage", 0)
_VIRTUAL_MEDIA_CD_SETTINGS = ''' _VIRTUAL_MEDIA_CD_SETTINGS = '''
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
@@ -113,15 +116,15 @@ _VIRTUAL_MEDIA_CD_SETTINGS = '''
<!-- "ConfBmcMediaOptionsCdNumber" --> <!-- "ConfBmcMediaOptionsCdNumber" -->
<!-- Number of emulated CDROM/DVD Devices --> <!-- Number of emulated CDROM/DVD Devices -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A68" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A68" OI="0" Type="SET">
<DATA Type="xsd::integer">1</DATA> <DATA Type="xsd::integer">2</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteCdImageServer" --> <!-- "ConfBmcRemoteCdImageServer" -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A60" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A60" OI="0" Type="SET">
<DATA Type="xsd::string">"%s"</DATA> <DATA Type="xsd::string">%s</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteCdImageUserDomain" --> <!-- "ConfBmcRemoteCdImageUserDomain" -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A63" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A63" OI="0" Type="SET">
<DATA Type="xsd::string">"%s"</DATA> <DATA Type="xsd::string">%s</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteCdImageShareType" --> <!-- "ConfBmcRemoteCdImageShareType" -->
<!-- 0 = NFS Share / 1 = CIFS Share --> <!-- 0 = NFS Share / 1 = CIFS Share -->
@@ -130,15 +133,15 @@ _VIRTUAL_MEDIA_CD_SETTINGS = '''
</CMD> </CMD>
<!-- "ConfBmcRemoteCdImageShareName" --> <!-- "ConfBmcRemoteCdImageShareName" -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A65" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A65" OI="0" Type="SET">
<DATA Type="xsd::string">"%s"</DATA> <DATA Type="xsd::string">%s</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteCdImageImageName" --> <!-- "ConfBmcRemoteCdImageImageName" -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A66" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A66" OI="0" Type="SET">
<DATA Type="xsd::string">"%s"</DATA> <DATA Type="xsd::string">%s</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteCdImageUserName" --> <!-- "ConfBmcRemoteCdImageUserName" -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A61" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A61" OI="0" Type="SET">
<DATA Type="xsd::string">"%s"</DATA> <DATA Type="xsd::string">%s</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteCdImageUserPassword" --> <!-- "ConfBmcRemoteCdImageUserPassword" -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A62" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A62" OI="0" Type="SET">
@@ -146,6 +149,8 @@ _VIRTUAL_MEDIA_CD_SETTINGS = '''
</CMD> </CMD>
</CMDSEQ> </CMDSEQ>
''' '''
_VIRTUAL_MEDIA_FD_SETTINGS = ''' _VIRTUAL_MEDIA_FD_SETTINGS = '''
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CMDSEQ> <CMDSEQ>
@@ -157,32 +162,32 @@ _VIRTUAL_MEDIA_FD_SETTINGS = '''
<!-- "ConfBmcMediaOptionsFdNumber" --> <!-- "ConfBmcMediaOptionsFdNumber" -->
<!-- Number of emulated FD Devices --> <!-- Number of emulated FD Devices -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A58" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A58" OI="0" Type="SET">
<DATA Type="xsd::integer">1</DATA> <DATA Type="xsd::integer">2</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteFdImageServer" --> <!-- "ConfBmcRemoteFdImageServer" -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A50" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A50" OI="0" Type="SET">
<DATA Type="xsd::string">"%s"</DATA> <DATA Type="xsd::string">%s</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteFdImageUserDomain" --> <!-- "ConfBmcRemoteFdImageUserDomain" -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A53" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A53" OI="0" Type="SET">
<DATA Type="xsd::string">"%s"</DATA> <DATA Type="xsd::string">%s</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteFdImageShareType" --> <!-- "ConfBmcRemoteFdImageShareType" -->
<!-- 0 = NFS Share / 1 = CIFS Share --> <!-- 0 = NFS Share / 1 = CIFS Share -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A54" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A54" OI="0" Type="SET">
<DATA Type="xsd::integer">"%d"</DATA> <DATA Type="xsd::integer">%d</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteFdImageShareName" --> <!-- "ConfBmcRemoteFdImageShareName" -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A55" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A55" OI="0" Type="SET">
<DATA Type="xsd::string">"%s"</DATA> <DATA Type="xsd::string">%s</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteFdImageImageName" --> <!-- "ConfBmcRemoteFdImageImageName" -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A56" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A56" OI="0" Type="SET">
<DATA Type="xsd::string">"%s"</DATA> <DATA Type="xsd::string">%s</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteFdImageUserName" --> <!-- "ConfBmcRemoteFdImageUserName" -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A51" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A51" OI="0" Type="SET">
<DATA Type="xsd::string">"%s"</DATA> <DATA Type="xsd::string">%s</DATA>
</CMD> </CMD>
<!-- "ConfBmcRemoteFdImageUserPassword" --> <!-- "ConfBmcRemoteFdImageUserPassword" -->
<CMD Context="SCCI" OC="ConfigSpace" OE="1A52" OI="0" Type="SET"> <CMD Context="SCCI" OC="ConfigSpace" OE="1A52" OI="0" Type="SET">
@@ -215,7 +220,6 @@ def scci_cmd(host, userid, password, cmd,
are invalid are invalid
:raises: SCCIClientError if SCCI failed :raises: SCCIClientError if SCCI failed
""" """
auth_obj = None auth_obj = None
try: try:
protocol = {80: 'http', 443: 'https'}[port] protocol = {80: 'http', 443: 'https'}[port]
@@ -231,10 +235,12 @@ def scci_cmd(host, userid, password, cmd,
{'port': port, 'auth_method': auth_method}) {'port': port, 'auth_method': auth_method})
try: try:
header = {'Content-type': 'application/x-www-form-urlencoded'}
r = requests.post(protocol + '://' + host + '/config', r = requests.post(protocol + '://' + host + '/config',
data=cmd, data=cmd,
headers=header,
verify=False, verify=False,
timeout=(10, client_timeout), timeout=client_timeout,
allow_redirects=False, allow_redirects=False,
auth=auth_obj) auth=auth_obj)

View File

@@ -145,8 +145,9 @@ class SCCITestCase(testtools.TestCase):
mock_requests.post.assert_called_with( mock_requests.post.assert_called_with(
'https://' + self.irmc_address + '/config', 'https://' + self.irmc_address + '/config',
data=scci.POWER_ON, data=scci.POWER_ON,
headers={'Content-type': 'application/x-www-form-urlencoded'},
verify=False, verify=False,
timeout=(10, self.irmc_client_timeout), timeout=self.irmc_client_timeout,
allow_redirects=False, allow_redirects=False,
auth=mock_requests.auth.HTTPBasicAuth(self.irmc_username, auth=mock_requests.auth.HTTPBasicAuth(self.irmc_username,
self.irmc_password)) self.irmc_password))