Exemple #1
0
 def test_power_state_snmp_failure(self, mock_get_client):
     # Ensure SNMP failure exceptions raised during a query are propagated
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     mock_client.get.side_effect = self._get_snmp_failure()
     self.assertRaises(exception.SNMPFailure,
                       driver.power_state)
     mock_client.get.assert_called_once_with(driver._snmp_oid())
Exemple #2
0
 def test_power_state_error(self, mock_get_client):
     # Ensure an unexpected power state returns an error
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     mock_client.get.return_value = 42
     pstate = driver.power_state()
     mock_client.get.assert_called_once_with(driver._snmp_oid())
     self.assertEqual(states.ERROR, pstate)
Exemple #3
0
 def test_power_state_off(self, mock_get_client):
     # Ensure the power off state is queried correctly
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     mock_client.get.return_value = driver.value_power_off
     pstate = driver.power_state()
     mock_client.get.assert_called_once_with(driver._snmp_oid())
     self.assertEqual(states.POWER_OFF, pstate)
Exemple #4
0
 def _test_simple_device_power_state_on(self, snmp_driver, mock_get_client):
     # Ensure a simple device driver queries power on correctly
     mock_client = mock_get_client.return_value
     self._set_snmp_driver(snmp_driver)
     driver = snmp._get_driver(self.node)
     mock_client.get.return_value = driver.value_power_on
     pstate = driver.power_state()
     mock_client.get.assert_called_once_with(driver._snmp_oid())
     self.assertEqual(states.POWER_ON, pstate)
Exemple #5
0
 def test_eaton_power_power_state_pending_on(self, mock_get_client):
     # Ensure the Eaton Power driver queries pending on correctly
     mock_client = mock_get_client.return_value
     self._set_snmp_driver("eatonpower")
     driver = snmp._get_driver(self.node)
     mock_client.get.return_value = driver.status_pending_on
     pstate = driver.power_state()
     mock_client.get.assert_called_once_with(
             driver._snmp_oid(driver.oid_status))
     self.assertEqual(states.POWER_OFF, pstate)
Exemple #6
0
 def test_cyberpower_snmp_objects(self, mock_get_client):
     # Ensure the correct SNMP object OIDs and values are used by the
     # CyberPower driver
     self._update_driver_info(snmp_driver="cyberpower",
                              snmp_outlet="3")
     driver = snmp._get_driver(self.node)
     oid = (1, 3, 6, 1, 4, 1, 3808, 1, 1, 3, 3, 3, 1, 1, 4, 3)
     self.assertEqual(oid, driver._snmp_oid())
     self.assertEqual(1, driver.value_power_on)
     self.assertEqual(2, driver.value_power_off)
Exemple #7
0
 def test_teltronix_snmp_objects(self, mock_get_client):
     # Ensure the correct SNMP object OIDs and values are used by the
     # Teltronix driver
     self._update_driver_info(snmp_driver="teltronix",
                              snmp_outlet="3")
     driver = snmp._get_driver(self.node)
     oid = (1, 3, 6, 1, 4, 1, 23620, 1, 2, 2, 1, 4, 3)
     self.assertEqual(oid, driver._snmp_oid())
     self.assertEqual(2, driver.value_power_on)
     self.assertEqual(1, driver.value_power_off)
Exemple #8
0
 def test_power_off(self, mock_get_client):
     # Ensure the device is powered off correctly
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     mock_client.get.return_value = driver.value_power_off
     pstate = driver.power_off()
     mock_client.set.assert_called_once_with(driver._snmp_oid(),
                                             driver.value_power_off)
     mock_client.get.assert_called_once_with(driver._snmp_oid())
     self.assertEqual(states.POWER_OFF, pstate)
Exemple #9
0
 def test_power_reset_off_snmp_get_failure(self, mock_get_client):
     # Ensure SNMP failure exceptions raised during a reset power off get
     # operation are propagated
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     mock_client.get.side_effect = self._get_snmp_failure()
     self.assertRaises(exception.SNMPFailure,
                       driver.power_reset)
     mock_client.set.assert_called_once_with(driver._snmp_oid(),
                                             driver.value_power_off)
     mock_client.get.assert_called_once_with(driver._snmp_oid())
Exemple #10
0
 def _test_simple_device_power_off(self, snmp_driver, mock_get_client):
     # Ensure a simple device driver powers off correctly
     mock_client = mock_get_client.return_value
     self._set_snmp_driver(snmp_driver)
     driver = snmp._get_driver(self.node)
     mock_client.get.return_value = driver.value_power_off
     pstate = driver.power_off()
     mock_client.set.assert_called_once_with(driver._snmp_oid(),
                                             driver.value_power_off)
     mock_client.get.assert_called_once_with(driver._snmp_oid())
     self.assertEqual(states.POWER_OFF, pstate)
Exemple #11
0
 def test_power_on_timeout(self, mock_sleep, mock_get_client):
     # Ensure that a power on consistency poll timeout causes an error
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     mock_client.get.return_value = driver.value_power_off
     pstate = driver.power_on()
     mock_client.set.assert_called_once_with(driver._snmp_oid(),
                                             driver.value_power_on)
     attempts = CONF.snmp.power_timeout // driver.retry_interval
     calls = [mock.call(driver._snmp_oid())] * attempts
     mock_client.get.assert_has_calls(calls)
     self.assertEqual(states.ERROR, pstate)
Exemple #12
0
 def test_power_off_delay(self, mock_sleep, mock_get_client):
     # Ensure driver waits for the state to change following a power off
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     mock_client.get.side_effect = [driver.value_power_on,
                                    driver.value_power_off]
     pstate = driver.power_off()
     mock_client.set.assert_called_once_with(driver._snmp_oid(),
                                             driver.value_power_off)
     calls = [mock.call(driver._snmp_oid())] * 2
     mock_client.get.assert_has_calls(calls)
     self.assertEqual(states.POWER_OFF, pstate)
Exemple #13
0
 def test_eaton_power_power_off(self, mock_get_client):
     # Ensure the Eaton Power driver powers off correctly
     mock_client = mock_get_client.return_value
     self._set_snmp_driver("eatonpower")
     driver = snmp._get_driver(self.node)
     mock_client.get.return_value = driver.status_off
     pstate = driver.power_off()
     mock_client.set.assert_called_once_with(
             driver._snmp_oid(driver.oid_poweroff), driver.value_power_off)
     mock_client.get.assert_called_once_with(
             driver._snmp_oid(driver.oid_status))
     self.assertEqual(states.POWER_OFF, pstate)
Exemple #14
0
 def test_power_reset(self, mock_get_client):
     # Ensure the device is reset correctly
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     mock_client.get.side_effect = [driver.value_power_off,
                                    driver.value_power_on]
     pstate = driver.power_reset()
     calls = [mock.call(driver._snmp_oid(), driver.value_power_off),
              mock.call(driver._snmp_oid(), driver.value_power_on)]
     mock_client.set.assert_has_calls(calls)
     calls = [mock.call(driver._snmp_oid())] * 2
     mock_client.get.assert_has_calls(calls)
     self.assertEqual(states.POWER_ON, pstate)
Exemple #15
0
 def test_power_reset_off_invalid_state(self, mock_sleep, mock_get_client):
     # Ensure driver retries when querying unexpected states following a
     # power off during a reset
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     mock_client.get.return_value = 42
     pstate = driver.power_reset()
     mock_client.set.assert_called_once_with(driver._snmp_oid(),
                                             driver.value_power_off)
     attempts = CONF.snmp.power_timeout // driver.retry_interval
     calls = [mock.call(driver._snmp_oid())] * attempts
     mock_client.get.assert_has_calls(calls)
     self.assertEqual(states.ERROR, pstate)
Exemple #16
0
 def test_power_reset_on_snmp_set_failure(self, mock_get_client):
     # Ensure SNMP failure exceptions raised during a reset power on set
     # operation are propagated
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     mock_client.set.side_effect = [None, self._get_snmp_failure()]
     mock_client.get.return_value = driver.value_power_off
     self.assertRaises(exception.SNMPFailure,
                       driver.power_reset)
     calls = [mock.call(driver._snmp_oid(), driver.value_power_off),
              mock.call(driver._snmp_oid(), driver.value_power_on)]
     mock_client.set.assert_has_calls(calls)
     mock_client.get.assert_called_once_with(driver._snmp_oid())
Exemple #17
0
 def test_power_reset_on_invalid_state(self, mock_sleep, mock_get_client):
     # Ensure driver retries when querying unexpected states following a
     # power on during a reset
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     attempts = CONF.snmp.power_timeout // driver.retry_interval
     mock_client.get.side_effect = ([driver.value_power_off] +
                                    [42] * attempts)
     pstate = driver.power_reset()
     calls = [mock.call(driver._snmp_oid(), driver.value_power_off),
              mock.call(driver._snmp_oid(), driver.value_power_on)]
     mock_client.set.assert_has_calls(calls)
     calls = [mock.call(driver._snmp_oid())] * (1 + attempts)
     mock_client.get.assert_has_calls(calls)
     self.assertEqual(states.ERROR, pstate)
Exemple #18
0
 def test_power_reset_off_delay_on_delay(self, mock_sleep, mock_get_client):
     # Ensure driver waits for both state changes following a power reset
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     mock_client.get.side_effect = [driver.value_power_on,
                                    driver.value_power_off,
                                    driver.value_power_off,
                                    driver.value_power_on]
     pstate = driver.power_reset()
     calls = [mock.call(driver._snmp_oid(), driver.value_power_off),
              mock.call(driver._snmp_oid(), driver.value_power_on)]
     mock_client.set.assert_has_calls(calls)
     calls = [mock.call(driver._snmp_oid())] * 4
     mock_client.get.assert_has_calls(calls)
     self.assertEqual(states.POWER_ON, pstate)
Exemple #19
0
 def test_eaton_power_power_reset(self, mock_get_client):
     # Ensure the Eaton Power driver resets correctly
     mock_client = mock_get_client.return_value
     self._set_snmp_driver("eatonpower")
     driver = snmp._get_driver(self.node)
     mock_client.get.side_effect = [driver.status_off, driver.status_on]
     pstate = driver.power_reset()
     calls = [mock.call(driver._snmp_oid(driver.oid_poweroff),
                        driver.value_power_off),
              mock.call(driver._snmp_oid(driver.oid_poweron),
                        driver.value_power_on)]
     mock_client.set.assert_has_calls(calls)
     calls = [mock.call(driver._snmp_oid(driver.oid_status))] * 2
     mock_client.get.assert_has_calls(calls)
     self.assertEqual(states.POWER_ON, pstate)
Exemple #20
0
 def test_power_reset_on_timeout(self, mock_sleep, mock_get_client):
     # Ensure that a power on consistency poll timeout during a reset
     # causes an error
     mock_client = mock_get_client.return_value
     driver = snmp._get_driver(self.node)
     attempts = CONF.snmp.power_timeout // driver.retry_interval
     mock_client.get.side_effect = ([driver.value_power_off] *
                                    (1 + attempts))
     pstate = driver.power_reset()
     calls = [mock.call(driver._snmp_oid(), driver.value_power_off),
              mock.call(driver._snmp_oid(), driver.value_power_on)]
     mock_client.set.assert_has_calls(calls)
     calls = [mock.call(driver._snmp_oid())] * (1 + attempts)
     mock_client.get.assert_has_calls(calls)
     self.assertEqual(states.ERROR, pstate)
Exemple #21
0
 def test_eaton_power_snmp_objects(self, mock_get_client):
     # Ensure the correct SNMP object OIDs and values are used by the Eaton
     # Power driver
     self._update_driver_info(snmp_driver="eatonpower",
                              snmp_outlet="3")
     driver = snmp._get_driver(self.node)
     status_oid = (1, 3, 6, 1, 4, 1, 534, 6, 6, 7, 6, 6, 1, 2, 3)
     poweron_oid = (1, 3, 6, 1, 4, 1, 534, 6, 6, 7, 6, 6, 1, 3, 3)
     poweroff_oid = (1, 3, 6, 1, 4, 1, 534, 6, 6, 7, 6, 6, 1, 4, 3)
     self.assertEqual(status_oid, driver._snmp_oid(driver.oid_status))
     self.assertEqual(poweron_oid, driver._snmp_oid(driver.oid_poweron))
     self.assertEqual(poweroff_oid, driver._snmp_oid(driver.oid_poweroff))
     self.assertEqual(0, driver.status_off)
     self.assertEqual(1, driver.status_on)
     self.assertEqual(2, driver.status_pending_off)
     self.assertEqual(3, driver.status_pending_on)