示例#1
0
def test_kubernetes_discovery(cfgdir, mocker):
    """
    Testing Kubernetes initializaion.

    Is fabric creating Stub by default?
    Does Kubernetes return []?
    """
    k8s = os.path.join(
        os.path.dirname(__file__),
        "..",
        "fixture",
        "k8s.cloud.yaml",
    )
    k8s_data = os.path.join(
        os.path.dirname(__file__),
        "..",
        "fixture",
        "k8s_discovery_data.yaml",
    )
    k8s_pods = []
    with open(k8s_data, "r") as data:
        k8s_pods = yaml.safe_load(data)
    cloud = CloudSelect(cfgdir)
    profile = cloud.configuration_read()
    profile = cloud.merge(profile, cloud.configuration_read(k8s))
    args = cloud.parse_args([])
    cloud.fabric(profile, args)
    assert Container.discovery().__class__.__name__ == "Kubernetes"
    mocker.patch.object(Kubernetes, "get_pods", return_value=k8s_pods)
    representation, instances = Container.discovery().run()
    assert len(instances) == 2
    assert representation == [36, 37, 21, 7, 7, 11]
示例#2
0
def test_select_single(cfgdir):
    """Testing that Selector automaticaly select the only one available instance."""
    profile = os.path.join(os.path.dirname(__file__), "fixture", "single.cloud.json")
    cloud = CloudSelect(cfgdir)
    args = cloud.parse_args([profile])
    configuration = cloud.configuration_read()
    configuration = cloud.merge(configuration, cloud.configuration_read(args.profile))
    assert args.profile == profile
    selector = cloud.fabric(configuration, args)
    assert isinstance(Container.discovery(), Local)
    report = selector.select()
    assert len(report["instances"]) == 1
    assert report["instances"][0]["host"] == "my.cloud.instance"
示例#3
0
def test_select_empty(cfgdir):
    """Testing that Selector exits if there is no any instances."""
    profile = os.path.join(os.path.dirname(__file__), "fixture", "empty.cloud.json")
    cloud = CloudSelect(cfgdir)
    args = cloud.parse_args([profile])
    configuration = cloud.configuration_read()
    configuration = cloud.merge(configuration, cloud.configuration_read(args.profile))
    assert args.profile == profile
    selector = cloud.fabric(configuration, args)
    assert isinstance(Container.discovery(), Local)
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        selector.select()
    assert pytest_wrapped_e.type == SystemExit
    assert pytest_wrapped_e.value.code == "Error: No instances found"