From 588b5651dc515d642b110f61c41d78860206841c Mon Sep 17 00:00:00 2001 From: Stanislaw Pitucha Date: Wed, 10 Apr 2013 18:59:23 +0000 Subject: Remove "undefined name" pyflake errors A number of places tried to use undefined names. This included one powervm test which turned out to not check anything at all (used fake implementation of tested method) and needed to be moved. Make sure that this class of errors causes run_pep8 failure in the future. Change-Id: I82ccb63bbc6f6d2b20ecb7f06b2fc22f8f034a33 --- nova/cmd/baremetal_deploy_helper.py | 1 + nova/cmd/baremetal_manage.py | 1 - nova/cmd/dhcpbridge.py | 1 + nova/tests/test_db_api.py | 2 +- nova/tests/test_powervm.py | 43 ++++++++++++++++++++++--------------- tools/run_pep8.sh | 3 ++- 6 files changed, 31 insertions(+), 20 deletions(-) diff --git a/nova/cmd/baremetal_deploy_helper.py b/nova/cmd/baremetal_deploy_helper.py index 5ccd43b56..caa50f20e 100644 --- a/nova/cmd/baremetal_deploy_helper.py +++ b/nova/cmd/baremetal_deploy_helper.py @@ -40,6 +40,7 @@ from nova.virt.baremetal import db QUEUE = Queue.Queue() +LOG = logging.getLogger(__name__) # All functions are called from deploy() directly or indirectly. diff --git a/nova/cmd/baremetal_manage.py b/nova/cmd/baremetal_manage.py index 881f2f60c..eaf4a8416 100644 --- a/nova/cmd/baremetal_manage.py +++ b/nova/cmd/baremetal_manage.py @@ -197,7 +197,6 @@ def main(): cliutils.validate_args(fn, *fn_args, **fn_kwargs) except cliutils.MissingArgs as e: print(fn.__doc__) - parser.print_help() print(e) return(1) try: diff --git a/nova/cmd/dhcpbridge.py b/nova/cmd/dhcpbridge.py index c874af51e..108aafcf9 100644 --- a/nova/cmd/dhcpbridge.py +++ b/nova/cmd/dhcpbridge.py @@ -41,6 +41,7 @@ from nova.openstack.common import rpc CONF = cfg.CONF CONF.import_opt('host', 'nova.netconf') CONF.import_opt('network_manager', 'nova.service') +LOG = logging.getLogger(__name__) def add_lease(mac, ip_address): diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index b81b04be9..fb7f8792d 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -2699,7 +2699,7 @@ class VirtualInterfaceTestCase(test.TestCase, ModelsObjectComparatorMixin): # NOTE(boris-42): Due to the bug 1156227 this won't work. In havana-1 # it will be fixed. self.assertRaises(exception.VirtualInterfaceCreateException, - self._create_virt_interface, {uuid: vif['uuid']}) + self._create_virt_interface, {"uuid": vif['uuid']}) def test_virtual_interface_get(self): vifs = [self._create_virt_interface({'address':'a'}), diff --git a/nova/tests/test_powervm.py b/nova/tests/test_powervm.py index 572c0f946..a8278f085 100644 --- a/nova/tests/test_powervm.py +++ b/nova/tests/test_powervm.py @@ -404,23 +404,6 @@ class PowerVMDriverTestCase(test.TestCase): context, instance, dest, instance_type, network_info, block_device_info) - def test_set_lpar_mac_base_value_command(self): - inst_name = 'some_instance' - mac = 'FA:98:64:2B:29:39' - exp_mac_str = mac[:-2].replace(':', '').lower() - - def fake_run_vios_command(cmd, *args, **kwargs): - exp_cmd = ('chsyscfg -r lpar -i "name=%(inst_name)s, ', - 'virtual_eth_mac_base_value=%(exp_mac_str)s"' % - locals()) - assertEqual(exp_cmd, cmd) - - self.stubs.Set(self.powervm_connection._powervm._operator, - 'run_vios_command', fake_run_vios_command) - - fake_op = self.powervm_connection._powervm - fake_op._operator.set_lpar_mac_base_value(inst_name, mac) - def test_migrate_build_scp_command(self): lv_name = 'logical-vol-name' src_host = 'compute_host_1' @@ -488,3 +471,29 @@ class PowerVMDriverTestCase(test.TestCase): self.assertEquals(host_stats['supported_instances'][0][0], "ppc64") self.assertEquals(host_stats['supported_instances'][0][1], "powervm") self.assertEquals(host_stats['supported_instances'][0][2], "hvm") + + +class PowerVMDriverLparTestCase(test.TestCase): + """Unit tests for PowerVM connection calls.""" + + def setUp(self): + super(PowerVMDriverLparTestCase, self).setUp() + self.stubs.Set(operator.PowerVMOperator, '_update_host_stats', + lambda self: None) + self.powervm_connection = powervm_driver.PowerVMDriver(None) + + def test_set_lpar_mac_base_value_command(self): + inst_name = 'some_instance' + mac = 'FA:98:64:2B:29:39' + exp_mac_str = mac[:-2].replace(':', '') + + exp_cmd = ('chsyscfg -r lpar -i "name=%(inst_name)s, ' + 'virtual_eth_mac_base_value=%(exp_mac_str)s"') % locals() + + fake_op = self.powervm_connection._powervm + self.mox.StubOutWithMock(fake_op._operator, 'run_vios_command') + fake_op._operator.run_vios_command(exp_cmd) + + self.mox.ReplayAll() + + fake_op._operator.set_lpar_mac_base_value(inst_name, mac) diff --git a/tools/run_pep8.sh b/tools/run_pep8.sh index 61b5f8985..7c2ec0130 100755 --- a/tools/run_pep8.sh +++ b/tools/run_pep8.sh @@ -22,4 +22,5 @@ PLUGINS_PATH=${SCRIPT_ROOT}/plugins/xenserver/xenapi/etc/xapi.d/plugins PYTHONPATH=${PLUGINS_PATH} ${PEP8} ./plugins/xenserver/xenapi \ `find plugins/xenserver/xenapi/etc/xapi.d/plugins -type f -perm +111` -! pyflakes nova/ | grep "imported but unused\|redefinition of function" +! pyflakes nova/ | grep "imported but unused\|redefinition of function\|undefined name '" | + grep -v "undefined name '_'" -- cgit