Skip to content

Commit 7d9f574

Browse files
committed
change test case and user response
1 parent 4650e01 commit 7d9f574

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

SoftLayer/CLI/image/import.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import SoftLayer
55
from SoftLayer.CLI import environment
66
from SoftLayer.CLI import exceptions
7+
from SoftLayer.CLI import formatting
78

89

910
import click
@@ -23,6 +24,7 @@ def cli(env, name, note, osrefcode, uri):
2324

2425
image_mgr = SoftLayer.ImageManager(env.client)
2526
data = {}
27+
output = []
2628
if name:
2729
data['name'] = name
2830
if note:
@@ -36,8 +38,17 @@ def cli(env, name, note, osrefcode, uri):
3638
# if uri.endswith(".vhd") and osrefcode == "":
3739
# raise exceptions.CLIAbort("Please specify osrefcode for .vhdImage")
3840

39-
newimage = image_mgr.import_image_from_uri(data)
40-
if not newimage:
41+
result = image_mgr.import_image_from_uri(data)
42+
43+
if not result:
4144
raise exceptions.CLIAbort("Failed to import Image")
4245

43-
return 'Image %s was imported succesfully!' % newimage
46+
table = formatting.KeyValueTable(['name', 'value'])
47+
table.align['name'] = 'r'
48+
table.align['value'] = 'l'
49+
table.add_row(['name', result['name']])
50+
table.add_row(['id', result['id']])
51+
table.add_row(['created', result['createDate']])
52+
table.add_row(['guid', result['globalIdentifier']])
53+
output.append(table)
54+
return output

SoftLayer/managers/image.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_image(self, image_id, **kwargs):
3838
def delete_image(self, image_id):
3939
"""Deletes the specified image.
4040
41-
:param int image: The ID of the image.
41+
:param int image_id: The ID of the image.
4242
"""
4343
self.vgbdtg.deleteObject(id=image_id)
4444

@@ -100,7 +100,7 @@ def _get_ids_from_name_private(self, name):
100100
def edit(self, image_id, name=None, note=None, tag=None):
101101
"""Edit image related details.
102102
103-
:param int image: The ID of the image
103+
:param int image_id: The ID of the image
104104
:param string name: Name of the Image.
105105
:param string note: Note of the image.
106106
:param string tag: Tags of the image to be updated to.
@@ -122,4 +122,4 @@ def edit(self, image_id, name=None, note=None, tag=None):
122122
def import_image_from_uri(self, data):
123123
"""Import images which match the given uri."""
124124
result = self.vgbdtg.createFromExternalSource(data)
125-
return result['name']
125+
return result

SoftLayer/testing/fixtures/SoftLayer_Virtual_Guest_Block_Device_Template_Group.py

+6
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@
2121
deleteObject = {}
2222
editObject = True
2323
setTags = True
24+
createFromExternalSource = [{
25+
'createDate': '2013-12-05T21:53:03-06:00',
26+
'globalIdentifier': '0B5DEAF4-643D-46CA-A695-CECBE8832C9D',
27+
'id': 100,
28+
'name': 'test_image',
29+
}]

SoftLayer/tests/managers/image_tests.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,13 @@ def test_edit_full(self):
131131
identifier=1,
132132
args=({'name': 'abc', 'note': 'xyz'},))
133133

134-
def test_import_invalid_image(self):
134+
def test_import_image(self):
135135
# Test updating tags
136-
self.image.import_image_from_uri(1, {'name':'test', 'note':'testimage', 'uri':'invaliduri'})
136+
self.image.import_image_from_uri({'name': 'test_image',
137+
'note': 'testimage',
138+
'uri': 'invaliduri'})
137139

138140
self.assert_called_with(IMAGE_SERVICE, 'createFromExternalSource',
139-
identifier=1,
140-
args=({'name':'test', 'note':'testimage', 'uri':'invaliduri'},))
141+
args=({'name': 'test_image',
142+
'note': 'testimage',
143+
'uri': 'invaliduri'},))

0 commit comments

Comments
 (0)