Skip to content

Commit

Permalink
Pods: method name changes
Browse files Browse the repository at this point in the history
The Openshift method is now list_pods(), taking an optional parameter
to specify a label to restrict the list to.

The OSBS API method is now get_pod_for_build(), reflecting the fact
that a build only has one pod.
  • Loading branch information
twaugh committed Sep 7, 2015
1 parent 21e723c commit 1df6430
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
20 changes: 12 additions & 8 deletions osbs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,20 @@ def cancel_build(self, build_id, namespace=DEFAULT_NAMESPACE):
return build_response

@osbsapi
def get_pods_for_build(self, build_id, namespace=DEFAULT_NAMESPACE):
def get_pod_for_build(self, build_id, namespace=DEFAULT_NAMESPACE):
"""
:return: list, PodResponse objects for pods relating to the build
:return: PodResponse object for pod relating to the build
"""
response = self.os.get_pods_for_build(build_id, namespace=namespace)
serialized_response = response.json()
pod_list = []
for pod in serialized_response["items"]:
pod_list.append(PodResponse(pod))
return pod_list
pods = self.os.list_pods(label='openshift.io/build.name=%s' % build_id,
namespace=namespace)
serialized_response = pods.json()
pod_list = [PodResponse(pod) for pod in serialized_response["items"]]
if not pod_list:
raise OsbsException("No pod for build")
elif len(pod_list) != 1:
raise OsbsException("Only one pod expected but %d returned",
len(pod_list))
return pod_list[0]

@osbsapi
def get_build_request(self, build_type=None):
Expand Down
6 changes: 1 addition & 5 deletions osbs/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,7 @@ def cmd_get_user(args, osbs):


def cmd_get_build_image_id(args, osbs):
pods = osbs.get_pods_for_build(args.BUILD_ID[0], namespace=args.namespace)
if len(pods) == 0:
return
assert len(pods) == 1
pod = pods[0]
pod = osbs.get_pod_for_build(args.BUILD_ID[0], namespace=args.namespace)
if args.output == 'json':
json_output = pod.get_container_image_ids()
print_json_nicely(json_output)
Expand Down
9 changes: 5 additions & 4 deletions osbs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,11 @@ def cancel_build(self, build_id, namespace=DEFAULT_NAMESPACE):
return self._put(url, data=json.dumps(br.json),
headers={"Content-Type": "application/json"})

def get_pods_for_build(self, build_id, namespace=DEFAULT_NAMESPACE):
labelSelector='openshift.io/build.name=%s' % build_id
url = self._build_k8s_url("namespaces/%s/pods/" % namespace,
labelSelector=labelSelector)
def list_pods(self, label=None, namespace=DEFAULT_NAMESPACE):
kwargs = {}
if label is not None:
kwargs['labelSelector'] = label
url = self._build_k8s_url("namespaces/%s/pods/" % namespace, **kwargs)
return self._get(url)

def get_build_config(self, build_config_id, namespace=DEFAULT_NAMESPACE):
Expand Down
6 changes: 2 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ def test_list_builds_api(self, osbs):
for build in response_list:
assert build.get_time_created_in_seconds() != 0.0

def test_get_pods_for_build(self, osbs):
response_list = osbs.get_pods_for_build(TEST_BUILD)
assert response_list is not None
pod = response_list[0]
def test_get_pod_for_build(self, osbs):
pod = osbs.get_pod_for_build(TEST_BUILD)
assert isinstance(pod, PodResponse)
images = pod.get_container_image_ids()
assert isinstance(images, dict)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
import six

from osbs.http import HttpResponse
from osbs.constants import BUILD_FINISHED_STATES

from tests.constants import TEST_BUILD, TEST_LABEL, TEST_LABEL_VALUE
Expand All @@ -23,6 +24,11 @@ def test_list_builds(self, openshift):
assert l is not None
assert bool(l.json()) # is there at least something

def test_list_pods(self, openshift):
response = openshift.list_pods(label="openshift.io/build.name=%s" %
TEST_BUILD)
assert isinstance(response, HttpResponse)

def test_get_oauth_token(self, openshift):
token = openshift.get_oauth_token()
assert token is not None
Expand Down

0 comments on commit 1df6430

Please sign in to comment.