Esempio n. 1
0
    def test__finds_power_address_from_mac_address(self):
        context = make_context()
        driver = IPMIPowerDriver()
        ip_address = factory.make_ipv4_address()
        find_ip_via_arp = self.patch(ipmi_module, 'find_ip_via_arp')
        find_ip_via_arp.return_value = ip_address
        power_change = random.choice(("on", "off"))

        context['mac_address'] = factory.make_mac_address()
        context['power_address'] = random.choice((None, "", "   "))

        self.patch_autospec(driver, "_issue_ipmi_chassis_config_command")
        self.patch_autospec(driver, "_issue_ipmipower_command")
        driver._issue_ipmi_command(power_change, **context)

        # The IP address is passed to _issue_ipmi_chassis_config_command.
        self.assertThat(
            driver._issue_ipmi_chassis_config_command,
            MockCalledOnceWith(ANY,
                               power_change,
                               ip_address,
                               power_boot_type=None))
        # The IP address is also within the command passed to
        # _issue_ipmi_chassis_config_command.
        self.assertThat(driver._issue_ipmi_chassis_config_command.call_args[0],
                        Contains(ip_address))
        # The IP address is passed to _issue_ipmipower_command.
        self.assertThat(driver._issue_ipmipower_command,
                        MockCalledOnceWith(ANY, power_change, ip_address))
        # The IP address is also within the command passed to
        # _issue_ipmipower_command.
        self.assertThat(driver._issue_ipmipower_command.call_args[0],
                        Contains(ip_address))
Esempio n. 2
0
    def test__issue_ipmi_command_issues_power_on(self):
        context = make_context()
        ipmi_chassis_config_command = make_ipmi_chassis_config_command(
            **context, tmp_config_name=ANY)
        ipmipower_command = make_ipmipower_command(**context)
        ipmipower_command += ("--cycle", "--on-if-off")
        ipmi_power_driver = IPMIPowerDriver()
        env = get_env_with_locale()
        popen_mock = self.patch(ipmi_module, "Popen")
        process = popen_mock.return_value
        process.communicate.side_effect = [(b"", b""), (b"on", b"")]
        process.returncode = 0

        result = ipmi_power_driver._issue_ipmi_command("on", **context)

        self.expectThat(
            popen_mock,
            MockCallsMatch(
                call(
                    ipmi_chassis_config_command,
                    stdout=PIPE,
                    stderr=PIPE,
                    env=env,
                ),
                call(ipmipower_command, stdout=PIPE, stderr=PIPE, env=env),
            ),
        )
        self.expectThat(result, Equals("on"))
Esempio n. 3
0
    def test__issue_ipmi_command_issues_power_off_soft_mode(self):
        context = make_context()
        context['power_off_mode'] = 'soft'
        ipmi_chassis_config_command = make_ipmi_chassis_config_command(
            **context, tmp_config_name=ANY)
        ipmipower_command = make_ipmipower_command(**context)
        ipmipower_command += ('--soft', )
        ipmi_power_driver = IPMIPowerDriver()
        env = get_env_with_locale()
        popen_mock = self.patch(ipmi_module, 'Popen')
        process = popen_mock.return_value
        process.communicate.side_effect = [(b'', b''), (b'off', b'')]
        process.returncode = 0

        result = ipmi_power_driver._issue_ipmi_command('off', **context)

        self.expectThat(
            popen_mock,
            MockCallsMatch(
                call(ipmi_chassis_config_command,
                     stdout=PIPE,
                     stderr=PIPE,
                     env=env),
                call(ipmipower_command, stdout=PIPE, stderr=PIPE, env=env)))
        self.expectThat(result, Equals('off'))
Esempio n. 4
0
 def test_issue_ipmi_command_issues_power_query(self):
     context = make_context()
     ipmipower_command = make_ipmipower_command(**context)
     ipmipower_command += ("--stat", )
     ipmi_power_driver = IPMIPowerDriver()
     run_command_mock = self.patch(ipmi_module.shell, "run_command")
     run_command_mock.return_value = ProcessResult(stdout="other")
     result = ipmi_power_driver._issue_ipmi_command("query", **context)
     run_command_mock.assert_called_once_with(*ipmipower_command)
     self.expectThat(result, Equals("other"))
Esempio n. 5
0
    def test__issue_ipmi_chassis_config_with_power_boot_type(self):
        context = make_context()
        driver = IPMIPowerDriver()
        ip_address = factory.make_ipv4_address()
        find_ip_via_arp = self.patch(ipmi_module, "find_ip_via_arp")
        find_ip_via_arp.return_value = ip_address
        power_change = "on"

        context["mac_address"] = factory.make_mac_address()
        context["power_address"] = random.choice((None, "", "   "))
        context["power_boot_type"] = IPMI_BOOT_TYPE.EFI

        self.patch_autospec(driver, "_issue_ipmi_chassis_config_command")
        self.patch_autospec(driver, "_issue_ipmipower_command")
        driver._issue_ipmi_command(power_change, **context)

        # The IP address is passed to _issue_ipmi_chassis_config_command.
        self.assertThat(
            driver._issue_ipmi_chassis_config_command,
            MockCalledOnceWith(
                ANY,
                power_change,
                ip_address,
                power_boot_type=IPMI_BOOT_TYPE.EFI,
            ),
        )
        # The IP address is also within the command passed to
        # _issue_ipmi_chassis_config_command.
        self.assertThat(
            driver._issue_ipmi_chassis_config_command.call_args[0],
            Contains(ip_address),
        )
        # The IP address is passed to _issue_ipmipower_command.
        self.assertThat(
            driver._issue_ipmipower_command,
            MockCalledOnceWith(ANY, power_change, ip_address),
        )
Esempio n. 6
0
 def test_issue_ipmi_command_issues_power_on(self):
     context = make_context()
     ipmi_chassis_config_command = make_ipmi_chassis_config_command(
         **context, tmp_config_name=ANY)
     ipmipower_command = make_ipmipower_command(**context)
     ipmipower_command += ("--cycle", "--on-if-off")
     ipmi_power_driver = IPMIPowerDriver()
     run_command_mock = self.patch(ipmi_module.shell, "run_command")
     run_command_mock.side_effect = [
         ProcessResult(),
         ProcessResult(stdout="on"),
     ]
     result = ipmi_power_driver._issue_ipmi_command("on", **context)
     run_command_mock.assert_has_calls(
         [call(*ipmi_chassis_config_command),
          call(*ipmipower_command)])
     self.expectThat(result, Equals("on"))
Esempio n. 7
0
    def test__issue_ipmi_command_issues_power_query(self):
        context = make_context()
        ipmipower_command = make_ipmipower_command(**context)
        ipmipower_command += ('--stat', )
        ipmi_power_driver = IPMIPowerDriver()
        env = select_c_utf8_locale()
        popen_mock = self.patch(ipmi_module, 'Popen')
        process = popen_mock.return_value
        process.communicate.return_value = (b'other', b'')
        process.returncode = 0

        result = ipmi_power_driver._issue_ipmi_command('query', **context)

        self.expectThat(
            popen_mock, MockCalledOnceWith(
                ipmipower_command, stdout=PIPE,
                stderr=PIPE, env=env))
        self.expectThat(result, Equals('other'))
Esempio n. 8
0
    def test__issue_ipmi_command_issues_power_off_soft_mode(self):
        context = make_context()
        context["power_off_mode"] = "soft"
        ipmipower_command = make_ipmipower_command(**context)
        ipmipower_command += ("--soft", )
        ipmi_power_driver = IPMIPowerDriver()
        env = get_env_with_locale()
        popen_mock = self.patch(ipmi_module, "Popen")
        process = popen_mock.return_value
        process.communicate.side_effect = [(b"off", b"")]
        process.returncode = 0

        result = ipmi_power_driver._issue_ipmi_command("off", **context)

        self.expectThat(
            popen_mock,
            MockCallsMatch(
                call(ipmipower_command, stdout=PIPE, stderr=PIPE, env=env)),
        )
        self.expectThat(result, Equals("off"))
Esempio n. 9
0
    def test__issue_ipmi_command_issues_power_query(self):
        context = make_context()
        ipmipower_command = make_ipmipower_command(**context)
        ipmipower_command += ("--stat", )
        ipmi_power_driver = IPMIPowerDriver()
        env = get_env_with_locale()
        popen_mock = self.patch(ipmi_module, "Popen")
        process = popen_mock.return_value
        process.communicate.return_value = (b"other", b"")
        process.returncode = 0

        result = ipmi_power_driver._issue_ipmi_command("query", **context)

        self.expectThat(
            popen_mock,
            MockCalledOnceWith(ipmipower_command,
                               stdout=PIPE,
                               stderr=PIPE,
                               env=env),
        )
        self.expectThat(result, Equals("other"))