def test_external_host_node(kiali_client):

    try:
        assert command_exec.oc_apply(conftest.EXTERNAL_HOST_SERVICE_FILE,
                                     conftest.get_bookinfo_namespace()) == True

        PARAMS['namespaces'] = conftest.get_bookinfo_namespace()
        response = kiali_client.request(method_name='graphNamespaces',
                                        params=PARAMS)
        assert response.status_code == 200

        nodes = response.json().get('elements').get('nodes')

        with timeout(seconds=60,
                     error_message='Timed out waiting for \"{}\"'.format(
                         EXPECTED_EXTERNAL_SERVICE_NAME)):
            wiat_for = True
            while wiat_for:
                for node in nodes:
                    name = node.get('data').get('service')
                    if name != None and name == EXPECTED_EXTERNAL_SERVICE_NAME:
                        wiat_for = False
                        break

                    time.sleep(1)

    finally:
        command_exec.oc_delete(conftest.EXTERNAL_HOST_SERVICE_FILE,
                               conftest.get_bookinfo_namespace())
Esempio n. 2
0
def __remove_assets():
    print('Cleanning up: ')
    namespace = get_bookinfo_namespace()
    file_count = 0
    for root, dirs, files in os.walk(ASSETS_PATH):
        file_count = len(files)

        for name in files:
            command_exec.oc_delete(ASSETS_PATH + name, namespace)

    print('Assets deleted: {}'.format(file_count))
Esempio n. 3
0
def __remove_assets():
  print('Cleanning up (Note: ignore messages: "Error from server (NotFound))": ')
  namespace = get_bookinfo_namespace()
  file_count = 0
  for root, dirs, files in os.walk(ASSETS_PATH):
    file_count = len(files)

    for name in files:
      command_exec.oc_delete(ASSETS_PATH + "/" + name, namespace)

  print('Assets deleted: {}'.format(file_count))
def test_service_detail_with_virtual_service(kiali_client):
    bookinfo_namespace = conftest.get_bookinfo_namespace()

    try:
      # Add a virtual service that will be tested
      assert command_exec.oc_apply(VIRTUAL_SERVICE_FILE, bookinfo_namespace) == True

      with timeout(seconds=30, error_message='Timed out waiting for virtual service creation'):
        while True:
          service_details = kiali_client.service_details(namespace=bookinfo_namespace, service=SERVICE_TO_VALIDATE)
          if service_details != None and service_details.get('virtualServices') != None and len(service_details.get('virtualServices').get('items')) > 0:
            break

          time.sleep(1)

      assert service_details != None

      virtual_service_descriptor = service_details.get('virtualServices')
      assert virtual_service_descriptor != None

      permissions = virtual_service_descriptor.get('permissions')
      assert permissions != None
      assert permissions.get('update') == False
      assert permissions.get('delete') == True

      virtual_service = virtual_service_descriptor.get('items')[0]
      assert virtual_service != None
      assert virtual_service.get('name') == 'reviews'

      https = virtual_service.get('http')
      assert https != None
      assert len (https) == 1

      routes = https[0].get('route')
      assert len (routes) == 2

      assert routes[0].get('weight') == 80
      destination = routes[0].get('destination')
      assert destination != None
      assert destination.get('host') == 'reviews'
      assert destination.get('subset') == 'v1'

      assert routes[1].get('weight') == 20
      destination = routes[1].get('destination')
      assert destination != None
      assert destination.get('host') == 'reviews'
      assert destination.get('subset') == 'v2'

    finally:
      assert command_exec.oc_delete(VIRTUAL_SERVICE_FILE, bookinfo_namespace) == True

      with timeout(seconds=30, error_message='Timed out waiting for virtual service deletion'):
        while True:
          service_details = kiali_client.service_details(namespace=bookinfo_namespace, service=SERVICE_TO_VALIDATE)
          if service_details != None and len(service_details.get('virtualServices').get('items')) == 0:
            break

          time.sleep(1)
def test_service_detail_with_destination_rule(kiali_client):
    bookinfo_namespace = conftest.get_bookinfo_namespace()

    try:
      # Add a destination rule that will be tested
      assert command_exec.oc_apply(DESTINATION_RULE_FILE, bookinfo_namespace) == True

      with timeout(seconds=30, error_message='Timed out waiting for destination rule creation'):
        while True:
          service_details = kiali_client.service_details(namespace=bookinfo_namespace, service=SERVICE_TO_VALIDATE)
          if service_details != None and service_details.get('destinationRules') != None and len(service_details.get('destinationRules').get('items')) > 0:
            break

          time.sleep(1)

      assert service_details != None

      destination_rule_descriptor = service_details.get('destinationRules')
      assert destination_rule_descriptor != None

      permissions = destination_rule_descriptor.get('permissions')
      assert permissions != None
      assert permissions.get('update') == False
      assert permissions.get('delete') == True

      destination_rule = destination_rule_descriptor.get('items')[0]
      assert destination_rule != None
      assert destination_rule.get('name') == 'reviews'
      assert 'trafficPolicy' in destination_rule

      subsets = destination_rule.get('subsets')
      assert subsets != None
      assert len (subsets) == 3

      for i, subset in enumerate(subsets):
        subset_number = str(i + 1)

        name = subset.get('name')
        assert name == 'v' + subset_number

        labels = subset.get('labels')
        assert labels != None and labels.get('version') == 'v' + subset_number

    finally:
      assert command_exec.oc_delete(DESTINATION_RULE_FILE, bookinfo_namespace) == True

      with timeout(seconds=30, error_message='Timed out waiting for destination rule deletion'):
        while True:
          service_details = kiali_client.service_details(namespace=bookinfo_namespace, service=SERVICE_TO_VALIDATE)
          if service_details != None and len(service_details.get('destinationRules').get('items')) == 0:
            break

          time.sleep(1)
def __test_diversity_in_workload_list_endpoint(kiali_client):
  bookinfo_namespace = conftest.get_bookinfo_namespace()

  try:
    # Add extra workloads that will be tested
    assert command_exec.oc_apply(conftest.WORKLOADS_FILE, bookinfo_namespace) == True

    with timeout(seconds=90, error_message='Timed out waiting for extra workloads creation'):
      while True:
        workload_list = kiali_client.request(method_name='workloadList', path={'namespace': bookinfo_namespace}).json()
        if workload_list != None and workload_list.get('workloads') != None:
          workload_names = set(list(map(lambda workload: workload.get('name'), workload_list.get('workloads'))))
          if EXTRA_WORKLOADS.issubset(workload_names):
            break

        time.sleep(1)

    # Dictionary that maps Workloads with its own types
    dicWorkloadType = {
      'details-v2': 'Pod',
      'reviews-v4': 'ReplicaSet',
      'reviews-v5': 'ReplicationController',
      'reviews-v6': 'StatefulSet'
    }

    for workload in workload_list.get('workloads'):
      if workload.get('name') in EXTRA_WORKLOADS:
        workloadType = dicWorkloadType[workload.get('name')]
        assert workload.get('type') == workloadType

  finally:
    assert command_exec.oc_delete(conftest.WORKLOADS_FILE, bookinfo_namespace) == True

    with timeout(seconds=90, error_message='Timed out waiting for extra workloads deletion'):
      print('Extra workloads added for this test:', EXTRA_WORKLOADS)
      while True:
        workload_list = kiali_client.request(method_name='workloadList', path={'namespace': bookinfo_namespace}).json()
        if workload_list != None and workload_list.get('workloads') != None:
          workload_names = set(list(map(lambda workload: workload.get('name'), workload_list.get('workloads'))))
          print('Still existing workloads:', workload_names)
          if EXTRA_WORKLOADS.intersection(workload_names) == set():
            break

        time.sleep(1)
Esempio n. 7
0
def do_test(kiali_client, graph_params, yaml_file, badge):
    bookinfo_namespace = conftest.get_bookinfo_namespace()
    graph_params["namespaces"] = bookinfo_namespace
    json = kiali_client.graph_namespaces(params=graph_params)

    print("Debug: Start do_test: JSON: {}".format(json))

    assert badge not in json
    assert json['graphType'] == graph_params.get('graphType')

    count = get_badge_count(kiali_client, bookinfo_namespace, graph_params, badge)

    try:
      assert command_exec.oc_apply(yaml_file, bookinfo_namespace) == True

      graph = kiali_client.graph_namespaces(params=graph_params)
      assert graph is not None

      try:
        with timeout(seconds=30, error_message='Timed out waiting for Create'):
          while True:
              new_count = get_badge_count(kiali_client, bookinfo_namespace, graph_params, badge)
              if new_count != 0 and new_count >= count:
                  break

              time.sleep(1)
      except:
        print ("Timeout Exception - Nodes: {}".format(kiali_client.graph_namespaces(params=graph_params)["elements"]['nodes']))
        raise Exception("Timeout - Waiting for badge: {}".format(badge))

    finally:
      assert command_exec.oc_delete(yaml_file, bookinfo_namespace) == True

      with timeout(seconds=30, error_message='Timed out waiting for Delete'):
          while True:
              # Validate that JSON no longer has Virtual Service
              if get_badge_count(kiali_client, bookinfo_namespace, graph_params, badge) <= count:
                  break

              time.sleep(1)

    return True
Esempio n. 8
0
def do_test(kiali_client, graph_params, yaml_file, badge):
    environment_configmap = conftest.__get_environment_config__(
        conftest.ENV_FILE)
    bookinfo_namespace = bookinfo_namespace = conftest.get_bookinfo_namespace()

    appType = kiali_client.graph_namespace(namespace=bookinfo_namespace,
                                           params=graph_params)['graphType']
    assert appType == graph_params.get('graphType')

    count = get_badge_count(kiali_client, bookinfo_namespace, graph_params,
                            badge)

    try:
        assert command_exec.oc_apply(yaml_file, bookinfo_namespace) == True

        graph = kiali_client.graph_namespace(namespace=bookinfo_namespace,
                                             params=graph_params)
        assert graph is not None

        with timeout(seconds=30, error_message='Timed out waiting for Create'):
            while True:
                new_count = get_badge_count(kiali_client, bookinfo_namespace,
                                            graph_params, badge)
                if new_count != 0 and new_count >= count:
                    break

                time.sleep(1)

    finally:
        assert command_exec.oc_delete(yaml_file, bookinfo_namespace) == True

        with timeout(seconds=30, error_message='Timed out waiting for Delete'):
            while True:
                # Validate that JSON no longer has Virtual Service
                if get_badge_count(kiali_client, bookinfo_namespace,
                                   graph_params, badge) <= count:
                    break

                time.sleep(1)

    return True
Esempio n. 9
0
def test_service_detail_with_virtual_service(kiali_client):
    bookinfo_namespace = conftest.get_bookinfo_namespace()

    try:
        # check if we have any existing virtual services
        pre_vs_count = len(
            kiali_client.request(method_name='serviceDetails',
                                 path={
                                     'namespace': bookinfo_namespace,
                                     'service': SERVICE_TO_VALIDATE
                                 }).json().get('virtualServices'))

        # Add a virtual service that will be tested
        assert command_exec.oc_apply(VIRTUAL_SERVICE_FILE,
                                     bookinfo_namespace) == True

        with timeout(
                seconds=60,
                error_message='Timed out waiting for virtual service creation'
        ):
            while True:
                service_details = kiali_client.request(
                    method_name='serviceDetails',
                    path={
                        'namespace': bookinfo_namespace,
                        'service': SERVICE_TO_VALIDATE
                    }).json()
                if service_details != None and service_details.get(
                        'virtualServices') != None and len(
                            service_details.get(
                                'virtualServices')) > pre_vs_count:
                    break

                time.sleep(1)

        assert service_details != None

        virtual_service_descriptor = service_details.get('virtualServices')
        assert virtual_service_descriptor != None

        # find our virtual service
        virtual_service = None
        for vs in virtual_service_descriptor:
            if (vs['metadata']['name'] == 'reviews'):
                virtual_service = vs
                break
        assert virtual_service != None

        virtual_service_meta = virtual_service.get('metadata')
        assert virtual_service_meta.get('name') == 'reviews'

        virtual_service_spec = virtual_service.get('spec')
        https = virtual_service_spec.get('http')
        assert https != None
        assert len(https) == 1

        routes = https[0].get('route')
        assert len(routes) == 2

        assert routes[0].get('weight') == 80
        destination = routes[0].get('destination')
        assert destination != None
        assert destination.get('host') == 'reviews'
        assert destination.get('subset') == 'v1'

        assert routes[1].get('weight') == 20
        destination = routes[1].get('destination')
        assert destination != None
        assert destination.get('host') == 'reviews'
        assert destination.get('subset') == 'v2'

    finally:
        assert command_exec.oc_delete(VIRTUAL_SERVICE_FILE,
                                      bookinfo_namespace) == True

        with timeout(
                seconds=60,
                error_message='Timed out waiting for virtual service deletion'
        ):
            while True:
                service_details = kiali_client.request(
                    method_name='serviceDetails',
                    path={
                        'namespace': bookinfo_namespace,
                        'service': SERVICE_TO_VALIDATE
                    }).json()
                if service_details != None and len(
                        service_details.get(
                            'virtualServices')) == pre_vs_count:
                    break

                time.sleep(1)
Esempio n. 10
0
def test_service_detail_with_destination_rule(kiali_client):
    bookinfo_namespace = conftest.get_bookinfo_namespace()

    try:
        # check if we have any existing rules
        pre_dr_count = len(
            kiali_client.request(method_name='serviceDetails',
                                 path={
                                     'namespace': bookinfo_namespace,
                                     'service': SERVICE_TO_VALIDATE
                                 }).json().get('destinationRules'))

        # Add a destination rule that will be tested
        assert command_exec.oc_apply(DESTINATION_RULE_FILE,
                                     bookinfo_namespace) == True

        with timeout(
                seconds=60,
                error_message='Timed out waiting for destination rule creation'
        ):
            while True:
                service_details = kiali_client.request(
                    method_name='serviceDetails',
                    path={
                        'namespace': bookinfo_namespace,
                        'service': SERVICE_TO_VALIDATE
                    }).json()
                if service_details != None and service_details.get(
                        'destinationRules') != None and len(
                            service_details.get(
                                'destinationRules')) > pre_dr_count:
                    break

                time.sleep(1)

        assert service_details != None

        destination_rule_descriptor = service_details.get('destinationRules')
        assert destination_rule_descriptor != None

        # find our destination rule
        destination_rule = None
        for dr in destination_rule_descriptor:
            if (dr['metadata']['name'] == 'reviews'):
                destination_rule = dr
                break
        assert destination_rule != None

        destination_rule_meta = destination_rule.get('metadata')
        assert destination_rule_meta.get('name') == 'reviews'

        destination_rule_spec = destination_rule.get('spec')
        assert 'trafficPolicy' in destination_rule_spec

        subsets = destination_rule_spec.get('subsets')
        assert subsets != None
        assert len(subsets) == 3

        for i, subset in enumerate(subsets):
            subset_number = str(i + 1)

            name = subset.get('name')
            assert name == 'v' + subset_number

            labels = subset.get('labels')
            assert labels != None and labels.get(
                'version') == 'v' + subset_number

    finally:
        assert command_exec.oc_delete(DESTINATION_RULE_FILE,
                                      bookinfo_namespace) == True

        with timeout(
                seconds=60,
                error_message='Timed out waiting for destination rule deletion'
        ):
            while True:
                service_details = kiali_client.request(
                    method_name='serviceDetails',
                    path={
                        'namespace': bookinfo_namespace,
                        'service': SERVICE_TO_VALIDATE
                    }).json()
                if service_details != None and len(
                        service_details.get(
                            'destinationRules')) == pre_dr_count:
                    break

                time.sleep(1)