Skip to content

Commit b63df47

Browse files
committed
add catalog list to cli
Signed-off-by: Chris Snow <[email protected]>
1 parent c040105 commit b63df47

File tree

2 files changed

+113
-57
lines changed

2 files changed

+113
-57
lines changed

bin/cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ def get_client():
9696
sys.exit(1)
9797

9898

99+
class CatalogProxy(object):
100+
def list(self):
101+
"""Retrieve the list of Catalog Images
102+
"""
103+
print(get_client().catalog.list())
104+
105+
99106
class GatewayProxy(object):
100107
def create_with_ssh_key(
101108
self,
@@ -1093,6 +1100,7 @@ def configure_cli():
10931100

10941101
class CLI(object):
10951102
def __init__(self,):
1103+
self.catalog = CatalogProxy()
10961104
self.k8sworker = K8sWorkerProxy()
10971105
self.k8scluster = K8sClusterProxy()
10981106
self.gateway = GatewayProxy()

tests/library/catalog_test.py

Lines changed: 105 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@
1818
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1919
# OTHER DEALINGS IN THE SOFTWARE.
2020

21+
22+
import os
23+
import sys
2124
import unittest
25+
from textwrap import dedent
2226

2327
import requests
2428
from mock import patch
2529

2630
from hpecp import ContainerPlatformClient
2731
from hpecp.catalog import CatalogList
2832
from hpecp.exceptions import APIItemNotFoundException
33+
import tempfile
2934

3035

3136
class MockResponse:
@@ -142,67 +147,68 @@ def test_get_catalog(self, mock_get, mock_post):
142147
get_client().catalog.get("/api/v1/catalog/100")
143148

144149

150+
catalog_list_json = {
151+
"_links": {
152+
"self": {"href": "/api/v1/catalog/"},
153+
"feedlog": {"href": "/api/v1/catalog/feedlog"},
154+
"feed": [
155+
{
156+
"href": "http://127.0.0.1:8080/api/v1/feed/local",
157+
"name": "Feed generated from local bundles.",
158+
},
159+
{
160+
"href": "https://s3.amazonaws.com/bluedata-catalog/bundles/catalog/external/docker/EPIC-5.0/feeds/feed.json",
161+
"name": "BlueData EPIC-5.0 catalog feed for docker",
162+
},
163+
],
164+
},
165+
"catalog_api_version": 6,
166+
"feeds_refresh_period_seconds": 86400,
167+
"feeds_read_counter": 5,
168+
"catalog_write_counter": 5,
169+
"_embedded": {
170+
"independent_catalog_entries": [
171+
{
172+
"_links": {
173+
"self": {"href": "/api/v1/catalog/29"},
174+
"feed": [
175+
{
176+
"href": "https://s3.amazonaws.com/bluedata-catalog/bundles/catalog/external/docker/EPIC-5.0/feeds/feed.json",
177+
"name": "BlueData EPIC-5.0 catalog feed for docker",
178+
}
179+
],
180+
},
181+
"distro_id": "bluedata/spark240juphub7xssl",
182+
"label": {
183+
"name": "Spark240",
184+
"description": "Spark240 multirole with Jupyter Notebook, Jupyterhub with SSL and gateway node",
185+
},
186+
"version": "2.8",
187+
"timestamp": 0,
188+
"isdebug": False,
189+
"osclass": ["centos"],
190+
"logo": {
191+
"checksum": "1471eb59356066ed4a06130566764ea6",
192+
"url": "http://10.1.0.53/catalog/logos/bluedata-spark240juphub7xssl-2.8",
193+
},
194+
"documentation": {
195+
"checksum": "52f53f1b2845463b9e370d17fb80bea6",
196+
"mimetype": "text/markdown",
197+
"file": "/opt/bluedata/catalog/documentation/bluedata-spark240juphub7xssl-2.8",
198+
},
199+
"state": "initialized",
200+
"state_info": "",
201+
}
202+
]
203+
},
204+
}
205+
206+
145207
class TestCatalogList(unittest.TestCase):
146208
def mocked_requests_get(*args, **kwargs):
147209
if args[0] == "https://127.0.0.1:8080/api/v1/catalog/":
148210
return MockResponse(
149-
json_data={
150-
"_links": {
151-
"self": {"href": "/api/v1/catalog/"},
152-
"feedlog": {"href": "/api/v1/catalog/feedlog"},
153-
"feed": [
154-
{
155-
"href": "http://127.0.0.1:8080/api/v1/feed/local",
156-
"name": "Feed generated from local bundles.",
157-
},
158-
{
159-
"href": "https://s3.amazonaws.com/bluedata-catalog/bundles/catalog/external/docker/EPIC-5.0/feeds/feed.json",
160-
"name": "BlueData EPIC-5.0 catalog feed for docker",
161-
},
162-
],
163-
},
164-
"catalog_api_version": 6,
165-
"feeds_refresh_period_seconds": 86400,
166-
"feeds_read_counter": 5,
167-
"catalog_write_counter": 5,
168-
"_embedded": {
169-
"independent_catalog_entries": [
170-
{
171-
"_links": {
172-
"self": {"href": "/api/v1/catalog/29"},
173-
"feed": [
174-
{
175-
"href": "https://s3.amazonaws.com/bluedata-catalog/bundles/catalog/external/docker/EPIC-5.0/feeds/feed.json",
176-
"name": "BlueData EPIC-5.0 catalog feed for docker",
177-
}
178-
],
179-
},
180-
"distro_id": "bluedata/spark240juphub7xssl",
181-
"label": {
182-
"name": "Spark240",
183-
"description": "Spark240 multirole with Jupyter Notebook, Jupyterhub with SSL and gateway node",
184-
},
185-
"version": "2.8",
186-
"timestamp": 0,
187-
"isdebug": False,
188-
"osclass": ["centos"],
189-
"logo": {
190-
"checksum": "1471eb59356066ed4a06130566764ea6",
191-
"url": "http://10.1.0.53/catalog/logos/bluedata-spark240juphub7xssl-2.8",
192-
},
193-
"documentation": {
194-
"checksum": "52f53f1b2845463b9e370d17fb80bea6",
195-
"mimetype": "text/markdown",
196-
"file": "/opt/bluedata/catalog/documentation/bluedata-spark240juphub7xssl-2.8",
197-
},
198-
"state": "initialized",
199-
"state_info": "",
200-
}
201-
]
202-
},
203-
},
204-
status_code=200,
205-
headers=dict(),
211+
json_data=catalog_list_json, status_code=200, headers=dict(),
206212
)
207213
raise RuntimeError("Unhandle GET request: " + args[0])
208214

@@ -212,3 +218,45 @@ def test_list(self, mock_get, mock_post):
212218

213219
catalogList = get_client().catalog.list()
214220
self.assertIsInstance(catalogList, CatalogList)
221+
222+
223+
class TestCLI(unittest.TestCase):
224+
def mocked_requests_get(*args, **kwargs):
225+
if args[0] == "https://127.0.0.1:8080/api/v1/catalog/":
226+
return MockResponse(
227+
json_data=catalog_list_json, status_code=200, headers=dict(),
228+
)
229+
raise RuntimeError("Unhandle GET request: " + args[0])
230+
231+
@patch("requests.post", side_effect=mocked_requests_post)
232+
@patch("requests.get", side_effect=mocked_requests_get)
233+
def test_cli(self, mock_post, mock_get):
234+
235+
sys.path.insert(0, os.path.abspath("../../"))
236+
from bin import cli
237+
238+
file_data = dedent(
239+
"""[default]
240+
api_host = 127.0.0.1
241+
api_port = 8080
242+
use_ssl = True
243+
verify_ssl = False
244+
warn_ssl = True
245+
username = admin
246+
password = admin123"""
247+
)
248+
249+
tmp = tempfile.NamedTemporaryFile(delete=True)
250+
try:
251+
tmp.write(file_data.encode("utf-8"))
252+
tmp.flush()
253+
254+
cli.HPECP_CONFIG_FILE = tmp.name
255+
256+
hpecp = cli.CLI()
257+
hpecp.catalog.list()
258+
259+
self.assertTrue(True)
260+
261+
finally:
262+
tmp.close()

0 commit comments

Comments
 (0)