Exemplo n.º 1
0
    def test_run_hmc_command_returns_command_output(self):
        driver = HMCPowerDriver()
        command = factory.make_name("command")
        context = make_context()
        SSHClient = self.patch(hmc_module, "SSHClient")
        AutoAddPolicy = self.patch(hmc_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_hmc_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))
Exemplo n.º 2
0
 def test_power_off_calls_run_hmc_command(self):
     driver = HMCPowerDriver()
     system_id = factory.make_name('system_id')
     context = make_context()
     run_hmc_command = self.patch(driver, "run_hmc_command")
     driver.power_off(system_id, context)
     self.assertThat(
         run_hmc_command,
         MockCalledOnceWith(
             "chsysstate -r lpar -m %s -o shutdown -n %s --immed" %
             (context['server_name'], context['lpar']), **context))
Exemplo n.º 3
0
    def test_power_query_returns_power_state(self, power_state):
        def get_hmc_state(power_state):
            if power_state in HMCState.OFF:
                return "off"
            elif power_state in HMCState.ON:
                return "on"

        driver = HMCPowerDriver()
        system_id = factory.make_name("system_id")
        context = make_context()
        run_hmc_command = self.patch(driver, "run_hmc_command")
        run_hmc_command.return_value = power_state
        output = driver.power_query(system_id, context)
        self.assertThat(output, Equals(get_hmc_state(power_state)))
Exemplo n.º 4
0
 def test_power_on_calls_run_hmc_command(self):
     driver = HMCPowerDriver()
     system_id = factory.make_name('system_id')
     context = make_context()
     power_query = self.patch(driver, "power_query")
     power_query.return_value = choice(HMCState.ON)
     self.patch(driver, "power_off")
     run_hmc_command = self.patch(driver, "run_hmc_command")
     driver.power_on(system_id, context)
     self.assertThat(
         run_hmc_command,
         MockCalledOnceWith(
             "chsysstate -r lpar -m %s -o on -n %s --bootstring network-all"
             % (context['server_name'], context['lpar']), **context))
Exemplo n.º 5
0
 def test_power_query_crashes_when_unable_to_find_match(self):
     driver = HMCPowerDriver()
     system_id = factory.make_name("system_id")
     context = make_context()
     run_hmc_command = self.patch(driver, "run_hmc_command")
     run_hmc_command.return_value = "Rubbish"
     self.assertRaises(PowerFatalError, driver.power_query, system_id,
                       context)
Exemplo n.º 6
0
 def test_power_query_crashes_for_connection_error(self):
     driver = HMCPowerDriver()
     system_id = factory.make_name("system_id")
     context = make_context()
     run_hmc_command = self.patch(driver, "run_hmc_command")
     run_hmc_command.side_effect = PowerConnError("Connection Error")
     self.assertRaises(PowerActionError, driver.power_query, system_id,
                       context)
Exemplo n.º 7
0
 def test_run_hmc_command_crashes_for_ssh_connection_error(self, error):
     driver = HMCPowerDriver()
     command = factory.make_name("command")
     context = make_context()
     self.patch(hmc_module, "AutoAddPolicy")
     SSHClient = self.patch(hmc_module, "SSHClient")
     ssh_client = SSHClient.return_value
     ssh_client.connect.side_effect = error
     self.assertRaises(PowerConnError, driver.run_hmc_command, command,
                       **context)
Exemplo n.º 8
0
 def test_power_on_crashes_for_connection_error(self):
     driver = HMCPowerDriver()
     system_id = factory.make_name('system_id')
     context = make_context()
     power_query = self.patch(driver, "power_query")
     power_query.return_value = 'off'
     run_hmc_command = self.patch(driver, "run_hmc_command")
     run_hmc_command.side_effect = PowerConnError("Connection Error")
     self.assertRaises(PowerActionError, driver.power_on, system_id,
                       context)
Exemplo n.º 9
0
        # be used through `PodDriverRegistry`, except when a power action
        # is to be performed.
        schemas = [
            driver.get_schema(detect_missing_packages=detect_missing_packages)
            for _, driver in cls
        ]
        validate(schemas, JSON_POWER_DRIVERS_SCHEMA)
        return schemas


# 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(),