Skip to content

Commit

Permalink
Merge pull request #46 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored Aug 1, 2019
2 parents 430431d + b92fa62 commit 8c35afc
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 8 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# IM - Infrastructure Manager client

[![Build Status](http://jenkins.i3m.upv.es/buildStatus/icon?job=grycap/im-client-unit)](http://jenkins.i3m.upv.es:8080/job/grycap/job/im-client-unit/) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/c74628a2fc134c2683d3fc57b571ce09)](https://www.codacy.com/app/micafer/im-client?utm_source=github.com&utm_medium=referral&utm_content=grycap/im-client&utm_campaign=Badge_Grade) [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/c74628a2fc134c2683d3fc57b571ce09)](https://www.codacy.com/app/micafer/im-client?utm_source=github.com&utm_medium=referral&utm_content=grycap/im-client&utm_campaign=Badge_Coverage) [![License](https://img.shields.io/badge/license-GPL%20v3.0-brightgreen.svg)](LICENSE) [![Docs](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://imdocs.readthedocs.io/en/latest/client.html)
[![PyPI](https://img.shields.io/pypi/v/im-client.svg)](https://pypi.org/project/im-client)
[![Build Status](http://jenkins.i3m.upv.es/buildStatus/icon?job=grycap/im-client-unit)](http://jenkins.i3m.upv.es:8080/job/grycap/job/im-client-unit/)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/c74628a2fc134c2683d3fc57b571ce09)](https://www.codacy.com/app/micafer/im-client?utm_source=github.com&utm_medium=referral&utm_content=grycap/im-client&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/c74628a2fc134c2683d3fc57b571ce09)](https://www.codacy.com/app/micafer/im-client?utm_source=github.com&utm_medium=referral&utm_content=grycap/im-client&utm_campaign=Badge_Coverage)
[![License](https://img.shields.io/badge/license-GPL%20v3.0-brightgreen.svg)](LICENSE)
[![Docs](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://imdocs.readthedocs.io/en/latest/client.html)


IM is a tool that ease the access and the usability of IaaS clouds by automating
Expand Down
21 changes: 16 additions & 5 deletions im_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,19 @@ def main(operation, options, args, parser):
print("RADL file to add resources not specified")
return False

radl = radl_parse.parse_radl(args[1])
_, file_extension = os.path.splitext(args[1])
if file_extension in [".yaml", ".yml"]:
f = open(args[1])
radl = "".join(f.readlines())
f.close()
else:
radl = radl_parse.parse_radl(args[1])
radl.check()

if options.restapi:
headers = {"Authorization": rest_auth_data, "Accept": "application/json"}
if file_extension in [".yaml", ".yml"]:
headers["Content-Type"] = "text/yaml"
url = "%s/infrastructures/%s" % (options.restapi, inf_id)
resp = requests.request("POST", url, verify=options.verify, headers=headers, data=str(radl))
success = resp.status_code == 200
Expand Down Expand Up @@ -905,6 +914,7 @@ def main(operation, options, args, parser):
print("Error getting infrastructure outputs: %s" % res)
return success


def get_parser():
"""
Get Client parser
Expand Down Expand Up @@ -933,16 +943,16 @@ def get_parser():
under certain conditions; please read the license at \n\
http://www.gnu.org/licenses/gpl-3.0.txt for details."

parser = PosOptionParser(usage="%prog [-u|--xmlrpc-url <url>] [-r|--restapi-url <url>] [-v|--verify-ssl] [-a|--auth_file <filename>] "
"operation op_parameters" + NOTICE, version="%prog 1.5.5")
parser = PosOptionParser(usage="%prog [-u|--xmlrpc-url <url>] [-r|--restapi-url <url>] [-v|--verify-ssl] "
"[-a|--auth_file <filename>] operation op_parameters" + NOTICE, version="%prog 1.5.6")
parser.add_option("-a", "--auth_file", dest="auth_file", nargs=1, default=default_auth_file, help="Authentication"
" data file", type="string")
parser.add_option("-u", "--xmlrpc-url", dest="xmlrpc", nargs=1, default=default_xmlrpc, help="URL address of the "
"InfrastructureManager XML-RCP daemon", type="string")
parser.add_option("-r", "--rest-url", dest="restapi", nargs=1, default=default_restapi, help="URL address of the "
"InfrastructureManager REST API", type="string")
parser.add_option("-v", "--verify-ssl", action="store_true", default=False, dest="verify", help="Verify the certificate of the "
"InfrastructureManager XML-RCP server")
parser.add_option("-v", "--verify-ssl", action="store_true", default=False, dest="verify",
help="Verify the certificate of the InfrastructureManager XML-RCP server")
parser.add_operation_help('list', '')
parser.add_operation_help('create', '<radl_file> [async_flag]')
parser.add_operation_help('destroy', '<inf_id>')
Expand All @@ -969,6 +979,7 @@ def get_parser():

return parser


if __name__ == "__main__":

parser = get_parser()
Expand Down
24 changes: 24 additions & 0 deletions test/files/tosca.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
tosca_definitions_version: tosca_simple_yaml_1_0

description: TOSCA test for the IM client

topology_template:

node_templates:

server:
type: tosca.nodes.Compute
capabilities:
# Host container properties
host:
properties:
num_cpus: 1
mem_size: 1 GB
# Guest Operating System properties
os:
properties:
# host Operating System image properties
type: linux
distribution: scientific
version: 6.6

27 changes: 25 additions & 2 deletions test/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,17 @@ def test_create(self, server_proxy, requests):
self.assertIn("Infrastructure successfully created with ID: inf1", output)
sys.stdout = oldstdout

out = StringIO()
sys.stdout = out
options.xmlrpc = None
options.restapi = "https://localhost:8800"
requests.side_effect = self.get_response
res = main("create", options, [get_abs_path("../files/tosca.yml")], parser)
self.assertEquals(res, True)
output = out.getvalue().strip()
self.assertIn("Infrastructure successfully created with ID: inf1", output)
sys.stdout = oldstdout

@patch('requests.request')
@patch("im_client.ServerProxy")
def test_removeresource(self, server_proxy, requests):
Expand Down Expand Up @@ -282,6 +293,17 @@ def test_addresource(self, server_proxy, requests):
self.assertIn("Resources with IDs: 1 successfully added.", output)
sys.stdout = oldstdout

out = StringIO()
sys.stdout = out
options.xmlrpc = None
options.restapi = "https://localhost:8800"
requests.side_effect = self.get_response
res = main("addresource", options, ["infid", get_abs_path("../files/tosca.yml")], parser)
self.assertEquals(res, True)
output = out.getvalue().strip()
self.assertIn("Resources with IDs: 1 successfully added.", output)
sys.stdout = oldstdout

@patch('requests.request')
@patch("im_client.ServerProxy")
def test_alter(self, server_proxy, requests):
Expand Down Expand Up @@ -957,9 +979,10 @@ def test_parser_help(self, option_parser_exit):
parser.parse_args(["--help"])
output = out.getvalue().strip()
self.assertEqual(output[:16], "Usage: nosetests")
self.assertIn("[-u|--xmlrpc-url <url>] [-r|--restapi-url <url>] [-v|--verify-ssl] [-a|--auth_file <filename>] operation op_parameters",
output)
self.assertIn("[-u|--xmlrpc-url <url>] [-r|--restapi-url <url>] [-v|--verify-ssl] "
"[-a|--auth_file <filename>] operation op_parameters", output)
sys.stdout = oldstdout


if __name__ == '__main__':
unittest.main()

0 comments on commit 8c35afc

Please sign in to comment.