def test_dns_discovery_for_service_with_sidekick_cross_stack(client):
    port = "432"
    service_scale = 2

    env, service, service_name, consumed_service_name = \
        create_env_with_sidekick(client, service_scale, port)

    env = env.activateservices()
    env = client.wait_success(env, 300)
    assert env.state == "active"

    service = client.wait_success(service, 300)
    assert service.state == "active"
    dnsname = service.secondaryLaunchConfigs[0].name

    validate_sidekick(client, service, service_name, consumed_service_name,
                      port, dnsname)

    secondary_cons = get_service_containers_with_name(client, service,
                                                      consumed_service_name)

    # Deploy client service in a different environment
    port = "433"
    launch_config_svc = {
        "imageUuid": SSH_IMAGE_UUID,
        "networkMode": MANAGED_NETWORK,
        "isolation": isolation,
        "stdinOpen": True,
        "tty": True
    }
    launch_config_svc["ports"] = [port + ":" + "22/tcp"]
    service_name = random_str()
    env1 = create_env(client)
    service1 = client.create_service(name=service_name,
                                     stackId=env1.id,
                                     launchConfig=launch_config_svc,
                                     scale=2)
    service1 = client.wait_success(service1, SERVICE_WAIT_TIMEOUT)
    service1.activate()
    service1 = client.wait_success(service1, SERVICE_WAIT_TIMEOUT)
    assert service1.state == "active"
    client_containers = get_service_container_list(client, service1)

    dnsname = \
        service.secondaryLaunchConfigs[0].name + "." + service.name + \
        "." + env.name + "." + RANCHER_FQDN

    validate_dns(client, client_containers, secondary_cons, port, dnsname)
    delete_all(client, [env, env1])
def test_dns_discovery_for_service_with_sidekick_cross_stack(
        super_client, client):
    port = "432"
    service_scale = 2

    env, service, service_name, consumed_service_name = \
        create_env_with_sidekick(client, service_scale, port)

    env = env.activateservices()
    env = client.wait_success(env, 120)
    assert env.state == "active"

    service = client.wait_success(service, 120)
    assert service.state == "active"
    dnsname = service.secondaryLaunchConfigs[0].name

    validate_sidekick(super_client, service, service_name,
                      consumed_service_name, port, dnsname)

    secondary_cons = get_service_containers_with_name(
        super_client, service, consumed_service_name)

    # Deploy client service in a different environment
    port = "433"
    launch_config_svc = {"imageUuid": SSH_IMAGE_UUID, }
    launch_config_svc["ports"] = [port+":"+"22/tcp"]
    service_name = random_str()
    env1 = create_env(client)
    service1 = client.create_service(name=service_name,
                                     environmentId=env1.id,
                                     launchConfig=launch_config_svc,
                                     scale=2)
    service1 = client.wait_success(service1, SERVICE_WAIT_TIMEOUT)
    service1.activate()
    service1 = client.wait_success(service1, SERVICE_WAIT_TIMEOUT)
    assert service1.state == "active"
    client_containers = get_service_container_list(super_client, service1)

    time.sleep(5)
    dnsname = \
        service.secondaryLaunchConfigs[0].name + "." + service.name + \
        "." + env.name + "." + RANCHER_FQDN

    validate_dns(
        super_client, client_containers, secondary_cons, port, dnsname)
    delete_all(client, [env, env1])
def test_dns_discovery_for_service_with_sidekick(admin_client, client):
    port = "430"
    service_scale = 2

    env, service, service_name, consumed_service_name = \
        create_env_with_sidekick(client, service_scale, port)

    env = env.activateservices()
    env = client.wait_success(env, 120)
    assert env.state == "active"

    service = client.wait_success(service, 120)
    assert service.state == "active"
    dnsname = service.secondaryLaunchConfigs[0].name

    validate_sidekick(admin_client, service, service_name,
                      consumed_service_name, port, dnsname)

    secondary_cons = get_service_containers_with_name(admin_client, service,
                                                      consumed_service_name)

    # Deploy client service in same environment
    port = "431"
    launch_config_svc = {
        "imageUuid": SSH_IMAGE_UUID,
    }
    launch_config_svc["ports"] = [port + ":" + "22/tcp"]
    service_name = random_str()
    service1 = client.create_service(name=service_name,
                                     stackId=env.id,
                                     launchConfig=launch_config_svc,
                                     scale=2)
    service1 = client.wait_success(service1, SERVICE_WAIT_TIMEOUT)
    service1.activate()
    service1 = client.wait_success(service1, SERVICE_WAIT_TIMEOUT)
    assert service1.state == "active"
    client_containers = get_service_container_list(admin_client, service1)

    dnsname = service.secondaryLaunchConfigs[0].name + "." + service.name
    validate_dns(admin_client, client_containers, secondary_cons, port,
                 dnsname)
    delete_all(client, [env])
def test_dns_discovery_for_service_with_sidekick(client):
    port = "430"
    service_scale = 2

    env, service, service_name, consumed_service_name = \
        create_env_with_sidekick(client, service_scale, port)

    env = client.wait_success(env, 120)
    assert env.state == "active"

    service = client.wait_success(service, 120)
    assert service.state == "active"
    dnsname = service.secondaryLaunchConfigs[0].name

    validate_sidekick(client, service, service_name,
                      consumed_service_name, port, dnsname)

    secondary_cons = get_service_containers_with_name(
        client, service, consumed_service_name)

    # Deploy client service in same environment
    port = "431"
    launch_config_svc = {"image": SSH_IMAGE_UUID, }
    launch_config_svc["ports"] = [port+":"+"22/tcp"]
    service_name = random_str()
    service1 = client.create_service(name=service_name,
                                     stackId=env.id,
                                     launchConfig=launch_config_svc,
                                     scale=2)
    service1 = client.wait_success(service1, SERVICE_WAIT_TIMEOUT)
    assert service1.state == "active"
    client_containers = get_service_container_list(client, service1)

    dnsname = service.secondaryLaunchConfigs[0].name + "." + service.name
    validate_dns(
        client, client_containers, secondary_cons, port, dnsname)
    delete_all(client, [env])