-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JIRA: 1025
- Loading branch information
Showing
6 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2015 Red Hat | ||
# Licensed under The MIT License (MIT) | ||
# http://opensource.org/licenses/MIT | ||
# | ||
import json | ||
import sys | ||
|
||
from pdc_client import get_paged | ||
from pdc_client.plugin_helpers import PDCClientPlugin, add_parser_arguments, extract_arguments | ||
|
||
|
||
class BuildImagePlugin(PDCClientPlugin): | ||
def register(self): | ||
subcmd = self.add_command('build-image-list', help='list all build images') | ||
subcmd.add_argument('--show-md5', action='store_true', | ||
help='whether to display md5 checksums') | ||
add_parser_arguments(subcmd, {'component_name': {}, | ||
'rpm_version': {}, | ||
'rpm_release': {}, | ||
'image_id': {}, | ||
'image_format': {}, | ||
'md5': {}, | ||
'archive_build_nvr': {}, | ||
'archive_name': {}, | ||
'archive_size': {}, | ||
'archive_md5': {}, | ||
'release_id': {}}, | ||
group='Filtering') | ||
|
||
subcmd.set_defaults(func=self.list_build_image) | ||
|
||
subcmd = self.add_command('build-image-info', help='display details of a build image') | ||
subcmd.add_argument('image_id', metavar='IMAGE_ID') | ||
subcmd.set_defaults(func=self.build_image_info) | ||
|
||
def _print_build_image_list(self, build_images, with_md5=False): | ||
fmt = '{image_id}' | ||
if with_md5: | ||
fmt += ' {md5}' | ||
for build_image in build_images: | ||
print fmt.format(**build_image) | ||
|
||
def list_build_image(self, args): | ||
filters = extract_arguments(args) | ||
build_images = get_paged(self.client['build-images']._, **filters) | ||
if args.json: | ||
print json.dumps(list(build_images)) | ||
return | ||
self._print_build_image_list(build_images, args.show_md5) | ||
|
||
def build_image_info(self, args, image_id=None): | ||
image_id = image_id or args.image_id | ||
build_images = self.client['build-images']._(image_id=image_id) | ||
if not build_images['count']: | ||
print 'Not found' | ||
sys.exit(1) | ||
build_image = build_images['results'][0] | ||
if args.json: | ||
print json.dumps(build_image) | ||
return | ||
fmt = '{:20} {}' | ||
print fmt.format('Image ID', build_image['image_id']) | ||
print fmt.format('Image Format', build_image['image_format']) | ||
print fmt.format('URL', build_image['url']) | ||
print fmt.format('MD5', build_image['md5']) | ||
|
||
for key in ('releases', 'rpms'): | ||
if build_image[key]: | ||
print '\nRelated %s:' % key | ||
for value in build_image[key]: | ||
print ' * {}'.format(value) | ||
|
||
if build_image['archives']: | ||
print '\nRelated archives:' | ||
fmt = '* {:40}{:60}{}' | ||
print fmt.format('MD5', 'Name', 'Build NVR') | ||
fmt = ' {:40}{:60}{}' | ||
for archive in build_image['archives']: | ||
print fmt.format(archive['md5'], archive['name'], archive['build_nvr']) | ||
|
||
|
||
PLUGIN_CLASSES = [BuildImagePlugin] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"archives": [], | ||
"image_format": "docker", | ||
"image_id": "test_image_1", | ||
"md5": "11112222333344445555666677778899", | ||
"releases": [], | ||
"rpms": [], | ||
"url": "http://127.0.0.1:8000/rest_api/v1/build-images/1/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Image ID test_image_1 | ||
Image Format docker | ||
URL http://127.0.0.1:8000/rest_api/v1/build-images/1/ | ||
MD5 11112222333344445555666677778899 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
build-image-0 | ||
build-image-1 | ||
build-image-2 | ||
build-image-3 | ||
build-image-4 | ||
build-image-5 | ||
build-image-6 | ||
build-image-7 | ||
build-image-8 | ||
build-image-9 | ||
build-image-10 | ||
build-image-11 | ||
build-image-12 | ||
build-image-13 | ||
build-image-14 | ||
build-image-15 | ||
build-image-16 | ||
build-image-17 | ||
build-image-18 | ||
build-image-19 | ||
build-image-20 | ||
build-image-21 | ||
build-image-22 | ||
build-image-23 | ||
build-image-24 | ||
build-image-25 | ||
build-image-26 | ||
build-image-27 | ||
build-image-28 | ||
build-image-29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2015 Red Hat | ||
# Licensed under The MIT License (MIT) | ||
# http://opensource.org/licenses/MIT | ||
# | ||
from pdc_client.test_helpers import CLITestCase | ||
from pdc_client.runner import Runner | ||
|
||
|
||
class BuildImageTestCase(CLITestCase): | ||
def setUp(self): | ||
self.runner = Runner() | ||
self.runner.setup() | ||
|
||
def _setup_list_1(self, api): | ||
api.add_endpoint('build-images', 'GET', [ | ||
{'image_id': 'build-image-{}'.format(x), | ||
'md5': '111122223333444455556666777788{:02}'.format(x)} | ||
for x in range(30) | ||
]) | ||
|
||
def _setup_detail(self, api): | ||
obj = {'image_id': 'test_image_1', | ||
'url': 'http://127.0.0.1:8000/rest_api/v1/build-images/1/', | ||
'image_format': 'docker', | ||
'md5': '11112222333344445555666677778899', | ||
'rpms': [], | ||
'archives': [], | ||
'releases': []} | ||
api.add_endpoint('build-images/1', 'PATCH', obj) | ||
api.add_endpoint('build-images/1', 'GET', obj) | ||
api.add_endpoint('build-images', 'POST', obj) | ||
|
||
def _setup_list_2(self, api): | ||
filter_result = { | ||
"count": 1, | ||
"next": None, | ||
"previous": None, | ||
"results": [ | ||
{ | ||
"archives": [], | ||
"image_format": "docker", | ||
"image_id": "test_image_1", | ||
"md5": "11112222333344445555666677778899", | ||
"releases": [], | ||
"rpms": [], | ||
"url": "http://127.0.0.1:8000/rest_api/v1/build-images/1/" | ||
} | ||
] | ||
} | ||
|
||
api.add_endpoint('build-images', 'GET', filter_result) | ||
|
||
def test_list(self, api): | ||
self._setup_list_1(api) | ||
with self.expect_output('list_multi_page.txt'): | ||
self.runner.run(['build-image-list']) | ||
self.assertEqual(api.calls['build-images'], | ||
[('GET', {'page': 1}), | ||
('GET', {'page': 2})]) | ||
|
||
def test_info(self, api): | ||
self._setup_detail(api) | ||
self._setup_list_2(api) | ||
with self.expect_output('detail.json', parse_json=True): | ||
self.runner.run(['--json', 'build-image-info', 'test_image_1']) | ||
self.assertEqual(api.calls['build-images'], [('GET', {'image_id': 'test_image_1'})]) |