diff options
author | George Kraft <george.kraft@calxeda.com> | 2013-12-16 14:31:44 -0600 |
---|---|---|
committer | George Kraft <george.kraft@calxeda.com> | 2013-12-16 14:43:53 -0600 |
commit | 45902a82a81c800ecfee03c5941493728118eccd (patch) | |
tree | 4f19e117bec8285904a36c239491ca74e99eaa4f | |
parent | c30e40cc01ea337e9fa1247d82cbd813119503f5 (diff) | |
download | cxmanage-45902a82a81c800ecfee03c5941493728118eccd.tar.gz |
nojira: Clean up pylint warnings in cxmanage_api.tests
I moved a bunch of the in-line pylint suppression to the top of the
modules instead. I find the comments get in the way of readability,
which sort of defeats the whole purpose.
Doing module-level suppression at least gets those comments out of
the way, but isn't ideal either. We really should just leave the
warnings there.
-rw-r--r-- | cxmanage_api/tests/__init__.py | 2 | ||||
-rw-r--r-- | cxmanage_api/tests/dummy.py | 2 | ||||
-rw-r--r-- | cxmanage_api/tests/dummy_bmc.py | 125 | ||||
-rw-r--r-- | cxmanage_api/tests/dummy_image.py | 5 | ||||
-rw-r--r-- | cxmanage_api/tests/dummy_ip_retriever.py | 6 | ||||
-rw-r--r-- | cxmanage_api/tests/dummy_node.py | 13 | ||||
-rw-r--r-- | cxmanage_api/tests/dummy_test.py | 64 | ||||
-rw-r--r-- | cxmanage_api/tests/dummy_ubootenv.py | 2 | ||||
-rw-r--r-- | cxmanage_api/tests/fabric_test.py | 88 | ||||
-rw-r--r-- | cxmanage_api/tests/image_test.py | 5 | ||||
-rw-r--r-- | cxmanage_api/tests/node_test.py | 22 | ||||
-rw-r--r-- | cxmanage_api/tests/tasks_test.py | 7 | ||||
-rw-r--r-- | cxmanage_api/tests/test_credentials.py | 4 | ||||
-rw-r--r-- | cxmanage_api/tests/tftp_test.py | 12 | ||||
-rw-r--r-- | cxmanage_api/tests/utilities.py | 5 |
15 files changed, 191 insertions, 171 deletions
diff --git a/cxmanage_api/tests/__init__.py b/cxmanage_api/tests/__init__.py index bf136c0..81cd1dd 100644 --- a/cxmanage_api/tests/__init__.py +++ b/cxmanage_api/tests/__init__.py @@ -28,6 +28,8 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. +""" cxmanage_api.tests convenience imports """ + from cxmanage_api.tests.utilities import random_file, TestImage, TestSensor from cxmanage_api.tests.dummy import Dummy from cxmanage_api.tests.dummy_bmc import DummyBMC diff --git a/cxmanage_api/tests/dummy.py b/cxmanage_api/tests/dummy.py index 72f04ed..27e5ba9 100644 --- a/cxmanage_api/tests/dummy.py +++ b/cxmanage_api/tests/dummy.py @@ -28,6 +28,8 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. +""" Module for the generic Dummy class """ + from mock import Mock diff --git a/cxmanage_api/tests/dummy_bmc.py b/cxmanage_api/tests/dummy_bmc.py index cc515db..79185bd 100644 --- a/cxmanage_api/tests/dummy_bmc.py +++ b/cxmanage_api/tests/dummy_bmc.py @@ -1,3 +1,11 @@ +# pylint: disable=invalid-name +# pylint: disable=no-self-use +# pylint: disable=too-few-public-methods +# pylint: disable=too-many-arguments +# pylint: disable=too-many-instance-attributes +# pylint: disable=too-many-public-methods +# pylint: disable=unused-argument + # Copyright (c) 2012-2013, Calxeda Inc. # # All rights reserved. @@ -28,6 +36,8 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. +""" Module for the DummyBMC class """ + import random import shutil import tempfile @@ -42,7 +52,6 @@ from cxmanage_api.simg import create_simg, get_simg_header from cxmanage_api.tftp import InternalTftp, ExternalTftp -# pylint: disable=R0902 class DummyBMC(Dummy): """ Dummy BMC for the node tests """ dummy_spec = LanBMC @@ -76,23 +85,11 @@ class DummyBMC(Dummy): def guid(self): """Returns the GUID""" - # pylint: disable=R0903 - class Result(object): - """Results class.""" - def __init__(self, dummybmc): - self.system_guid = dummybmc.unique_guid - self.time_stamp = None - return Result(self) + return Result(system_guid=self.unique_guid, time_stamp=None) def get_chassis_status(self): """ Get chassis status """ - # pylint: disable=R0903 - class Result(object): - """Results class.""" - def __init__(self): - self.power_on = False - self.power_restore_policy = "always-off" - return Result() + return Result(power_on=False, power_restore_policy="always-off") def sel_elist(self): """ List SEL. with_errors=True simulates a SEL that contains errors """ @@ -135,15 +132,10 @@ class DummyBMC(Dummy): self.partitions[partition].fwinfo.priority = "%8x" % simg.priority self.partitions[partition].fwinfo.daddr = "%8x" % simg.daddr - # pylint: disable=R0903 - class Result(object): - """Results class.""" - def __init__(self): - """Default constructor for the Result class.""" - self.tftp_handle_id = 0 - return Result() + return Result(tftp_handle_id = 0) def retrieve_firmware(self, filename, partition, image_type, tftp_addr): + """ Mock retrieve_firmware method """ self.partitions[partition].retrieves += 1 # Upload blank image to tftp @@ -155,42 +147,28 @@ class DummyBMC(Dummy): tftp.put_file("%s/%s" % (work_dir, filename), filename) shutil.rmtree(work_dir) - # pylint: disable=R0903 - class Result(object): - """Results class.""" - def __init__(self): - self.tftp_handle_id = 0 - return Result() + return Result(tftp_handle_id = 0) def register_firmware_read(self, filename, partition, image_type): + """ Mock register_firmware_read method. currently not supported """ raise IpmiError() def register_firmware_write(self, filename, partition, image_type): + """ Mock register_firmware_write method. currently not supported """ raise IpmiError() def get_firmware_status(self, handle): - # pylint: disable=R0903 - class Result(object): - """Results class.""" - def __init__(self): - self.status = "Complete" - - del handle - - return Result() + """ Mock get_firmware_status method """ + return Result(status="Complete") def check_firmware(self, partition): + """ Mock check_firmware method """ self.partitions[partition].checks += 1 - # pylint: disable=R0903 - class Result(object): - """Results class.""" - def __init__(self): - self.crc32 = 0 - self.error = None - return Result() + return Result(crc32=0, error=None) def activate_firmware(self, partition): + """ Mock activate_firmware method """ self.partitions[partition].activates += 1 def sdr_list(self): @@ -206,27 +184,20 @@ class DummyBMC(Dummy): def get_info_basic(self): """ Get basic SoC info from this node """ - # pylint: disable=R0903 - class Result(object): - """Results class.""" - def __init__(self): - self.iana = int("0x0096CD", 16) - self.firmware_version = "ECX-0000-v0.0.0" - self.ecme_version = "v0.0.0" - self.ecme_timestamp = 0 - return Result() + return Result( + iana=int("0x0096CD", 16), + firmware_version="ECX-0000-v0.0.0", + ecme_version="v0.0.0", + ecme_timestamp=0 + ) def get_info_card(self): - # pylint: disable=R0903 - class Result(object): - """Results class.""" - def __init__(self): - self.type = "TestBoard" - self.revision = "0" - return Result() + """ Mock get_info_card method """ + return Result(type="TestBoard", revision="0") node_count = 0 def fabric_get_node_id(self): + """ Mock fabric_get_node_id method """ result = DummyBMC.node_count DummyBMC.node_count += 1 return result @@ -350,7 +321,6 @@ class DummyBMC(Dummy): 'other hops/neighbors - 5/12' ) - work_dir = tempfile.mkdtemp(prefix="cxmanage_test-") with open('%s/%s' % (work_dir, filename), 'w') as dc_file: for dchart in depth_chart: @@ -365,9 +335,8 @@ class DummyBMC(Dummy): shutil.rmtree(work_dir) - # pylint: disable=W0222 def fabric_get_linkstats(self, filename, tftp_addr=None, - link=None): + link=None): """Upload a link_stats file from the node to TFTP""" if not(tftp_addr): raise IpmiError('No tftp address!') @@ -432,6 +401,7 @@ class DummyBMC(Dummy): shutil.rmtree(work_dir) def fabric_config_get_uplink_info(self, filename, tftp_addr=None): + """ Mock fabric_config_get_uplink_info method """ if not(tftp_addr): raise IpmiError('No tftp address!') @@ -451,6 +421,7 @@ class DummyBMC(Dummy): shutil.rmtree(work_dir) def fabric_config_get_uplink(self, iface): + """ Mock fabric_config_get_uplink """ return 0 def fabric_config_get_mac_addresses(self, filename, tftp_addr=None): @@ -477,40 +448,35 @@ class DummyBMC(Dummy): shutil.rmtree(work_dir) def fabric_config_get_ip_src(self): + """ Mock fabric_config_get_ip_src """ return 2 - def fabric_config_set_ip_src(self, ipsrc_mode): - self.fabric_ipsrc = ipsrc_mode - def fabric_config_get_ip_addr_base(self): """Provide a fake base IP addr""" return self.ipaddr_base def fabric_get_linkspeed(self, link="", actual=""): + """ Mock fabric_get_linkspeed """ return 1 def fabric_config_get_linkspeed(self): + """ Mock fabric_config_get_linkspeed """ return 1 - def fabric_config_set_linkspeed(self, linkspeed): - self.fabric_linkspeed = linkspeed - def fabric_config_get_linkspeed_policy(self): + """ Mock fabric_config_get_linkspeed_policy """ return 1 - def fabric_config_set_linkspeed_policy(self, ls_policy): - self.fabric_ls_policy = ls_policy - def fabric_config_get_link_users_factor(self): + """ Mock fabric_config_get_link_users_factor """ return 1 - def fabric_config_set_link_users_factor(self, lu_factor): - self.fabric_lu_factor = lu_factor - def fabric_config_get_macaddr_base(self): + """ Mock fabric_config_get_macaddr_base """ return "00:00:00:00:00:00" def fabric_config_get_macaddr_mask(self): + """ Mock fabric_config_get_macaddr_mask """ return "00:00:00:00:00:00" def fabric_get_uplink_info(self): @@ -522,15 +488,16 @@ class DummyBMC(Dummy): return 1 def fru_read(self, fru_number, filename): + """ Mock fru_read method """ with open(filename, "w") as fru_image: # Writes a fake FRU image with version "0.0" fru_image.write("x00" * 516 + "0.0" + "x00"*7673) def pmic_get_version(self): + """ Mock pmic_get_version method """ return "0" -# pylint: disable=R0913, R0903 class Partition(object): """Partition class.""" def __init__(self, partition, type_, offset=0, @@ -562,3 +529,9 @@ class FWInfoEntry(object): self.in_use = {None: "Unknown", True: "1", False: "0"}[in_use] self.flags = "fffffffd" self.version = "v0.0.0" + + +class Result(object): + """ Generic result object. Converts kwargs into instance vars """ + def __init__(self, **kwargs): + self.__dict__.update(kwargs) diff --git a/cxmanage_api/tests/dummy_image.py b/cxmanage_api/tests/dummy_image.py index 534befa..556a6b5 100644 --- a/cxmanage_api/tests/dummy_image.py +++ b/cxmanage_api/tests/dummy_image.py @@ -1,3 +1,5 @@ +# pylint: disable=too-few-public-methods + # Copyright (c) 2012-2013, Calxeda Inc. # # All rights reserved. @@ -28,7 +30,8 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. -# pylint: disable=R0903 +""" Module for the DummyImage class """ + class DummyImage(object): """Dummy Image class.""" diff --git a/cxmanage_api/tests/dummy_ip_retriever.py b/cxmanage_api/tests/dummy_ip_retriever.py index 4767856..11a25e9 100644 --- a/cxmanage_api/tests/dummy_ip_retriever.py +++ b/cxmanage_api/tests/dummy_ip_retriever.py @@ -1,3 +1,5 @@ +# pylint: disable=too-few-public-methods + # Copyright (c) 2012-2013, Calxeda Inc. # # All rights reserved. @@ -28,10 +30,11 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. +""" Dummy implementation of cxmanage_api.ipretriever.IPRetriever """ + from cxmanage_api.cx_exceptions import IPDiscoveryError -# pylint: disable=R0903 class DummyIPRetriever(object): """ Dummy IP retriever """ @@ -40,6 +43,7 @@ class DummyIPRetriever(object): self.ecme_ip = ecme_ip self.aggressive = aggressive self.verbosity = verbosity + self.server_ip = None for name, value in kwargs.iteritems(): setattr(self, name, value) diff --git a/cxmanage_api/tests/dummy_node.py b/cxmanage_api/tests/dummy_node.py index 6d54646..8d411f0 100644 --- a/cxmanage_api/tests/dummy_node.py +++ b/cxmanage_api/tests/dummy_node.py @@ -1,3 +1,9 @@ +# pylint: disable=no-self-use +# pylint: disable=too-few-public-methods +# pylint: disable=too-many-instance-attributes +# pylint: disable=too-many-public-methods +# pylint: disable=unused-argument + # Copyright (c) 2012-2013, Calxeda Inc. # # All rights reserved. @@ -28,6 +34,8 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. +""" Dummy implementation for cxmanage_api.node.Node """ + import random from cxmanage_api.ubootenv import UbootEnv @@ -41,7 +49,6 @@ class DummyNode(Dummy): ip_addresses = DummyBMC.ip_addresses - # pylint: disable=W0613 def __init__(self, ip_address, username="admin", password="admin", tftp=None, *args, **kwargs): super(DummyNode, self).__init__() @@ -58,7 +65,7 @@ class DummyNode(Dummy): @property def guid(self): """Returns the node GUID""" - return self.bmc.guid().system_guid + return self.bmc.unique_guid @property def chassis_id(self): @@ -97,7 +104,6 @@ class DummyNode(Dummy): def get_versions(self): """Simulate get_versions(). """ - # pylint: disable=R0902, R0903 class Result(object): """Result Class. """ def __init__(self): @@ -127,7 +133,6 @@ class DummyNode(Dummy): """Simulates get_fabric_ipinfo(). """ return {} - # pylint: disable=R0913 def get_server_ip(self, interface=None, ipv6=False, aggressive=False): """Simulate get_server_ip(). """ return "192.168.200.1" diff --git a/cxmanage_api/tests/dummy_test.py b/cxmanage_api/tests/dummy_test.py index 8012ed2..f9efc54 100644 --- a/cxmanage_api/tests/dummy_test.py +++ b/cxmanage_api/tests/dummy_test.py @@ -1,3 +1,38 @@ +# pylint: disable=no-self-use +# pylint: disable=too-many-public-methods + +# Copyright (c) 2012-2013, Calxeda Inc. +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of Calxeda Inc. nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +# DAMAGE. + +""" Unit tests for the cxmanage_api.tests.Dummy class """ + import unittest from mock import Mock, call from cxmanage_api.tests import Dummy @@ -21,14 +56,14 @@ class DummyTest(unittest.TestCase): self.assertTrue(isinstance(DummyChild(), Parent)) self.assertTrue(isinstance(DummyChild(), Child)) - def test_ignored(self): + def test_undefined(self): """ Make sure we can call methods that aren't defined in the dummy """ parent = DummyParent() child = DummyChild() - self.assertTrue(isinstance(parent.p_ignored(), Mock)) - self.assertTrue(isinstance(child.p_ignored(), Mock)) - self.assertTrue(isinstance(child.c_ignored(), Mock)) + self.assertTrue(isinstance(parent.p_undefined(), Mock)) + self.assertTrue(isinstance(child.p_undefined(), Mock)) + self.assertTrue(isinstance(child.c_undefined(), Mock)) def test_defined(self): """ Make sure that defined method calls give us their return values """ @@ -39,7 +74,7 @@ class DummyTest(unittest.TestCase): self.assertEqual(child.p_defined(), "DummyParent.p_defined") self.assertEqual(child.c_defined(), "DummyChild.c_defined") - def test_undefined(self): + def test_nonexistent(self): """ Make sure we raise an error if we call a nonexistent method """ parent = DummyParent() child = DummyChild() @@ -59,29 +94,33 @@ class DummyTest(unittest.TestCase): def test_method_calls(self): """ Test that method calls can be tracked """ parent = DummyParent() - parent.p_ignored() + parent.p_undefined() parent.p_defined() self.assertEqual( - parent.method_calls, [call.p_ignored(), call.p_defined()] + parent.method_calls, [call.p_undefined(), call.p_defined()] ) class Parent(object): """ Parent class that we want to mock """ - def p_ignored(self): - return "Parent.p_ignored" + def p_undefined(self): + """ Parent method that we'll leave undefined """ + return "Parent.p_undefined" def p_defined(self): + """ Parent method that we'll define in DummyParent """ return "Parent.p_defined" class Child(Parent): """ Child class that we want to mock """ - def c_ignored(self): - return "Child.c_ignored" + def c_undefined(self): + """ Child method that we'll leave undefined """ + return "Child.c_undefined" def c_defined(self): + """ Child method that we'll define in DummyChild """ return "Child.c_defined" @@ -91,9 +130,11 @@ class DummyParent(Dummy): @property def dp_property(self): + """ Property defined only in DummyParent """ return "DummyParent.dp_property" def p_defined(self): + """ Dummy definition of Parent.p_defined """ return "DummyParent.p_defined" @@ -102,4 +143,5 @@ class DummyChild(DummyParent): dummy_spec = Child def c_defined(self): + """ Dummy definition of Child.c_defined """ return "DummyChild.c_defined" diff --git a/cxmanage_api/tests/dummy_ubootenv.py b/cxmanage_api/tests/dummy_ubootenv.py index a937419..085e928 100644 --- a/cxmanage_api/tests/dummy_ubootenv.py +++ b/cxmanage_api/tests/dummy_ubootenv.py @@ -28,6 +28,8 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. +""" Dummy implementation of cxmanage_api.ubootenv.UbootEnv """ + from cxmanage_api.ubootenv import UbootEnv diff --git a/cxmanage_api/tests/fabric_test.py b/cxmanage_api/tests/fabric_test.py index 757edc1..159f312 100644 --- a/cxmanage_api/tests/fabric_test.py +++ b/cxmanage_api/tests/fabric_test.py @@ -1,4 +1,5 @@ -"""Calxeda: fabric_test.py """ +# pylint: disable=protected-access +# pylint: disable=too-many-public-methods # Copyright (c) 2012-2013, Calxeda Inc. # @@ -30,6 +31,8 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. +"""Calxeda: fabric_test.py """ + import random import unittest from mock import call @@ -41,14 +44,12 @@ from cxmanage_api.cx_exceptions import CommandFailedError from cxmanage_api.tests import DummyNode, DummyFailNode -# pylint: disable=R0904 class FabricTest(unittest.TestCase): """ Test the various Fabric commands """ def setUp(self): # Set up the controller and add targets self.fabric = Fabric(DummyNode.ip_addresses[0], node=DummyNode) self.nodes = [DummyNode(i) for i in DummyNode.ip_addresses] - # pylint: disable=W0212 self.fabric._nodes = dict((i, self.nodes[i]) for i in xrange(len(self.nodes))) @@ -201,7 +202,6 @@ class FabricTest(unittest.TestCase): def test_failed_command(self): """ Test a failed command """ fail_nodes = [DummyFailNode(i) for i in DummyNode.ip_addresses] - # pylint: disable=W0212 self.fabric._nodes = dict( (i, fail_nodes[i]) for i in xrange(len(self.nodes)) ) @@ -224,8 +224,9 @@ class FabricTest(unittest.TestCase): """ self.fabric.get_ipsrc() - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_config_get_ip_src.called) + self.assertEqual(self.fabric.primary_node.bmc.method_calls, [ + call.fabric_config_get_ip_src() + ]) def test_set_ipsrc(self): """Test the set_ipsrc method""" @@ -233,42 +234,42 @@ class FabricTest(unittest.TestCase): ipsrc = random.randint(1, 2) self.fabric.set_ipsrc(ipsrc) - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_config_set_ip_src.called) - - # fabric_ipsrc is just part of DummyBMC - not a real bmc attribute - # it's there to make sure the ipsrc_mode value gets passed to the bmc. - self.assertEqual(bmc.fabric_ipsrc, ipsrc) + self.assertEqual(self.fabric.primary_node.bmc.method_calls, [ + call.fabric_config_set_ip_src(ipsrc) + ]) def test_apply_fdc(self): """Test the apply_factory_default_config method""" self.fabric.apply_factory_default_config() - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_config_factory_default.called) + self.assertEqual(self.fabric.primary_node.bmc.method_calls, [ + call.fabric_config_factory_default() + ]) def test_get_ipaddr_base(self): """Test the get_ipaddr_base method""" - ipaddr_base = self.fabric.get_ipaddr_base() - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_config_get_ip_addr_base.called) - self.assertEqual(bmc.ipaddr_base, ipaddr_base) + self.fabric.get_ipaddr_base() + self.assertEqual(self.fabric.primary_node.bmc.method_calls, [ + call.fabric_config_get_ip_addr_base() + ]) def test_update_config(self): """Test the update_config method """ self.fabric.update_config() - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_config_update_config.called) + self.assertEqual(self.fabric.primary_node.bmc.method_calls, [ + call.fabric_config_update_config() + ]) def test_get_linkspeed(self): """Test the get_linkspeed method """ self.fabric.get_linkspeed() - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_config_get_linkspeed.called) + self.assertEqual(self.fabric.primary_node.bmc.method_calls, [ + call.fabric_config_get_linkspeed() + ]) def test_set_linkspeed(self): """Test the set_linkspeed method""" @@ -277,20 +278,18 @@ class FabricTest(unittest.TestCase): linkspeed = random.choice(valid_linkspeeds) self.fabric.set_linkspeed(linkspeed) - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_config_set_linkspeed.called) - - # fabric_linkspeed is just part of DummyBMC - not a real bmc attribute - # it's there to make sure the ipsrc_mode value gets passed to the bmc. - self.assertEqual(bmc.fabric_linkspeed, linkspeed) + self.assertEqual(self.fabric.primary_node.bmc.method_calls, [ + call.fabric_config_set_linkspeed(linkspeed) + ]) def test_get_linkspeed_policy(self): """Test the get_linkspeed_policy method """ self.fabric.get_linkspeed_policy() - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_config_get_linkspeed_policy.called) + self.assertTrue(self.fabric.primary_node.bmc.method_calls, [ + call.fabric_config_get_linkspeed_policy() + ]) def test_set_linkspeed_policy(self): """Test the set_linkspeed_policy method""" @@ -298,12 +297,9 @@ class FabricTest(unittest.TestCase): ls_policy = random.randint(0, 1) self.fabric.set_linkspeed_policy(ls_policy) - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_config_set_linkspeed_policy.called) - - # fabric_ls_policy is just part of DummyBMC - not a real bmc attribute - # it's there to make sure the ipsrc_mode value gets passed to the bmc. - self.assertEqual(bmc.fabric_ls_policy, ls_policy) + self.assertEqual(self.fabric.primary_node.bmc.method_calls, [ + call.fabric_config_set_linkspeed_policy(ls_policy) + ]) def test_get_link_stats(self): """Test the get_link_stats() method.""" @@ -335,8 +331,9 @@ class FabricTest(unittest.TestCase): """ self.fabric.get_link_users_factor() - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_config_get_link_users_factor.called) + self.assertEqual(self.fabric.primary_node.bmc.method_calls, [ + call.fabric_config_get_link_users_factor() + ]) def test_set_link_users_factor(self): """Test the set_link_users_factor method""" @@ -344,12 +341,9 @@ class FabricTest(unittest.TestCase): lu_factor = random.randint(5, 50) self.fabric.set_link_users_factor(lu_factor) - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_config_set_link_users_factor.called) - - # fabric_lu_factor is just part of DummyBMC - not a real bmc attribute - # it's there to make sure the ipsrc_mode value gets passed to the bmc. - self.assertEqual(bmc.fabric_lu_factor, lu_factor) + self.assertEqual(self.fabric.primary_node.bmc.method_calls, [ + call.fabric_config_set_link_users_factor(lu_factor) + ]) def test_add_macaddr (self): """Test the add_macaddr method""" @@ -363,8 +357,7 @@ class FabricTest(unittest.TestCase): t_macaddr = "66:55:44:33:22:11" self.fabric.add_macaddr (t_nodeid, t_iface, t_macaddr) - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_add_macaddr.called) + self.assertTrue(self.fabric.primary_node.bmc.fabric_add_macaddr.called) def test_rm_macaddr (self): """Test the rm_macaddr method""" @@ -378,8 +371,7 @@ class FabricTest(unittest.TestCase): t_macaddr = "66:55:44:33:22:11" self.fabric.rm_macaddr (t_nodeid, t_iface, t_macaddr) - bmc = self.fabric.primary_node.bmc - self.assertTrue(bmc.fabric_rm_macaddr.called) + self.assertTrue(self.fabric.primary_node.bmc.fabric_rm_macaddr.called) def test_set_macaddr_base(self): """Test the set_macaddr_base method""" diff --git a/cxmanage_api/tests/image_test.py b/cxmanage_api/tests/image_test.py index f84f5c9..f785700 100644 --- a/cxmanage_api/tests/image_test.py +++ b/cxmanage_api/tests/image_test.py @@ -1,5 +1,4 @@ -"""Calxeda: image_test.py""" - +# pylint: disable=too-many-public-methods # Copyright (c) 2012-2013, Calxeda Inc. # @@ -31,6 +30,7 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. +"""Calxeda: image_test.py""" import os import shutil @@ -42,7 +42,6 @@ from cxmanage_api.tftp import InternalTftp from cxmanage_api.tests import random_file, TestImage -# pylint: disable=R0904 class ImageTest(unittest.TestCase): """ Tests involving cxmanage images diff --git a/cxmanage_api/tests/node_test.py b/cxmanage_api/tests/node_test.py index 1bbd6bc..f3cf08f 100644 --- a/cxmanage_api/tests/node_test.py +++ b/cxmanage_api/tests/node_test.py @@ -1,6 +1,4 @@ -# pylint: disable=C0302 -"""Unit tests for the Node class.""" - +# pylint: disable=too-many-public-methods # Copyright (c) 2012-2013, Calxeda Inc. # @@ -32,6 +30,8 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. +"""Unit tests for the Node class.""" + import shutil import tempfile import unittest @@ -43,21 +43,17 @@ from cxmanage_api.node import Node from cxmanage_api.firmware_package import FirmwarePackage -# pylint: disable=R0904, W0201 class NodeTest(unittest.TestCase): """ Tests involving cxmanage Nodes """ def setUp(self): - self.nodes = [Node(ip_address=ip, tftp=DummyBMC.tftp, bmc=DummyBMC, + self.nodes = [ + Node( + ip_address=ip, tftp=DummyBMC.tftp, bmc=DummyBMC, image=TestImage, ubootenv=DummyUbootEnv, - ipretriever=DummyIPRetriever, verbose=True) - for ip in DummyBMC.ip_addresses] - - self.server_ip = None - self.fabric_ipsrc = None - self.fabric_ls_policy = None - self.fabric_linkspeed = None - self.fabric_lu_factor = None + ipretriever=DummyIPRetriever, verbose=True + ) for ip in DummyBMC.ip_addresses + ] # Give each node a node_id count = 0 diff --git a/cxmanage_api/tests/tasks_test.py b/cxmanage_api/tests/tasks_test.py index 2d7b9a3..4f3ee56 100644 --- a/cxmanage_api/tests/tasks_test.py +++ b/cxmanage_api/tests/tasks_test.py @@ -1,5 +1,5 @@ -"""Calxeda: task_test.py""" - +# pylint: disable=too-few-public-methods +# pylint: disable=too-many-public-methods # Copyright (c) 2012-2013, Calxeda Inc. # @@ -31,6 +31,7 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. +"""Calxeda: task_test.py""" import unittest import time @@ -38,7 +39,6 @@ import time from cxmanage_api.tasks import TaskQueue -# pylint: disable=R0904 class TaskTest(unittest.TestCase): """Test for the TaskQueue Class.""" @@ -70,7 +70,6 @@ class TaskTest(unittest.TestCase): self.assertGreaterEqual(finish - start, 2.0) -# pylint: disable=R0903 class Counter(object): """ Simple counter object for testing purposes """ def __init__(self): diff --git a/cxmanage_api/tests/test_credentials.py b/cxmanage_api/tests/test_credentials.py index 19de536..088c893 100644 --- a/cxmanage_api/tests/test_credentials.py +++ b/cxmanage_api/tests/test_credentials.py @@ -1,3 +1,5 @@ +# pylint: disable=too-many-public-methods + # Copyright (c) 2012-2013, Calxeda Inc. # # All rights reserved. @@ -28,6 +30,8 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. +""" Tests for the cxmanage_api.credentials module """ + import unittest from cxmanage_api.credentials import Credentials diff --git a/cxmanage_api/tests/tftp_test.py b/cxmanage_api/tests/tftp_test.py index ccf2859..d3dcff1 100644 --- a/cxmanage_api/tests/tftp_test.py +++ b/cxmanage_api/tests/tftp_test.py @@ -1,5 +1,4 @@ -"""Calxeda: tftp_test.py""" - +# pylint: disable=too-many-public-methods # Copyright (c) 2012-2013, Calxeda Inc. # @@ -31,11 +30,7 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. - -# -# Unit tests for the Internal and External Tftp classes. -# - +"""Calxeda: tftp_test.py""" import os import socket @@ -58,7 +53,7 @@ def _get_relative_host(): except socket.error: raise -# pylint: disable=R0904 + class InternalTftpTest(unittest.TestCase): """ Tests the functions of the InternalTftp class.""" @@ -105,7 +100,6 @@ class InternalTftpTest(unittest.TestCase): sock.close() -# pylint: disable=R0904 class ExternalTftpTest(unittest.TestCase): """Tests the ExternalTftp class. ..note: diff --git a/cxmanage_api/tests/utilities.py b/cxmanage_api/tests/utilities.py index 6a405d7..183475e 100644 --- a/cxmanage_api/tests/utilities.py +++ b/cxmanage_api/tests/utilities.py @@ -1,3 +1,5 @@ +# pylint: disable=too-few-public-methods + # Copyright (c) 2012-2013, Calxeda Inc. # # All rights reserved. @@ -28,6 +30,8 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. +""" Utilities used by cxmanage unit tests """ + import os import random import tempfile @@ -51,7 +55,6 @@ class TestImage(Image): return True -# pylint: disable=R0903 class TestSensor(object): """ Sensor result from bmc/target """ def __init__(self, sensor_name, sensor_reading): |