Merge pull request #36 from stephanerobert/async_switch_call
Async calls to libvirt driver
This commit is contained in:
commit
6daec3f99d
|
@ -5,3 +5,4 @@
|
|||
pbr>=1.6 # Apache-2.0
|
||||
libvirt-python>=1.2.5 # LGPLv2+
|
||||
pysnmp==4.3.2 # BSD
|
||||
futures==3.0.5 # BSD
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
# 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 concurrent.futures import ThreadPoolExecutor
|
||||
import logging
|
||||
|
||||
POWER_ON = 'POWER_ON'
|
||||
|
@ -42,13 +43,25 @@ class Core(object):
|
|||
except KeyError:
|
||||
return
|
||||
|
||||
self._async_change(device, state)
|
||||
|
||||
def _async_change(self, device, state):
|
||||
if state == POWER_ON:
|
||||
self.driver.power_on(device)
|
||||
def switch_power():
|
||||
self.driver.power_on(device)
|
||||
elif state == POWER_OFF:
|
||||
self.driver.power_off(device)
|
||||
def switch_power():
|
||||
self.driver.power_off(device)
|
||||
elif state == REBOOT:
|
||||
self.driver.power_off(device)
|
||||
self.driver.power_on(device)
|
||||
def switch_power():
|
||||
self.driver.power_off(device)
|
||||
self.driver.power_on(device)
|
||||
else:
|
||||
self.logger.error("Unknown power state: {}".format(state))
|
||||
return
|
||||
|
||||
with ThreadPoolExecutor(max_workers=1) as executor:
|
||||
executor.submit(switch_power)
|
||||
|
||||
def get_pdu_outlet_state(self, pdu, outlet):
|
||||
try:
|
||||
|
|
|
@ -13,14 +13,13 @@
|
|||
# limitations under the License.
|
||||
|
||||
from pyasn1.type import univ
|
||||
|
||||
from virtualpdu import core
|
||||
from virtualpdu.pdu import BasePDUOutletStates
|
||||
from virtualpdu.pdu import PDU
|
||||
from virtualpdu.pdu import PDUOutletControl
|
||||
from virtualpdu.pdu import static_info
|
||||
from virtualpdu.pdu import sysDescr
|
||||
from virtualpdu.pdu import sysObjectID
|
||||
from virtualpdu.pdu import static_info
|
||||
|
||||
sBTA = (1, 3, 6, 1, 4, 1, 4779)
|
||||
sBTA_modules_RPC_outlet_state = sBTA + (1, 3, 5, 3, 1, 3)
|
||||
|
|
|
@ -49,3 +49,7 @@ class TestLibvirtDeviceProviderIntegration(base.TestCase):
|
|||
def test_power_off_domain_not_found(self):
|
||||
self.assertRaises(drivers.DeviceNotFound,
|
||||
self.driver.power_off, 'i-dont-exist')
|
||||
|
||||
def test_get_power_domain_not_found_raises(self):
|
||||
self.assertRaises(drivers.DeviceNotFound,
|
||||
self.driver.get_power_state, 'i-dont-exist')
|
||||
|
|
|
@ -12,10 +12,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from pyasn1.type import univ
|
||||
|
||||
from virtualpdu.pdu import baytech_mrp27
|
||||
from virtualpdu.pdu import sysObjectID
|
||||
from virtualpdu.pdu import sysDescr
|
||||
from virtualpdu.pdu import sysObjectID
|
||||
from virtualpdu.tests import base
|
||||
from virtualpdu.tests.unit.pdu.base_pdu_test_cases import BasePDUTests
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
# 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.
|
||||
import time
|
||||
|
||||
from mock import mock
|
||||
from virtualpdu import core
|
||||
|
@ -35,7 +36,7 @@ class TestCore(base.TestCase):
|
|||
self.core.pdu_outlet_state_changed(pdu='my_pdu',
|
||||
outlet=1,
|
||||
state=core.POWER_OFF)
|
||||
|
||||
time.sleep(0)
|
||||
self.driver_mock.power_off.assert_called_with('server_one')
|
||||
|
||||
def test_pdu_outlet_state_changed_machine_not_in_mapping_noop(self):
|
||||
|
@ -50,14 +51,14 @@ class TestCore(base.TestCase):
|
|||
self.core.pdu_outlet_state_changed(pdu='my_pdu',
|
||||
outlet=1,
|
||||
state=core.POWER_ON)
|
||||
|
||||
time.sleep(0)
|
||||
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(pdu='my_pdu',
|
||||
outlet=1,
|
||||
state=core.REBOOT)
|
||||
|
||||
time.sleep(0)
|
||||
self.driver_mock.assert_has_calls([mock.call.power_off('server_one'),
|
||||
mock.call.power_on('server_one')])
|
||||
|
||||
|
|
Loading…
Reference in New Issue