Add Metadata field for image-search support

Change-Id: If45db6f785e4187165e2497e5efad351fe1c2da7
Related-Bug: #1658365
This commit is contained in:
cooldharma06 2017-11-21 17:30:34 +05:30
parent 55e316b19e
commit 1d1bf66868
2 changed files with 15 additions and 4 deletions

View File

@ -95,5 +95,12 @@ class DockerDriver(driver.ContainerImageDriver):
if exact_match:
images = [i for i in images if i['name'] == repo]
for image in images:
image['metadata'] = {}
for key in ('is_official', 'star_count'):
value = image.pop(key, None)
if value is not None:
image['metadata'][key] = value
# TODO(hongbin): convert images to a list of Zun Image object
return images

View File

@ -153,7 +153,8 @@ class TestDriver(base.BaseTestCase):
self.assertEqual(1, mock_init.call_count)
def test_search_image_success(self):
search_ret_val = [{'name': 'test_image', 'stars': 3}]
search_ret_val = [{'name': 'test_image', 'star_count': 3,
'is_official': True}]
with mock.patch.object(self.mock_docker, 'search',
return_value=search_ret_val) as mock_search:
ret = self.driver.search_image(None, 'image', 'test', False)
@ -163,7 +164,8 @@ class TestDriver(base.BaseTestCase):
self.assertEqual(1, mock_search.call_count)
def test_search_image_not_found_success(self):
search_ret_val = [{'name': 'test_image', 'stars': 3}]
search_ret_val = [{'name': 'test_image', 'star_count': 3,
'is_official': True}]
with mock.patch.object(self.mock_docker, 'search',
return_value=search_ret_val) as mock_search:
ret = self.driver.search_image(None, 'image1', 'test', False)
@ -173,7 +175,8 @@ class TestDriver(base.BaseTestCase):
self.assertEqual(1, mock_search.call_count)
def test_search_image_exact_match_success(self):
search_ret_val = [{'name': 'test_image', 'stars': 3}]
search_ret_val = [{'name': 'test_image', 'star_count': 3,
'is_official': True}]
with mock.patch.object(self.mock_docker, 'search',
return_value=search_ret_val) as mock_search:
ret = self.driver.search_image(None, 'test_image', 'test', True)
@ -183,7 +186,8 @@ class TestDriver(base.BaseTestCase):
self.assertEqual(1, mock_search.call_count)
def test_search_image_not_found_exact_match_success(self):
search_ret_val = [{'name': 'test_image', 'stars': 3}]
search_ret_val = [{'name': 'test_image', 'star_count': 3,
'is_official': True}]
with mock.patch.object(self.mock_docker, 'search',
return_value=search_ret_val) as mock_search:
ret = self.driver.search_image(None, 'image', 'test', True)