Esempio n. 1
0
    def test_run_wedge_command_returns_command_output(self):
        driver = WedgePowerDriver()
        command = factory.make_name("command")
        context = make_context()
        SSHClient = self.patch(wedge_module, "SSHClient")
        AutoAddPolicy = self.patch(wedge_module, "AutoAddPolicy")
        ssh_client = SSHClient.return_value
        expected = factory.make_name("output").encode("utf-8")
        stdout = BytesIO(expected)
        streams = factory.make_streams(stdout=stdout)
        ssh_client.exec_command = Mock(return_value=streams)
        output = driver.run_wedge_command(command, **context)

        self.expectThat(expected.decode("utf-8"), Equals(output))
        self.expectThat(SSHClient, MockCalledOnceWith())
        self.expectThat(
            ssh_client.set_missing_host_key_policy,
            MockCalledOnceWith(AutoAddPolicy.return_value),
        )
        self.expectThat(
            ssh_client.connect,
            MockCalledOnceWith(
                context["power_address"],
                username=context["power_user"],
                password=context["power_pass"],
            ),
        )
        self.expectThat(ssh_client.exec_command, MockCalledOnceWith(command))
Esempio n. 2
0
 def test_power_off_calls_run_wedge_command(self):
     driver = WedgePowerDriver()
     system_id = factory.make_name("system_id")
     context = make_context()
     run_wedge_command = self.patch(driver, "run_wedge_command")
     driver.power_off(system_id, context)
     self.assertThat(
         run_wedge_command,
         MockCalledOnceWith("/usr/local/bin/wedge_power.sh off", **context),
     )
Esempio n. 3
0
 def test_power_on_calls_run_wedge_command(self):
     driver = WedgePowerDriver()
     system_id = factory.make_name("system_id")
     context = make_context()
     power_query = self.patch(driver, "power_query")
     power_query.return_value = choice(WedgeState.ON)
     self.patch(driver, "power_off")
     run_wedge_command = self.patch(driver, "run_wedge_command")
     driver.power_on(system_id, context)
     self.assertThat(
         run_wedge_command,
         MockCalledOnceWith("/usr/local/bin/wedge_power.sh on", **context),
     )
Esempio n. 4
0
 def test_power_query_returns_power_state(self, power_state):
     def get_wedge_state(power_state):
         if power_state in WedgeState.OFF:
             return 'off'
         elif power_state in WedgeState.ON:
             return 'on'
     driver = WedgePowerDriver()
     system_id = factory.make_name('system_id')
     context = make_context()
     run_wedge_command = self.patch(driver, "run_wedge_command")
     run_wedge_command.return_value = power_state
     output = driver.power_query(system_id, context)
     self.assertThat(output, Equals(get_wedge_state(power_state)))
Esempio n. 5
0
 def test_power_query_crashes_when_unable_to_find_match(self):
     driver = WedgePowerDriver()
     system_id = factory.make_name('system_id')
     context = make_context()
     run_wedge_command = self.patch(driver, "run_wedge_command")
     run_wedge_command.return_value = "Rubbish"
     self.assertRaises(
         PowerFatalError, driver.power_query, system_id, context)
Esempio n. 6
0
 def test_power_query_crashes_for_connection_error(self):
     driver = WedgePowerDriver()
     system_id = factory.make_name('system_id')
     context = make_context()
     run_wedge_command = self.patch(driver, "run_wedge_command")
     run_wedge_command.side_effect = PowerConnError("Connection Error")
     self.assertRaises(
         PowerActionError, driver.power_query, system_id, context)
Esempio n. 7
0
 def test_run_wedge_command_crashes_for_ssh_connection_error(self, error):
     driver = WedgePowerDriver()
     command = factory.make_name('command')
     context = make_context()
     self.patch(wedge_module, "AutoAddPolicy")
     SSHClient = self.patch(wedge_module, "SSHClient")
     ssh_client = SSHClient.return_value
     ssh_client.connect.side_effect = error
     self.assertRaises(
         PowerConnError, driver.run_wedge_command, command, **context)
Esempio n. 8
0
# Register all the power drivers.
power_drivers = [
    AMTPowerDriver(),
    APCPowerDriver(),
    DLIPowerDriver(),
    HMCPowerDriver(),
    IPMIPowerDriver(),
    LXDPowerDriver(),
    ManualPowerDriver(),
    MoonshotIPMIPowerDriver(),
    MSCMPowerDriver(),
    MicrosoftOCSPowerDriver(),
    NovaPowerDriver(),
    OpenBMCPowerDriver(),
    RECSPowerDriver(),
    RedfishPowerDriver(),
    SeaMicroPowerDriver(),
    UCSMPowerDriver(),
    VirshPowerDriver(),
    VMwarePowerDriver(),
    WedgePowerDriver(),
]
for driver in power_drivers:
    PowerDriverRegistry.register_item(driver.name, driver)


# Pod drivers are also power drivers.
for driver_name, driver in PodDriverRegistry:
    PowerDriverRegistry.register_item(driver_name, driver)