From ff1ee2de9a7388c007673b7ed5d2f9d441d0ed01 Mon Sep 17 00:00:00 2001 From: Naohiro Tamura Date: Thu, 7 May 2015 00:17:46 +0900 Subject: [PATCH] reflected the comment iRMC vmedia deploy patch #15 added MetaShareType class, get_share_type function, and wait param to scci_cmd function. --- requirements.txt | 1 + scciclient/irmc/scci.py | 38 +++++++++++++++++++++++------- scciclient/tests/irmc/test_scci.py | 18 +++++++++++++- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 883a3ba..1e4d0f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ pbr>=0.6,!=0.7,<1.0 Babel>=1.3 requests>=2.2.0,!=2.4.0 +six>=1.9.0 diff --git a/scciclient/irmc/scci.py b/scciclient/irmc/scci.py index 629a113..55a78a8 100644 --- a/scciclient/irmc/scci.py +++ b/scciclient/irmc/scci.py @@ -17,9 +17,11 @@ SCCI functionalities shared between different iRMC modules. """ import functools +import time import xml.etree.ElementTree as ET import requests +import six class SCCIError(Exception): @@ -197,14 +199,31 @@ _VIRTUAL_MEDIA_FD_SETTINGS = ''' ''' -class SHARETYPE(object): +class MetaShareType(type): + @property + def nfs(cls): + return cls.NFS + + @property + def cifs(cls): + return cls.CIFS + + +@six.add_metaclass(MetaShareType) +class ShareType(object): """"Virtual Media Share Type.""" NFS = 0 CIFS = 1 -def scci_cmd(host, userid, password, cmd, - port=443, auth_method='basic', client_timeout=60): +def get_share_type(share_type): + """get share type.""" + return({'nfs': ShareType.nfs, + 'cifs': ShareType.cifs}[share_type.lower()]) + + +def scci_cmd(host, userid, password, cmd, port=443, auth_method='basic', + client_timeout=60, wait=0, **kwargs): """execute SCCI command This function calls SCCI server modules @@ -215,6 +234,7 @@ def scci_cmd(host, userid, password, cmd, :param port: port number of iRMC :param auth_method: irmc_username :param client_timeout: timeout for SCCI operations + :param wait: wait seconds before issuing SCCI command :returns: requests.Response from SCCI server :raises: SCCIInvalidInputError if port and/or auth_method params are invalid @@ -234,6 +254,8 @@ def scci_cmd(host, userid, password, cmd, "auth_method for method %(auth_method)s") % {'port': port, 'auth_method': auth_method}) + # wait + time.sleep(wait) try: header = {'Content-type': 'application/x-www-form-urlencoded'} r = requests.post(protocol + '://' + host + '/config', @@ -267,8 +289,8 @@ def scci_cmd(host, userid, password, cmd, raise SCCIClientError(requests_exception) -def get_client(host, userid, password, - port=443, auth_method='basic', client_timeout=60): +def get_client(host, userid, password, port=443, auth_method='basic', + client_timeout=60, **kwargs): """get SCCI command partial function This function returs SCCI command partial function @@ -283,7 +305,7 @@ def get_client(host, userid, password, return functools.partial(scci_cmd, host, userid, password, port=port, auth_method=auth_method, - client_timeout=client_timeout) + client_timeout=client_timeout, **kwargs) def get_virtual_cd_set_params_cmd(remote_image_server, @@ -298,7 +320,7 @@ def get_virtual_cd_set_params_cmd(remote_image_server, This function returs Virtual CD Media Set Parameters Command :param remote_image_server: remote image server name or IP :param remote_image_user_domain: domain name of remote image server - :param remote_image_share_type: share type of SHARETYPE + :param remote_image_share_type: share type of ShareType :param remote_image_share_name: share name :param remote_image_deploy_iso: deploy ISO image file name :param remote_image_username: username of remote image server @@ -330,7 +352,7 @@ def get_virtual_fd_set_params_cmd(remote_image_server, This function returs Virtual FD Media Set Parameters Command :param remote_image_server: remote image server name or IP :param remote_image_user_domain: domain name of remote image server - :param remote_image_share_type: share type of SHARETYPE + :param remote_image_share_type: share type of ShareType :param remote_image_share_name: share name :param remote_image_deploy_iso: deploy ISO image file name :param remote_image_username: username of remote image server diff --git a/scciclient/tests/irmc/test_scci.py b/scciclient/tests/irmc/test_scci.py index 2aa25c9..7910853 100644 --- a/scciclient/tests/irmc/test_scci.py +++ b/scciclient/tests/irmc/test_scci.py @@ -75,7 +75,7 @@ class SCCITestCase(testtools.TestCase): self.irmc_remote_image_server = '10.33.110.49' self.irmc_remote_image_user_domain = 'example.local' - self.irmc_remote_image_share_type = scci.SHARETYPE.NFS + self.irmc_remote_image_share_type = scci.ShareType.nfs self.irmc_remote_image_share_name = 'share' self.irmc_remote_image_deploy_iso = 'ubuntu-14.04.1-server-amd64.iso' self.irmc_remote_image_username = 'deployer' @@ -122,6 +122,22 @@ class SCCITestCase(testtools.TestCase): 'https://github.com', verify=False) self.assertEqual("'member_descriptor' object is not callable", str(e)) + def test_get_share_type_ok(self): + nfs_result = scci.get_share_type("nfs") + self.assertEqual(scci.ShareType.nfs, nfs_result) + cifs_result = scci.get_share_type("cifs") + self.assertEqual(scci.ShareType.cifs, cifs_result) + + NFS_result = scci.get_share_type("NFS") + self.assertEqual(scci.ShareType.nfs, NFS_result) + CIFS_result = scci.get_share_type("CIFS") + self.assertEqual(scci.ShareType.cifs, CIFS_result) + + def test_get_share_type_ng(self): + self.assertRaises(KeyError, + scci.get_share_type, + "abc") + @mock.patch('scciclient.irmc.scci.requests') def test_scci_cmd_protocol_https_ok(self, mock_requests): https_port = 443