Merge pull request #9 from idjaw/power_state_refactor

Using the Power States Defined in The Core
This commit is contained in:
Mathieu Mitchell 2016-08-25 07:17:22 -04:00 committed by GitHub
commit 5c228b775d
6 changed files with 19 additions and 40 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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')])