-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for compose-tree-locations.
JIRA: PDC-1259
- Loading branch information
Showing
9 changed files
with
328 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,130 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2015 Red Hat | ||
# Licensed under The MIT License (MIT) | ||
# http://opensource.org/licenses/MIT | ||
# | ||
import json | ||
|
||
from pdc_client.plugin_helpers import (PDCClientPlugin, | ||
extract_arguments, | ||
add_parser_arguments, | ||
add_create_update_args) | ||
|
||
|
||
class ComposeTreeLocationsPlugin(PDCClientPlugin): | ||
def register(self): | ||
self.set_command('compose-tree-locations') | ||
|
||
list_parser = self.add_action('list', help='list all compose-variant-arch \ | ||
relevant to location') | ||
add_parser_arguments(list_parser, {'compose': {}, | ||
'variant': {}, | ||
'arch': {}, | ||
'location': {}, | ||
'scheme': {}}, | ||
group='Filtering') | ||
list_parser.set_defaults(func=self.compose_tree_location_list) | ||
|
||
info_parser = self.add_action('info', help='display details of a compose-variant-arch \ | ||
relevant to a location') | ||
self._add_common_arguments(info_parser) | ||
info_parser.set_defaults(func=self.compose_tree_location_info) | ||
|
||
help_text = 'update an existing compose-tree-locations\'s fields scheme, synced-content and url' | ||
update_parser = self.add_action('update', help=help_text) | ||
self._add_common_arguments(update_parser) | ||
add_parser_arguments(update_parser, {'scheme': {}, | ||
'url': {}, | ||
'synced_content': {'nargs': '*', 'choices': ['binary', 'debug', | ||
'source']}}) | ||
update_parser.set_defaults(func=self.compose_tree_location_update) | ||
|
||
create_parser = self.add_action('create', help='create a new compose-variant-arch relevant to a location') | ||
self.add_compose_tree_location_arguments(create_parser, required=True) | ||
create_parser.set_defaults(func=self.compose_tree_location_create) | ||
|
||
delete_parser = self.add_action('delete', help='delete a compose-variant-arch relevant to a location') | ||
self._add_common_arguments(delete_parser) | ||
delete_parser.set_defaults(func=self.compose_tree_location_delete) | ||
|
||
def _add_common_arguments(self, parser): | ||
parser.add_argument('compose_id', metavar='COMPOSE_ID') | ||
parser.add_argument('variant_uid', metavar='VARIANT_UID') | ||
parser.add_argument('arch', metavar='ARCH') | ||
parser.add_argument('location', metavar='LOCATION') | ||
|
||
def add_compose_tree_location_arguments(self, parser, required=False): | ||
required_args = { | ||
'compose': {}, | ||
'variant': {}, | ||
'arch': {}, | ||
'location': {}, | ||
'scheme': {}, | ||
'synced_content': {'nargs': '*', 'choices': ['binary', 'debug', 'source']}, | ||
'url': {}} | ||
optional_args = {} | ||
add_create_update_args(parser, required_args, optional_args, required) | ||
|
||
def _display_compose_tree_location_info(self, args, compose_tree_location_info): | ||
if args.json: | ||
print json.dumps(compose_tree_location_info) | ||
return | ||
fmt = '{0:20} {1}' | ||
print fmt.format('Compose', compose_tree_location_info['compose']) | ||
print fmt.format('Variant', compose_tree_location_info['variant']) | ||
print fmt.format('Arch', compose_tree_location_info['arch']) | ||
print fmt.format('Location', compose_tree_location_info['location']) | ||
print fmt.format('Scheme', compose_tree_location_info['scheme']) | ||
print fmt.format('Synced Content', compose_tree_location_info['synced_content']) | ||
print fmt.format('Url', compose_tree_location_info['url']) | ||
|
||
def compose_tree_location_list(self, args): | ||
filters = extract_arguments(args) | ||
compose_tree_locations = self.client.get_paged(self.client['compose-tree-locations']._, **filters) | ||
if args.json: | ||
print json.dumps(list(compose_tree_locations)) | ||
return | ||
fmt = '{0:<50} {1:20} {2:10} {3:10} {4:10} {5:40} {6}' | ||
if compose_tree_locations: | ||
print fmt.format( | ||
'Compose', | ||
'Variant', | ||
'Arch', | ||
'Location', | ||
'Scheme', | ||
'Synced Content', | ||
'Url') | ||
for compose_tree_location in compose_tree_locations: | ||
print fmt.format( | ||
compose_tree_location['compose'], | ||
compose_tree_location['variant'], | ||
compose_tree_location['arch'], | ||
compose_tree_location['location'], | ||
compose_tree_location['scheme'], | ||
compose_tree_location['synced_content'], | ||
compose_tree_location['url']) | ||
|
||
def compose_tree_location_info(self, args): | ||
compose_tree_location_info =\ | ||
self.client['compose-tree-locations'][args.compose_id][args.variant_uid][args.arch][args.location]._() | ||
self._display_compose_tree_location_info(args, compose_tree_location_info) | ||
|
||
def compose_tree_location_update(self, args): | ||
data = extract_arguments(args) | ||
compose_tree_location_info =\ | ||
self.client['compose-tree-locations'][args.compose_id][args.variant_uid][args.arch][args.location]._('PATCH', data) | ||
self._display_compose_tree_location_info(args, compose_tree_location_info) | ||
|
||
def compose_tree_location_create(self, args): | ||
data = extract_arguments(args) | ||
response = self.client['compose-tree-locations']._(data) | ||
self._display_compose_tree_location_info(args, response) | ||
|
||
def compose_tree_location_delete(self, args): | ||
data = extract_arguments(args) | ||
self.client['compose-tree-locations'][args.compose_id][args.variant_uid][args.arch][args.location]\ | ||
._("DELETE", data) | ||
|
||
PLUGIN_CLASSES = [ComposeTreeLocationsPlugin] |
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 @@ | ||
{ | ||
"arch": "x86_64", | ||
"compose": "Awesome-product-7.0-0", | ||
"variant": "Server", | ||
"location": "NAY", | ||
"scheme": "http", | ||
"synced_content": "debug", | ||
"url": "http://example.com" | ||
} |
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,7 @@ | ||
Compose Awesome-product-7.0-0 | ||
Variant Server | ||
Arch x86_64 | ||
Location NAY | ||
Scheme http | ||
Synced Content debug | ||
Url http://example.com |
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,7 @@ | ||
Compose Awesome-product-7.0-0 | ||
Variant Server | ||
Arch x86_64 | ||
Location NAY | ||
Scheme https | ||
Synced Content source | ||
Url https://example1.com |
7 changes: 7 additions & 0 deletions
7
tests/compose_tree_locations/data/detail_multi_synced_contents.txt
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,7 @@ | ||
Compose Awesome-product-7.0-0 | ||
Variant Server | ||
Arch x86_64 | ||
Location NAY | ||
Scheme http | ||
Synced Content debug source binary | ||
Url http://example.com |
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,32 @@ | ||
Compose Variant Arch Location Scheme Synced Content Url | ||
|
||
Awesome-product-7.0-0 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-1 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-2 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-3 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-4 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-5 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-6 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-7 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-8 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-9 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-10 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-11 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-12 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-13 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-14 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-15 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-16 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-17 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-18 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-19 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-20 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-21 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-22 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-23 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-24 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-25 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-26 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-27 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-28 Server x86_64 NAY http debug http://example.com | ||
Awesome-product-7.0-29 Server x86_64 NAY http debug http://example.com |
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,136 @@ | ||
# -*- 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 | ||
from copy import deepcopy | ||
|
||
|
||
class ComposeTreeLocationsTestCase(CLITestCase): | ||
def setUp(self): | ||
self.runner = Runner() | ||
self.runner.setup() | ||
self.compose_tree_location_detail = {"arch": "x86_64", | ||
"compose": "Awesome-product-7.0-0", | ||
"variant": "Server", | ||
"location": "NAY", | ||
"scheme": "http", | ||
"synced_content": "debug", | ||
"url": "http://example.com"} | ||
|
||
def _setup_list(self, api): | ||
api.add_endpoint('compose-tree-locations', 'GET', [ | ||
{"arch": "x86_64", | ||
"compose": "Awesome-product-7.0-{0}".format(x), | ||
"variant": "Server", | ||
"location": "NAY", | ||
"scheme": "http", | ||
"synced_content": "debug", | ||
"url": "http://example.com"} | ||
for x in range(30) | ||
]) | ||
|
||
def _setup_detail(self, api): | ||
obj = {"arch": "x86_64", | ||
"compose": "Awesome-product-7.0-0", | ||
"variant": "Server", | ||
"location": "NAY", | ||
"scheme": "http", | ||
"synced_content": "debug", | ||
"url": "http://example.com"} | ||
api.add_endpoint('compose-tree-locations/Awesome-product-7.0-0/Server/x86_64/NAY', | ||
'GET', obj) | ||
# PATCH test result to passed | ||
obj_update = deepcopy(obj) | ||
obj_update["scheme"] = "https" | ||
obj_update["url"] = "https://example1.com" | ||
obj_update["synced_content"] = "source" | ||
api.add_endpoint('compose-tree-locations/Awesome-product-7.0-0/Server/x86_64/NAY', | ||
'PATCH', obj_update) | ||
|
||
def test_list(self, api): | ||
self._setup_list(api) | ||
with self.expect_output('list_multi_page.txt'): | ||
self.runner.run(['compose-tree-locations', 'list']) | ||
self.assertEqual(api.calls['compose-tree-locations'], | ||
[('GET', {'page': 1}), | ||
('GET', {'page': 2})]) | ||
|
||
def test_info(self, api): | ||
self._setup_detail(api) | ||
with self.expect_output('detail.txt'): | ||
self.runner.run(['compose-tree-locations', 'info', 'Awesome-product-7.0-0', 'Server', | ||
'x86_64', 'NAY']) | ||
self.assertEqual( | ||
api.calls['compose-tree-locations/Awesome-product-7.0-0/Server/x86_64/NAY'], | ||
[('GET', {})]) | ||
|
||
def test_info_json(self, api): | ||
self._setup_detail(api) | ||
with self.expect_output('detail.json', parse_json=True): | ||
self.runner.run(['--json', 'compose-tree-locations', 'info', 'Awesome-product-7.0-0', 'Server', | ||
'x86_64', 'NAY']) | ||
self.assertEqual( | ||
api.calls['compose-tree-locations/Awesome-product-7.0-0/Server/x86_64/NAY'], | ||
[('GET', {})]) | ||
|
||
def test_update(self, api): | ||
self._setup_detail(api) | ||
with self.expect_output('detail_for_patch.txt'): | ||
self.runner.run(['compose-tree-locations', 'update', 'Awesome-product-7.0-0', 'Server', 'x86_64', 'NAY', | ||
'--scheme', 'https', '--synced-content', 'source', '--url', 'https://example1.com']) | ||
self.assertEqual(api.calls, {'compose-tree-locations/Awesome-product-7.0-0/Server/x86_64/NAY': | ||
[('PATCH', {'scheme': 'https', | ||
'synced_content': ['source'], | ||
'url': 'https://example1.com'})]}) | ||
|
||
def test_create(self, api): | ||
obj = {'arch': 'x86_64', | ||
'compose': 'Awesome-product-7.0-0', | ||
'variant': 'Server', | ||
'location': 'NAY', | ||
'scheme': 'http', | ||
'synced_content': 'debug', | ||
'url': 'http://example.com'} | ||
|
||
api.add_endpoint('compose-tree-locations', 'POST', obj) | ||
with self.expect_output('detail.txt'): | ||
self.runner.run(['compose-tree-locations', 'create', '--compose', 'Awesome-product-7.0-0', '--variant', | ||
'Server', '--arch', 'x86_64', '--location', 'NAY', '--scheme', 'http', '--synced-content', | ||
'debug', '--url', 'http://example.com']) | ||
self.assertEqual(api.calls, {'compose-tree-locations': [('POST', {'compose': 'Awesome-product-7.0-0', | ||
'variant': 'Server', 'arch': 'x86_64', | ||
'location': 'NAY', 'scheme': 'http', | ||
'synced_content': ['debug'], | ||
'url': 'http://example.com'})]}) | ||
|
||
def test_create_multi_synced_contents(self, api): | ||
obj = {'arch': 'x86_64', | ||
'compose': 'Awesome-product-7.0-0', | ||
'variant': 'Server', | ||
'location': 'NAY', | ||
'scheme': 'http', | ||
'synced_content': 'debug source binary', | ||
'url': 'http://example.com'} | ||
|
||
api.add_endpoint('compose-tree-locations', 'POST', obj) | ||
with self.expect_output('detail_multi_synced_contents.txt'): | ||
self.runner.run(['compose-tree-locations', 'create', '--compose', 'Awesome-product-7.0-0', '--variant', | ||
'Server', '--arch', 'x86_64', '--location', 'NAY', '--scheme', 'http', '--synced-content', | ||
'debug', 'source', 'binary', '--url', 'http://example.com']) | ||
self.assertEqual(api.calls, {'compose-tree-locations': [('POST', {'compose': 'Awesome-product-7.0-0', | ||
'variant': 'Server', 'arch': 'x86_64', | ||
'location': 'NAY', 'scheme': 'http', | ||
'synced_content': ['debug', 'source', 'binary'], | ||
'url': 'http://example.com'})]}) | ||
|
||
def test_delete(self, api): | ||
api.add_endpoint('compose-tree-locations/Awesome-product-7.0-0/Server/x86_64/NAY', | ||
'DELETE', None) | ||
with self.expect_output('empty.txt'): | ||
self.runner.run(['compose-tree-locations', 'delete', 'Awesome-product-7.0-0', 'Server', 'x86_64', 'NAY']) | ||
self.assertEqual(api.calls, {'compose-tree-locations/Awesome-product-7.0-0/Server/x86_64/NAY': | ||
[('DELETE', {})]}) |