예제 #1
0
파일: test_ssh.py 프로젝트: mydaisy2/ironic
    def test_set_power_state_off_fail(self):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]

        self.mox.StubOutWithMock(ssh, '_parse_driver_info')
        self.mox.StubOutWithMock(ssh, '_get_nodes_mac_addresses')
        self.mox.StubOutWithMock(ssh, '_get_connection')
        self.mox.StubOutWithMock(ssh, '_power_off')
        ssh._parse_driver_info(self.node).\
                AndReturn(info)
        ssh._get_nodes_mac_addresses(mox.IgnoreArg(), self.node).\
                AndReturn(info['macs'])
        ssh._get_connection(self.node).\
                AndReturn(self.sshclient)
        ssh._power_off(self.sshclient, info).\
                AndReturn(states.POWER_ON)
        self.mox.ReplayAll()

        with task_manager.acquire([info['uuid']], shared=False) as task:
            self.assertRaises(exception.PowerStateFailure,
                task.resources[0].driver.power.set_power_state,
                task,
                self.node,
                states.POWER_OFF)
        self.mox.VerifyAll()
예제 #2
0
파일: test_ssh.py 프로젝트: mydaisy2/ironic
    def test_reboot_good(self):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]

        self.mox.StubOutWithMock(ssh, '_parse_driver_info')
        self.mox.StubOutWithMock(ssh, '_get_nodes_mac_addresses')
        self.mox.StubOutWithMock(ssh, '_get_connection')
        self.mox.StubOutWithMock(ssh, '_get_power_status')
        self.mox.StubOutWithMock(ssh, '_power_off')
        self.mox.StubOutWithMock(ssh, '_power_on')
        ssh._parse_driver_info(self.node).\
                AndReturn(info)
        ssh._get_nodes_mac_addresses(mox.IgnoreArg(), self.node).\
                AndReturn(info['macs'])
        ssh._get_connection(self.node).\
                AndReturn(self.sshclient)
        ssh._get_power_status(self.sshclient, info).\
                AndReturn(states.POWER_ON)
        ssh._power_off(self.sshclient, info).\
                AndReturn(None)
        ssh._power_on(self.sshclient, info).\
                AndReturn(states.POWER_ON)
        self.mox.ReplayAll()

        with task_manager.acquire([info['uuid']], shared=False) as task:
            task.resources[0].driver.power.reboot(task, self.node)
        self.mox.VerifyAll()
예제 #3
0
    def test__validate_info_ssh_connect_failed(self, ssh_connect_mock):
        info = ssh._parse_driver_info(self.node)

        ssh_connect_mock.side_effect = exception.SSHConnectFailed(host="fake")
        with task_manager.acquire(self.context, info["uuid"], shared=False) as task:
            self.assertRaises(exception.InvalidParameterValue, task.driver.power.validate, task)
            driver_info = ssh._parse_driver_info(task.node)
            ssh_connect_mock.assert_called_once_with(driver_info)
예제 #4
0
    def test__validate_info_ssh_connect_failed(self, ssh_connect_mock):
        info = ssh._parse_driver_info(self.node)

        ssh_connect_mock.side_effect = exception.SSHConnectFailed(host='fake')
        with task_manager.acquire(self.context, info['uuid'],
                                  shared=False) as task:
            self.assertRaises(exception.InvalidParameterValue,
                              task.driver.power.validate, task)
            driver_info = ssh._parse_driver_info(task.node)
            ssh_connect_mock.assert_called_once_with(driver_info)
예제 #5
0
파일: test_ssh.py 프로젝트: ravello/ironic
 def test_reboot_fail(self, power_on_mock, power_off_mock,
                      get_power_stat_mock, get_conn_mock,
                      get_mac_addr_mock):
     info = ssh._parse_driver_info(self.node)
     info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
     get_mac_addr_mock.return_value = info['macs']
     get_conn_mock.return_value = self.sshclient
     get_power_stat_mock.return_value = states.POWER_ON
     power_off_mock.return_value = None
     power_on_mock.return_value = states.POWER_OFF
     with mock.patch.object(ssh,
                            '_parse_driver_info') as parse_drv_info_mock:
         parse_drv_info_mock.return_value = info
         with task_manager.acquire(self.context, [info['uuid']],
                                   shared=False) as task:
             self.assertRaises(exception.PowerStateFailure,
                               task.resources[0].driver.power.reboot,
                               task)
             parse_drv_info_mock.assert_called_once_with(task.node)
             get_mac_addr_mock.assert_called_once_with(mock.ANY)
             get_conn_mock.assert_called_once_with(task.node)
             get_power_stat_mock.assert_called_once_with(self.sshclient,
                                                         info)
             power_off_mock.assert_called_once_with(self.sshclient, info)
             power_on_mock.assert_called_once_with(self.sshclient, info)
예제 #6
0
    def test__get_power_status_exception(self, exec_ssh_mock):
        info = ssh._parse_driver_info(self.node)
        exec_ssh_mock.side_effect = processutils.ProcessExecutionError

        self.assertRaises(exception.SSHCommandFailed, ssh._get_power_status, self.sshclient, info)
        ssh_cmd = "%s %s" % (info["cmd_set"]["base_cmd"], info["cmd_set"]["list_all"])
        exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd)
예제 #7
0
    def test__power_off_exception(self):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
        self.exec_ssh_mock.side_effect = processutils.ProcessExecutionError
        with mock.patch.object(ssh,
                               '_get_power_status') as get_power_status_mock:
            with mock.patch.object(
                    ssh, '_get_hosts_name_for_node') as get_hosts_name_mock:
                self.exec_ssh_mock.side_effect = (
                    processutils.ProcessExecutionError)
                get_power_status_mock.side_effect = [
                    states.POWER_ON, states.POWER_OFF
                ]
                get_hosts_name_mock.return_value = "NodeName"

                cmd_to_exec = "%s %s" % (info['cmd_set']['base_cmd'],
                                         info['cmd_set']['stop_cmd'])
                cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', 'NodeName')

                self.assertRaises(exception.SSHCommandFailed, ssh._power_off,
                                  self.sshclient, info)
                get_power_status_mock.assert_called_once_with(
                    self.sshclient, info)
                get_hosts_name_mock.assert_called_once_with(
                    self.sshclient, info)
                self.exec_ssh_mock.assert_called_once_with(
                    self.sshclient, cmd_to_exec)
예제 #8
0
    def test__validate_info_ssh_connect_failed(self):
        info = ssh._parse_driver_info(self.node)
        self.get_conn_patcher.stop()
        self.get_conn_mock = None

        with mock.patch.object(utils, 'ssh_connect') \
                as ssh_connect_mock:
            ssh_connect_mock.side_effect = exception.SSHConnectFailed(
                                                                  host='fake')
            with task_manager.acquire(self.context, [info['uuid']],
                                      shared=False) as task:
                self.assertRaises(exception.InvalidParameterValue,
                                  task.resources[0].driver.power.validate,
                                  task, self.node)
                driver_info = ssh._parse_driver_info(self.node)
                ssh_connect_mock.assert_called_once_with(driver_info)
예제 #9
0
    def test__power_off_fail(self):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
        with mock.patch.object(ssh, '_get_power_status') \
                as get_power_status_mock:
            with mock.patch.object(ssh, '_get_hosts_name_for_node') \
                    as get_hosts_name_mock:
                get_power_status_mock.side_effect = [states.POWER_ON,
                                                     states.POWER_ON]
                get_hosts_name_mock.return_value = "NodeName"
                expected = [mock.call(self.sshclient, info),
                            mock.call(self.sshclient, info)]

                cmd_to_exec = "%s %s" % (info['cmd_set']['base_cmd'],
                                         info['cmd_set']['stop_cmd'])
                cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', 'NodeName')
                current_state = ssh._power_off(self.sshclient, info)

                self.assertEqual(states.ERROR, current_state)
                self.assertEqual(expected,
                                 get_power_status_mock.call_args_list)
                get_hosts_name_mock.assert_called_once_with(self.sshclient,
                                                            info)
                self.exec_ssh_mock.assert_called_once_with(self.sshclient,
                                                           cmd_to_exec)
예제 #10
0
    def test_set_power_state_off_fail(self):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]

        self.parse_drv_info_mock = self.parse_drv_info_patcher.start()
        self.parse_drv_info_mock.return_value = info
        self.get_mac_addr_mock.return_value = info['macs']
        self.get_conn_mock.return_value = self.sshclient

        with mock.patch.object(ssh, '_power_off') as power_off_mock:
            power_off_mock.return_value = states.POWER_ON

            with task_manager.acquire(self.context, [info['uuid']],
                                      shared=False) as task:
                self.assertRaises(
                        exception.PowerStateFailure,
                        task.resources[0].driver.power.set_power_state,
                        task,
                        self.node,
                        states.POWER_OFF)

            self.parse_drv_info_mock.assert_called_once_with(self.node)
            self.get_mac_addr_mock.assert_called_once_with(mock.ANY, self.node)
            self.get_conn_mock.assert_called_once_with(self.node)
            power_off_mock.assert_called_once_with(self.sshclient, info)
예제 #11
0
    def test_reboot_good(self):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]

        self.parse_drv_info_mock = self.parse_drv_info_patcher.start()
        self.parse_drv_info_mock.return_value = info
        self.get_mac_addr_mock.return_value = info['macs']
        self.get_conn_mock.return_value = self.sshclient

        with mock.patch.object(ssh, '_get_power_status') \
                as get_power_stat_mock:
            with mock.patch.object(ssh, '_power_off') as power_off_mock:
                with mock.patch.object(ssh, '_power_on') as power_on_mock:
                    get_power_stat_mock.return_value = states.POWER_ON
                    power_off_mock.return_value = None
                    power_on_mock.return_value = states.POWER_ON

                    with task_manager.acquire(self.context, [info['uuid']],
                                              shared=False) as task:
                        task.resources[0].driver.power.reboot(task, self.node)

                    self.parse_drv_info_mock.assert_called_once_with(self.node)
                    self.get_mac_addr_mock.assert_called_once_with(mock.ANY,
                                                                   self.node)
                    self.get_conn_mock.assert_called_once_with(self.node)
                    get_power_stat_mock.assert_called_once_with(self.sshclient,
                                                                info)
                    power_off_mock.assert_called_once_with(self.sshclient,
                                                           info)
                    power_on_mock.assert_called_once_with(self.sshclient, info)
예제 #12
0
    def test__validate_info_ssh_connect_failed(self):
        info = ssh._parse_driver_info(self.node)
        self.get_conn_patcher.stop()
        self.get_conn_mock = None

        with mock.patch.object(utils, 'ssh_connect') \
                as ssh_connect_mock:
            ssh_connect_mock.side_effect = exception.SSHConnectFailed(
                host='fake')
            with task_manager.acquire(self.context, [info['uuid']],
                                      shared=False) as task:
                self.assertRaises(exception.InvalidParameterValue,
                                  task.resources[0].driver.power.validate,
                                  task, self.node)
                driver_info = ssh._parse_driver_info(self.node)
                ssh_connect_mock.assert_called_once_with(driver_info)
예제 #13
0
    def test_reboot_fail(self):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]

        self.parse_drv_info_mock = self.parse_drv_info_patcher.start()
        self.parse_drv_info_mock.return_value = info
        self.get_mac_addr_mock.return_value = info['macs']
        self.get_conn_mock.return_value = self.sshclient

        with mock.patch.object(ssh, '_get_power_status') \
                as get_power_stat_mock:
            with mock.patch.object(ssh, '_power_off') as power_off_mock:
                with mock.patch.object(ssh, '_power_on') as power_on_mock:
                    get_power_stat_mock.return_value = states.POWER_ON
                    power_off_mock.return_value = None
                    power_on_mock.return_value = states.POWER_OFF

                    with task_manager.acquire(self.context, [info['uuid']],
                                              shared=False) as task:
                        self.assertRaises(
                            exception.PowerStateFailure,
                            task.resources[0].driver.power.reboot, task,
                            self.node)
                    self.parse_drv_info_mock.assert_called_once_with(self.node)
                    self.get_mac_addr_mock.assert_called_once_with(
                        mock.ANY, self.node)
                    self.get_conn_mock.assert_called_once_with(self.node)
                    get_power_stat_mock.assert_called_once_with(
                        self.sshclient, info)
                    power_off_mock.assert_called_once_with(
                        self.sshclient, info)
                    power_on_mock.assert_called_once_with(self.sshclient, info)
예제 #14
0
    def test__power_off_fail(self):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
        with mock.patch.object(ssh, '_get_power_status') \
                as get_power_status_mock:
            with mock.patch.object(ssh, '_get_hosts_name_for_node') \
                    as get_hosts_name_mock:
                get_power_status_mock.side_effect = [
                    states.POWER_ON, states.POWER_ON
                ]
                get_hosts_name_mock.return_value = "NodeName"
                expected = [
                    mock.call(self.sshclient, info),
                    mock.call(self.sshclient, info)
                ]

                cmd_to_exec = "%s %s" % (info['cmd_set']['base_cmd'],
                                         info['cmd_set']['stop_cmd'])
                cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', 'NodeName')
                current_state = ssh._power_off(self.sshclient, info)

                self.assertEqual(current_state, states.ERROR)
                self.assertEqual(get_power_status_mock.call_args_list,
                                 expected)
                get_hosts_name_mock.assert_called_once_with(
                    self.sshclient, info)
                self.exec_ssh_mock.assert_called_once_with(
                    self.sshclient, cmd_to_exec)
예제 #15
0
 def test__get_connection_exception(self, ssh_connect_mock):
     ssh_connect_mock.side_effect = exception.SSHConnectFailed(host='fake')
     self.assertRaises(exception.SSHConnectFailed,
                       ssh._get_connection,
                       self.node)
     driver_info = ssh._parse_driver_info(self.node)
     ssh_connect_mock.assert_called_once_with(driver_info)
예제 #16
0
    def test__power_off_exception(self):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
        self.exec_ssh_mock.side_effect = processutils.ProcessExecutionError
        with mock.patch.object(
                ssh, '_get_power_status') as get_power_status_mock:
            with mock.patch.object(
                    ssh, '_get_hosts_name_for_node') as get_hosts_name_mock:
                self.exec_ssh_mock.side_effect = (
                        processutils.ProcessExecutionError)
                get_power_status_mock.side_effect = [states.POWER_ON,
                                                     states.POWER_OFF]
                get_hosts_name_mock.return_value = "NodeName"

                cmd_to_exec = "%s %s" % (info['cmd_set']['base_cmd'],
                                         info['cmd_set']['stop_cmd'])
                cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', 'NodeName')

                self.assertRaises(exception.SSHCommandFailed,
                                  ssh._power_off,
                                  self.sshclient,
                                  info)
                get_power_status_mock.assert_called_once_with(self.sshclient,
                                                            info)
                get_hosts_name_mock.assert_called_once_with(self.sshclient,
                                                            info)
                self.exec_ssh_mock.assert_called_once_with(self.sshclient,
                                                           cmd_to_exec)
예제 #17
0
파일: test_ssh.py 프로젝트: jriguera/ironic
    def test__get_hosts_name_for_node_match_after_retry(self, exec_ssh_mock):
        self.config(group='ssh', get_vm_name_attempts=2)
        self.config(group='ssh', get_vm_name_retry_interval=0)
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "22:22:22:22:22:22"]
        exec_ssh_mock.side_effect = iter([('NodeName', ''), ('', ''),
                                          ('NodeName', ''),
                                          ('11:11:11:11:11:11', '')])

        ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'],
                             info['cmd_set']['list_all'])

        cmd_to_exec = "%s %s" % (info['cmd_set']['base_cmd'],
                                 info['cmd_set']['get_node_macs'])

        cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', 'NodeName')
        expected = [
            mock.call(self.sshclient, ssh_cmd),
            mock.call(self.sshclient, cmd_to_exec)
        ] * 2

        found_name = ssh._get_hosts_name_for_node(self.sshclient, info)

        self.assertEqual('NodeName', found_name)
        self.assertEqual(expected, exec_ssh_mock.call_args_list)
예제 #18
0
 def test__get_connection_client(self):
     with mock.patch.object(utils, 'ssh_connect') as ssh_connect_mock:
         ssh_connect_mock.return_value = self.sshclient
         client = ssh._get_connection(self.node)
         self.assertEqual(self.sshclient, client)
         driver_info = ssh._parse_driver_info(self.node)
         ssh_connect_mock.assert_called_once_with(driver_info)
예제 #19
0
파일: test_ssh.py 프로젝트: jriguera/ironic
 def test__get_connection_exception(self, ssh_connect_mock):
     ssh_connect_mock.side_effect = iter(
         [exception.SSHConnectFailed(host='fake')])
     self.assertRaises(exception.SSHConnectFailed, ssh._get_connection,
                       self.node)
     driver_info = ssh._parse_driver_info(self.node)
     ssh_connect_mock.assert_called_once_with(driver_info)
예제 #20
0
    def test__parse_driver_info_with_custom_libvirt_uri(self):
        CONF.set_override("libvirt_uri", "qemu:///foo", "ssh")
        expected_base_cmd = "LC_ALL=C /usr/bin/virsh --connect qemu:///foo"

        node = obj_utils.get_test_node(self.context, driver="fake_ssh", driver_info=db_utils.get_test_ssh_info())
        node["driver_info"]["ssh_virt_type"] = "virsh"
        info = ssh._parse_driver_info(node)
        self.assertEqual(expected_base_cmd, info["cmd_set"]["base_cmd"])
예제 #21
0
 def test__get_connection_client(self):
     with mock.patch.object(
             utils, 'ssh_connect') as ssh_connect_mock:
         ssh_connect_mock.return_value = self.sshclient
         client = ssh._get_connection(self.node)
         self.assertEqual(self.sshclient, client)
         driver_info = ssh._parse_driver_info(self.node)
         ssh_connect_mock.assert_called_once_with(driver_info)
예제 #22
0
 def test__get_connection_exception(self):
     with mock.patch.object(utils, 'ssh_connect') as ssh_connect_mock:
         ssh_connect_mock.side_effect = exception.SSHConnectFailed(
             host='fake')
         self.assertRaises(exception.SSHConnectFailed, ssh._get_connection,
                           self.node)
         driver_info = ssh._parse_driver_info(self.node)
         ssh_connect_mock.assert_called_once_with(driver_info)
예제 #23
0
    def test__parse_driver_info_with_custom_libvirt_uri(self):
        CONF.set_override('libvirt_uri', 'qemu:///foo', 'ssh')
        expected_base_cmd = "/usr/bin/virsh --connect qemu:///foo"

        node = db_utils.get_test_node(driver='fake_ssh', driver_info=INFO_DICT)
        node['driver_info']['ssh_virt_type'] = 'virsh'
        info = ssh._parse_driver_info(node)
        self.assertEqual(expected_base_cmd, info['cmd_set']['base_cmd'])
예제 #24
0
파일: test_ssh.py 프로젝트: krast/ironic
    def test_set_power_state_bad_state(self):
        info = ssh._parse_driver_info(self.node)
        info["macs"] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]

        self.mox.StubOutWithMock(ssh, "_parse_driver_info")
        self.mox.StubOutWithMock(ssh, "_get_nodes_mac_addresses")
        self.mox.StubOutWithMock(ssh, "_get_connection")
        ssh._parse_driver_info(self.node).AndReturn(info)
        ssh._get_nodes_mac_addresses(mox.IgnoreArg(), self.node).AndReturn(info["macs"])
        ssh._get_connection(self.node).AndReturn(self.sshclient)
        self.mox.ReplayAll()

        with task_manager.acquire([info["uuid"]], shared=False) as task:
            self.assertRaises(
                exception.IronicException, task.resources[0].driver.power.set_power_state, task, self.node, "BAD_PSTATE"
            )
        self.mox.VerifyAll()
예제 #25
0
    def test__parse_driver_info_with_custom_libvirt_uri(self):
        CONF.set_override('libvirt_uri', 'qemu:///foo', 'ssh')
        expected_base_cmd = "/usr/bin/virsh --connect qemu:///foo"

        node = db_utils.get_test_node(driver='fake_ssh', driver_info=INFO_DICT)
        node['driver_info']['ssh_virt_type'] = 'virsh'
        info = ssh._parse_driver_info(node)
        self.assertEqual(expected_base_cmd, info['cmd_set']['base_cmd'])
예제 #26
0
    def test__get_power_status_exception(self, exec_ssh_mock):
        info = ssh._parse_driver_info(self.node)
        exec_ssh_mock.side_effect = processutils.ProcessExecutionError

        self.assertRaises(exception.SSHCommandFailed, ssh._get_power_status,
                          self.sshclient, info)
        ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'],
                             info['cmd_set']['list_running'])
        exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd)
예제 #27
0
파일: test_ssh.py 프로젝트: krast/ironic
    def test_set_power_state_off_good(self):
        info = ssh._parse_driver_info(self.node)
        info["macs"] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]

        self.mox.StubOutWithMock(ssh, "_parse_driver_info")
        self.mox.StubOutWithMock(ssh, "_get_nodes_mac_addresses")
        self.mox.StubOutWithMock(ssh, "_get_connection")
        self.mox.StubOutWithMock(ssh, "_power_off")
        ssh._parse_driver_info(self.node).AndReturn(info)
        ssh._get_nodes_mac_addresses(mox.IgnoreArg(), self.node).AndReturn(info["macs"])
        ssh._get_connection(self.node).AndReturn(self.sshclient)
        ssh._power_off(self.sshclient, info).AndReturn(states.POWER_OFF)
        self.mox.ReplayAll()

        with task_manager.acquire([info["uuid"]], shared=False) as task:
            task.resources[0].driver.power.set_power_state(task, self.node, states.POWER_OFF)
        self.assert_(True)
        self.mox.VerifyAll()
예제 #28
0
    def test__get_power_status_correct_node(self, get_hosts_name_mock, exec_ssh_mock):
        # Bug: #1397834 test that get_power_status return status of
        # baremeta_1 (off) and not baremetal_11 (on)
        info = ssh._parse_driver_info(self.node)
        exec_ssh_mock.return_value = ('"baremetal_11"\n"seed"\n', "")
        get_hosts_name_mock.return_value = "baremetal_1"

        pstate = ssh._get_power_status(self.sshclient, info)
        self.assertEqual(states.POWER_OFF, pstate)
예제 #29
0
    def test__get_power_status_error(self, get_hosts_name_mock, exec_ssh_mock):

        info = ssh._parse_driver_info(self.node)

        info["macs"] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
        get_hosts_name_mock.return_value = None
        self.assertRaises(exception.NodeNotFound, ssh._get_power_status, self.sshclient, info)

        get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
        exec_ssh_mock.assert_not_called()
예제 #30
0
파일: test_ssh.py 프로젝트: jriguera/ironic
    def test__get_power_status_correct_node(self, get_hosts_name_mock,
                                            exec_ssh_mock):
        # Bug: #1397834 test that get_power_status return status of
        # baremeta_1 (off) and not baremetal_11 (on)
        info = ssh._parse_driver_info(self.node)
        exec_ssh_mock.return_value = ('"baremetal_11"\n"seed"\n', '')
        get_hosts_name_mock.return_value = "baremetal_1"

        pstate = ssh._get_power_status(self.sshclient, info)
        self.assertEqual(states.POWER_OFF, pstate)
예제 #31
0
 def test__parse_driver_info_good(self):
     # make sure we get back the expected things
     node = db_utils.get_test_node(driver='fake_ssh', driver_info=INFO_DICT)
     info = ssh._parse_driver_info(node)
     self.assertIsNotNone(info.get('host'))
     self.assertIsNotNone(info.get('username'))
     self.assertIsNotNone(info.get('password'))
     self.assertIsNotNone(info.get('port'))
     self.assertIsNotNone(info.get('virt_type'))
     self.assertIsNotNone(info.get('cmd_set'))
     self.assertIsNotNone(info.get('uuid'))
예제 #32
0
 def test__parse_driver_info_good_key(self):
     # make sure we get back the expected things
     node = obj_utils.get_test_node(self.context, driver="fake_ssh", driver_info=db_utils.get_test_ssh_info("key"))
     info = ssh._parse_driver_info(node)
     self.assertIsNotNone(info.get("host"))
     self.assertIsNotNone(info.get("username"))
     self.assertIsNotNone(info.get("key_contents"))
     self.assertIsNotNone(info.get("port"))
     self.assertIsNotNone(info.get("virt_type"))
     self.assertIsNotNone(info.get("cmd_set"))
     self.assertIsNotNone(info.get("uuid"))
예제 #33
0
파일: test_ssh.py 프로젝트: skw0rm/ironic
    def test__get_power_status_error(self, get_hosts_name_mock, exec_ssh_mock):

        info = ssh._parse_driver_info(self.node)

        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
        get_hosts_name_mock.return_value = None
        self.assertRaises(exception.NodeNotFound, ssh._get_power_status,
                          self.sshclient, info)

        get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
        exec_ssh_mock.assert_not_called()
예제 #34
0
    def test__get_power_status_off(self, get_hosts_name_mock, exec_ssh_mock):
        info = ssh._parse_driver_info(self.node)
        exec_ssh_mock.return_value = ('"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}', "")
        get_hosts_name_mock.return_value = "NotNodeName"

        pstate = ssh._get_power_status(self.sshclient, info)

        ssh_cmd = "%s %s" % (info["cmd_set"]["base_cmd"], info["cmd_set"]["list_running"])
        self.assertEqual(states.POWER_OFF, pstate)
        exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd)
        get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
예제 #35
0
파일: test_ssh.py 프로젝트: krast/ironic
    def test_reboot_fail(self):
        info = ssh._parse_driver_info(self.node)
        info["macs"] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]

        self.mox.StubOutWithMock(ssh, "_parse_driver_info")
        self.mox.StubOutWithMock(ssh, "_get_nodes_mac_addresses")
        self.mox.StubOutWithMock(ssh, "_get_connection")
        self.mox.StubOutWithMock(ssh, "_get_power_status")
        self.mox.StubOutWithMock(ssh, "_power_off")
        self.mox.StubOutWithMock(ssh, "_power_on")
        ssh._parse_driver_info(self.node).AndReturn(info)
        ssh._get_nodes_mac_addresses(mox.IgnoreArg(), self.node).AndReturn(info["macs"])
        ssh._get_connection(self.node).AndReturn(self.sshclient)
        ssh._get_power_status(self.sshclient, info).AndReturn(states.POWER_ON)
        ssh._power_off(self.sshclient, info).AndReturn(None)
        ssh._power_on(self.sshclient, info).AndReturn(states.POWER_OFF)
        self.mox.ReplayAll()

        with task_manager.acquire([info["uuid"]], shared=False) as task:
            self.assertRaises(exception.PowerStateFailure, task.resources[0].driver.power.reboot, task, self.node)
        self.mox.VerifyAll()
예제 #36
0
파일: test_ssh.py 프로젝트: krast/ironic
 def test__parse_driver_info_good(self):
     # make sure we get back the expected things
     node = db_utils.get_test_node(driver="fake_ssh", driver_info=db_utils.ssh_info)
     info = ssh._parse_driver_info(node)
     self.assertIsNotNone(info.get("host"))
     self.assertIsNotNone(info.get("username"))
     self.assertIsNotNone(info.get("password"))
     self.assertIsNotNone(info.get("port"))
     self.assertIsNotNone(info.get("virt_type"))
     self.assertIsNotNone(info.get("cmd_set"))
     self.assertIsNotNone(info.get("uuid"))
     self.mox.VerifyAll()
예제 #37
0
 def test__parse_driver_info_good_key(self):
     # make sure we get back the expected things
     node = db_utils.get_test_node(
         driver='fake_ssh', driver_info=db_utils.get_test_ssh_info('key'))
     info = ssh._parse_driver_info(node)
     self.assertIsNotNone(info.get('host'))
     self.assertIsNotNone(info.get('username'))
     self.assertIsNotNone(info.get('key_contents'))
     self.assertIsNotNone(info.get('port'))
     self.assertIsNotNone(info.get('virt_type'))
     self.assertIsNotNone(info.get('cmd_set'))
     self.assertIsNotNone(info.get('uuid'))
예제 #38
0
    def test__get_power_status_exception(self):
        info = ssh._parse_driver_info(self.node)
        self.exec_ssh_mock.side_effect = processutils.ProcessExecutionError

        self.assertRaises(exception.SSHCommandFailed,
                          ssh._get_power_status,
                          self.sshclient,
                          info)
        ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'],
                             info['cmd_set']['list_running'])
        self.exec_ssh_mock.assert_called_once_with(
                self.sshclient, ssh_cmd)
예제 #39
0
파일: test_ssh.py 프로젝트: krast/ironic
    def test__get_hosts_name_for_node_no_match(self):
        info = ssh._parse_driver_info(self.node)
        info["macs"] = ["11:11:11:11:11:11", "22:22:22:22:22:22"]
        self.mox.StubOutWithMock(ssh, "_exec_ssh_command")
        ssh._exec_ssh_command(self.sshclient, info["cmd_set"]["list_all"]).AndReturn(["NodeName"])
        cmd_to_exec = info["cmd_set"]["get_node_macs"]
        cmd_to_exec = cmd_to_exec.replace("{_NodeName_}", "NodeName")
        ssh._exec_ssh_command(self.sshclient, cmd_to_exec).AndReturn(["52:54:00:cf:2d:31"])
        self.mox.ReplayAll()

        found_name = ssh._get_hosts_name_for_node(self.sshclient, info)
        self.assertEqual(found_name, None)
        self.mox.VerifyAll()
예제 #40
0
 def test__parse_driver_info_good_key(self):
     # make sure we get back the expected things
     node = db_utils.get_test_node(
                 driver='fake_ssh',
                 driver_info=db_utils.get_test_ssh_info('key'))
     info = ssh._parse_driver_info(node)
     self.assertIsNotNone(info.get('host'))
     self.assertIsNotNone(info.get('username'))
     self.assertIsNotNone(info.get('key_contents'))
     self.assertIsNotNone(info.get('port'))
     self.assertIsNotNone(info.get('virt_type'))
     self.assertIsNotNone(info.get('cmd_set'))
     self.assertIsNotNone(info.get('uuid'))
예제 #41
0
    def test__get_power_status_off(self, get_hosts_name_mock, exec_ssh_mock):
        info = ssh._parse_driver_info(self.node)
        exec_ssh_mock.return_value = (
            '"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}', '')
        get_hosts_name_mock.return_value = "NotNodeName"

        pstate = ssh._get_power_status(self.sshclient, info)

        ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'],
                             info['cmd_set']['list_running'])
        self.assertEqual(states.POWER_OFF, pstate)
        exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd)
        get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
예제 #42
0
파일: test_ssh.py 프로젝트: mydaisy2/ironic
    def test_set_power_state_bad_state(self):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]

        self.mox.StubOutWithMock(ssh, '_parse_driver_info')
        self.mox.StubOutWithMock(ssh, '_get_nodes_mac_addresses')
        self.mox.StubOutWithMock(ssh, '_get_connection')
        ssh._parse_driver_info(self.node).\
                AndReturn(info)
        ssh._get_nodes_mac_addresses(mox.IgnoreArg(), self.node).\
                AndReturn(info['macs'])
        ssh._get_connection(self.node).\
                AndReturn(self.sshclient)
        self.mox.ReplayAll()

        with task_manager.acquire([info['uuid']], shared=False) as task:
            self.assertRaises(exception.IronicException,
                task.resources[0].driver.power.set_power_state,
                task,
                self.node,
                "BAD_PSTATE")
        self.mox.VerifyAll()
예제 #43
0
파일: test_ssh.py 프로젝트: jriguera/ironic
    def test__get_power_status_on_unquoted(self, get_hosts_name_mock,
                                           exec_ssh_mock):
        info = ssh._parse_driver_info(self.node)
        exec_ssh_mock.return_value = ('ExactNodeName', '')
        get_hosts_name_mock.return_value = "ExactNodeName"

        pstate = ssh._get_power_status(self.sshclient, info)

        ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'],
                             info['cmd_set']['list_running'])
        self.assertEqual(states.POWER_ON, pstate)
        exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd)
        get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
예제 #44
0
 def test__parse_driver_info_good(self):
     # make sure we get back the expected things
     node = db_utils.get_test_node(
                 driver='fake_ssh',
                 driver_info=INFO_DICT)
     info = ssh._parse_driver_info(node)
     self.assertIsNotNone(info.get('host'))
     self.assertIsNotNone(info.get('username'))
     self.assertIsNotNone(info.get('password'))
     self.assertIsNotNone(info.get('port'))
     self.assertIsNotNone(info.get('virt_type'))
     self.assertIsNotNone(info.get('cmd_set'))
     self.assertIsNotNone(info.get('uuid'))
예제 #45
0
    def test__get_hosts_name_for_node_exception(self, exec_ssh_mock):
        info = ssh._parse_driver_info(self.node)
        info["macs"] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
        ssh_cmd = "%s %s" % (info["cmd_set"]["base_cmd"], info["cmd_set"]["list_all"])

        cmd_to_exec = "%s %s" % (info["cmd_set"]["base_cmd"], info["cmd_set"]["get_node_macs"])
        cmd_to_exec = cmd_to_exec.replace("{_NodeName_}", "NodeName")

        exec_ssh_mock.side_effect = [("NodeName", ""), processutils.ProcessExecutionError]
        expected = [mock.call(self.sshclient, ssh_cmd), mock.call(self.sshclient, cmd_to_exec)]

        self.assertRaises(exception.SSHCommandFailed, ssh._get_hosts_name_for_node, self.sshclient, info)
        self.assertEqual(expected, exec_ssh_mock.call_args_list)
예제 #46
0
파일: test_ssh.py 프로젝트: krast/ironic
    def test__get_power_status_error(self):
        info = ssh._parse_driver_info(self.node)
        self.mox.StubOutWithMock(ssh, "_exec_ssh_command")
        self.mox.StubOutWithMock(ssh, "_get_hosts_name_for_node")

        ssh._exec_ssh_command(self.sshclient, info["cmd_set"]["list_running"]).AndReturn(
            ['"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}']
        )
        ssh._get_hosts_name_for_node(self.sshclient, info).AndReturn(None)
        self.mox.ReplayAll()

        pstate = ssh._get_power_status(self.sshclient, info)
        self.assertEqual(pstate, states.ERROR)
        self.mox.VerifyAll()
예제 #47
0
    def test__power_off_exception(self, get_hosts_name_mock, get_power_status_mock, exec_ssh_mock):
        info = ssh._parse_driver_info(self.node)
        info["macs"] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
        exec_ssh_mock.side_effect = processutils.ProcessExecutionError
        get_power_status_mock.side_effect = [states.POWER_ON, states.POWER_OFF]
        get_hosts_name_mock.return_value = "NodeName"

        cmd_to_exec = "%s %s" % (info["cmd_set"]["base_cmd"], info["cmd_set"]["stop_cmd"])
        cmd_to_exec = cmd_to_exec.replace("{_NodeName_}", "NodeName")

        self.assertRaises(exception.SSHCommandFailed, ssh._power_off, self.sshclient, info)
        get_power_status_mock.assert_called_once_with(self.sshclient, info)
        get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
        exec_ssh_mock.assert_called_once_with(self.sshclient, cmd_to_exec)
예제 #48
0
파일: test_ssh.py 프로젝트: naterh/ironic
    def test__get_power_status_on_unquoted(self, get_hosts_name_mock,
                                           exec_ssh_mock):
        info = ssh._parse_driver_info(self.node)
        exec_ssh_mock.return_value = (
            'ExactNodeName', '')
        get_hosts_name_mock.return_value = "ExactNodeName"

        pstate = ssh._get_power_status(self.sshclient, info)

        ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'],
                             info['cmd_set']['list_running'])
        self.assertEqual(states.POWER_ON, pstate)
        exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd)
        get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
예제 #49
0
파일: test_ssh.py 프로젝트: mydaisy2/ironic
    def test__get_hosts_name_for_node_no_match(self):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "22:22:22:22:22:22"]
        self.mox.StubOutWithMock(ssh, '_exec_ssh_command')
        ssh._exec_ssh_command(self.sshclient, info['cmd_set']['list_all']).\
                AndReturn(['NodeName'])
        cmd_to_exec = info['cmd_set']['get_node_macs']
        cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', 'NodeName')
        ssh._exec_ssh_command(self.sshclient, cmd_to_exec).\
                AndReturn(['52:54:00:cf:2d:31'])
        self.mox.ReplayAll()

        found_name = ssh._get_hosts_name_for_node(self.sshclient, info)
        self.assertEqual(found_name, None)
        self.mox.VerifyAll()
예제 #50
0
파일: test_ssh.py 프로젝트: mydaisy2/ironic
    def test__get_power_status_error(self):
        info = ssh._parse_driver_info(self.node)
        self.mox.StubOutWithMock(ssh, '_exec_ssh_command')
        self.mox.StubOutWithMock(ssh, '_get_hosts_name_for_node')

        ssh._exec_ssh_command(
            self.sshclient, info['cmd_set']['list_running']).AndReturn(
            ['"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}'])
        ssh._get_hosts_name_for_node(self.sshclient, info).\
                AndReturn(None)
        self.mox.ReplayAll()

        pstate = ssh._get_power_status(self.sshclient, info)
        self.assertEqual(pstate, states.ERROR)
        self.mox.VerifyAll()
예제 #51
0
    def test__get_power_status_on(self):
        info = ssh._parse_driver_info(self.node)
        with mock.patch.object(ssh, '_get_hosts_name_for_node') \
                as get_hosts_name_mock:
            self.exec_ssh_mock.return_value = (
                '"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}', '')
            get_hosts_name_mock.return_value = "NodeName"

            pstate = ssh._get_power_status(self.sshclient, info)

            ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'],
                                 info['cmd_set']['list_running'])
            self.assertEqual(pstate, states.POWER_ON)
            self.exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd)
            get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
예제 #52
0
 def test__parse_driver_info_good_file(self):
     # make sure we get back the expected things
     d_info = db_utils.get_test_ssh_info('file')
     tempdir = self.useFixture(fixtures.TempDir())
     key_path = tempdir.path + '/foo'
     open(key_path, 'wt').close()
     d_info['ssh_key_filename'] = key_path
     node = db_utils.get_test_node(driver='fake_ssh', driver_info=d_info)
     info = ssh._parse_driver_info(node)
     self.assertIsNotNone(info.get('host'))
     self.assertIsNotNone(info.get('username'))
     self.assertIsNotNone(info.get('key_filename'))
     self.assertIsNotNone(info.get('port'))
     self.assertIsNotNone(info.get('virt_type'))
     self.assertIsNotNone(info.get('cmd_set'))
     self.assertIsNotNone(info.get('uuid'))
예제 #53
0
    def test__get_power_status_error(self, get_hosts_name_mock, exec_ssh_mock):

        info = ssh._parse_driver_info(self.node)

        exec_ssh_mock.return_value = (
            '"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}', '')
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
        get_hosts_name_mock.return_value = None
        self.assertRaises(exception.NodeNotFound, ssh._get_power_status,
                          self.sshclient, info)

        ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'],
                             info['cmd_set']['list_running'])

        exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd)
        get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
예제 #54
0
    def test_set_power_state_bad_state(self, get_conn_mock, get_mac_addr_mock):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
        get_mac_addr_mock.return_value = info['macs']
        get_conn_mock.return_value = self.sshclient
        with mock.patch.object(ssh,
                               '_parse_driver_info') as parse_drv_info_mock:
            parse_drv_info_mock.return_value = info
            with task_manager.acquire(self.context, info['uuid'],
                                      shared=False) as task:
                self.assertRaises(exception.InvalidParameterValue,
                                  task.driver.power.set_power_state, task,
                                  "BAD_PSTATE")

                parse_drv_info_mock.assert_called_once_with(task.node)
                get_mac_addr_mock.assert_called_once_with(mock.ANY)
                get_conn_mock.assert_called_once_with(task.node)
예제 #55
0
    def test__power_on_exception(self, get_hosts_name_mock,
                                 get_power_status_mock, exec_ssh_mock):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]

        exec_ssh_mock.side_effect = processutils.ProcessExecutionError
        get_power_status_mock.side_effect = [states.POWER_OFF, states.POWER_ON]
        get_hosts_name_mock.return_value = "NodeName"

        cmd_to_exec = "%s %s" % (info['cmd_set']['base_cmd'],
                                 info['cmd_set']['start_cmd'])
        cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', 'NodeName')

        self.assertRaises(exception.SSHCommandFailed, ssh._power_on,
                          self.sshclient, info)
        get_power_status_mock.assert_called_once_with(self.sshclient, info)
        get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
        exec_ssh_mock.assert_called_once_with(self.sshclient, cmd_to_exec)
예제 #56
0
파일: test_ssh.py 프로젝트: jriguera/ironic
 def test_reboot_fail(self, power_on_mock, get_conn_mock,
                      get_mac_addr_mock):
     info = ssh._parse_driver_info(self.node)
     info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
     get_mac_addr_mock.return_value = info['macs']
     get_conn_mock.return_value = self.sshclient
     power_on_mock.return_value = states.POWER_OFF
     with mock.patch.object(ssh, '_parse_driver_info',
                            autospec=True) as parse_drv_info_mock:
         parse_drv_info_mock.return_value = info
         with task_manager.acquire(self.context, info['uuid'],
                                   shared=False) as task:
             self.assertRaises(exception.PowerStateFailure,
                               task.driver.power.reboot, task)
             parse_drv_info_mock.assert_called_once_with(task.node)
             get_mac_addr_mock.assert_called_once_with(mock.ANY)
             get_conn_mock.assert_called_once_with(task.node)
             power_on_mock.assert_called_once_with(self.sshclient, info)
예제 #57
0
    def test_set_power_state_bad_state(self):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]

        self.parse_drv_info_mock = self.parse_drv_info_patcher.start()
        self.parse_drv_info_mock.return_value = info
        self.get_mac_addr_mock.return_value = info['macs']
        self.get_conn_mock.return_value = self.sshclient

        with task_manager.acquire(self.context, [info['uuid']],
                                  shared=False) as task:
            self.assertRaises(exception.InvalidParameterValue,
                              task.resources[0].driver.power.set_power_state,
                              task, self.node, "BAD_PSTATE")

        self.parse_drv_info_mock.assert_called_once_with(self.node)
        self.get_mac_addr_mock.assert_called_once_with(mock.ANY, self.node)
        self.get_conn_mock.assert_called_once_with(self.node)
예제 #58
0
    def test_set_power_state_off_good(self, power_off_mock, get_conn_mock,
                                      get_mac_addr_mock):
        info = ssh._parse_driver_info(self.node)
        info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
        get_mac_addr_mock.return_value = info['macs']
        get_conn_mock.return_value = self.sshclient
        power_off_mock.return_value = states.POWER_OFF
        with mock.patch.object(ssh,
                               '_parse_driver_info') as parse_drv_info_mock:
            parse_drv_info_mock.return_value = info
            with task_manager.acquire(self.context, info['uuid'],
                                      shared=False) as task:
                task.driver.power.set_power_state(task, states.POWER_OFF)

                parse_drv_info_mock.assert_called_once_with(task.node)
                get_mac_addr_mock.assert_called_once_with(mock.ANY)
                get_conn_mock.assert_called_once_with(task.node)
                power_off_mock.assert_called_once_with(self.sshclient, info)