Пример #1
0
def test_get_compute_lists(mocker, cmd_output, enabled, disabled):
    controller = mock.Mock()
    run_nova_cmd = mocker.patch(
        "octane.util.nova.run_nova_cmd", return_value=cmd_output)

    assert (enabled, disabled) == nova.get_compute_lists(controller)
    run_nova_cmd.assert_called_once_with(
        ["nova", "service-list", "--binary", "nova-compute"], controller)
Пример #2
0
    def evacuate_host(self):
        controller = env_util.get_one_controller(self.env)

        enabled_computes, disabled_computes = nova.get_compute_lists(
            controller)

        node_fqdn = node_util.get_nova_node_handle(self.node)
        if [node_fqdn] == enabled_computes:
            raise Exception("You try to disable last enabled nova-compute "
                            "service on {hostname} in cluster. "
                            "This leads to disable host evacuation. "
                            "Fix this problem and run unpgrade-node "
                            "command again".format(hostname=node_fqdn))

        if nova.do_nova_instances_exist(controller, node_fqdn, "ERROR"):
            raise Exception(
                "There are instances in ERROR state on {hostname},"
                "please fix this problem and start upgrade_node "
                "command again".format(hostname=node_fqdn))

        if node_fqdn in disabled_computes:
            LOG.warn("Node {0} already disabled".format(node_fqdn))
        else:
            nova.run_nova_cmd(
                ["nova", "service-disable", node_fqdn, "nova-compute"],
                controller, False)
        for instance_id in nova.get_active_instances(controller, node_fqdn):
            nova.run_nova_cmd(
                ["nova", "live-migration", instance_id], controller, False)
            nova.waiting_for_status_completed(
                controller, node_fqdn, "MIGRATING")
        if nova.do_nova_instances_exist(controller, node_fqdn):
            raise Exception(
                "There are instances on {hostname} after host-evacuation, "
                "please fix this problem and start upgrade_node "
                "command again".format(hostname=node_fqdn))