From 54cb0849532e0d64adba523b8e8ad5c05beebab8 Mon Sep 17 00:00:00 2001 From: Wajdi Al-Hawari Date: Wed, 24 Aug 2016 14:28:40 -0400 Subject: [PATCH] Using the Power States Defined in The Core Refactored out the usage of power_states.py to make use of intended power states defined inside the core --- virtualpdu/pdu/__init__.py | 6 +++--- virtualpdu/pdu/apc_rackpdu.py | 6 +++--- virtualpdu/power_states.py | 20 ------------------- .../tests/integration/pdu/test_apc_rackpdu.py | 4 ++-- .../tests/unit/pdu/base_pdu_test_cases.py | 14 ++++++------- virtualpdu/tests/unit/test_core.py | 9 ++++----- 6 files changed, 19 insertions(+), 40 deletions(-) delete mode 100644 virtualpdu/power_states.py diff --git a/virtualpdu/pdu/__init__.py b/virtualpdu/pdu/__init__.py index 721f692..673b9ef 100644 --- a/virtualpdu/pdu/__init__.py +++ b/virtualpdu/pdu/__init__.py @@ -14,9 +14,9 @@ from pyasn1.type import univ -from virtualpdu.power_states import POWER_OFF -from virtualpdu.power_states import POWER_ON -from virtualpdu.power_states import REBOOT +from virtualpdu.core import POWER_OFF +from virtualpdu.core import POWER_ON +from virtualpdu.core import REBOOT class PDUOutlet(object): diff --git a/virtualpdu/pdu/apc_rackpdu.py b/virtualpdu/pdu/apc_rackpdu.py index 0f88012..48bb6ce 100644 --- a/virtualpdu/pdu/apc_rackpdu.py +++ b/virtualpdu/pdu/apc_rackpdu.py @@ -14,11 +14,11 @@ from pyasn1.type import univ +from virtualpdu.core import POWER_OFF +from virtualpdu.core import POWER_ON +from virtualpdu.core import REBOOT from virtualpdu.pdu import PDU from virtualpdu.pdu import PDUOutlet -from virtualpdu.power_states import POWER_OFF -from virtualpdu.power_states import POWER_ON -from virtualpdu.power_states import REBOOT rPDU_outlet_control_outlet_command = \ (1, 3, 6, 1, 4, 1, 318, 1, 1, 12, 3, 3, 1, 1, 4) diff --git a/virtualpdu/power_states.py b/virtualpdu/power_states.py deleted file mode 100644 index 98b4ef4..0000000 --- a/virtualpdu/power_states.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2016 Internap -# -# 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 -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from virtualpdu import core - -# TODO(mmitchell): Refactor the imports around to remove this file. -POWER_ON = core.POWER_ON -POWER_OFF = core.POWER_OFF -REBOOT = core.REBOOT diff --git a/virtualpdu/tests/integration/pdu/test_apc_rackpdu.py b/virtualpdu/tests/integration/pdu/test_apc_rackpdu.py index 7ee7ec4..4023611 100644 --- a/virtualpdu/tests/integration/pdu/test_apc_rackpdu.py +++ b/virtualpdu/tests/integration/pdu/test_apc_rackpdu.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +from virtualpdu.core import POWER_OFF +from virtualpdu.core import POWER_ON from virtualpdu.pdu.apc_rackpdu import APCRackPDU -from virtualpdu.power_states import POWER_OFF -from virtualpdu.power_states import POWER_ON from virtualpdu.tests.integration.pdu import PDUTestCase diff --git a/virtualpdu/tests/unit/pdu/base_pdu_test_cases.py b/virtualpdu/tests/unit/pdu/base_pdu_test_cases.py index e79f20b..9726f16 100644 --- a/virtualpdu/tests/unit/pdu/base_pdu_test_cases.py +++ b/virtualpdu/tests/unit/pdu/base_pdu_test_cases.py @@ -12,33 +12,33 @@ # See the License for the specific language governing permissions and # limitations under the License. -from virtualpdu import power_states +from virtualpdu import core class BasePDUTests(object): def test_power_on_notifies_core(self): self.pdu.oids[0].value = \ - self.pdu.get_native_power_state_from_core(power_states.POWER_ON) + self.pdu.get_native_power_state_from_core(core.POWER_ON) self.core_mock.pdu_outlet_state_changed.assert_called_with( name='my_pdu', outlet_number=1, - state=power_states.POWER_ON) + state=core.POWER_ON) def test_reboot_notifies_core(self): self.pdu.oids[0].value = \ - self.pdu.get_native_power_state_from_core(power_states.REBOOT) + self.pdu.get_native_power_state_from_core(core.REBOOT) self.core_mock.pdu_outlet_state_changed.assert_called_with( name='my_pdu', outlet_number=1, - state=power_states.REBOOT) + state=core.REBOOT) def test_power_off_notifies_core(self): self.pdu.oids[0].value = \ - self.pdu.get_native_power_state_from_core(power_states.POWER_OFF) + self.pdu.get_native_power_state_from_core(core.POWER_OFF) self.core_mock.pdu_outlet_state_changed.assert_called_with( name='my_pdu', outlet_number=1, - state=power_states.POWER_OFF) + state=core.POWER_OFF) diff --git a/virtualpdu/tests/unit/test_core.py b/virtualpdu/tests/unit/test_core.py index 7adf2d6..ec9d6c1 100644 --- a/virtualpdu/tests/unit/test_core.py +++ b/virtualpdu/tests/unit/test_core.py @@ -15,7 +15,6 @@ from mock import mock from virtualpdu import core from virtualpdu import drivers -from virtualpdu import power_states from virtualpdu.tests import base @@ -33,14 +32,14 @@ class TestCore(base.TestCase): def test_pdu_outlet_state_changed_on_power_off(self): self.core.pdu_outlet_state_changed(name='my_pdu', outlet_number=1, - state=power_states.POWER_OFF) + state=core.POWER_OFF) self.driver_mock.power_off.assert_called_with('server_one') def test_pdu_outlet_state_changed_machine_not_in_mapping_noop(self): self.core.pdu_outlet_state_changed(name='my_pdu', outlet_number=2, - state=power_states.POWER_OFF) + state=core.POWER_OFF) self.assertFalse(self.driver_mock.power_off.called) self.assertFalse(self.driver_mock.power_on.called) @@ -48,14 +47,14 @@ class TestCore(base.TestCase): def test_pdu_outlet_state_changed_on_power_on(self): self.core.pdu_outlet_state_changed(name='my_pdu', outlet_number=1, - state=power_states.POWER_ON) + state=core.POWER_ON) self.driver_mock.power_on.assert_called_with('server_one') def test_pdu_outlet_state_changed_on_reboot(self): self.core.pdu_outlet_state_changed(name='my_pdu', outlet_number=1, - state=power_states.REBOOT) + state=core.REBOOT) self.driver_mock.assert_has_calls([mock.call.power_off('server_one'), mock.call.power_on('server_one')])