示例#1
0
    def test__issue_wsman_command_calls__run_for_query(self):
        amt_power_driver = AMTPowerDriver()
        ip_address = factory.make_ipv4_address()
        power_pass = factory.make_name("power_pass")
        wsman_query_schema_uri = (
            "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"
            "CIM_AssociatedPowerManagementService"
        )
        wsman_opts = (
            "--port",
            "16992",
            "--hostname",
            ip_address,
            "--username",
            "admin",
            "--password",
            power_pass,
            "--noverifypeer",
            "--noverifyhost",
        )
        wsman_query_opts = wsman_opts + ("--optimize", "--encoding", "utf-8")
        action = ("enumerate", wsman_query_schema_uri)
        command = ("wsman",) + wsman_query_opts + action
        _run_mock = self.patch(amt_power_driver, "_run")
        _run_mock.return_value = b"ignored"

        amt_power_driver._issue_wsman_command("query", ip_address, power_pass)

        self.assertThat(
            _run_mock, MockCalledOnceWith(command, power_pass, stdin=None)
        )
示例#2
0
    def test__issue_wsman_command_calls__run_for_power(self):
        amt_power_driver = AMTPowerDriver()
        power_change = choice(['on', 'off', 'restart'])
        ip_address = factory.make_ipv4_address()
        power_pass = factory.make_name('power_pass')
        wsman_power_schema_uri = (
            'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/'
            'CIM_PowerManagementService?SystemCreationClassName='
            '"CIM_ComputerSystem",SystemName="Intel(r) AMT"'
            ',CreationClassName="CIM_PowerManagementService",Name='
            '"Intel(r) AMT Power Management Service"')
        wsman_opts = ('--port', '16992', '--hostname', ip_address,
                      '--username', 'admin', '--password', power_pass,
                      '--noverifypeer', '--noverifyhost')
        _render_wsman_state_xml_mock = self.patch(amt_power_driver,
                                                  '_render_wsman_state_xml')
        _render_wsman_state_xml_mock.return_value = b'stdin'
        command = ('wsman', 'invoke', '--method', 'RequestPowerStateChange',
                   wsman_power_schema_uri) + wsman_opts + ('--input', '-')
        _run_mock = self.patch(amt_power_driver, '_run')
        _run_mock.return_value = b'output'

        result = amt_power_driver._issue_wsman_command(power_change,
                                                       ip_address, power_pass)

        self.expectThat(
            _run_mock, MockCalledOnceWith(command, power_pass, stdin=b'stdin'))
        self.expectThat(result, Equals(b'output'))
示例#3
0
 def test_issue_wsman_has_config_file_from_snap(self):
     self.patch(amt_module.snappy,
                "get_snap_path").return_value = "/snap/maas/current"
     ip_address = factory.make_ipv4_address()
     power_pass = factory.make_name("power_pass")
     amt_power_driver = AMTPowerDriver()
     _run_mock = self.patch(amt_power_driver, "_run")
     amt_power_driver._issue_wsman_command("query", ip_address, power_pass)
     [call] = _run_mock.mock_calls
     self.assertEqual(
         call.args[0][:3],
         (
             "wsman",
             "-C",
             "/snap/maas/current/etc/openwsman/openwsman_client.conf",
         ),
     )
示例#4
0
    def test__issue_wsman_command_calls__run_for_query(self):
        amt_power_driver = AMTPowerDriver()
        ip_address = factory.make_ipv4_address()
        power_pass = factory.make_name('power_pass')
        wsman_query_schema_uri = (
            'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/'
            'CIM_AssociatedPowerManagementService')
        wsman_opts = ('--port', '16992', '--hostname', ip_address,
                      '--username', 'admin', '--password', power_pass,
                      '--noverifypeer', '--noverifyhost')
        wsman_query_opts = wsman_opts + ('--optimize', '--encoding', 'utf-8')
        command = ('wsman', 'enumerate',
                   wsman_query_schema_uri) + wsman_query_opts
        _run_mock = self.patch(amt_power_driver, '_run')
        _run_mock.return_value = b'ignored'

        amt_power_driver._issue_wsman_command('query', ip_address, power_pass)

        self.assertThat(_run_mock,
                        MockCalledOnceWith(command, power_pass, stdin=None))
示例#5
0
    def test__issue_wsman_command_calls__run_for_power(self):
        amt_power_driver = AMTPowerDriver()
        power_change = choice(["on", "off", "restart"])
        ip_address = factory.make_ipv4_address()
        power_pass = factory.make_name("power_pass")
        wsman_power_schema_uri = (
            "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"
            "CIM_PowerManagementService?SystemCreationClassName="
            '"CIM_ComputerSystem"&SystemName="Intel(r) AMT"'
            '&CreationClassName="CIM_PowerManagementService"&Name='
            '"Intel(r) AMT Power Management Service"'
        )
        wsman_opts = (
            "--port",
            "16992",
            "--hostname",
            ip_address,
            "--username",
            "admin",
            "--password",
            power_pass,
            "--noverifypeer",
            "--noverifyhost",
        )
        _render_wsman_state_xml_mock = self.patch(
            amt_power_driver, "_render_wsman_state_xml"
        )
        _render_wsman_state_xml_mock.return_value = b"stdin"
        action = (
            "invoke",
            "--method",
            "RequestPowerStateChange",
            wsman_power_schema_uri,
        )
        wsman_opts += ("--input", "-")
        command = ("wsman",) + wsman_opts + action
        _run_mock = self.patch(amt_power_driver, "_run")
        _run_mock.return_value = b"output"

        result = amt_power_driver._issue_wsman_command(
            power_change, ip_address, power_pass
        )

        self.expectThat(
            _run_mock, MockCalledOnceWith(command, power_pass, stdin=b"stdin")
        )
        self.expectThat(result, Equals(b"output"))