-
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.
Create a new plugin of compose-full-import
The plugin of compose-full-import is mapping to the rpc/compose-full-import resource; which use to import a compose. JIRA: PDC-1736
- Loading branch information
1 parent
b755a0a
commit 8bdbf01
Showing
10 changed files
with
174 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,73 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2015 Red Hat | ||
# Licensed under The MIT License (MIT) | ||
# http://opensource.org/licenses/MIT | ||
# | ||
|
||
from __future__ import print_function | ||
|
||
import json | ||
import sys | ||
import os | ||
|
||
from pdc_client.plugin_helpers import PDCClientPlugin, add_create_update_args, extract_arguments | ||
|
||
|
||
class ComposeFullImportPlugin(PDCClientPlugin): | ||
def register(self): | ||
self.set_command('compose-full-import') | ||
create_parser = self.add_action('create', help='Import RPMs, images, create new compose and set compose tree location', | ||
description='The composeinfo, rpm_manifest and image_manifest values ' + | ||
'should be actual JSON representation of composeinfo, ' + | ||
'rpm manifest and image manifest, as stored in ' + | ||
'composeinfo.json, rpm-manifest.json and image-manifest.json files. ' + | ||
'location, url, scheme are used to set compose tree location.') | ||
self.add_compose_full_import_arguments(create_parser, required=True) | ||
create_parser.set_defaults(func=self.compose_full_import_create) | ||
|
||
def add_compose_full_import_arguments(self, parser, required=False): | ||
required_args = { | ||
'release_id': {'type': str}, | ||
'composeinfo': {}, | ||
'rpm_manifest': {}, | ||
'image_manifest': {}, | ||
'location': {'type': str}, | ||
'url': {'type': str}, | ||
'scheme': {'type': str}} | ||
optional_args = {} | ||
add_create_update_args(parser, required_args, optional_args, required) | ||
|
||
def _display_compose_import_info(self, args, compose_import_info): | ||
if args.json: | ||
print(json.dumps(compose_import_info)) | ||
return | ||
fmt = '{0:20} {1}' | ||
print(fmt.format('Compose', compose_import_info['compose'])) | ||
print(fmt.format('Imported Images', compose_import_info['imported images'])) | ||
print(fmt.format('Imported Rpms', compose_import_info['imported rpms'])) | ||
print(fmt.format('Set_locations', compose_import_info['set_locations'])) | ||
|
||
def compose_full_import_create(self, args): | ||
parser_args = self._get_value_from_json(args) | ||
data = extract_arguments(parser_args) | ||
response = self.client['rpc/compose-full-import']._(data) | ||
self._display_compose_import_info(parser_args, response) | ||
|
||
def _get_value_from_json(self, args): | ||
args.data__composeinfo = self._read_json_file(args.data__composeinfo) | ||
args.data__image_manifest = self._read_json_file(args.data__image_manifest) | ||
args.data__rpm_manifest = self._read_json_file(args.data__rpm_manifest) | ||
return args | ||
|
||
def _read_json_file(self, path): | ||
if os.path.isfile(path): | ||
with open(path, 'r') as f: | ||
data = json.load(f) | ||
else: | ||
print("Error: '%s' file can't find, please verify it" % path) | ||
sys.exit(1) | ||
return data | ||
|
||
|
||
PLUGIN_CLASSES = [ComposeFullImportPlugin] |
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
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
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
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,4 @@ | ||
Compose Awesome-product-7.0-0 | ||
Imported Images 1 | ||
Imported Rpms 1 | ||
Set_locations 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,20 @@ | ||
{ | ||
"composes": [ | ||
"compose-1" | ||
], | ||
"sha256": "3333333333333333333333333333333333333333333333333333333333333333", | ||
"sha1": "2222222222222222222222222222222222222222", | ||
"md5": "11111111111111111111111111111111", | ||
"implant_md5": "00000000000000000000000000000000", | ||
"volume_id": "VolumeID", | ||
"bootable": true, | ||
"file_name": "unique_image.iso", | ||
"image_type": "dvd", | ||
"image_format": "iso", | ||
"arch": "x86_64", | ||
"disc_number": 1, | ||
"disc_count": 1, | ||
"mtime": 1442923687, | ||
"size": 123456789, | ||
"subvariant": "subvariant_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,22 @@ | ||
{ | ||
"id": 1, | ||
"name": "bash", | ||
"epoch": 0, | ||
"version": "4.3.42", | ||
"release": 1, | ||
"arch": "x86_64", | ||
"srpm_name": "bash", | ||
"srpm_nevra": "bash-4.3.42-1.src", | ||
"filename": "bash-0:4.3.42-1.x86_64.rpm", | ||
"linked_composes": ["compose-1"], | ||
"linked_releases": ["release-1"], | ||
"dependencies": { | ||
"requires": ["glibc > 0"], | ||
"obsoletes": [], | ||
"recommends": [], | ||
"suggests": [], | ||
"conflicts": [], | ||
"provides": [] | ||
} | ||
} | ||
|
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,39 @@ | ||
# -*- 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 ComposeFullImportTestCase(CLITestCase): | ||
def setUp(self): | ||
self.runner = Runner() | ||
self.runner.setup() | ||
|
||
def _setup_detail(self, api): | ||
obj = {'set_locations': 1, | ||
'compose': 'Awesome-product-7.0-0', | ||
'imported images': 1, | ||
'imported rpms': 1} | ||
|
||
api.add_endpoint('rpc/compose-full-import', | ||
'POST', obj) | ||
|
||
def test_create(self, api): | ||
self._setup_detail(api) | ||
composeinfo_path = self.data_file_abspath('composeinfo.json') | ||
image_manifest_path = self.data_file_abspath('image_manifest.json') | ||
rpm_manifest_path = self.data_file_abspath('rpm_manifest.json') | ||
|
||
with self.expect_output('detail.txt'): | ||
self.runner.run(['compose-full-import', 'create', | ||
'--composeinfo', composeinfo_path, | ||
'--image-manifest', image_manifest_path, | ||
'--rpm-manifest', rpm_manifest_path, | ||
'--release-id', 'rhel-7.3', | ||
'--url', 'abc.com', | ||
'--location', 'nay', | ||
'--scheme', 'http']) |