Allowed to use the artifacts by name
Added the ability to access by name of the artifact. To access the artifacts by 'id' must specify the appropriate flag. Change-Id: I776cd8cb0c15fb58891ae7f06d1c1272a4f3478c
This commit is contained in:
parent
b8d2760fe5
commit
6abe210de2
@ -42,6 +42,18 @@ def print_artifact(client, data, type_name):
|
|||||||
table)
|
table)
|
||||||
|
|
||||||
|
|
||||||
|
def get_artifact_id(client, parsed_args):
|
||||||
|
if parsed_args.id:
|
||||||
|
if parsed_args.artifact_version != 'latest':
|
||||||
|
LOG.warn('Specified version is not considered when '
|
||||||
|
'receiving of the artifact by ID.')
|
||||||
|
return parsed_args.name
|
||||||
|
|
||||||
|
return client.artifacts.get_by_name(parsed_args.name,
|
||||||
|
version=parsed_args.artifact_version,
|
||||||
|
type_name=parsed_args.type_name)['id']
|
||||||
|
|
||||||
|
|
||||||
class ListArtifacts(command.Lister):
|
class ListArtifacts(command.Lister):
|
||||||
"""List of artifacts"""
|
"""List of artifacts"""
|
||||||
|
|
||||||
@ -118,18 +130,31 @@ class ShowArtifact(command.Lister):
|
|||||||
help='Name of artifact type.',
|
help='Name of artifact type.',
|
||||||
),
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'id',
|
'name',
|
||||||
metavar='<ID>',
|
metavar='<NAME>',
|
||||||
help='ID of the artifact to update.',
|
help='Name or id of the artifact to show.',
|
||||||
)
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--artifact-version', '-v',
|
||||||
|
metavar='<VERSION>',
|
||||||
|
default='latest',
|
||||||
|
help='Version of the artifact.',
|
||||||
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--id', '-i',
|
||||||
|
action='store_true',
|
||||||
|
help='The specified id of the artifact.',
|
||||||
|
),
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
LOG.debug('take_action({0})'.format(parsed_args))
|
LOG.debug('take_action({0})'.format(parsed_args))
|
||||||
client = self.app.client_manager.artifact
|
client = self.app.client_manager.artifact
|
||||||
|
|
||||||
data = client.artifacts.get(parsed_args.id,
|
af_id = get_artifact_id(client, parsed_args)
|
||||||
|
data = client.artifacts.get(af_id,
|
||||||
type_name=parsed_args.type_name)
|
type_name=parsed_args.type_name)
|
||||||
|
|
||||||
return print_artifact(client, data, parsed_args.type_name)
|
return print_artifact(client, data, parsed_args.type_name)
|
||||||
|
|
||||||
|
|
||||||
@ -200,7 +225,18 @@ class UpdateArtifact(command.Lister):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--name', '-n',
|
'--name', '-n',
|
||||||
metavar='<NAME>',
|
metavar='<NAME>',
|
||||||
help='Name of the artifact.',
|
help='Name or id of the artifact to update.',
|
||||||
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--artifact-version', '-v',
|
||||||
|
metavar='<VERSION>',
|
||||||
|
default='latest',
|
||||||
|
help='Version of the artifact.',
|
||||||
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--id', '-i',
|
||||||
|
action='store_true',
|
||||||
|
help='The specified id of the artifact.',
|
||||||
),
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--remove-property', '-r',
|
'--remove-property', '-r',
|
||||||
@ -208,7 +244,7 @@ class UpdateArtifact(command.Lister):
|
|||||||
action='append',
|
action='append',
|
||||||
default=[],
|
default=[],
|
||||||
help='Property that will be removed.'
|
help='Property that will be removed.'
|
||||||
)
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--property', '-p',
|
'--property', '-p',
|
||||||
metavar='<key=value>',
|
metavar='<key=value>',
|
||||||
@ -227,8 +263,9 @@ class UpdateArtifact(command.Lister):
|
|||||||
prop[key] = value
|
prop[key] = value
|
||||||
|
|
||||||
client = self.app.client_manager.artifact
|
client = self.app.client_manager.artifact
|
||||||
|
af_id = get_artifact_id(client, parsed_args)
|
||||||
data = client.artifacts.update(
|
data = client.artifacts.update(
|
||||||
parsed_args.id, type_name=parsed_args.type_name,
|
af_id, type_name=parsed_args.type_name,
|
||||||
remove_props=parsed_args.remove_property, **prop)
|
remove_props=parsed_args.remove_property, **prop)
|
||||||
|
|
||||||
return print_artifact(client, data, parsed_args.type_name)
|
return print_artifact(client, data, parsed_args.type_name)
|
||||||
@ -246,16 +283,28 @@ class DeleteArtifact(command.Command):
|
|||||||
help='Name of artifact type.',
|
help='Name of artifact type.',
|
||||||
),
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'id',
|
'name',
|
||||||
metavar='<ID>',
|
metavar='<NAME>',
|
||||||
help='ID of the artifact to update.',
|
help='Name or id of the artifact to delete.',
|
||||||
)
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--artifact-version', '-v',
|
||||||
|
metavar='<VERSION>',
|
||||||
|
default='latest',
|
||||||
|
help='Version of the artifact.',
|
||||||
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--id', '-i',
|
||||||
|
action='store_true',
|
||||||
|
help='The specified id of the artifact.',
|
||||||
|
),
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
LOG.debug('take_action({0})'.format(parsed_args))
|
LOG.debug('take_action({0})'.format(parsed_args))
|
||||||
client = self.app.client_manager.artifact
|
client = self.app.client_manager.artifact
|
||||||
client.artifacts.delete(parsed_args.id,
|
af_id = get_artifact_id(client, parsed_args)
|
||||||
|
client.artifacts.delete(af_id,
|
||||||
type_name=parsed_args.type_name)
|
type_name=parsed_args.type_name)
|
||||||
|
|
||||||
|
|
||||||
@ -271,17 +320,29 @@ class ActivateArtifact(command.Lister):
|
|||||||
help='Name of artifact type.',
|
help='Name of artifact type.',
|
||||||
),
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'id',
|
'name',
|
||||||
metavar='<ID>',
|
metavar='<NAME>',
|
||||||
help='ID of the artifact to update.',
|
help='Name or id of the artifact to activate.',
|
||||||
)
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--artifact-version', '-v',
|
||||||
|
metavar='<VERSION>',
|
||||||
|
default='latest',
|
||||||
|
help='Version of the artifact.',
|
||||||
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--id', '-i',
|
||||||
|
action='store_true',
|
||||||
|
help='The specified id of the artifact.',
|
||||||
|
),
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
LOG.debug('take_action({0})'.format(parsed_args))
|
LOG.debug('take_action({0})'.format(parsed_args))
|
||||||
client = self.app.client_manager.artifact
|
client = self.app.client_manager.artifact
|
||||||
data = client.artifacts.activate(
|
af_id = get_artifact_id(client, parsed_args)
|
||||||
parsed_args.id, type_name=parsed_args.type_name)
|
data = client.artifacts.activate(af_id,
|
||||||
|
type_name=parsed_args.type_name)
|
||||||
return print_artifact(client, data, parsed_args.type_name)
|
return print_artifact(client, data, parsed_args.type_name)
|
||||||
|
|
||||||
|
|
||||||
@ -297,16 +358,28 @@ class DeactivateArtifact(command.Lister):
|
|||||||
help='Name of artifact type.',
|
help='Name of artifact type.',
|
||||||
),
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'id',
|
'name',
|
||||||
metavar='<ID>',
|
metavar='<NAME>',
|
||||||
help='ID of the artifact to update.',
|
help='Name or id of the artifact to deactivate.',
|
||||||
)
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--artifact-version', '-v',
|
||||||
|
metavar='<VERSION>',
|
||||||
|
default='latest',
|
||||||
|
help='Version of the artifact.',
|
||||||
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--id', '-i',
|
||||||
|
action='store_true',
|
||||||
|
help='The specified id of the artifact.',
|
||||||
|
),
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
LOG.debug('take_action({0})'.format(parsed_args))
|
LOG.debug('take_action({0})'.format(parsed_args))
|
||||||
client = self.app.client_manager.artifact
|
client = self.app.client_manager.artifact
|
||||||
data = client.artifacts.deactivate(parsed_args.id,
|
af_id = get_artifact_id(client, parsed_args)
|
||||||
|
data = client.artifacts.deactivate(af_id,
|
||||||
type_name=parsed_args.type_name)
|
type_name=parsed_args.type_name)
|
||||||
return print_artifact(client, data, parsed_args.type_name)
|
return print_artifact(client, data, parsed_args.type_name)
|
||||||
|
|
||||||
@ -323,16 +396,28 @@ class ReactivateArtifact(command.Lister):
|
|||||||
help='Name of artifact type.',
|
help='Name of artifact type.',
|
||||||
),
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'id',
|
'name',
|
||||||
metavar='<ID>',
|
metavar='<NAME>',
|
||||||
help='ID of the artifact to update.',
|
help='Name or id of the artifact to reactivate.',
|
||||||
)
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--artifact-version', '-v',
|
||||||
|
metavar='<VERSION>',
|
||||||
|
default='latest',
|
||||||
|
help='Version of the artifact.',
|
||||||
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--id', '-i',
|
||||||
|
action='store_true',
|
||||||
|
help='The specified id of the artifact.',
|
||||||
|
),
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
LOG.debug('take_action({0})'.format(parsed_args))
|
LOG.debug('take_action({0})'.format(parsed_args))
|
||||||
client = self.app.client_manager.artifact
|
client = self.app.client_manager.artifact
|
||||||
data = client.artifacts.reactivate(parsed_args.id,
|
af_id = get_artifact_id(client, parsed_args)
|
||||||
|
data = client.artifacts.reactivate(af_id,
|
||||||
type_name=parsed_args.type_name)
|
type_name=parsed_args.type_name)
|
||||||
return print_artifact(client, data, parsed_args.type_name)
|
return print_artifact(client, data, parsed_args.type_name)
|
||||||
|
|
||||||
@ -349,16 +434,28 @@ class PublishArtifact(command.Lister):
|
|||||||
help='Name of artifact type.',
|
help='Name of artifact type.',
|
||||||
),
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'id',
|
'name',
|
||||||
metavar='<ID>',
|
metavar='<NAME>',
|
||||||
help='ID of the artifact to update.',
|
help='Name or id of the artifact to publish.',
|
||||||
)
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--artifact-version', '-v',
|
||||||
|
metavar='<VERSION>',
|
||||||
|
default='latest',
|
||||||
|
help='Version of the artifact.',
|
||||||
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--id', '-i',
|
||||||
|
action='store_true',
|
||||||
|
help='The specified id of the artifact.',
|
||||||
|
),
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
LOG.debug('take_action({0})'.format(parsed_args))
|
LOG.debug('take_action({0})'.format(parsed_args))
|
||||||
client = self.app.client_manager.artifact
|
client = self.app.client_manager.artifact
|
||||||
data = client.artifacts.publish(parsed_args.id,
|
af_id = get_artifact_id(client, parsed_args)
|
||||||
|
data = client.artifacts.publish(af_id,
|
||||||
type_name=parsed_args.type_name)
|
type_name=parsed_args.type_name)
|
||||||
return print_artifact(client, data, parsed_args.type_name)
|
return print_artifact(client, data, parsed_args.type_name)
|
||||||
|
|
||||||
|
@ -36,6 +36,18 @@ def _default_blob_property(type_name):
|
|||||||
utils.exit('Unknown artifact type. Please specify --blob-property.')
|
utils.exit('Unknown artifact type. Please specify --blob-property.')
|
||||||
|
|
||||||
|
|
||||||
|
def get_artifact_id(client, parsed_args):
|
||||||
|
if parsed_args.id:
|
||||||
|
if parsed_args.artifact_version != 'latest':
|
||||||
|
LOG.warn('Specified version is not considered when '
|
||||||
|
'receiving of the artifact by ID.')
|
||||||
|
return parsed_args.name
|
||||||
|
|
||||||
|
return client.artifacts.get_by_name(parsed_args.name,
|
||||||
|
version=parsed_args.artifact_version,
|
||||||
|
type_name=parsed_args.type_name)['id']
|
||||||
|
|
||||||
|
|
||||||
class UploadBlob(command.ShowOne):
|
class UploadBlob(command.ShowOne):
|
||||||
"""Upload blob"""
|
"""Upload blob"""
|
||||||
|
|
||||||
@ -48,10 +60,21 @@ class UploadBlob(command.ShowOne):
|
|||||||
help='Name of artifact type.',
|
help='Name of artifact type.',
|
||||||
),
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'id',
|
'name',
|
||||||
metavar='<ID>',
|
metavar='<NAME>',
|
||||||
help='ID of the artifact to update.',
|
help='Name or id of the artifact to upload.',
|
||||||
)
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--artifact-version', '-v',
|
||||||
|
metavar='<VERSION>',
|
||||||
|
default='latest',
|
||||||
|
help='Version of the artifact.',
|
||||||
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--id', '-i',
|
||||||
|
action='store_true',
|
||||||
|
help='The specified id of the artifact.',
|
||||||
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--file',
|
'--file',
|
||||||
metavar='<FILE_PATH>',
|
metavar='<FILE_PATH>',
|
||||||
@ -78,6 +101,7 @@ class UploadBlob(command.ShowOne):
|
|||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
LOG.debug('take_action({0})'.format(parsed_args))
|
LOG.debug('take_action({0})'.format(parsed_args))
|
||||||
client = self.app.client_manager.artifact
|
client = self.app.client_manager.artifact
|
||||||
|
af_id = get_artifact_id(client, parsed_args)
|
||||||
|
|
||||||
if not parsed_args.blob_property:
|
if not parsed_args.blob_property:
|
||||||
parsed_args.blob_property = _default_blob_property(
|
parsed_args.blob_property = _default_blob_property(
|
||||||
@ -89,13 +113,11 @@ class UploadBlob(command.ShowOne):
|
|||||||
if file_size is not None:
|
if file_size is not None:
|
||||||
blob = progressbar.VerboseFileWrapper(blob, file_size)
|
blob = progressbar.VerboseFileWrapper(blob, file_size)
|
||||||
|
|
||||||
client.artifacts.upload_blob(parsed_args.id,
|
client.artifacts.upload_blob(af_id, parsed_args.blob_property, blob,
|
||||||
parsed_args.blob_property, blob,
|
|
||||||
content_type=parsed_args.content_type,
|
content_type=parsed_args.content_type,
|
||||||
type_name=parsed_args.type_name)
|
type_name=parsed_args.type_name)
|
||||||
|
|
||||||
data = client.artifacts.get(parsed_args.id,
|
data = client.artifacts.get(af_id, type_name=parsed_args.type_name)
|
||||||
type_name=parsed_args.type_name)
|
|
||||||
|
|
||||||
data_to_display = {'blob_property': parsed_args.blob_property}
|
data_to_display = {'blob_property': parsed_args.blob_property}
|
||||||
data_to_display.update(data[parsed_args.blob_property])
|
data_to_display.update(data[parsed_args.blob_property])
|
||||||
@ -114,10 +136,21 @@ class DownloadBlob(command.Command):
|
|||||||
help='Name of artifact type.',
|
help='Name of artifact type.',
|
||||||
),
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'id',
|
'name',
|
||||||
metavar='<ID>',
|
metavar='<NAME>',
|
||||||
help='ID of the artifact to update.',
|
help='Name or id of the artifact to download.',
|
||||||
)
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--artifact-version', '-v',
|
||||||
|
metavar='<VERSION>',
|
||||||
|
default='latest',
|
||||||
|
help='Version of the artifact.',
|
||||||
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--id', '-i',
|
||||||
|
action='store_true',
|
||||||
|
help='The specified id of the artifact.',
|
||||||
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--progress',
|
'--progress',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -144,7 +177,8 @@ class DownloadBlob(command.Command):
|
|||||||
if not parsed_args.blob_property:
|
if not parsed_args.blob_property:
|
||||||
parsed_args.blob_property = _default_blob_property(
|
parsed_args.blob_property = _default_blob_property(
|
||||||
parsed_args.type_name)
|
parsed_args.type_name)
|
||||||
data = client.artifacts.download_blob(parsed_args.id,
|
af_id = get_artifact_id(client, parsed_args)
|
||||||
|
data = client.artifacts.download_blob(af_id,
|
||||||
parsed_args.blob_property,
|
parsed_args.blob_property,
|
||||||
type_name=parsed_args.type_name)
|
type_name=parsed_args.type_name)
|
||||||
if parsed_args.progress:
|
if parsed_args.progress:
|
||||||
@ -170,10 +204,21 @@ class AddLocation(command.ShowOne):
|
|||||||
help='Name of artifact type.',
|
help='Name of artifact type.',
|
||||||
),
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'id',
|
'name',
|
||||||
metavar='<ID>',
|
metavar='<NAME>',
|
||||||
help='ID of the artifact to update.',
|
help='Name or id of the artifact to download.',
|
||||||
)
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--artifact-version', '-v',
|
||||||
|
metavar='<VERSION>',
|
||||||
|
default='latest',
|
||||||
|
help='Version of the artifact.',
|
||||||
|
),
|
||||||
|
parser.add_argument(
|
||||||
|
'--id', '-i',
|
||||||
|
action='store_true',
|
||||||
|
help='The specified id of the artifact.',
|
||||||
|
),
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--url',
|
'--url',
|
||||||
metavar='<FILE_PATH>',
|
metavar='<FILE_PATH>',
|
||||||
@ -210,6 +255,7 @@ class AddLocation(command.ShowOne):
|
|||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
LOG.debug('take_action({0})'.format(parsed_args))
|
LOG.debug('take_action({0})'.format(parsed_args))
|
||||||
client = self.app.client_manager.artifact
|
client = self.app.client_manager.artifact
|
||||||
|
af_id = get_artifact_id(client, parsed_args)
|
||||||
|
|
||||||
if not parsed_args.blob_property:
|
if not parsed_args.blob_property:
|
||||||
parsed_args.blob_property = _default_blob_property(
|
parsed_args.blob_property = _default_blob_property(
|
||||||
@ -223,13 +269,13 @@ class AddLocation(command.ShowOne):
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.artifacts.add_external_location(
|
client.artifacts.add_external_location(
|
||||||
parsed_args.id,
|
af_id,
|
||||||
parsed_args.blob_property,
|
parsed_args.blob_property,
|
||||||
data,
|
data,
|
||||||
content_type=parsed_args.content_type,
|
content_type=parsed_args.content_type,
|
||||||
type_name=parsed_args.type_name)
|
type_name=parsed_args.type_name)
|
||||||
|
|
||||||
data = client.artifacts.get(parsed_args.id,
|
data = client.artifacts.get(af_id,
|
||||||
type_name=parsed_args.type_name)
|
type_name=parsed_args.type_name)
|
||||||
|
|
||||||
data_to_display = {'blob_property': parsed_args.blob_property}
|
data_to_display = {'blob_property': parsed_args.blob_property}
|
||||||
|
@ -88,6 +88,7 @@ class TestArtifacts(utils.TestCommand):
|
|||||||
self.app.client_manager.artifact = mock.MagicMock()
|
self.app.client_manager.artifact = mock.MagicMock()
|
||||||
self.app.client_manager.artifact.artifacts.list = mock_list
|
self.app.client_manager.artifact.artifacts.list = mock_list
|
||||||
self.app.client_manager.artifact.artifacts.get = mock_get
|
self.app.client_manager.artifact.artifacts.get = mock_get
|
||||||
|
self.app.client_manager.artifact.artifacts.get_by_name = mock_get
|
||||||
self.app.client_manager.artifact.artifacts.create = mock_g_servs
|
self.app.client_manager.artifact.artifacts.create = mock_g_servs
|
||||||
self.app.client_manager.artifact.artifacts.update = mock_g_servs
|
self.app.client_manager.artifact.artifacts.update = mock_g_servs
|
||||||
self.app.client_manager.artifact.artifacts.delete = mock_g_servs
|
self.app.client_manager.artifact.artifacts.delete = mock_g_servs
|
||||||
|
@ -153,6 +153,20 @@ class TestShowArtifacts(TestArtifacts):
|
|||||||
with testtools.ExpectedException(ParserException):
|
with testtools.ExpectedException(ParserException):
|
||||||
self.check_parser(self.cmd, arglist, verify)
|
self.check_parser(self.cmd, arglist, verify)
|
||||||
|
|
||||||
|
def test_artifact_show_by_name(self):
|
||||||
|
arglist = ['images', 'name1']
|
||||||
|
verify = [('type_name', 'images'), ('id', False)]
|
||||||
|
COLUMNS = set(['blob', 'environment', 'id', 'image',
|
||||||
|
'name', 'owner', 'package', 'status',
|
||||||
|
'template', 'version', 'visibility'])
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verify)
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
name_fields = set([column[0] for column in data])
|
||||||
|
# Check that columns are correct
|
||||||
|
self.assertEqual(COLUMNS, name_fields)
|
||||||
|
|
||||||
|
|
||||||
class TestCreateArtifacts(TestArtifacts):
|
class TestCreateArtifacts(TestArtifacts):
|
||||||
|
|
||||||
@ -258,9 +272,10 @@ class TestDeleteArtifacts(TestArtifacts):
|
|||||||
|
|
||||||
def test_artifact_delete(self):
|
def test_artifact_delete(self):
|
||||||
arglist = ['images',
|
arglist = ['images',
|
||||||
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba']
|
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba', '--id']
|
||||||
verify = [('type_name', 'images'),
|
verify = [('type_name', 'images'),
|
||||||
('id', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba')]
|
('name', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba'),
|
||||||
|
('id', True)]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verify)
|
parsed_args = self.check_parser(self.cmd, arglist, verify)
|
||||||
self.assertIsNone(self.cmd.take_action(parsed_args))
|
self.assertIsNone(self.cmd.take_action(parsed_args))
|
||||||
|
|
||||||
@ -277,9 +292,11 @@ class TestActivateArtifacts(TestArtifacts):
|
|||||||
|
|
||||||
def test_artifact_activate(self):
|
def test_artifact_activate(self):
|
||||||
arglist = ['images',
|
arglist = ['images',
|
||||||
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba']
|
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba',
|
||||||
|
'--id']
|
||||||
verify = [('type_name', 'images'),
|
verify = [('type_name', 'images'),
|
||||||
('id', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba')]
|
('name', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba'),
|
||||||
|
('id', True)]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verify)
|
parsed_args = self.check_parser(self.cmd, arglist, verify)
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
@ -300,9 +317,10 @@ class TestDeactivateArtifacts(TestArtifacts):
|
|||||||
|
|
||||||
def test_artifact_deactivate(self):
|
def test_artifact_deactivate(self):
|
||||||
arglist = ['images',
|
arglist = ['images',
|
||||||
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba']
|
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba', '--id']
|
||||||
verify = [('type_name', 'images'),
|
verify = [('type_name', 'images'),
|
||||||
('id', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba')]
|
('name', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba'),
|
||||||
|
('id', True)]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verify)
|
parsed_args = self.check_parser(self.cmd, arglist, verify)
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
@ -323,9 +341,10 @@ class TestReactivateArtifacts(TestArtifacts):
|
|||||||
|
|
||||||
def test_artifact_rectivate(self):
|
def test_artifact_rectivate(self):
|
||||||
arglist = ['images',
|
arglist = ['images',
|
||||||
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba']
|
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba', '--id']
|
||||||
verify = [('type_name', 'images'),
|
verify = [('type_name', 'images'),
|
||||||
('id', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba')]
|
('name', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba'),
|
||||||
|
('id', True)]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verify)
|
parsed_args = self.check_parser(self.cmd, arglist, verify)
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
@ -346,9 +365,10 @@ class TestPublishArtifacts(TestArtifacts):
|
|||||||
|
|
||||||
def test_publish_delete(self):
|
def test_publish_delete(self):
|
||||||
arglist = ['images',
|
arglist = ['images',
|
||||||
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba']
|
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba', '--id']
|
||||||
verify = [('type_name', 'images'),
|
verify = [('type_name', 'images'),
|
||||||
('id', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba')]
|
('name', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba'),
|
||||||
|
('id', True)]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verify)
|
parsed_args = self.check_parser(self.cmd, arglist, verify)
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ class TestAddLocation(TestBlobs):
|
|||||||
|
|
||||||
def test_add_location(self):
|
def test_add_location(self):
|
||||||
arglist = ['images',
|
arglist = ['images',
|
||||||
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba',
|
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba', '--id',
|
||||||
'--url', 'fake_url',
|
'--url', 'fake_url',
|
||||||
'--md5', "35d83e8eedfbdb87ff97d1f2761f8ebf",
|
'--md5', "35d83e8eedfbdb87ff97d1f2761f8ebf",
|
||||||
'--sha1', "942854360eeec1335537702399c5aed940401602",
|
'--sha1', "942854360eeec1335537702399c5aed940401602",
|
||||||
|
@ -214,5 +214,33 @@ data_fixtures = {
|
|||||||
'properties': {'foo': 'bar'}
|
'properties': {'foo': 'bar'}
|
||||||
}}}
|
}}}
|
||||||
)
|
)
|
||||||
|
},
|
||||||
|
'/artifacts/images?name=name1&version=latest': {
|
||||||
|
'GET': (
|
||||||
|
# headers
|
||||||
|
{},
|
||||||
|
# response
|
||||||
|
{'images': [
|
||||||
|
{
|
||||||
|
'name': 'name1',
|
||||||
|
'id': '3a4560a1-e585-443e-9b39-553b46ec92d1',
|
||||||
|
'version': '3.0.0'
|
||||||
}
|
}
|
||||||
|
]},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
'/artifacts/images?name=name1&version=1.0.0': {
|
||||||
|
'GET': (
|
||||||
|
# headers
|
||||||
|
{},
|
||||||
|
# response
|
||||||
|
{'images': [
|
||||||
|
{
|
||||||
|
'name': 'name1',
|
||||||
|
'id': '3a4560a1-e585-443e-9b39-553b46ec92d1',
|
||||||
|
'version': '1.0.0'
|
||||||
|
}
|
||||||
|
]},
|
||||||
|
),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
@ -368,6 +368,21 @@ class TestController(testtools.TestCase):
|
|||||||
self.assertEqual(art_id, art['images'][0]['id'])
|
self.assertEqual(art_id, art['images'][0]['id'])
|
||||||
self.assertEqual('art_1', art['images'][0]['name'])
|
self.assertEqual('art_1', art['images'][0]['name'])
|
||||||
|
|
||||||
|
def test_get_by_name(self):
|
||||||
|
art_name = 'name1'
|
||||||
|
art = self.controller.get_by_name(name=art_name,
|
||||||
|
type_name='images')
|
||||||
|
self.assertEqual(art_name, art['name'])
|
||||||
|
self.assertEqual('3.0.0', art['version'])
|
||||||
|
|
||||||
|
def test_get_by_name_with_version(self):
|
||||||
|
art_name = 'name1'
|
||||||
|
art = self.controller.get_by_name(name=art_name,
|
||||||
|
version='1.0.0',
|
||||||
|
type_name='images')
|
||||||
|
self.assertEqual(art_name, art['name'])
|
||||||
|
self.assertEqual('1.0.0', art['version'])
|
||||||
|
|
||||||
def test_type_list(self):
|
def test_type_list(self):
|
||||||
data = self.controller.get_type_list()
|
data = self.controller.get_type_list()
|
||||||
expect_data = [('images', '1.0'), ('heat_environments', '1.0')]
|
expect_data = [('images', '1.0'), ('heat_environments', '1.0')]
|
||||||
|
@ -104,6 +104,19 @@ class Controller(object):
|
|||||||
resp, body = self.http_client.get(url)
|
resp, body = self.http_client.get(url)
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
def get_by_name(self, name, version='latest', type_name=None):
|
||||||
|
"""Get information about an artifact by name.
|
||||||
|
|
||||||
|
:param name: name of the artifact to get.
|
||||||
|
"""
|
||||||
|
type_name = self._check_type_name(type_name)
|
||||||
|
url = '/artifacts/%s?version=%s&name=%s' % (type_name, version, name)
|
||||||
|
resp, body = self.http_client.get(url)
|
||||||
|
if not body[type_name]:
|
||||||
|
utils.exit('Artifact with name=%s and version=%s not found.' %
|
||||||
|
(name, version))
|
||||||
|
return body[type_name][0]
|
||||||
|
|
||||||
def list(self, type_name=None, **kwargs):
|
def list(self, type_name=None, **kwargs):
|
||||||
"""Retrieve a listing of artifacts objects.
|
"""Retrieve a listing of artifacts objects.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user