Added ValidateDesign to API Client

- Added ValidateDesign to API client.
- Added ValidteDesign to CI client.
- Added a couple unit tests.

Change-Id: I1def14b3703eba12b10a063bf09a3120dcf54b8d
This commit is contained in:
Aaron Sheffield 2018-05-14 10:54:26 -05:00
parent 8274d56c71
commit 506e06623a
4 changed files with 88 additions and 0 deletions

View File

@ -61,3 +61,17 @@ class DesignShow(CliAction): # pylint: disable=too-few-public-methods
def invoke(self):
return self.api_client.get_design(
design_id=self.design_id, source=self.source)
class DesignValidate(CliAction): # pylint: disable=too-few-public-methods
"""Action to validate a design.
:param string design_href: A href key to the design_ref.
"""
def __init__(self, api_client, design_href):
super().__init__(api_client)
self.design_href = design_href
self.logger.debug("DesignValidate action initialized")
def invoke(self):
return self.api_client.validate_design(href=self.design_href)

View File

@ -21,6 +21,7 @@ import json
from drydock_provisioner.cli.design.actions import DesignList
from drydock_provisioner.cli.design.actions import DesignShow
from drydock_provisioner.cli.design.actions import DesignCreate
from drydock_provisioner.cli.design.actions import DesignValidate
@click.group()
@ -57,3 +58,14 @@ def design_show(ctx, design_id):
ctx.fail('The design id must be specified by --design-id')
click.echo(json.dumps(DesignShow(ctx.obj['CLIENT'], design_id).invoke()))
@design.command(name='validate')
@click.option(
'--design-href',
'-h',
help='The design href key to the design ref')
@click.pass_context
def design_validate(ctx, design_href=None):
"""Validate a design."""
click.echo(
json.dumps(DesignValidate(ctx.obj['CLIENT'], design_href).invoke()))

View File

@ -131,6 +131,22 @@ class DrydockClient(object):
return resp.json()
def validate_design(self, href):
"""Get list of nodes in MaaS and their status.
:param href: A href that points to the design_ref.
:return: A dict containing the validation.
"""
endpoint = 'v1.0/validatedesign'
body = {
'href': href
}
resp = self.session.post(endpoint, data=body)
self._check_response(resp)
return resp.json()
def _check_response(self, resp):
if resp.status_code == 401:
raise errors.ClientUnauthorizedError(

View File

@ -124,3 +124,49 @@ def test_client_task_get():
task_resp = dd_client.get_task('1476902c-758b-49c0-b618-79ff3fd15166')
assert task_resp['status'] == task['status']
@responses.activate
def test_client_get_nodes_for_filter_post():
node_list = ['node1', 'node2']
host = 'foo.bar.baz'
responses.add(
responses.POST,
"http://%s/api/v1.0/nodefilter" %
(host),
json=node_list,
status=200)
dd_ses = dc_session.DrydockSession(host)
dd_client = dc_client.DrydockClient(dd_ses)
design_ref = {
'ref': 'hello'
}
validation_resp = dd_client.get_nodes_for_filter(design_ref)
assert 'node1' in validation_resp
assert 'node2' in validation_resp
@responses.activate
def test_client_validate_design_post():
validation = {
'status': 'success'
}
host = 'foo.bar.baz'
responses.add(
responses.POST,
"http://%s/api/v1.0/validatedesign" %
(host),
json=validation,
status=200)
dd_ses = dc_session.DrydockSession(host)
dd_client = dc_client.DrydockClient(dd_ses)
validation_resp = dd_client.validate_design('href-placeholder')
assert validation_resp['status'] == validation['status']