def test_compute_engine_wait_for_status(compute_engine, http_sequence_factory):
    http = http_sequence_factory([
        ({
            'status': '200'
        }, 'file:tests/http/compute-discovery.json'),
        ({
            'status': '200'
        }, 'file:tests/http/compute.instances.get.build1-terminated.json'),
        ({
            'status': '200'
        }, 'file:tests/http/compute.instances.get.build1-terminated.json'),
        ({
            'status': '200'
        }, 'file:tests/http/compute.instances.get.build1-provisioning.json'),
        ({
            'status': '200'
        }, 'file:tests/http/compute.instances.get.build1-provisioning.json'),
        ({
            'status': '200'
        }, 'file:tests/http/compute.instances.get.build1-provisioning.json'),
        ({
            'status': '200'
        }, 'file:tests/http/compute.instances.get.build1-running.json'),
    ])
    compute_engine.http = http
    with tests.helpers.helpers_compute_engine.no_pause():
        instance = compute_engine.get_instance('build1')
        assert instance.status is InstanceStatus.TERMINATED
        instance.wait_for_status(InstanceStatus.RUNNING)
        assert instance.status is InstanceStatus.RUNNING
def test_compute_engine_stop_instance(compute_engine, http_sequence_factory):
    http = http_sequence_factory([
        ({
            'status': '200'
        }, 'file:tests/http/compute-discovery.json'),
        ({
            'status': '200'
        }, 'file:tests/http/compute.instances.get.build1-running.json'),
        ({
            'status': '200'
        }, 'file:tests/http/compute.instances.stop.build1.json'),
        ({
            'status': '200'
        }, 'file:tests/http/compute.operations.get-stop-running.json'),
        ({
            'status': '200'
        }, 'file:tests/http/compute.operations.get-stop-done.json'),
        ({
            'status': '200'
        }, 'file:tests/http/compute.instances.get.build1-terminated.json'),
    ])
    compute_engine.http = http
    with tests.helpers.helpers_compute_engine.no_pause():
        instance = compute_engine.get_instance('build1')
        assert instance.status is InstanceStatus.RUNNING
        instance.stop()
        tests.helpers.helpers_compute_engine.make_info_instantly_stale(
            instance)
        assert instance.status is InstanceStatus.TERMINATED
def test_compute_engine_get_instance_exists(compute_engine,
                                            http_sequence_factory):
    http = http_sequence_factory([
        ({
            'status': '200'
        }, 'file:tests/http/compute-discovery.json'),
        ({
            'status': '200'
        }, 'file:tests/http/compute.instances.get.build1-running.json'),
    ])
    compute_engine.http = http
    with tests.helpers.helpers_compute_engine.no_pause():
        instance = compute_engine.get_instance('build1')
        assert instance.name == 'build1'
        assert instance.status is InstanceStatus.RUNNING
def test_compute_engine_get_instance_not_exists(compute_engine,
                                                http_sequence_factory):
    http = http_sequence_factory([
        ({
            'status': '200'
        }, 'file:tests/http/compute-discovery.json'),
        ({
            'status': '404'
        }, 'file:tests/http/compute.instances.get.nonexistentnode.json'),
    ])
    compute_engine.http = http
    with tests.helpers.helpers_compute_engine.no_pause():
        instance = compute_engine.get_instance('nonexistentnode')
        assert instance.name == 'nonexistentnode'
        with pytest.raises(jam.libs.compute_engine.InstanceNotFound):
            _ = instance.status  # noqa: F841