Skip to content

Commit

Permalink
FIX: using namespaces --> This parameter is not passed to the request (
Browse files Browse the repository at this point in the history
…#81)

* fix parameters when you are using namespaces
  • Loading branch information
pserranoa authored and jrxFive committed Nov 9, 2018
1 parent ec2c529 commit f7037ac
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 3 deletions.
2 changes: 1 addition & 1 deletion nomad/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _request(self, method, endpoint, params=None, data=None, json=None, headers=
qs = self._query_string_builder(endpoint)

if params:
qs.update(params)
params.update(qs)
else:
params = qs

Expand Down
2 changes: 1 addition & 1 deletion nomad/api/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def periodic_job(self, id):
- nomad.api.exceptions.URLNotFoundNomadException
"""
return self.request(id, "periodic", "force", method="post").json()

def dispatch_job(self, id, payload=None, meta=None):
""" Dispatches a new instance of a parameterized job.
Expand Down
3 changes: 3 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@

# Security token
NOMAD_TOKEN = os.environ.get("NOMAD_TOKEN", None)

# Test namespace
NOMAD_NAMESPACE = "admin"
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
def nomad_setup():
n = nomad.Nomad(host=common.IP, port=common.NOMAD_PORT, verify=False, token=common.NOMAD_TOKEN)
return n

@pytest.fixture
def nomad_setup_with_namespace():
n = nomad.Nomad(host=common.IP, port=common.NOMAD_PORT, verify=False, token=common.NOMAD_TOKEN, namespace=common.NOMAD_NAMESPACE)
return n
16 changes: 16 additions & 0 deletions tests/test_allocation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import json
import uuid
import responses
import tests.common as common


# integration tests requires nomad Vagrant VM or Binary running
Expand Down Expand Up @@ -51,3 +53,17 @@ def test_dunder_getattr(nomad_setup):

with pytest.raises(AttributeError):
d = nomad_setup.allocation.does_not_exist


@responses.activate
#
# fix No data when you are using namespaces #82
#
def test_get_allocation_with_namespace(nomad_setup_with_namespace):
responses.add(
responses.GET,
"http://{ip}:{port}/v1/allocation/a8198d79-cfdb-6593-a999-1e9adabcba2e?namespace={namespace}".format(ip=common.IP, port=common.NOMAD_PORT, namespace=common.NOMAD_NAMESPACE),
status=200,
json={"ID": "a8198d79-cfdb-6593-a999-1e9adabcba2e","EvalID": "5456bd7a-9fc0-c0dd-6131-cbee77f57577","Namespace": common.NOMAD_NAMESPACE, "Name": "example.cache[0]","NodeID": "fb2170a8-257d-3c64-b14d-bc06cc94e34c","PreviousAllocation": "516d2753-0513-cfc7-57ac-2d6fac18b9dc","NextAllocation": "cd13d9b9-4f97-7184-c88b-7b451981616b"}
)
assert common.NOMAD_NAMESPACE in nomad_setup_with_namespace.allocation.get_allocation("a8198d79-cfdb-6593-a999-1e9adabcba2e")["Namespace"]
16 changes: 16 additions & 0 deletions tests/test_allocations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
import pytest
import responses
import tests.common as common


def test_register_job(nomad_setup):
Expand Down Expand Up @@ -37,3 +39,17 @@ def test_dunder_iter(nomad_setup):

def test_dunder_len(nomad_setup):
assert len(nomad_setup.allocations) >= 0


@responses.activate
#
# fix No data when you are using namespaces #82
#
def test_get_allocations_with_namespace(nomad_setup_with_namespace):
responses.add(
responses.GET,
"http://{ip}:{port}/v1/allocations?namespace={namespace}".format(ip=common.IP, port=common.NOMAD_PORT, namespace=common.NOMAD_NAMESPACE),
status=200,
json=[{"ID": "a8198d79-cfdb-6593-a999-1e9adabcba2e","EvalID": "5456bd7a-9fc0-c0dd-6131-cbee77f57577","Namespace": common.NOMAD_NAMESPACE, "Name": "example.cache[0]","NodeID": "fb2170a8-257d-3c64-b14d-bc06cc94e34c","PreviousAllocation": "516d2753-0513-cfc7-57ac-2d6fac18b9dc","NextAllocation": "cd13d9b9-4f97-7184-c88b-7b451981616b"}]
)
assert common.NOMAD_NAMESPACE in nomad_setup_with_namespace.allocations.get_allocations()[0]["Namespace"]
15 changes: 15 additions & 0 deletions tests/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os
import nomad
import uuid
import responses
import tests.common as common


def test_register_job(nomad_setup):
Expand Down Expand Up @@ -108,3 +110,16 @@ def test_dunder_getattr(nomad_setup):

with pytest.raises(AttributeError):
_ = nomad_setup.deployment.does_not_exist

@responses.activate
#
# fix No data when you are using namespaces #82
#
def test_get_deployment_with_namespace(nomad_setup_with_namespace):
responses.add(
responses.GET,
"http://{ip}:{port}/v1/deployment/a8198d79-cfdb-6593-a999-1e9adabcba2e?namespace={namespace}".format(ip=common.IP, port=common.NOMAD_PORT, namespace=common.NOMAD_NAMESPACE),
status=200,
json={"ID": "70638f62-5c19-193e-30d6-f9d6e689ab8e","JobID": "example", "JobVersion": 1, "JobModifyIndex": 17, "JobSpecModifyIndex": 17, "JobCreateIndex": 7,"Namespace": common.NOMAD_NAMESPACE, "Name": "example.cache[0]"}
)
assert common.NOMAD_NAMESPACE in nomad_setup_with_namespace.deployment.get_deployment("a8198d79-cfdb-6593-a999-1e9adabcba2e")["Namespace"]
15 changes: 15 additions & 0 deletions tests/test_deployments.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
import pytest
import os
import responses
import tests.common as common


def test_register_job(nomad_setup):
Expand Down Expand Up @@ -64,3 +66,16 @@ def test_dunder_getattr(nomad_setup):

with pytest.raises(AttributeError):
_ = nomad_setup.deployments.does_not_exist

@responses.activate
#
# fix No data when you are using namespaces #82
#
def test_get_deployments_with_namespace(nomad_setup_with_namespace):
responses.add(
responses.GET,
"http://{ip}:{port}/v1/deployments?namespace={namespace}".format(ip=common.IP, port=common.NOMAD_PORT, namespace=common.NOMAD_NAMESPACE),
status=200,
json=[{"ID": "70638f62-5c19-193e-30d6-f9d6e689ab8e","JobID": "example", "JobVersion": 1, "JobModifyIndex": 17, "JobSpecModifyIndex": 17, "JobCreateIndex": 7,"Namespace": common.NOMAD_NAMESPACE, "Name": "example.cache[0]"}]
)
assert common.NOMAD_NAMESPACE in nomad_setup_with_namespace.deployments.get_deployments()[0]["Namespace"]
16 changes: 15 additions & 1 deletion tests/test_jobs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import pytest
import json

import responses
import tests.common as common

# integration tests requires nomad Vagrant VM or Binary running
def test_register_job(nomad_setup):
Expand Down Expand Up @@ -66,3 +67,16 @@ def test_dunder_iter(nomad_setup):

def test_dunder_len(nomad_setup):
assert len(nomad_setup.jobs) >= 0

@responses.activate
#
# fix No data when you are using namespaces #82
#
def test_get_jobs_with_namespace(nomad_setup_with_namespace):
responses.add(
responses.GET,
"http://{ip}:{port}/v1/jobs?namespace={namespace}".format(ip=common.IP, port=common.NOMAD_PORT, namespace=common.NOMAD_NAMESPACE),
status=200,
json=[{"Region": "global","ID": "my-job", "ParentID": "", "Name": "my-job","Namespace": common.NOMAD_NAMESPACE, "Type": "batch", "Priority": 50}]
)
assert common.NOMAD_NAMESPACE in nomad_setup_with_namespace.jobs.get_jobs()[0]["Namespace"]

0 comments on commit f7037ac

Please sign in to comment.