From 62c7c14f7793502c5dda5498369e45c8cc21ca70 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Mon, 16 Apr 2018 12:06:46 +0200 Subject: [PATCH] pep8 ovirt classes, added copyright statement to ovirt files Change-Id: Ibc25a574e9f0572d62d86dc0df0cbeef6eb7e93c --- ironic_staging_drivers/common/exception.py | 2 +- ironic_staging_drivers/ovirt/__init__.py | 7 ++++--- ironic_staging_drivers/ovirt/ovirt.py | 19 ++++++++++--------- .../tests/unit/ovirt/test_ovirt.py | 13 +++++++------ setup.cfg | 6 +++--- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/ironic_staging_drivers/common/exception.py b/ironic_staging_drivers/common/exception.py index da3990f..a6787f3 100644 --- a/ironic_staging_drivers/common/exception.py +++ b/ironic_staging_drivers/common/exception.py @@ -39,5 +39,5 @@ class InvalidIPMITimestamp(exception.IronicException): pass -class oVirtError(exception.IronicException): +class OVirtError(exception.IronicException): message = _("oVirt call failed: %(err)s.") diff --git a/ironic_staging_drivers/ovirt/__init__.py b/ironic_staging_drivers/ovirt/__init__.py index eb75f9c..603910f 100644 --- a/ironic_staging_drivers/ovirt/__init__.py +++ b/ironic_staging_drivers/ovirt/__init__.py @@ -1,5 +1,6 @@ # -*- encoding: utf-8 -*- # +# Copyright 2017 Red Hat, Inc. # 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 @@ -20,7 +21,7 @@ from ironic.drivers import generic from ironic_staging_drivers.ovirt import ovirt -class oVirtHardware(generic.GenericHardware): +class OVirtHardware(generic.GenericHardware): """oVirt hardware type. Uses oVirt for power and management. @@ -29,9 +30,9 @@ class oVirtHardware(generic.GenericHardware): @property def supported_management_interfaces(self): """List of supported management interfaces.""" - return [ovirt.oVirtManagement] + return [ovirt.OVirtManagement] @property def supported_power_interfaces(self): """List of supported power interfaces.""" - return [ovirt.oVirtPower] + return [ovirt.OVirtPower] diff --git a/ironic_staging_drivers/ovirt/ovirt.py b/ironic_staging_drivers/ovirt/ovirt.py index 433ff49..4c3348e 100644 --- a/ironic_staging_drivers/ovirt/ovirt.py +++ b/ironic_staging_drivers/ovirt/ovirt.py @@ -1,3 +1,4 @@ +# Copyright 2017 Red Hat, Inc. # 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 @@ -140,15 +141,15 @@ def _getvm(driver_info): except sdk.Error as e: LOG.error("Could not fetch information about VM vm %(name)s, " "got error: %(error)s", {'name': name, 'error': e}) - raise staging_exception.oVirtError(err=e) + raise staging_exception.OVirtError(err=e) if vmsearch: return vms_service.vm_service(vmsearch[0].id) else: - raise staging_exception.oVirtError(_("VM with name " + raise staging_exception.OVirtError(_("VM with name " "%s was not found") % name) -class oVirtPower(base.PowerInterface): +class OVirtPower(base.PowerInterface): def get_properties(self): return PROPERTIES @@ -220,7 +221,7 @@ class oVirtPower(base.PowerInterface): except sdk.Error as e: LOG.error("Could not change status of VM vm %(name)s " "got error: %(error)s", {'name': vm_name, 'error': e}) - raise staging_exception.oVirtError(err=e) + raise staging_exception.OVirtError(err=e) @task_manager.require_exclusive_lock def reboot(self, task, timeout=None): @@ -237,7 +238,7 @@ class oVirtPower(base.PowerInterface): self.set_power_state(task, states.REBOOT, timeout=timeout) -class oVirtManagement(base.ManagementInterface): +class OVirtManagement(base.ManagementInterface): def get_properties(self): return PROPERTIES @@ -275,7 +276,7 @@ class oVirtManagement(base.ManagementInterface): missing in the node's driver_info. :raises: InvalidParameterValue, if some parameter(s) have invalid value(s) in the node's driver_info. - :raises: oVirtError, if error encountered from + :raises: OVirtError, if error encountered from oVirt operation. """ driver_info = _parse_driver_info(task.node) @@ -288,8 +289,8 @@ class oVirtManagement(base.ManagementInterface): msg = _("oVirt returned unknown boot device '%(device)s' " "for node %(node)s") LOG.error(msg, {'device': boot_dev, 'node': task.node.uuid}) - raise staging_exception.oVirtError(msg.format(device=boot_dev, - node=task.node.uuid)) + raise staging_exception.OVirtError(msg.format(device=boot_dev, + node=task.node.uuid)) return {'boot_device': ironic_boot_dev, 'persistent': persistent} @@ -321,7 +322,7 @@ class oVirtManagement(base.ManagementInterface): LOG.error("Setting boot device failed for node %(node_id)s " "with error: %(error)s", {'node_id': task.node.uuid, 'error': e}) - raise staging_exception.oVirtError(err=e) + raise staging_exception.OVirtError(err=e) def get_sensors_data(self, task): """Get sensors data. diff --git a/ironic_staging_drivers/tests/unit/ovirt/test_ovirt.py b/ironic_staging_drivers/tests/unit/ovirt/test_ovirt.py index 4d351fb..3aa858a 100644 --- a/ironic_staging_drivers/tests/unit/ovirt/test_ovirt.py +++ b/ironic_staging_drivers/tests/unit/ovirt/test_ovirt.py @@ -1,3 +1,4 @@ +# Copyright 2017 Red Hat, Inc. # 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 @@ -36,10 +37,10 @@ def _ovirt_info(): @mock.patch.object(time, 'sleep', lambda *_: None) -class oVirtDriverTestCase(db_base.DbTestCase): +class OVirtDriverTestCase(db_base.DbTestCase): def setUp(self): - super(oVirtDriverTestCase, self).setUp() + super(OVirtDriverTestCase, self).setUp() self.config(enabled_power_interfaces='staging-ovirt', enabled_management_interfaces='staging-ovirt') namespace = 'ironic.hardware.types' @@ -66,7 +67,7 @@ class oVirtDriverTestCase(db_base.DbTestCase): if prop in expected] self.assertEqual(sorted(expected), sorted(driver_properties)) - @mock.patch.object(ovirt_power.oVirtPower, 'set_power_state', + @mock.patch.object(ovirt_power.OVirtPower, 'set_power_state', autospec=True, spec_set=True) def test_set_power_state_power_on(self, mock_power): with task_manager.acquire(self.context, self.node.uuid) as task: @@ -74,7 +75,7 @@ class oVirtDriverTestCase(db_base.DbTestCase): mock_power.assert_called_once_with(task.driver.power, task, states.POWER_ON) - @mock.patch.object(ovirt_power.oVirtPower, 'set_power_state', + @mock.patch.object(ovirt_power.OVirtPower, 'set_power_state', autospec=True, spec_set=True) def test_set_power_state_power_off(self, mock_power): with task_manager.acquire(self.context, self.node.uuid) as task: @@ -96,14 +97,14 @@ class oVirtDriverTestCase(db_base.DbTestCase): self.assertEqual([boot_devices.CDROM, boot_devices.DISK, boot_devices.PXE], bdevices) - @mock.patch.object(ovirt_power.oVirtManagement, 'get_boot_device', + @mock.patch.object(ovirt_power.OVirtManagement, 'get_boot_device', return_value='hd') def test_get_boot_device(self, mock_management): with task_manager.acquire(self.context, self.node.uuid) as task: boot_dev = task.driver.management.get_boot_device(task) self.assertEqual('hd', boot_dev) - @mock.patch.object(ovirt_power.oVirtManagement, 'set_boot_device', + @mock.patch.object(ovirt_power.OVirtManagement, 'set_boot_device', autospec=True, spec_set=True) def test_set_boot_device(self, mock_power): with task_manager.acquire(self.context, self.node.uuid) as task: diff --git a/setup.cfg b/setup.cfg index b778b66..8842c94 100644 --- a/setup.cfg +++ b/setup.cfg @@ -45,13 +45,13 @@ ironic.hardware.interfaces.deploy = ironic.hardware.interfaces.management = staging-amt = ironic_staging_drivers.amt.management:AMTManagement staging-libvirt = ironic_staging_drivers.libvirt.power:LibvirtManagement - staging-ovirt = ironic_staging_drivers.ovirt.ovirt:oVirtManagement + staging-ovirt = ironic_staging_drivers.ovirt.ovirt:OVirtManagement ironic.hardware.interfaces.power = staging-amt = ironic_staging_drivers.amt.power:AMTPower staging-iboot = ironic_staging_drivers.iboot.power:IBootPower staging-libvirt = ironic_staging_drivers.libvirt.power:LibvirtPower - staging-ovirt = ironic_staging_drivers.ovirt.ovirt:oVirtPower + staging-ovirt = ironic_staging_drivers.ovirt.ovirt:OVirtPower staging-wol = ironic_staging_drivers.wol.power:WakeOnLanPower ironic.hardware.interfaces.vendor = @@ -62,7 +62,7 @@ ironic.hardware.types = staging-iboot = ironic_staging_drivers.iboot:IBootHardware staging-nm = ironic_staging_drivers.intel_nm:IntelNMHardware staging-libvirt = ironic_staging_drivers.libvirt:LibvirtHardware - staging-ovirt = ironic_staging_drivers.ovirt:oVirtHardware + staging-ovirt = ironic_staging_drivers.ovirt:OVirtHardware staging-wol = ironic_staging_drivers.wol:WOLHardware [build_sphinx]