def test_get_active_instances(mocker, cmd_out, result, node_fqdn):
    controller = mock.Mock()
    nova_mock = mocker.patch(
        "octane.util.nova.run_nova_cmd", return_value=cmd_out)
    assert result == nova.get_active_instances(controller, node_fqdn)
    nova_mock.assert_called_once_with([
        "nova", "list",
        "--host", node_fqdn,
        "--limit", "-1",
        "--status", "ACTIVE",
        "--minimal"],
        controller)
Beispiel #2
0
    def shutoff_vms(self):
        controller = env_util.get_one_controller(self.env)
        node_fqdn = node_util.get_nova_node_handle(self.node)

        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))

        for instance_id in nova.get_active_instances(controller, node_fqdn):
            nova.run_nova_cmd(
                ["nova", "stop", instance_id], controller, output=False)
        nova.waiting_for_status_completed(controller, node_fqdn, "ACTIVE")
Beispiel #3
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))