def namespace(auth):
    name = "test-{}".format(uuid.uuid4())

    helper = KubernetesAnsibleModuleHelper('v1', 'namespace', debug=True, reset_logfile=False, **auth)

    k8s_obj = helper.create_object(V1Namespace(metadata=V1ObjectMeta(name=name)))
    assert k8s_obj is not None

    yield name

    helper.delete_object(name, None)
def admin_k8s_ansible_helper(request, admin_kubeconfig):
    _, _, api_version, resource = request.module.__name__.split('_', 3)
    auth = {}
    if admin_kubeconfig is not None:
        auth = {
            'kubeconfig': str(admin_kubeconfig),
            'host': 'https://localhost:8443',
            'verify_ssl': False
        }
    helper = KubernetesAnsibleModuleHelper(api_version, resource, **auth)
    helper.enable_debug(to_file=False)
    helper.api_client.config.debug = True

    return helper
Exemplo n.º 3
0
def ansible_helper(request, kubeconfig, admin_kubeconfig, port):
    api_version, resource = parse_test_name(request.node.name)
    needs_admin = request.node.cls.tasks.get('admin')
    config = admin_kubeconfig if needs_admin else kubeconfig
    auth = {}
    if kubeconfig is not None:
        auth = {
            'kubeconfig': str(config),
            'host': 'https://localhost:{}'.format(port),
            'verify_ssl': False
        }
    try:
        helper = KubernetesAnsibleModuleHelper(api_version,
                                               resource,
                                               debug=True,
                                               reset_logfile=False,
                                               **auth)
    except Exception:
        helper = OpenShiftAnsibleModuleHelper(api_version,
                                              resource,
                                              debug=True,
                                              reset_logfile=False,
                                              **auth)

    helper.api_client.config.debug = True

    return helper
 def dependencies(self, project, auth):
     dependencies = []
     for dependency in self.tasks.get('dependencies', []):
         resource_name, params = list(dependency.items())[0]
         api, api_version, kind = resource_name.split('_')
         if api == 'k8s':
             ansible_helper = KubernetesAnsibleModuleHelper(
                 api_version, kind, debug=True, reset_logfile=False, **auth)
         else:
             ansible_helper = OpenShiftAnsibleModuleHelper(
                 api_version, kind, debug=True, reset_logfile=False, **auth)
         if params.get('namespace'):
             params['namespace'] = project
         name = params.get('name')
         request_body = ansible_helper.request_body_from_params(params)
         dependencies.append(
             (name, project,
              ansible_helper.create_object(project, body=request_body)))
     try:
         yield dependencies
     finally:
         for name, namespace, dependency in dependencies:
             try:
                 ansible_helper.delete_object(name, namespace)
             except KubernetesException:
                 pass
def namespace(kubeconfig):
    name = "test-{}".format(uuid.uuid4())

    auth = {}
    if kubeconfig is not None:
        auth = {
            'kubeconfig': str(kubeconfig),
            'host': 'https://localhost:8443',
            'verify_ssl': False
        }
    helper = KubernetesAnsibleModuleHelper('v1', 'namespace', debug=True, reset_logfile=False, **auth)

    k8s_obj = helper.create_object(V1Namespace(metadata=V1ObjectMeta(name=name)))
    assert k8s_obj is not None

    yield name

    helper.delete_object(name, None)
def ansible_helper(request, auth):
    cluster_type, api_version, resource = parse_test_name(request.node.name)
    if cluster_type == 'k8s':
        helper = KubernetesAnsibleModuleHelper(api_version, resource, debug=True, reset_logfile=False, **auth)
    else:
        helper = OpenShiftAnsibleModuleHelper(api_version, resource, debug=True, reset_logfile=False, **auth)

    helper.api_client.configuration.debug = True

    return helper
Exemplo n.º 7
0
def ansible_helper(request, auth):
    api_version, resource = parse_test_name(request.node.name)
    try:
        helper = KubernetesAnsibleModuleHelper(api_version,
                                               resource,
                                               debug=True,
                                               reset_logfile=False,
                                               **auth)
    except Exception:
        helper = OpenShiftAnsibleModuleHelper(api_version,
                                              resource,
                                              debug=True,
                                              reset_logfile=False,
                                              **auth)

    helper.api_client.config.debug = True

    return helper
Exemplo n.º 8
0
 def get_helper(api_version, kind):
     return KubernetesAnsibleModuleHelper(api_version, kind)