Exemple #1
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.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()
Exemple #2
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.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()
Exemple #3
0
    def test__get_nodes_mac_addresses(self):
        #stop all the mocks because this test does not use them
        self.get_mac_addr_patcher.stop()
        self.get_mac_addr_mock = None
        self.get_conn_patcher.stop()
        self.get_conn_mock = None

        ports = []
        ports.append(self.port)
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=6,
                    node_id=self.node['id'],
                    address='aa:bb:cc',
                    uuid='bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53')))
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=7,
                    node_id=self.node['id'],
                    address='dd:ee:ff',
                    uuid='4fc26c0b-03f2-4d2e-ae87-c02d7f33c234')))

        with task_manager.acquire(self.context, [self.node['uuid']]) as task:
            node_macs = ssh._get_nodes_mac_addresses(task, self.node)
        self.assertEqual(sorted([p.address for p in ports]), sorted(node_macs))
Exemple #4
0
    def test__get_nodes_mac_addresses(self):
        #stop all the mocks because this test does not use them
        self.get_mac_addr_patcher.stop()
        self.get_mac_addr_mock = None
        self.get_conn_patcher.stop()
        self.get_conn_mock = None

        ports = []
        ports.append(self.port)
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=6,
                    node_id=self.node['id'],
                    address='aa:bb:cc',
                    uuid='bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53')))
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=7,
                    node_id=self.node['id'],
                    address='dd:ee:ff',
                    uuid='4fc26c0b-03f2-4d2e-ae87-c02d7f33c234')))

        with task_manager.acquire(self.context, [self.node['uuid']]) as task:
            node_macs = ssh._get_nodes_mac_addresses(task, self.node)
        self.assertEqual(sorted(node_macs), sorted([p.address for p in ports]))
Exemple #5
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.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()
Exemple #6
0
    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()
Exemple #7
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.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()
Exemple #8
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.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()
Exemple #9
0
    def test__get_nodes_mac_addresses(self):
        ports = []
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(id=6, address="aa:bb:cc", uuid="bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53")
            )
        )
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(id=7, address="dd:ee:ff", uuid="4fc26c0b-03f2-4d2e-ae87-c02d7f33c234")
            )
        )

        with task_manager.acquire([self.node["uuid"]]) as task:
            node_macs = ssh._get_nodes_mac_addresses(task, self.node)
        self.assertEqual(node_macs, ["aa:bb:cc", "dd:ee:ff"])
Exemple #10
0
    def test__get_nodes_mac_addresses(self):
        ports = []
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=6,
                    address='aa:bb:cc',
                    uuid='bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53')))
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=7,
                    address='dd:ee:ff',
                    uuid='4fc26c0b-03f2-4d2e-ae87-c02d7f33c234')))

        with task_manager.acquire([self.node['uuid']]) as task:
            node_macs = ssh._get_nodes_mac_addresses(task, self.node)
        self.assertEqual(node_macs, ['aa:bb:cc', 'dd:ee:ff'])
Exemple #11
0
    def test__get_nodes_mac_addresses(self):
        ports = []
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=6,
                    node_id=self.node['id'],
                    address='aa:bb:cc',
                    uuid='bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53')))
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=7,
                    node_id=self.node['id'],
                    address='dd:ee:ff',
                    uuid='4fc26c0b-03f2-4d2e-ae87-c02d7f33c234')))

        with task_manager.acquire([self.node['uuid']]) as task:
            node_macs = ssh._get_nodes_mac_addresses(task, self.node)
        self.assertEqual(node_macs, ['aa:bb:cc', 'dd:ee:ff'])